text
stringlengths
2
100k
meta
dict
/** ****************************************************************************** * @file usbd_msc_storage.h * @author MCD Application Team * @brief Header file for the usbd_msc_storage.c file ****************************************************************************** * @attention * * <h2><center>&copy; Copyright (c) 2015 STMicroelectronics. * All rights reserved.</center></h2> * * This software component is licensed by ST under Ultimate Liberty license * SLA0044, 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.st.com/SLA0044 * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __USBD_MSC_STORAGE_H #define __USBD_MSC_STORAGE_H #ifdef __cplusplus extern "C" { #endif /* Includes ------------------------------------------------------------------*/ #include "usbd_msc.h" /** @addtogroup STM32_USB_DEVICE_LIBRARY * @{ */ /** @defgroup USBD_STORAGE * @brief header file for the usbd_msc_storage.c file * @{ */ /** @defgroup USBD_STORAGE_Exported_Defines * @{ */ /** * @} */ /** @defgroup USBD_STORAGE_Exported_Types * @{ */ /** * @} */ /** @defgroup USBD_STORAGE_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_STORAGE_Exported_Variables * @{ */ extern USBD_StorageTypeDef USBD_MSC_Template_fops; /** * @} */ /** @defgroup USBD_STORAGE_Exported_FunctionsPrototype * @{ */ /** * @} */ #ifdef __cplusplus } #endif #endif /* __USBD_MSC_STORAGE_H */ /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
{ "language": "C" }
/*************************************************************************** * This file is part of the CuteReport project * * Copyright (C) 2012-2015 by Alexander Mikhalov * * alexander.mikhalov@gmail.com * * * ** GNU General Public License Usage ** * * * 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 of the License, or * * (at your option) any later version. * * You should have received a copy of the GNU General Public License * * along with this program. If not, see <http://www.gnu.org/licenses/>. * * * ** GNU Lesser General Public License ** * * * This library is free software: you can redistribute it and/or modify * * it under the terms of the GNU Lesser General Public License as * * published by the Free Software Foundation, either version 3 of the * * License, or (at your option) any later version. * * You should have received a copy of the GNU Lesser General Public * * License along with this library. * * If not, see <http://www.gnu.org/licenses/>. * * * * 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. * ***************************************************************************/ #ifndef RECTANGLE_P_H #define RECTANGLE_P_H #include "iteminterface_p.h" #include "iteminterface.h" #include "rectangle.h" class RectangleItemPrivate : public CuteReport::ItemInterfacePrivate { public: RectangleItemPrivate() :ItemInterfacePrivate() {} RectangleItemPrivate(const RectangleItemPrivate & p) :ItemInterfacePrivate(p) {} virtual ~RectangleItemPrivate(){} }; QDataStream &operator<<(QDataStream &s, const RectangleItemPrivate &p); QDataStream &operator>>(QDataStream &s, RectangleItemPrivate &p); #endif // RECTANGLE_P_H
{ "language": "C" }
// Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. namespace System.Globalization { /// <remarks> /// Calendar support range: /// Calendar Minimum Maximum /// ========== ========== ========== /// Gregorian 1960/01/28 2050/01/22 /// JapaneseLunisolar 1960/01/01 2049/12/29 /// </remarks> public class JapaneseLunisolarCalendar : EastAsianLunisolarCalendar { public const int JapaneseEra = 1; private readonly GregorianCalendarHelper _helper; private const int MinLunisolarYear = 1960; private const int MaxLunisolarYear = 2049; private static readonly DateTime s_minDate = new DateTime(1960, 1, 28); private static readonly DateTime s_maxDate = new DateTime((new DateTime(2050, 1, 22, 23, 59, 59, 999)).Ticks + 9999); public override DateTime MinSupportedDateTime => s_minDate; public override DateTime MaxSupportedDateTime => s_maxDate; protected override int DaysInYearBeforeMinSupportedYear => // 1959 from ChineseLunisolarCalendar 354; // Data for years 1960-2049 matches output of Calendrical Calculations [1] and published calendar tables [2]. // [1] Reingold, Edward M, and Nachum Dershowitz. Calendrical Calculations: The Ultimate Edition. Cambridge [etc.: Cambridge University Press, 2018. Print. // [2] Nishizawa, Yūsō. Rekijitsu Taikan: Meiji Kaireki 1873-Nen-2100-Nen Shinkyūreki, Kanshi Kyūsei Rokuyō Taishō. Tōkyō: Shin Jinbutsu Ōraisha, 1994. Print. private static readonly int[,] s_yinfo = { /*Y LM Lmon Lday DaysPerMonth D1 D2 D3 D4 D5 D6 D7 D8 D9 D10 D11 D12 D13 #Days 1960 */ { 06, 01, 28, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 29 384 1961 */ { 00, 02, 15, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 355 1962 */ { 00, 02, 05, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354 1963 */ { 04, 01, 25, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384 1964 */ { 00, 02, 13, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355 1965 */ { 00, 02, 02, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 354 1966 */ { 03, 01, 22, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 29 383 1967 */ { 00, 02, 09, 0b1101100101010000 }, /* 30 30 29 30 30 29 29 30 29 30 29 30 355 1968 */ { 07, 01, 30, 0b0110101010101000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 30 384 1969 */ { 00, 02, 17, 0b0101011010100000 }, /* 29 30 29 30 29 30 30 29 30 29 30 29 354 1970 */ { 00, 02, 06, 0b1001101011010000 }, /* 30 29 29 30 30 29 30 29 30 30 29 30 355 1971 */ { 05, 01, 27, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384 1972 */ { 00, 02, 15, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354 1973 */ { 00, 02, 03, 0b1010010011100000 }, /* 30 29 30 29 29 30 29 29 30 30 30 29 354 1974 */ { 04, 01, 23, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384 1975 */ { 00, 02, 11, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354 1976 */ { 08, 01, 31, 0b1101010101001000 }, /* 30 30 29 30 29 30 29 30 29 30 29 29 30 384 1977 */ { 00, 02, 18, 0b1011010101000000 }, /* 30 29 30 30 29 30 29 30 29 30 29 29 354 1978 */ { 00, 02, 07, 0b1101011010100000 }, /* 30 30 29 30 29 30 30 29 30 29 30 29 355 1979 */ { 06, 01, 28, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 29 384 1980 */ { 00, 02, 16, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355 1981 */ { 00, 02, 05, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354 1982 */ { 04, 01, 25, 0b1010010011011000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 30 384 1983 */ { 00, 02, 13, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354 1984 */ { 10, 02, 02, 0b1011001001011000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 30 384 1985 */ { 00, 02, 20, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 354 1986 */ { 00, 02, 09, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354 1987 */ { 06, 01, 29, 0b1011010110101000 }, /* 30 29 30 30 29 30 29 30 30 29 30 29 30 385 1988 */ { 00, 02, 18, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354 1989 */ { 00, 02, 06, 0b1001010110110000 }, /* 30 29 29 30 29 30 29 30 30 29 30 30 355 1990 */ { 05, 01, 27, 0b0100100110111000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 30 384 1991 */ { 00, 02, 15, 0b0100100101110000 }, /* 29 30 29 29 30 29 29 30 29 30 30 30 354 1992 */ { 00, 02, 04, 0b0110010010110000 }, /* 29 30 30 29 29 30 29 29 30 29 30 30 354 1993 */ { 03, 01, 23, 0b0110101001010000 }, /* 29 30 30 29 30 29 30 29 29 30 29 30 29 383 1994 */ { 00, 02, 10, 0b1110101001010000 }, /* 30 30 30 29 30 29 30 29 29 30 29 30 355 1995 */ { 08, 01, 31, 0b0110110101001000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 30 384 1996 */ { 00, 02, 19, 0b0101101011010000 }, /* 29 30 29 30 30 29 30 29 30 30 29 30 355 1997 */ { 00, 02, 08, 0b0010101101100000 }, /* 29 29 30 29 30 29 30 30 29 30 30 29 354 1998 */ { 05, 01, 28, 0b1001001101110000 }, /* 30 29 29 30 29 29 30 30 29 30 30 30 29 384 1999 */ { 00, 02, 16, 0b1001001011100000 }, /* 30 29 29 30 29 29 30 29 30 30 30 29 354 2000 */ { 00, 02, 05, 0b1100100101100000 }, /* 30 30 29 29 30 29 29 30 29 30 30 29 354 2001 */ { 04, 01, 24, 0b1110010010101000 }, /* 30 30 30 29 29 30 29 29 30 29 30 29 30 384 2002 */ { 00, 02, 12, 0b1101010010100000 }, /* 30 30 29 30 29 30 29 29 30 29 30 29 354 2003 */ { 00, 02, 01, 0b1101101001010000 }, /* 30 30 29 30 30 29 30 29 29 30 29 30 355 2004 */ { 02, 01, 22, 0b0101101010101000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 30 384 2005 */ { 00, 02, 09, 0b0101011011000000 }, /* 29 30 29 30 29 30 30 29 30 30 29 29 354 2006 */ { 07, 01, 29, 0b1010101011011000 }, /* 30 29 30 29 30 29 30 29 30 30 29 30 30 385 2007 */ { 00, 02, 18, 0b0010010111010000 }, /* 29 29 30 29 29 30 29 30 30 30 29 30 354 2008 */ { 00, 02, 07, 0b1001001011010000 }, /* 30 29 29 30 29 29 30 29 30 30 29 30 354 2009 */ { 05, 01, 26, 0b1100100101011000 }, /* 30 30 29 29 30 29 29 30 29 30 29 30 30 384 2010 */ { 00, 02, 14, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354 2011 */ { 00, 02, 03, 0b1011010010100000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 354 2012 */ { 03, 01, 23, 0b1011101001010000 }, /* 30 29 30 30 30 29 30 29 29 30 29 30 29 384 2013 */ { 00, 02, 10, 0b1011010101010000 }, /* 30 29 30 30 29 30 29 30 29 30 29 30 355 2014 */ { 09, 01, 31, 0b0101010110101000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384 2015 */ { 00, 02, 19, 0b0100101110100000 }, /* 29 30 29 29 30 29 30 30 30 29 30 29 354 2016 */ { 00, 02, 08, 0b1010010110110000 }, /* 30 29 30 29 29 30 29 30 30 29 30 30 355 2017 */ { 05, 01, 28, 0b0101001010111000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 30 384 2018 */ { 00, 02, 16, 0b0101001010110000 }, /* 29 30 29 30 29 29 30 29 30 29 30 30 354 2019 */ { 00, 02, 05, 0b1010100101010000 }, /* 30 29 30 29 30 29 29 30 29 30 29 30 354 2020 */ { 04, 01, 25, 0b1011010010101000 }, /* 30 29 30 30 29 30 29 29 30 29 30 29 30 384 2021 */ { 00, 02, 12, 0b0110101010100000 }, /* 29 30 30 29 30 29 30 29 30 29 30 29 354 2022 */ { 00, 02, 01, 0b1010110101010000 }, /* 30 29 30 29 30 30 29 30 29 30 29 30 355 2023 */ { 02, 01, 22, 0b0101010110101000 }, /* 29 30 29 30 29 30 29 30 30 29 30 29 30 384 2024 */ { 00, 02, 10, 0b0100101101100000 }, /* 29 30 29 29 30 29 30 30 29 30 30 29 354 2025 */ { 06, 01, 29, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 29 384 2026 */ { 00, 02, 17, 0b1010010101110000 }, /* 30 29 30 29 29 30 29 30 29 30 30 30 355 2027 */ { 00, 02, 07, 0b0101001001110000 }, /* 29 30 29 30 29 29 30 29 29 30 30 30 354 2028 */ { 05, 01, 27, 0b0110100100110000 }, /* 29 30 30 29 30 29 29 30 29 29 30 30 29 383 2029 */ { 00, 02, 13, 0b1101100100110000 }, /* 30 30 29 30 30 29 29 30 29 29 30 30 355 2030 */ { 00, 02, 03, 0b0101101010100000 }, /* 29 30 29 30 30 29 30 29 30 29 30 29 354 2031 */ { 03, 01, 23, 0b1010101101010000 }, /* 30 29 30 29 30 29 30 30 29 30 29 30 29 384 2032 */ { 00, 02, 11, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355 2033 */ { 11, 01, 31, 0b0100101011101000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 30 384 2034 */ { 00, 02, 19, 0b0100101011100000 }, /* 29 30 29 29 30 29 30 29 30 30 30 29 354 2035 */ { 00, 02, 08, 0b1010010011010000 }, /* 30 29 30 29 29 30 29 29 30 30 29 30 354 2036 */ { 06, 01, 28, 0b1101001001101000 }, /* 30 30 29 30 29 29 30 29 29 30 30 29 30 384 2037 */ { 00, 02, 15, 0b1101001001010000 }, /* 30 30 29 30 29 29 30 29 29 30 29 30 354 2038 */ { 00, 02, 04, 0b1101010100100000 }, /* 30 30 29 30 29 30 29 30 29 29 30 29 354 2039 */ { 05, 01, 24, 0b1101101010100000 }, /* 30 30 29 30 30 29 30 29 30 29 30 29 29 384 2040 */ { 00, 02, 12, 0b1011011010100000 }, /* 30 29 30 30 29 30 30 29 30 29 30 29 355 2041 */ { 00, 02, 01, 0b1001011011010000 }, /* 30 29 29 30 29 30 30 29 30 30 29 30 355 2042 */ { 02, 01, 22, 0b0100101011011000 }, /* 29 30 29 29 30 29 30 29 30 30 29 30 30 384 2043 */ { 00, 02, 10, 0b0100100110110000 }, /* 29 30 29 29 30 29 29 30 30 29 30 30 354 2044 */ { 07, 01, 30, 0b1010010010111000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 30 384 2045 */ { 00, 02, 17, 0b1010010010110000 }, /* 30 29 30 29 29 30 29 29 30 29 30 30 354 2046 */ { 00, 02, 06, 0b1011001001010000 }, /* 30 29 30 30 29 29 30 29 29 30 29 30 354 2047 */ { 05, 01, 26, 0b1011010100101000 }, /* 30 29 30 30 29 30 29 30 29 29 30 29 30 384 2048 */ { 00, 02, 14, 0b0110110101000000 }, /* 29 30 30 29 30 30 29 30 29 30 29 29 354 2049 */ { 00, 02, 02, 0b1010110110100000 }, /* 30 29 30 29 30 30 29 30 30 29 30 29 355 */ }; internal override int MinCalendarYear => MinLunisolarYear; internal override int MaxCalendarYear => MaxLunisolarYear; internal override DateTime MinDate => s_minDate; internal override DateTime MaxDate => s_maxDate; internal override EraInfo[]? CalEraInfo => JapaneseCalendar.GetEraInfo(); internal override int GetYearInfo(int lunarYear, int index) { if (lunarYear < MinLunisolarYear || lunarYear > MaxLunisolarYear) { throw new ArgumentOutOfRangeException( "year", lunarYear, SR.Format(SR.ArgumentOutOfRange_Range, MinLunisolarYear, MaxLunisolarYear)); } return s_yinfo[lunarYear - MinLunisolarYear, index]; } internal override int GetYear(int year, DateTime time) { return _helper.GetYear(year, time); } internal override int GetGregorianYear(int year, int era) { return _helper.GetGregorianYear(year, era); } /// <summary> /// Trim off the eras that are before our date range /// </summary> private static EraInfo[] TrimEras(EraInfo[] baseEras) { EraInfo[] newEras = new EraInfo[baseEras.Length]; int newIndex = 0; // Eras have most recent first, so start with that for (int i = 0; i < baseEras.Length; i++) { // If this one's minimum year is bigger than our maximum year // then we can't use it. if (baseEras[i].yearOffset + baseEras[i].minEraYear >= MaxLunisolarYear) { // skip this one. continue; } // If this one's maximum era is less than our minimum era // then we've gotten too low in the era #s, so we're done if (baseEras[i].yearOffset + baseEras[i].maxEraYear < MinLunisolarYear) { break; } // Wasn't too large or too small, can use this one newEras[newIndex] = baseEras[i]; newIndex++; } // If we didn't copy any then something was wrong, just return base if (newIndex == 0) return baseEras; Array.Resize(ref newEras!, newIndex); return newEras; } public JapaneseLunisolarCalendar() { _helper = new GregorianCalendarHelper(this, TrimEras(JapaneseCalendar.GetEraInfo())); } public override int GetEra(DateTime time) => _helper.GetEra(time); internal override CalendarId BaseCalendarID => CalendarId.JAPAN; internal override CalendarId ID => CalendarId.JAPANESELUNISOLAR; public override int[] Eras => _helper.Eras; } }
{ "language": "C" }
//================================================================================== // Copyright (c) 2016 , Advanced Micro Devices, Inc. All rights reserved. // /// \author AMD Developer Tools Team /// \file suMemoryAllocationMonitor.h /// //================================================================================== //------------------------------ suMemoryAllocationMonitor.h ------------------------------ #ifndef __SUMEMORYALLOCATIONMONITOR_H #define __SUMEMORYALLOCATIONMONITOR_H // Local: #include <AMDTServerUtilities/Include/suSpiesUtilitiesDLLBuild.h> // ---------------------------------------------------------------------------------- // Class Name: SU_API suMemoryAllocationMonitor // General Description: A class used to Monitor memory allocation // Author: Gilad Yarnitzky // Creation Date: 6/1/2015 // ---------------------------------------------------------------------------------- class SU_API suMemoryAllocationMonitor { private: friend class suSingletonsDelete; public: static suMemoryAllocationMonitor& instance(); ~suMemoryAllocationMonitor(); static void HandlerMemoryAllocationFailure(); private: // The constructor should only be called by the instance() function: suMemoryAllocationMonitor(); private: // My single instance: static suMemoryAllocationMonitor* m_spMySingleInstance; }; #endif //__SUMEMORYALLOCATIONMONITOR_H
{ "language": "C" }
#ifndef GSPCAV2_H #define GSPCAV2_H #include <linux/module.h> #include <linux/kernel.h> #include <linux/usb.h> #include <linux/videodev2.h> #include <media/v4l2-common.h> #include <media/v4l2-ctrls.h> #include <media/v4l2-device.h> #include <linux/mutex.h> /* GSPCA debug codes */ #define D_PROBE 1 #define D_CONF 2 #define D_STREAM 3 #define D_FRAM 4 #define D_PACK 5 #define D_USBI 6 #define D_USBO 7 extern int gspca_debug; #define PDEBUG(level, fmt, ...) \ v4l2_dbg(level, gspca_debug, &gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__) #define PERR(fmt, ...) \ v4l2_err(&gspca_dev->v4l2_dev, fmt, ##__VA_ARGS__) #define GSPCA_MAX_FRAMES 16 /* maximum number of video frame buffers */ /* image transfers */ #define MAX_NURBS 4 /* max number of URBs */ /* used to list framerates supported by a camera mode (resolution) */ struct framerates { const u8 *rates; int nrates; }; /* device information - set at probe time */ struct cam { const struct v4l2_pix_format *cam_mode; /* size nmodes */ const struct framerates *mode_framerates; /* must have size nmodes, * just like cam_mode */ u32 bulk_size; /* buffer size when image transfer by bulk */ u32 input_flags; /* value for ENUM_INPUT status flags */ u8 nmodes; /* size of cam_mode */ u8 no_urb_create; /* don't create transfer URBs */ u8 bulk_nurbs; /* number of URBs in bulk mode * - cannot be > MAX_NURBS * - when 0 and bulk_size != 0 means * 1 URB and submit done by subdriver */ u8 bulk; /* image transfer by 0:isoc / 1:bulk */ u8 npkt; /* number of packets in an ISOC message * 0 is the default value: 32 packets */ u8 needs_full_bandwidth;/* Set this flag to notify the bandwidth calc. * code that the cam fills all image buffers to * the max, even when using compression. */ }; struct gspca_dev; struct gspca_frame; /* subdriver operations */ typedef int (*cam_op) (struct gspca_dev *); typedef void (*cam_v_op) (struct gspca_dev *); typedef int (*cam_cf_op) (struct gspca_dev *, const struct usb_device_id *); typedef int (*cam_get_jpg_op) (struct gspca_dev *, struct v4l2_jpegcompression *); typedef int (*cam_set_jpg_op) (struct gspca_dev *, const struct v4l2_jpegcompression *); typedef int (*cam_get_reg_op) (struct gspca_dev *, struct v4l2_dbg_register *); typedef int (*cam_set_reg_op) (struct gspca_dev *, const struct v4l2_dbg_register *); typedef int (*cam_chip_info_op) (struct gspca_dev *, struct v4l2_dbg_chip_info *); typedef void (*cam_streamparm_op) (struct gspca_dev *, struct v4l2_streamparm *); typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev, u8 *data, int len); typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev, u8 *data, int len); typedef void (*cam_format_op) (struct gspca_dev *gspca_dev, struct v4l2_format *fmt); typedef int (*cam_frmsize_op) (struct gspca_dev *gspca_dev, struct v4l2_frmsizeenum *fsize); /* subdriver description */ struct sd_desc { /* information */ const char *name; /* sub-driver name */ /* mandatory operations */ cam_cf_op config; /* called on probe */ cam_op init; /* called on probe and resume */ cam_op init_controls; /* called on probe */ cam_op start; /* called on stream on after URBs creation */ cam_pkt_op pkt_scan; /* optional operations */ cam_op isoc_init; /* called on stream on before getting the EP */ cam_op isoc_nego; /* called when URB submit failed with NOSPC */ cam_v_op stopN; /* called on stream off - main alt */ cam_v_op stop0; /* called on stream off & disconnect - alt 0 */ cam_v_op dq_callback; /* called when a frame has been dequeued */ cam_get_jpg_op get_jcomp; cam_set_jpg_op set_jcomp; cam_streamparm_op get_streamparm; cam_streamparm_op set_streamparm; cam_format_op try_fmt; cam_frmsize_op enum_framesizes; #ifdef CONFIG_VIDEO_ADV_DEBUG cam_set_reg_op set_register; cam_get_reg_op get_register; cam_chip_info_op get_chip_info; #endif #if IS_ENABLED(CONFIG_INPUT) cam_int_pkt_op int_pkt_scan; /* other_input makes the gspca core create gspca_dev->input even when int_pkt_scan is NULL, for cams with non interrupt driven buttons */ u8 other_input; #endif }; /* packet types when moving from iso buf to frame buf */ enum gspca_packet_type { DISCARD_PACKET, FIRST_PACKET, INTER_PACKET, LAST_PACKET }; struct gspca_frame { __u8 *data; /* frame buffer */ int vma_use_count; struct v4l2_buffer v4l2_buf; }; struct gspca_dev { struct video_device vdev; /* !! must be the first item */ struct module *module; /* subdriver handling the device */ struct v4l2_device v4l2_dev; struct usb_device *dev; struct file *capt_file; /* file doing video capture */ /* protected by queue_lock */ #if IS_ENABLED(CONFIG_INPUT) struct input_dev *input_dev; char phys[64]; /* physical device path */ #endif struct cam cam; /* device information */ const struct sd_desc *sd_desc; /* subdriver description */ struct v4l2_ctrl_handler ctrl_handler; /* autogain and exposure or gain control cluster, these are global as the autogain/exposure functions in autogain_functions.c use them */ struct { struct v4l2_ctrl *autogain; struct v4l2_ctrl *exposure; struct v4l2_ctrl *gain; int exp_too_low_cnt, exp_too_high_cnt; }; #define USB_BUF_SZ 64 __u8 *usb_buf; /* buffer for USB exchanges */ struct urb *urb[MAX_NURBS]; #if IS_ENABLED(CONFIG_INPUT) struct urb *int_urb; #endif __u8 *frbuf; /* buffer for nframes */ struct gspca_frame frame[GSPCA_MAX_FRAMES]; u8 *image; /* image beeing filled */ __u32 frsz; /* frame size */ u32 image_len; /* current length of image */ atomic_t fr_q; /* next frame to queue */ atomic_t fr_i; /* frame being filled */ signed char fr_queue[GSPCA_MAX_FRAMES]; /* frame queue */ char nframes; /* number of frames */ u8 fr_o; /* next frame to dequeue */ __u8 last_packet_type; __s8 empty_packet; /* if (-1) don't check empty packets */ __u8 streaming; /* protected by both mutexes (*) */ __u8 curr_mode; /* current camera mode */ struct v4l2_pix_format pixfmt; /* current mode parameters */ __u32 sequence; /* frame sequence number */ wait_queue_head_t wq; /* wait queue */ struct mutex usb_lock; /* usb exchange protection */ struct mutex queue_lock; /* ISOC queue protection */ int usb_err; /* USB error - protected by usb_lock */ u16 pkt_size; /* ISOC packet size */ #ifdef CONFIG_PM char frozen; /* suspend - resume */ #endif char present; /* device connected */ char nbufread; /* number of buffers for read() */ char memory; /* memory type (V4L2_MEMORY_xxx) */ __u8 iface; /* USB interface number */ __u8 alt; /* USB alternate setting */ int xfer_ep; /* USB transfer endpoint address */ u8 audio; /* presence of audio device */ /* (*) These variables are proteced by both usb_lock and queue_lock, that is any code setting them is holding *both*, which means that any code getting them needs to hold at least one of them */ }; int gspca_dev_probe(struct usb_interface *intf, const struct usb_device_id *id, const struct sd_desc *sd_desc, int dev_size, struct module *module); int gspca_dev_probe2(struct usb_interface *intf, const struct usb_device_id *id, const struct sd_desc *sd_desc, int dev_size, struct module *module); void gspca_disconnect(struct usb_interface *intf); void gspca_frame_add(struct gspca_dev *gspca_dev, enum gspca_packet_type packet_type, const u8 *data, int len); #ifdef CONFIG_PM int gspca_suspend(struct usb_interface *intf, pm_message_t message); int gspca_resume(struct usb_interface *intf); #endif int gspca_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum, int desired_avg_lum, int deadzone, int gain_knee, int exposure_knee); int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev, int avg_lum, int desired_avg_lum, int deadzone); #endif /* GSPCAV2_H */
{ "language": "C" }
/******************************************************************** * * * THIS FILE IS PART OF THE OggVorbis SOFTWARE CODEC SOURCE CODE. * * USE, DISTRIBUTION AND REPRODUCTION OF THIS LIBRARY SOURCE IS * * GOVERNED BY A BSD-STYLE SOURCE LICENSE INCLUDED WITH THIS SOURCE * * IN 'COPYING'. PLEASE READ THESE TERMS BEFORE DISTRIBUTING. * * * * THE OggVorbis SOURCE CODE IS (C) COPYRIGHT 1994-2009 * * by the Xiph.Org Foundation https://xiph.org/ * * * ******************************************************************** function: masking curve data for psychoacoustics ********************************************************************/ #ifndef _V_MASKING_H_ #define _V_MASKING_H_ /* more detailed ATH; the bass if flat to save stressing the floor overly for only a bin or two of savings. */ #define MAX_ATH 88 static const float ATH[]={ /*15*/ -51, -52, -53, -54, -55, -56, -57, -58, /*31*/ -59, -60, -61, -62, -63, -64, -65, -66, /*63*/ -67, -68, -69, -70, -71, -72, -73, -74, /*125*/ -75, -76, -77, -78, -80, -81, -82, -83, /*250*/ -84, -85, -86, -87, -88, -88, -89, -89, /*500*/ -90, -91, -91, -92, -93, -94, -95, -96, /*1k*/ -96, -97, -98, -98, -99, -99,-100,-100, /*2k*/ -101,-102,-103,-104,-106,-107,-107,-107, /*4k*/ -107,-105,-103,-102,-101, -99, -98, -96, /*8k*/ -95, -95, -96, -97, -96, -95, -93, -90, /*16k*/ -80, -70, -50, -40, -30, -30, -30, -30 }; /* The tone masking curves from Ehmer's and Fielder's papers have been replaced by an empirically collected data set. The previously published values were, far too often, simply on crack. */ #define EHMER_OFFSET 16 #define EHMER_MAX 56 /* masking tones from -50 to 0dB, 62.5 through 16kHz at half octaves test tones from -2 octaves to +5 octaves sampled at eighth octaves */ /* (Vorbis 0dB, the loudest possible tone, is assumed to be ~100dB SPL for collection of these curves) */ static const float tonemasks[P_BANDS][6][EHMER_MAX]={ /* 62.5 Hz */ {{ -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -60, -62, -62, -65, -73, -69, -68, -68, -67, -70, -70, -72, -74, -75, -79, -79, -80, -83, -88, -93, -100, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -48, -53, -61, -66, -66, -68, -67, -70, -76, -76, -72, -73, -75, -76, -78, -79, -83, -88, -93, -100, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -37, -37, -37, -37, -37, -37, -37, -37, -38, -40, -42, -46, -48, -53, -55, -62, -65, -58, -56, -56, -61, -60, -65, -67, -69, -71, -77, -77, -78, -80, -82, -84, -88, -93, -98, -106, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -25, -25, -25, -25, -25, -25, -25, -25, -25, -26, -27, -29, -32, -38, -48, -52, -52, -50, -48, -48, -51, -52, -54, -60, -67, -67, -66, -68, -69, -73, -73, -76, -80, -81, -81, -85, -85, -86, -88, -93, -100, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -16, -16, -16, -16, -16, -16, -16, -16, -17, -19, -20, -22, -26, -28, -31, -40, -47, -39, -39, -40, -42, -43, -47, -51, -57, -52, -55, -55, -60, -58, -62, -63, -70, -67, -69, -72, -73, -77, -80, -82, -83, -87, -90, -94, -98, -104, -115, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -8, -8, -8, -8, -8, -8, -8, -8, -8, -8, -10, -11, -15, -19, -25, -30, -34, -31, -30, -31, -29, -32, -35, -42, -48, -42, -44, -46, -50, -50, -51, -52, -59, -54, -55, -55, -58, -62, -63, -66, -72, -73, -76, -75, -78, -80, -80, -81, -84, -88, -90, -94, -98, -101, -106, -110}}, /* 88Hz */ {{ -66, -66, -66, -66, -66, -66, -66, -66, -66, -66, -66, -66, -66, -67, -67, -67, -76, -72, -71, -74, -76, -76, -75, -78, -79, -79, -81, -83, -86, -89, -93, -97, -100, -105, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -47, -47, -47, -47, -47, -47, -47, -47, -47, -47, -47, -48, -51, -55, -59, -66, -66, -66, -67, -66, -68, -69, -70, -74, -79, -77, -77, -78, -80, -81, -82, -84, -86, -88, -91, -95, -100, -108, -116, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -36, -36, -36, -36, -36, -36, -36, -36, -36, -37, -37, -41, -44, -48, -51, -58, -62, -60, -57, -59, -59, -60, -63, -65, -72, -71, -70, -72, -74, -77, -76, -78, -81, -81, -80, -83, -86, -91, -96, -100, -105, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -28, -28, -28, -28, -28, -28, -28, -28, -28, -30, -32, -32, -33, -35, -41, -49, -50, -49, -47, -48, -48, -52, -51, -57, -65, -61, -59, -61, -64, -69, -70, -74, -77, -77, -78, -81, -84, -85, -87, -90, -92, -96, -100, -107, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -19, -19, -19, -19, -19, -19, -19, -19, -20, -21, -23, -27, -30, -35, -36, -41, -46, -44, -42, -40, -41, -41, -43, -48, -55, -53, -52, -53, -56, -59, -58, -60, -67, -66, -69, -71, -72, -75, -79, -81, -84, -87, -90, -93, -97, -101, -107, -114, -999, -999, -999, -999, -999, -999, -999, -999}, { -9, -9, -9, -9, -9, -9, -9, -9, -11, -12, -12, -15, -16, -20, -23, -30, -37, -34, -33, -34, -31, -32, -32, -38, -47, -44, -41, -40, -47, -49, -46, -46, -58, -50, -50, -54, -58, -62, -64, -67, -67, -70, -72, -76, -79, -83, -87, -91, -96, -100, -104, -110, -999, -999, -999, -999}}, /* 125 Hz */ {{ -62, -62, -62, -62, -62, -62, -62, -62, -62, -62, -63, -64, -66, -67, -66, -68, -75, -72, -76, -75, -76, -78, -79, -82, -84, -85, -90, -94, -101, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -59, -59, -59, -59, -59, -59, -59, -59, -59, -59, -59, -60, -60, -61, -63, -66, -71, -68, -70, -70, -71, -72, -72, -75, -81, -78, -79, -82, -83, -86, -90, -97, -103, -113, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -53, -53, -53, -53, -53, -53, -53, -53, -53, -54, -55, -57, -56, -57, -55, -61, -65, -60, -60, -62, -63, -63, -66, -68, -74, -73, -75, -75, -78, -80, -80, -82, -85, -90, -96, -101, -108, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -46, -46, -46, -46, -46, -46, -46, -46, -46, -46, -47, -47, -47, -47, -48, -51, -57, -51, -49, -50, -51, -53, -54, -59, -66, -60, -62, -67, -67, -70, -72, -75, -76, -78, -81, -85, -88, -94, -97, -104, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -36, -36, -36, -36, -36, -36, -36, -36, -39, -41, -42, -42, -39, -38, -41, -43, -52, -44, -40, -39, -37, -37, -40, -47, -54, -50, -48, -50, -55, -61, -59, -62, -66, -66, -66, -69, -69, -73, -74, -74, -75, -77, -79, -82, -87, -91, -95, -100, -108, -115, -999, -999, -999, -999, -999, -999}, { -28, -26, -24, -22, -20, -20, -23, -29, -30, -31, -28, -27, -28, -28, -28, -35, -40, -33, -32, -29, -30, -30, -30, -37, -45, -41, -37, -38, -45, -47, -47, -48, -53, -49, -48, -50, -49, -49, -51, -52, -58, -56, -57, -56, -60, -61, -62, -70, -72, -74, -78, -83, -88, -93, -100, -106}}, /* 177 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -105, -100, -95, -91, -87, -83, -80, -78, -76, -78, -78, -81, -83, -85, -86, -85, -86, -87, -90, -97, -107, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -110, -105, -100, -95, -90, -85, -81, -77, -73, -70, -67, -67, -68, -75, -73, -70, -69, -70, -72, -75, -79, -84, -83, -84, -86, -88, -89, -89, -93, -98, -105, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-105, -100, -95, -90, -85, -80, -76, -71, -68, -68, -65, -63, -63, -62, -62, -64, -65, -64, -61, -62, -63, -64, -66, -68, -73, -73, -74, -75, -76, -81, -83, -85, -88, -89, -92, -95, -100, -108, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -80, -75, -71, -68, -65, -63, -62, -61, -61, -61, -61, -59, -56, -57, -53, -50, -58, -52, -50, -50, -52, -53, -54, -58, -67, -63, -67, -68, -72, -75, -78, -80, -81, -81, -82, -85, -89, -90, -93, -97, -101, -107, -114, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, { -65, -61, -59, -57, -56, -55, -55, -56, -56, -57, -55, -53, -52, -47, -44, -44, -50, -44, -41, -39, -39, -42, -40, -46, -51, -49, -50, -53, -54, -63, -60, -61, -62, -66, -66, -66, -70, -73, -74, -75, -76, -75, -79, -85, -89, -91, -96, -102, -110, -999, -999, -999, -999, -999, -999, -999}, { -52, -50, -49, -49, -48, -48, -48, -49, -50, -50, -49, -46, -43, -39, -35, -33, -38, -36, -32, -29, -32, -32, -32, -35, -44, -39, -38, -38, -46, -50, -45, -46, -53, -50, -50, -50, -54, -54, -53, -53, -56, -57, -59, -66, -70, -72, -74, -79, -83, -85, -90, -97, -114, -999, -999, -999}}, /* 250 Hz */ {{-999, -999, -999, -999, -999, -999, -110, -105, -100, -95, -90, -86, -80, -75, -75, -79, -80, -79, -80, -81, -82, -88, -95, -103, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -108, -103, -98, -93, -88, -83, -79, -78, -75, -71, -67, -68, -73, -73, -72, -73, -75, -77, -80, -82, -88, -93, -100, -107, -114, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -110, -105, -101, -96, -90, -86, -81, -77, -73, -69, -66, -61, -62, -66, -64, -62, -65, -66, -70, -72, -76, -81, -80, -84, -90, -95, -102, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -107, -103, -97, -92, -88, -83, -79, -74, -70, -66, -59, -53, -58, -62, -55, -54, -54, -54, -58, -61, -62, -72, -70, -72, -75, -78, -80, -81, -80, -83, -83, -88, -93, -100, -107, -115, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -105, -100, -95, -90, -85, -80, -75, -70, -66, -62, -56, -48, -44, -48, -46, -46, -43, -46, -48, -48, -51, -58, -58, -59, -60, -62, -62, -61, -61, -65, -64, -65, -68, -70, -74, -75, -78, -81, -86, -95, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -105, -100, -95, -90, -85, -80, -75, -70, -65, -61, -55, -49, -39, -33, -40, -35, -32, -38, -40, -33, -35, -37, -46, -41, -45, -44, -46, -42, -45, -46, -52, -50, -50, -50, -54, -54, -55, -57, -62, -64, -66, -68, -70, -76, -81, -90, -100, -110, -999, -999, -999, -999, -999, -999}}, /* 354 hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -105, -98, -90, -85, -82, -83, -80, -78, -84, -79, -80, -83, -87, -89, -91, -93, -99, -106, -117, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -105, -98, -90, -85, -80, -75, -70, -68, -74, -72, -74, -77, -80, -82, -85, -87, -92, -89, -91, -95, -100, -106, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -105, -98, -90, -83, -75, -71, -63, -64, -67, -62, -64, -67, -70, -73, -77, -81, -84, -83, -85, -89, -90, -93, -98, -104, -109, -114, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -103, -96, -88, -81, -75, -68, -58, -54, -56, -54, -56, -56, -58, -60, -63, -66, -74, -69, -72, -72, -75, -74, -77, -81, -81, -82, -84, -87, -93, -96, -99, -104, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -108, -102, -96, -91, -85, -80, -74, -68, -60, -51, -46, -48, -46, -43, -45, -47, -47, -49, -48, -56, -53, -55, -58, -57, -63, -58, -60, -66, -64, -67, -70, -70, -74, -77, -84, -86, -89, -91, -93, -94, -101, -109, -118, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -108, -103, -98, -93, -88, -83, -78, -73, -68, -60, -53, -44, -35, -38, -38, -34, -34, -36, -40, -41, -44, -51, -45, -46, -47, -46, -54, -50, -49, -50, -50, -50, -51, -54, -57, -58, -60, -66, -66, -66, -64, -65, -68, -77, -82, -87, -95, -110, -999, -999, -999, -999, -999}}, /* 500 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -107, -102, -97, -92, -87, -83, -78, -75, -82, -79, -83, -85, -89, -92, -95, -98, -101, -105, -109, -113, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -106, -100, -95, -90, -86, -81, -78, -74, -69, -74, -74, -76, -79, -83, -84, -86, -89, -92, -97, -93, -100, -103, -107, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -106, -100, -95, -90, -87, -83, -80, -75, -69, -60, -66, -66, -68, -70, -74, -78, -79, -81, -81, -83, -84, -87, -93, -96, -99, -103, -107, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -108, -103, -98, -93, -89, -85, -82, -78, -71, -62, -55, -58, -58, -54, -54, -55, -59, -61, -62, -70, -66, -66, -67, -70, -72, -75, -78, -84, -84, -84, -88, -91, -90, -95, -98, -102, -103, -106, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -108, -103, -98, -94, -90, -87, -82, -79, -73, -67, -58, -47, -50, -45, -41, -45, -48, -44, -44, -49, -54, -51, -48, -47, -49, -50, -51, -57, -58, -60, -63, -69, -70, -69, -71, -74, -78, -82, -90, -95, -101, -105, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -105, -101, -97, -93, -90, -85, -80, -77, -72, -65, -56, -48, -37, -40, -36, -34, -40, -50, -47, -38, -41, -47, -38, -35, -39, -38, -43, -40, -45, -50, -45, -44, -47, -50, -55, -48, -48, -52, -66, -70, -76, -82, -90, -97, -105, -110, -999, -999, -999, -999, -999, -999, -999}}, /* 707 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -108, -103, -98, -93, -86, -79, -76, -83, -81, -85, -87, -89, -93, -98, -102, -107, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -108, -103, -98, -93, -86, -79, -71, -77, -74, -77, -79, -81, -84, -85, -90, -92, -93, -92, -98, -101, -108, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -108, -103, -98, -93, -87, -78, -68, -65, -66, -62, -65, -67, -70, -73, -75, -78, -82, -82, -83, -84, -91, -93, -98, -102, -106, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -105, -100, -95, -90, -82, -74, -62, -57, -58, -56, -51, -52, -52, -54, -54, -58, -66, -59, -60, -63, -66, -69, -73, -79, -83, -84, -80, -81, -81, -82, -88, -92, -98, -105, -113, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -107, -102, -97, -92, -84, -79, -69, -57, -47, -52, -47, -44, -45, -50, -52, -42, -42, -53, -43, -43, -48, -51, -56, -55, -52, -57, -59, -61, -62, -67, -71, -78, -83, -86, -94, -98, -103, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -105, -100, -95, -90, -84, -78, -70, -61, -51, -41, -40, -38, -40, -46, -52, -51, -41, -40, -46, -40, -38, -38, -41, -46, -41, -46, -47, -43, -43, -45, -41, -45, -56, -67, -68, -83, -87, -90, -95, -102, -107, -113, -999, -999, -999, -999, -999, -999, -999, -999}}, /* 1000 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -109, -105, -101, -96, -91, -84, -77, -82, -82, -85, -89, -94, -100, -106, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -106, -103, -98, -92, -85, -80, -71, -75, -72, -76, -80, -84, -86, -89, -93, -100, -107, -113, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -107, -104, -101, -97, -92, -88, -84, -80, -64, -66, -63, -64, -66, -69, -73, -77, -83, -83, -86, -91, -98, -104, -111, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -107, -104, -101, -97, -92, -90, -84, -74, -57, -58, -52, -55, -54, -50, -52, -50, -52, -63, -62, -69, -76, -77, -78, -78, -79, -82, -88, -94, -100, -106, -111, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -106, -102, -98, -95, -90, -85, -83, -78, -70, -50, -50, -41, -44, -49, -47, -50, -50, -44, -55, -46, -47, -48, -48, -54, -49, -49, -58, -62, -71, -81, -87, -92, -97, -102, -108, -114, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -106, -102, -98, -95, -90, -85, -83, -78, -70, -45, -43, -41, -47, -50, -51, -50, -49, -45, -47, -41, -44, -41, -39, -43, -38, -37, -40, -41, -44, -50, -58, -65, -73, -79, -85, -92, -97, -101, -105, -109, -113, -999, -999, -999, -999, -999, -999, -999, -999, -999}}, /* 1414 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -107, -100, -95, -87, -81, -85, -83, -88, -93, -100, -107, -114, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -107, -101, -95, -88, -83, -76, -73, -72, -79, -84, -90, -95, -100, -105, -110, -115, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -104, -98, -92, -87, -81, -70, -65, -62, -67, -71, -74, -80, -85, -91, -95, -99, -103, -108, -111, -114, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -103, -97, -90, -85, -76, -60, -56, -54, -60, -62, -61, -56, -63, -65, -73, -74, -77, -75, -78, -81, -86, -87, -88, -91, -94, -98, -103, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -105, -100, -97, -92, -86, -81, -79, -70, -57, -51, -47, -51, -58, -60, -56, -53, -50, -58, -52, -50, -50, -53, -55, -64, -69, -71, -85, -82, -78, -81, -85, -95, -102, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -105, -100, -97, -92, -85, -83, -79, -72, -49, -40, -43, -43, -54, -56, -51, -50, -40, -43, -38, -36, -35, -37, -38, -37, -44, -54, -60, -57, -60, -70, -75, -84, -92, -103, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}}, /* 2000 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -102, -95, -89, -82, -83, -84, -90, -92, -99, -107, -113, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -107, -101, -95, -89, -83, -72, -74, -78, -85, -88, -88, -90, -92, -98, -105, -111, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -109, -103, -97, -93, -87, -81, -70, -70, -67, -75, -73, -76, -79, -81, -83, -88, -89, -97, -103, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -107, -100, -94, -88, -83, -75, -63, -59, -59, -63, -66, -60, -62, -67, -67, -77, -76, -81, -88, -86, -92, -96, -102, -109, -116, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -105, -98, -92, -86, -81, -73, -56, -52, -47, -55, -60, -58, -52, -51, -45, -49, -50, -53, -54, -61, -71, -70, -69, -78, -79, -87, -90, -96, -104, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -103, -96, -90, -86, -78, -70, -51, -42, -47, -48, -55, -54, -54, -53, -42, -35, -28, -33, -38, -37, -44, -47, -49, -54, -63, -68, -78, -82, -89, -94, -99, -104, -109, -114, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}}, /* 2828 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -100, -90, -79, -85, -81, -82, -82, -89, -94, -99, -103, -109, -115, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -105, -97, -85, -72, -74, -70, -70, -70, -76, -85, -91, -93, -97, -103, -109, -115, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -112, -93, -81, -68, -62, -60, -60, -57, -63, -70, -77, -82, -90, -93, -98, -104, -109, -113, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -113, -100, -93, -84, -63, -58, -48, -53, -54, -52, -52, -57, -64, -66, -76, -83, -81, -85, -85, -90, -95, -98, -101, -103, -106, -108, -111, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -105, -95, -86, -74, -53, -50, -38, -43, -49, -43, -42, -39, -39, -46, -52, -57, -56, -72, -69, -74, -81, -87, -92, -94, -97, -99, -102, -105, -108, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -108, -99, -90, -76, -66, -45, -43, -41, -44, -47, -43, -47, -40, -30, -31, -31, -39, -33, -40, -41, -43, -53, -59, -70, -73, -77, -79, -82, -84, -87, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}}, /* 4000 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -91, -76, -75, -85, -93, -98, -104, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -91, -70, -70, -75, -86, -89, -94, -98, -101, -106, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -95, -80, -60, -65, -64, -74, -83, -88, -91, -95, -99, -103, -107, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -95, -80, -58, -55, -49, -66, -68, -71, -78, -78, -80, -88, -85, -89, -97, -100, -105, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -95, -80, -53, -52, -41, -59, -59, -49, -58, -56, -63, -86, -79, -90, -93, -98, -103, -107, -112, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -97, -91, -73, -45, -40, -33, -53, -61, -49, -54, -50, -50, -60, -52, -67, -74, -81, -92, -96, -100, -105, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}}, /* 5657 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -113, -106, -99, -92, -77, -80, -88, -97, -106, -115, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -116, -109, -102, -95, -89, -74, -72, -88, -87, -95, -102, -109, -116, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -116, -109, -102, -95, -89, -75, -66, -74, -77, -78, -86, -87, -90, -96, -105, -115, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -115, -108, -101, -94, -88, -66, -56, -61, -70, -65, -78, -72, -83, -84, -93, -98, -105, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -105, -95, -89, -82, -57, -52, -52, -59, -56, -59, -58, -69, -67, -88, -82, -82, -89, -94, -100, -108, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -101, -96, -90, -83, -77, -54, -43, -38, -50, -48, -52, -48, -42, -42, -51, -52, -53, -59, -65, -71, -78, -85, -95, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}}, /* 8000 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -120, -105, -86, -68, -78, -79, -90, -100, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -120, -105, -86, -66, -73, -77, -88, -96, -105, -115, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -120, -105, -92, -80, -61, -64, -68, -80, -87, -92, -100, -110, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -120, -104, -91, -79, -52, -60, -54, -64, -69, -77, -80, -82, -84, -85, -87, -88, -90, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -118, -100, -87, -77, -49, -50, -44, -58, -61, -61, -67, -65, -62, -62, -62, -65, -68, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -115, -98, -84, -62, -49, -44, -38, -46, -49, -49, -46, -39, -37, -39, -40, -42, -43, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}}, /* 11314 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -88, -74, -77, -82, -82, -85, -90, -94, -99, -104, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -88, -66, -70, -81, -80, -81, -84, -88, -91, -93, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -88, -61, -63, -70, -71, -74, -77, -80, -83, -85, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -86, -62, -63, -62, -62, -58, -52, -50, -50, -52, -54, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -118, -108, -84, -53, -50, -50, -50, -55, -47, -45, -40, -40, -40, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -118, -100, -73, -43, -37, -42, -43, -53, -38, -37, -35, -35, -38, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}}, /* 16000 Hz */ {{-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -100, -91, -84, -74, -80, -80, -80, -80, -80, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -100, -91, -84, -74, -68, -68, -68, -68, -68, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -100, -86, -78, -70, -60, -45, -30, -21, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -100, -87, -78, -67, -48, -38, -29, -21, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -100, -86, -69, -56, -45, -35, -33, -29, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}, {-999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -110, -100, -83, -71, -48, -27, -38, -37, -34, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999, -999}} }; #endif
{ "language": "C" }
/* ********************************************************************** * Copyright (C) 1998-2012, International Business Machines Corporation * and others. All Rights Reserved. ********************************************************************** * * File date.c * * Modification History: * * Date Name Description * 06/16/99 stephen Creation. ******************************************************************************* */ #include <stdio.h> #include <string.h> #include <stdlib.h> #include "unicode/uloc.h" #include "unicode/udat.h" #include "unicode/ucal.h" #include "unicode/ustring.h" #include "unicode/uclean.h" #include "uprint.h" #if UCONFIG_NO_FORMATTING int main(int argc, char **argv) { printf("%s: Sorry, UCONFIG_NO_FORMATTING was turned on (see uconfig.h). No formatting can be done. \n", argv[0]); return 0; } #else /* Protos */ static void usage(void); static void version(void); static void cal(int32_t month, int32_t year, UBool useLongNames, UErrorCode *status); static void get_symbols(const UDateFormat *fmt, UDateFormatSymbolType type, UChar *array[], int32_t arrayLength, int32_t lowestIndex, int32_t firstIndex, UErrorCode *status); static void free_symbols(UChar *array[], int32_t arrayLength); static void get_days(const UDateFormat *fmt, UChar *days [], UBool useLongNames, int32_t fdow, UErrorCode *status); static void free_days(UChar *days[]); static void get_months(const UDateFormat *fmt, UChar *months [], UBool useLongNames, UErrorCode *status); static void free_months(UChar *months[]); static void indent(int32_t count, FILE *f); static void print_days(UChar *days [], FILE *f, UErrorCode *status); static void print_month(UCalendar *c, UChar *days [], UBool useLongNames, int32_t fdow, UErrorCode *status); static void print_year(UCalendar *c, UChar *days [], UChar *months [], UBool useLongNames, int32_t fdow, UErrorCode *status); /* The version of cal */ #define CAL_VERSION "1.0" /* Number of days in a week */ #define DAY_COUNT 7 /* Number of months in a year (yes, 13) */ #define MONTH_COUNT 13 /* Separation between months in year view */ #define MARGIN_WIDTH 4 /* Size of stack buffers */ #define BUF_SIZE 64 /* Patterm string - "MMM yyyy" */ static const UChar sShortPat [] = { 0x004D, 0x004D, 0x004D, 0x0020, 0x0079, 0x0079, 0x0079, 0x0079 }; /* Pattern string - "MMMM yyyy" */ static const UChar sLongPat [] = { 0x004D, 0x004D, 0x004D, 0x004D, 0x0020, 0x0079, 0x0079, 0x0079, 0x0079 }; int main(int argc, char **argv) { int printUsage = 0; int printVersion = 0; UBool useLongNames = 0; int optInd = 1; char *arg; int32_t month = -1, year = -1; UErrorCode status = U_ZERO_ERROR; /* parse the options */ for(optInd = 1; optInd < argc; ++optInd) { arg = argv[optInd]; /* version info */ if(strcmp(arg, "-v") == 0 || strcmp(arg, "--version") == 0) { printVersion = 1; } /* usage info */ else if(strcmp(arg, "-h") == 0 || strcmp(arg, "--help") == 0) { printUsage = 1; } /* use long day names */ else if(strcmp(arg, "-l") == 0 || strcmp(arg, "--long") == 0) { useLongNames = 1; } /* POSIX.1 says all arguments after -- are not options */ else if(strcmp(arg, "--") == 0) { /* skip the -- */ ++optInd; break; } /* unrecognized option */ else if(strncmp(arg, "-", strlen("-")) == 0) { printf("cal: invalid option -- %s\n", arg+1); printUsage = 1; } /* done with options, display cal */ else { break; } } /* Get the month and year to display, if specified */ if(optInd != argc) { /* Month and year specified */ if(argc - optInd == 2) { sscanf(argv[optInd], "%d", (int*)&month); sscanf(argv[optInd + 1], "%d", (int*)&year); /* Make sure the month value is legal */ if(month < 0 || month > 12) { printf("icucal: Bad value for month -- %d\n", (int)month); /* Display usage */ printUsage = 1; } /* Adjust because months are 0-based */ --month; } /* Only year specified */ else { sscanf(argv[optInd], "%d", (int*)&year); } } /* print usage info */ if(printUsage) { usage(); return 0; } /* print version info */ if(printVersion) { version(); return 0; } /* print the cal */ cal(month, year, useLongNames, &status); /* ICU cleanup. Deallocate any memory ICU may be holding. */ u_cleanup(); return (U_FAILURE(status) ? 1 : 0); } /* Usage information */ static void usage() { puts("Usage: icucal [OPTIONS] [[MONTH] YEAR]"); puts(""); puts("Options:"); puts(" -h, --help Print this message and exit."); puts(" -v, --version Print the version number of cal and exit."); puts(" -l, --long Use long names."); puts(""); puts("Arguments (optional):"); puts(" MONTH An integer (1-12) indicating the month to display"); puts(" YEAR An integer indicating the year to display"); puts(""); puts("For an interesting calendar, look at October 1582"); } /* Version information */ static void version() { printf("icucal version %s (ICU version %s), created by Stephen F. Booth.\n", CAL_VERSION, U_ICU_VERSION); puts(U_COPYRIGHT_STRING); } static void cal(int32_t month, int32_t year, UBool useLongNames, UErrorCode *status) { UCalendar *c; UChar *days [DAY_COUNT]; UChar *months [MONTH_COUNT]; int32_t fdow; if(U_FAILURE(*status)) return; /* Create a new calendar */ c = ucal_open(0, -1, uloc_getDefault(), UCAL_TRADITIONAL, status); /* Determine if we are printing a calendar for one month or for a year */ /* Print an entire year */ if(month == -1 && year != -1) { /* Set the year */ ucal_set(c, UCAL_YEAR, year); /* Determine the first day of the week */ fdow = ucal_getAttribute(c, UCAL_FIRST_DAY_OF_WEEK); /* Print the calendar for the year */ print_year(c, days, months, useLongNames, fdow, status); } /* Print only one month */ else { /* Set the month and the year, if specified */ if(month != -1) ucal_set(c, UCAL_MONTH, month); if(year != -1) ucal_set(c, UCAL_YEAR, year); /* Determine the first day of the week */ fdow = ucal_getAttribute(c, UCAL_FIRST_DAY_OF_WEEK); /* Print the calendar for the month */ print_month(c, days, useLongNames, fdow, status); } /* Clean up */ ucal_close(c); } /* * Get a set of DateFormat symbols of a given type. * * lowestIndex is the index of the first symbol to fetch. * (e.g. it will be one to fetch day names, since Sunday is * day 1 *not* day 0.) * * firstIndex is the index of the symbol to place first in * the output array. This is used when fetching day names * in locales where the week doesn't start on Sunday. */ static void get_symbols(const UDateFormat *fmt, UDateFormatSymbolType type, UChar *array[], int32_t arrayLength, int32_t lowestIndex, int32_t firstIndex, UErrorCode *status) { int32_t count, i; if (U_FAILURE(*status)) { return; } count = udat_countSymbols(fmt, type); if(count != arrayLength + lowestIndex) { return; } for(i = 0; i < arrayLength; i++) { int32_t idx = (i + firstIndex) % arrayLength; int32_t size = 1 + udat_getSymbols(fmt, type, idx + lowestIndex, NULL, 0, status); array[idx] = (UChar *) malloc(sizeof(UChar) * size); *status = U_ZERO_ERROR; udat_getSymbols(fmt, type, idx + lowestIndex, array[idx], size, status); } } /* Free the symbols allocated by get_symbols(). */ static void free_symbols(UChar *array[], int32_t arrayLength) { int32_t i; for(i = 0; i < arrayLength; i++) { free(array[i]); } } /* Get the day names for the specified locale, in either long or short form. Also, reorder the days so that they are in the proper order for the locale (not all locales begin weeks on Sunday; in France, weeks start on Monday) */ static void get_days(const UDateFormat *fmt, UChar *days [], UBool useLongNames, int32_t fdow, UErrorCode *status) { UDateFormatSymbolType dayType = (useLongNames ? UDAT_WEEKDAYS : UDAT_SHORT_WEEKDAYS); if(U_FAILURE(*status)) return; /* fdow is 1-based */ --fdow; get_symbols(fmt, dayType, days, DAY_COUNT, 1, fdow, status); } static void free_days(UChar *days[]) { free_symbols(days, DAY_COUNT); } /* Get the month names for the specified locale, in either long or short form. */ static void get_months(const UDateFormat *fmt, UChar *months [], UBool useLongNames, UErrorCode *status) { UDateFormatSymbolType monthType = (useLongNames ? UDAT_MONTHS : UDAT_SHORT_MONTHS); if(U_FAILURE(*status)) return; get_symbols(fmt, monthType, months, MONTH_COUNT - 1, 0, 0, status); /* some locales have 13 months, no idea why */ } static void free_months(UChar *months[]) { free_symbols(months, MONTH_COUNT - 1); } /* Indent a certain number of spaces */ static void indent(int32_t count, FILE *f) { char c [BUF_SIZE]; if(count <= 0) { return; } if(count < BUF_SIZE) { memset(c, (int)' ', count); fwrite(c, sizeof(char), count, f); } else { int32_t i; for(i = 0; i < count; ++i) putc(' ', f); } } /* Print the days */ static void print_days(UChar *days [], FILE *f, UErrorCode *status) { int32_t i; if(U_FAILURE(*status)) return; /* Print the day names */ for(i = 0; i < DAY_COUNT; ++i) { uprint(days[i], f, status); putc(' ', f); } } /* Print out a calendar for c's current month */ static void print_month(UCalendar *c, UChar *days [], UBool useLongNames, int32_t fdow, UErrorCode *status) { int32_t width, pad, i, day; int32_t lens [DAY_COUNT]; int32_t firstday, current; UNumberFormat *nfmt; UDateFormat *dfmt; UChar s [BUF_SIZE]; const UChar *pat = (useLongNames ? sLongPat : sShortPat); int32_t len = (useLongNames ? 9 : 8); if(U_FAILURE(*status)) return; /* ========== Generate the header containing the month and year */ /* Open a formatter with a month and year only pattern */ dfmt = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,NULL,0,pat, len,status); /* Format the date */ udat_format(dfmt, ucal_getMillis(c, status), s, BUF_SIZE, 0, status); /* ========== Get the day names */ get_days(dfmt, days, useLongNames, fdow, status); /* ========== Print the header */ /* Calculate widths for justification */ width = 6; /* 6 spaces, 1 between each day name */ for(i = 0; i < DAY_COUNT; ++i) { lens[i] = u_strlen(days[i]); width += lens[i]; } /* Print the header, centered among the day names */ pad = width - u_strlen(s); indent(pad / 2, stdout); uprint(s, stdout, status); putc('\n', stdout); /* ========== Print the day names */ print_days(days, stdout, status); putc('\n', stdout); /* ========== Print the calendar */ /* Get the first of the month */ ucal_set(c, UCAL_DATE, 1); firstday = ucal_get(c, UCAL_DAY_OF_WEEK, status); /* The day of the week for the first day of the month is based on 1-based days of the week, which were also reordered when placed in the days array. Account for this here by offsetting by the first day of the week for the locale, which is also 1-based. */ firstday -= fdow; /* Open the formatter */ nfmt = unum_open(UNUM_DECIMAL, NULL,0,NULL,NULL, status); /* Indent the correct number of spaces for the first week */ current = firstday; if(current < 0) { current += 7; } for(i = 0; i < current; ++i) indent(lens[i] + 1, stdout); /* Finally, print out the days */ day = ucal_get(c, UCAL_DATE, status); do { /* Format the current day string */ unum_format(nfmt, day, s, BUF_SIZE, 0, status); /* Calculate the justification and indent */ pad = lens[current] - u_strlen(s); indent(pad, stdout); /* Print the day number out, followed by a space */ uprint(s, stdout, status); putc(' ', stdout); /* Update the current day */ ++current; current %= DAY_COUNT; /* If we're at day 0 (first day of the week), insert a newline */ if(current == 0) { putc('\n', stdout); } /* Go to the next day */ ucal_add(c, UCAL_DATE, 1, status); day = ucal_get(c, UCAL_DATE, status); } while(day != 1); /* Output a trailing newline */ putc('\n', stdout); /* Clean up */ free_days(days); unum_close(nfmt); udat_close(dfmt); } /* Print out a calendar for c's current year */ static void print_year(UCalendar *c, UChar *days [], UChar *months [], UBool useLongNames, int32_t fdow, UErrorCode *status) { int32_t width, pad, i, j; int32_t lens [DAY_COUNT]; UNumberFormat *nfmt; UDateFormat *dfmt; UChar s [BUF_SIZE]; const UChar pat [] = { 0x0079, 0x0079, 0x0079, 0x0079 }; int32_t len = 4; UCalendar *left_cal, *right_cal; int32_t left_day, right_day; int32_t left_firstday, right_firstday, left_current, right_current; int32_t left_month, right_month; if(U_FAILURE(*status)) return; /* Alias */ left_cal = c; /* ========== Generate the header containing the year (only) */ /* Open a formatter with a month and year only pattern */ dfmt = udat_open(UDAT_PATTERN,UDAT_PATTERN,NULL,NULL,0,pat, len, status); /* Format the date */ udat_format(dfmt, ucal_getMillis(left_cal, status), s, BUF_SIZE, 0, status); /* ========== Get the month and day names */ get_days(dfmt, days, useLongNames, fdow, status); get_months(dfmt, months, useLongNames, status); /* ========== Print the header, centered */ /* Calculate widths for justification */ width = 6; /* 6 spaces, 1 between each day name */ for(i = 0; i < DAY_COUNT; ++i) { lens[i] = u_strlen(days[i]); width += lens[i]; } /* width is the width for 1 calendar; we are displaying in 2 cols with MARGIN_WIDTH spaces between months */ /* Print the header, centered among the day names */ pad = 2 * width + MARGIN_WIDTH - u_strlen(s); indent(pad / 2, stdout); uprint(s, stdout, status); putc('\n', stdout); putc('\n', stdout); /* Generate a copy of the calendar to use */ right_cal = ucal_open(0, -1, uloc_getDefault(), UCAL_TRADITIONAL, status); ucal_setMillis(right_cal, ucal_getMillis(left_cal, status), status); /* Open the formatter */ nfmt = unum_open(UNUM_DECIMAL,NULL, 0,NULL,NULL, status); /* ========== Calculate and display the months, two at a time */ for(i = 0; i < MONTH_COUNT - 1; i += 2) { /* Print the month names for the two current months */ pad = width - u_strlen(months[i]); indent(pad / 2, stdout); uprint(months[i], stdout, status); indent(pad / 2 + MARGIN_WIDTH, stdout); pad = width - u_strlen(months[i + 1]); indent(pad / 2, stdout); uprint(months[i + 1], stdout, status); putc('\n', stdout); /* Print the day names, twice */ print_days(days, stdout, status); indent(MARGIN_WIDTH, stdout); print_days(days, stdout, status); putc('\n', stdout); /* Setup the two calendars */ ucal_set(left_cal, UCAL_MONTH, i); ucal_set(left_cal, UCAL_DATE, 1); ucal_set(right_cal, UCAL_MONTH, i + 1); ucal_set(right_cal, UCAL_DATE, 1); left_firstday = ucal_get(left_cal, UCAL_DAY_OF_WEEK, status); right_firstday = ucal_get(right_cal, UCAL_DAY_OF_WEEK, status); /* The day of the week for the first day of the month is based on 1-based days of the week. However, the days were reordered when placed in the days array. Account for this here by offsetting by the first day of the week for the locale, which is also 1-based. */ /* We need to mod by DAY_COUNT since fdow can be > firstday. IE, if fdow = 2 = Monday (like in France) and the first day of the month is a 1 = Sunday, we want firstday to be 6, not -1 */ left_firstday += (DAY_COUNT - fdow); left_firstday %= DAY_COUNT; right_firstday += (DAY_COUNT - fdow); right_firstday %= DAY_COUNT; left_current = left_firstday; right_current = right_firstday; left_day = ucal_get(left_cal, UCAL_DATE, status); right_day = ucal_get(right_cal, UCAL_DATE, status); left_month = ucal_get(left_cal, UCAL_MONTH, status); right_month = ucal_get(right_cal, UCAL_MONTH, status); /* Finally, print out the days */ while(left_month == i || right_month == i + 1) { /* If the left month is finished printing, but the right month still has days to be printed, indent the width of the days strings and reset the left calendar's current day to 0 */ if(left_month != i && right_month == i + 1) { indent(width + 1, stdout); left_current = 0; } while(left_month == i) { /* If the day is the first, indent the correct number of spaces for the first week */ if(left_day == 1) { for(j = 0; j < left_current; ++j) indent(lens[j] + 1, stdout); } /* Format the current day string */ unum_format(nfmt, left_day, s, BUF_SIZE, 0, status); /* Calculate the justification and indent */ pad = lens[left_current] - u_strlen(s); indent(pad, stdout); /* Print the day number out, followed by a space */ uprint(s, stdout, status); putc(' ', stdout); /* Update the current day */ ++left_current; left_current %= DAY_COUNT; /* Go to the next day */ ucal_add(left_cal, UCAL_DATE, 1, status); left_day = ucal_get(left_cal, UCAL_DATE, status); /* Determine the month */ left_month = ucal_get(left_cal, UCAL_MONTH, status); /* If we're at day 0 (first day of the week), break and go to the next month */ if(left_current == 0) { break; } }; /* If the current day isn't 0, indent to make up for missing days at the end of the month */ if(left_current != 0) { for(j = left_current; j < DAY_COUNT; ++j) indent(lens[j] + 1, stdout); } /* Indent between the two months */ indent(MARGIN_WIDTH, stdout); while(right_month == i + 1) { /* If the day is the first, indent the correct number of spaces for the first week */ if(right_day == 1) { for(j = 0; j < right_current; ++j) indent(lens[j] + 1, stdout); } /* Format the current day string */ unum_format(nfmt, right_day, s, BUF_SIZE, 0, status); /* Calculate the justification and indent */ pad = lens[right_current] - u_strlen(s); indent(pad, stdout); /* Print the day number out, followed by a space */ uprint(s, stdout, status); putc(' ', stdout); /* Update the current day */ ++right_current; right_current %= DAY_COUNT; /* Go to the next day */ ucal_add(right_cal, UCAL_DATE, 1, status); right_day = ucal_get(right_cal, UCAL_DATE, status); /* Determine the month */ right_month = ucal_get(right_cal, UCAL_MONTH, status); /* If we're at day 0 (first day of the week), break out */ if(right_current == 0) { break; } }; /* Output a newline */ putc('\n', stdout); } /* Output a trailing newline */ putc('\n', stdout); } /* Clean up */ free_months(months); free_days(days); udat_close(dfmt); unum_close(nfmt); ucal_close(right_cal); } #endif
{ "language": "C" }
#ifndef Z_EN_ESTONE_H #define Z_EN_ESTONE_H #include <global.h> struct EnEstone; typedef struct EnEstone { /* 0x0000 */ Actor actor; /* 0x0144 */ char unk_0144[0x2C30]; } EnEstone; // size = 0x2D74 extern const ActorInit En_Estone_InitVars; #endif // Z_EN_ESTONE_H
{ "language": "C" }
/* config.h.in. Generated from configure.ac by autoheader. */ /* Define to 1 if you have the <dlfcn.h> header file. */ #undef HAVE_DLFCN_H /* Define to 1 if you have the <inttypes.h> header file. */ #undef HAVE_INTTYPES_H /* Define to 1 if you have the <memory.h> header file. */ #undef HAVE_MEMORY_H /* Define to 1 if you have the <stdint.h> header file. */ #undef HAVE_STDINT_H /* Define to 1 if you have the <stdlib.h> header file. */ #undef HAVE_STDLIB_H /* Define to 1 if you have the <strings.h> header file. */ #undef HAVE_STRINGS_H /* Define to 1 if you have the <string.h> header file. */ #undef HAVE_STRING_H /* Define to 1 if you have the <sys/stat.h> header file. */ #undef HAVE_SYS_STAT_H /* Define to 1 if you have the <sys/types.h> header file. */ #undef HAVE_SYS_TYPES_H /* Define to 1 if you have the <unistd.h> header file. */ #undef HAVE_UNISTD_H /* Define to the sub-directory in which libtool stores uninstalled libraries. */ #undef LT_OBJDIR /* Disable floating-point API */ #undef OP_DISABLE_FLOAT_API /* Enable assertions in code */ #undef OP_ENABLE_ASSERTIONS /* Enable HTTP support */ #undef OP_ENABLE_HTTP /* Enable fixed-point calculation */ #undef OP_FIXED_POINT /* Enable use of lrintf function */ #undef OP_HAVE_LRINTF /* Define to the address where bug reports for this package should be sent. */ #undef PACKAGE_BUGREPORT /* Define to the full name of this package. */ #undef PACKAGE_NAME /* Define to the full name and version of this package. */ #undef PACKAGE_STRING /* Define to the one symbol short name of this package. */ #undef PACKAGE_TARNAME /* Define to the home page for this package. */ #undef PACKAGE_URL /* Define to the version of this package. */ #undef PACKAGE_VERSION /* Define to 1 if you have the ANSI C header files. */ #undef STDC_HEADERS /* Define this if the compiler supports __attribute__(( ifelse([visibility("default")], , [visibility_default], [visibility("default")]) )) */ #undef SUPPORT_ATTRIBUTE_VISIBILITY_DEFAULT /* Define this if the compiler supports the -fvisibility flag */ #undef SUPPORT_FLAG_VISIBILITY /* Enable extensions on AIX 3, Interix. */ #ifndef _ALL_SOURCE # undef _ALL_SOURCE #endif /* Enable GNU extensions on systems that have them. */ #ifndef _GNU_SOURCE # undef _GNU_SOURCE #endif /* Enable threading extensions on Solaris. */ #ifndef _POSIX_PTHREAD_SEMANTICS # undef _POSIX_PTHREAD_SEMANTICS #endif /* Enable extensions on HP NonStop. */ #ifndef _TANDEM_SOURCE # undef _TANDEM_SOURCE #endif /* Enable general extensions on Solaris. */ #ifndef __EXTENSIONS__ # undef __EXTENSIONS__ #endif /* Enable large inode numbers on Mac OS X 10.5. */ #ifndef _DARWIN_USE_64_BIT_INODE # define _DARWIN_USE_64_BIT_INODE 1 #endif /* Number of bits in a file offset, on hosts where this is settable. */ #undef _FILE_OFFSET_BITS /* Define for large files, on AIX-style hosts. */ #undef _LARGE_FILES /* Define to 1 if on MINIX. */ #undef _MINIX /* Define to 2 if the system does not provide POSIX.1 features except with this defined. */ #undef _POSIX_1_SOURCE /* Define to 1 if you need to in order for `stat' and other things to work. */ #undef _POSIX_SOURCE /* We need at least WindowsXP for getaddrinfo/freeaddrinfo */ #undef _WIN32_WINNT
{ "language": "C" }
/* * Copyright (c) 2014-2018 Cesanta Software Limited * 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. */ #ifndef CS_FW_PLATFORMS_STM32_INCLUDE_STM32_UART_H_ #define CS_FW_PLATFORMS_STM32_INCLUDE_STM32_UART_H_ #ifdef __cplusplus extern "C" { #endif struct stm32_uart_pins { int tx, rx, ck, cts, rts; }; struct mgos_uart_dev_config { struct stm32_uart_pins pins; }; #ifdef __cplusplus } #endif #endif /* CS_FW_PLATFORMS_STM32_INCLUDE_STM32_UART_H_ */
{ "language": "C" }
/***************************************************************************** Copyright (c) 2014, Intel Corp. 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. ***************************************************************************** * Contents: Native high-level C interface to LAPACK function zpstrf * Author: Intel Corporation * Generated November 2015 *****************************************************************************/ #include "lapacke_utils.h" lapack_int LAPACKE_zpstrf( int matrix_layout, char uplo, lapack_int n, lapack_complex_double* a, lapack_int lda, lapack_int* piv, lapack_int* rank, double tol ) { lapack_int info = 0; double* work = NULL; if( matrix_layout != LAPACK_COL_MAJOR && matrix_layout != LAPACK_ROW_MAJOR ) { LAPACKE_xerbla( "LAPACKE_zpstrf", -1 ); return -1; } #ifndef LAPACK_DISABLE_NAN_CHECK if( LAPACKE_get_nancheck() ) { /* Optionally check input matrices for NaNs */ if( LAPACKE_zpo_nancheck( matrix_layout, uplo, n, a, lda ) ) { return -4; } if( LAPACKE_d_nancheck( 1, &tol, 1 ) ) { return -8; } } #endif /* Allocate memory for working array(s) */ work = (double*)LAPACKE_malloc( sizeof(double) * MAX(1,2*n) ); if( work == NULL ) { info = LAPACK_WORK_MEMORY_ERROR; goto exit_level_0; } /* Call middle-level interface */ info = LAPACKE_zpstrf_work( matrix_layout, uplo, n, a, lda, piv, rank, tol, work ); /* Release memory and exit */ LAPACKE_free( work ); exit_level_0: if( info == LAPACK_WORK_MEMORY_ERROR ) { LAPACKE_xerbla( "LAPACKE_zpstrf", info ); } return info; }
{ "language": "C" }
/* * L3 code * * Copyright (C) 2008, Christian Pellegrin <chripell@evolware.org> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * * * based on: * * L3 bus algorithm module. * * Copyright (C) 2001 Russell King, All Rights Reserved. * * */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/delay.h> #include <sound/l3.h> /* * Send one byte of data to the chip. Data is latched into the chip on * the rising edge of the clock. */ static void sendbyte(struct l3_pins *adap, unsigned int byte) { int i; for (i = 0; i < 8; i++) { adap->setclk(0); udelay(adap->data_hold); adap->setdat(byte & 1); udelay(adap->data_setup); adap->setclk(1); udelay(adap->clock_high); byte >>= 1; } } /* * Send a set of bytes to the chip. We need to pulse the MODE line * between each byte, but never at the start nor at the end of the * transfer. */ static void sendbytes(struct l3_pins *adap, const u8 *buf, int len) { int i; for (i = 0; i < len; i++) { if (i) { udelay(adap->mode_hold); adap->setmode(0); udelay(adap->mode); } adap->setmode(1); udelay(adap->mode_setup); sendbyte(adap, buf[i]); } } int l3_write(struct l3_pins *adap, u8 addr, u8 *data, int len) { adap->setclk(1); adap->setdat(1); adap->setmode(1); udelay(adap->mode); adap->setmode(0); udelay(adap->mode_setup); sendbyte(adap, addr); udelay(adap->mode_hold); sendbytes(adap, data, len); adap->setclk(1); adap->setdat(1); adap->setmode(0); return len; } EXPORT_SYMBOL_GPL(l3_write); MODULE_DESCRIPTION("L3 bit-banging driver"); MODULE_AUTHOR("Christian Pellegrin <chripell@evolware.org>"); MODULE_LICENSE("GPL");
{ "language": "C" }
#pragma once // MESSAGE LANDING_TARGET PACKING #define MAVLINK_MSG_ID_LANDING_TARGET 149 MAVPACKED( typedef struct __mavlink_landing_target_t { uint64_t time_usec; /*< Timestamp (micros since boot or Unix epoch)*/ float angle_x; /*< X-axis angular offset (in radians) of the target from the center of the image*/ float angle_y; /*< Y-axis angular offset (in radians) of the target from the center of the image*/ float distance; /*< Distance to the target from the vehicle in meters*/ float size_x; /*< Size in radians of target along x-axis*/ float size_y; /*< Size in radians of target along y-axis*/ uint8_t target_num; /*< The ID of the target if multiple targets are present*/ uint8_t frame; /*< MAV_FRAME enum specifying the whether the following feilds are earth-frame, body-frame, etc.*/ }) mavlink_landing_target_t; #define MAVLINK_MSG_ID_LANDING_TARGET_LEN 30 #define MAVLINK_MSG_ID_LANDING_TARGET_MIN_LEN 30 #define MAVLINK_MSG_ID_149_LEN 30 #define MAVLINK_MSG_ID_149_MIN_LEN 30 #define MAVLINK_MSG_ID_LANDING_TARGET_CRC 200 #define MAVLINK_MSG_ID_149_CRC 200 #if MAVLINK_COMMAND_24BIT #define MAVLINK_MESSAGE_INFO_LANDING_TARGET { \ 149, \ "LANDING_TARGET", \ 8, \ { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_landing_target_t, time_usec) }, \ { "target_num", NULL, MAVLINK_TYPE_UINT8_T, 0, 28, offsetof(mavlink_landing_target_t, target_num) }, \ { "frame", NULL, MAVLINK_TYPE_UINT8_T, 0, 29, offsetof(mavlink_landing_target_t, frame) }, \ { "angle_x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_landing_target_t, angle_x) }, \ { "angle_y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_landing_target_t, angle_y) }, \ { "distance", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_landing_target_t, distance) }, \ { "size_x", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_landing_target_t, size_x) }, \ { "size_y", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_landing_target_t, size_y) }, \ } \ } #else #define MAVLINK_MESSAGE_INFO_LANDING_TARGET { \ "LANDING_TARGET", \ 8, \ { { "time_usec", NULL, MAVLINK_TYPE_UINT64_T, 0, 0, offsetof(mavlink_landing_target_t, time_usec) }, \ { "target_num", NULL, MAVLINK_TYPE_UINT8_T, 0, 28, offsetof(mavlink_landing_target_t, target_num) }, \ { "frame", NULL, MAVLINK_TYPE_UINT8_T, 0, 29, offsetof(mavlink_landing_target_t, frame) }, \ { "angle_x", NULL, MAVLINK_TYPE_FLOAT, 0, 8, offsetof(mavlink_landing_target_t, angle_x) }, \ { "angle_y", NULL, MAVLINK_TYPE_FLOAT, 0, 12, offsetof(mavlink_landing_target_t, angle_y) }, \ { "distance", NULL, MAVLINK_TYPE_FLOAT, 0, 16, offsetof(mavlink_landing_target_t, distance) }, \ { "size_x", NULL, MAVLINK_TYPE_FLOAT, 0, 20, offsetof(mavlink_landing_target_t, size_x) }, \ { "size_y", NULL, MAVLINK_TYPE_FLOAT, 0, 24, offsetof(mavlink_landing_target_t, size_y) }, \ } \ } #endif /** * @brief Pack a landing_target message * @param system_id ID of this system * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * * @param time_usec Timestamp (micros since boot or Unix epoch) * @param target_num The ID of the target if multiple targets are present * @param frame MAV_FRAME enum specifying the whether the following feilds are earth-frame, body-frame, etc. * @param angle_x X-axis angular offset (in radians) of the target from the center of the image * @param angle_y Y-axis angular offset (in radians) of the target from the center of the image * @param distance Distance to the target from the vehicle in meters * @param size_x Size in radians of target along x-axis * @param size_y Size in radians of target along y-axis * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_landing_target_pack(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, uint64_t time_usec, uint8_t target_num, uint8_t frame, float angle_x, float angle_y, float distance, float size_x, float size_y) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char buf[MAVLINK_MSG_ID_LANDING_TARGET_LEN]; _mav_put_uint64_t(buf, 0, time_usec); _mav_put_float(buf, 8, angle_x); _mav_put_float(buf, 12, angle_y); _mav_put_float(buf, 16, distance); _mav_put_float(buf, 20, size_x); _mav_put_float(buf, 24, size_y); _mav_put_uint8_t(buf, 28, target_num); _mav_put_uint8_t(buf, 29, frame); memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_LANDING_TARGET_LEN); #else mavlink_landing_target_t packet; packet.time_usec = time_usec; packet.angle_x = angle_x; packet.angle_y = angle_y; packet.distance = distance; packet.size_x = size_x; packet.size_y = size_y; packet.target_num = target_num; packet.frame = frame; memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_LANDING_TARGET_LEN); #endif msg->msgid = MAVLINK_MSG_ID_LANDING_TARGET; return mavlink_finalize_message(msg, system_id, component_id, MAVLINK_MSG_ID_LANDING_TARGET_MIN_LEN, MAVLINK_MSG_ID_LANDING_TARGET_LEN, MAVLINK_MSG_ID_LANDING_TARGET_CRC); } /** * @brief Pack a landing_target message on a channel * @param system_id ID of this system * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message will be sent over * @param msg The MAVLink message to compress the data into * @param time_usec Timestamp (micros since boot or Unix epoch) * @param target_num The ID of the target if multiple targets are present * @param frame MAV_FRAME enum specifying the whether the following feilds are earth-frame, body-frame, etc. * @param angle_x X-axis angular offset (in radians) of the target from the center of the image * @param angle_y Y-axis angular offset (in radians) of the target from the center of the image * @param distance Distance to the target from the vehicle in meters * @param size_x Size in radians of target along x-axis * @param size_y Size in radians of target along y-axis * @return length of the message in bytes (excluding serial stream start sign) */ static inline uint16_t mavlink_msg_landing_target_pack_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, uint64_t time_usec,uint8_t target_num,uint8_t frame,float angle_x,float angle_y,float distance,float size_x,float size_y) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char buf[MAVLINK_MSG_ID_LANDING_TARGET_LEN]; _mav_put_uint64_t(buf, 0, time_usec); _mav_put_float(buf, 8, angle_x); _mav_put_float(buf, 12, angle_y); _mav_put_float(buf, 16, distance); _mav_put_float(buf, 20, size_x); _mav_put_float(buf, 24, size_y); _mav_put_uint8_t(buf, 28, target_num); _mav_put_uint8_t(buf, 29, frame); memcpy(_MAV_PAYLOAD_NON_CONST(msg), buf, MAVLINK_MSG_ID_LANDING_TARGET_LEN); #else mavlink_landing_target_t packet; packet.time_usec = time_usec; packet.angle_x = angle_x; packet.angle_y = angle_y; packet.distance = distance; packet.size_x = size_x; packet.size_y = size_y; packet.target_num = target_num; packet.frame = frame; memcpy(_MAV_PAYLOAD_NON_CONST(msg), &packet, MAVLINK_MSG_ID_LANDING_TARGET_LEN); #endif msg->msgid = MAVLINK_MSG_ID_LANDING_TARGET; return mavlink_finalize_message_chan(msg, system_id, component_id, chan, MAVLINK_MSG_ID_LANDING_TARGET_MIN_LEN, MAVLINK_MSG_ID_LANDING_TARGET_LEN, MAVLINK_MSG_ID_LANDING_TARGET_CRC); } /** * @brief Encode a landing_target struct * * @param system_id ID of this system * @param component_id ID of this component (e.g. 200 for IMU) * @param msg The MAVLink message to compress the data into * @param landing_target C-struct to read the message contents from */ static inline uint16_t mavlink_msg_landing_target_encode(uint8_t system_id, uint8_t component_id, mavlink_message_t* msg, const mavlink_landing_target_t* landing_target) { return mavlink_msg_landing_target_pack(system_id, component_id, msg, landing_target->time_usec, landing_target->target_num, landing_target->frame, landing_target->angle_x, landing_target->angle_y, landing_target->distance, landing_target->size_x, landing_target->size_y); } /** * @brief Encode a landing_target struct on a channel * * @param system_id ID of this system * @param component_id ID of this component (e.g. 200 for IMU) * @param chan The MAVLink channel this message will be sent over * @param msg The MAVLink message to compress the data into * @param landing_target C-struct to read the message contents from */ static inline uint16_t mavlink_msg_landing_target_encode_chan(uint8_t system_id, uint8_t component_id, uint8_t chan, mavlink_message_t* msg, const mavlink_landing_target_t* landing_target) { return mavlink_msg_landing_target_pack_chan(system_id, component_id, chan, msg, landing_target->time_usec, landing_target->target_num, landing_target->frame, landing_target->angle_x, landing_target->angle_y, landing_target->distance, landing_target->size_x, landing_target->size_y); } /** * @brief Send a landing_target message * @param chan MAVLink channel to send the message * * @param time_usec Timestamp (micros since boot or Unix epoch) * @param target_num The ID of the target if multiple targets are present * @param frame MAV_FRAME enum specifying the whether the following feilds are earth-frame, body-frame, etc. * @param angle_x X-axis angular offset (in radians) of the target from the center of the image * @param angle_y Y-axis angular offset (in radians) of the target from the center of the image * @param distance Distance to the target from the vehicle in meters * @param size_x Size in radians of target along x-axis * @param size_y Size in radians of target along y-axis */ #ifdef MAVLINK_USE_CONVENIENCE_FUNCTIONS static inline void mavlink_msg_landing_target_send(mavlink_channel_t chan, uint64_t time_usec, uint8_t target_num, uint8_t frame, float angle_x, float angle_y, float distance, float size_x, float size_y) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char buf[MAVLINK_MSG_ID_LANDING_TARGET_LEN]; _mav_put_uint64_t(buf, 0, time_usec); _mav_put_float(buf, 8, angle_x); _mav_put_float(buf, 12, angle_y); _mav_put_float(buf, 16, distance); _mav_put_float(buf, 20, size_x); _mav_put_float(buf, 24, size_y); _mav_put_uint8_t(buf, 28, target_num); _mav_put_uint8_t(buf, 29, frame); _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LANDING_TARGET, buf, MAVLINK_MSG_ID_LANDING_TARGET_MIN_LEN, MAVLINK_MSG_ID_LANDING_TARGET_LEN, MAVLINK_MSG_ID_LANDING_TARGET_CRC); #else mavlink_landing_target_t packet; packet.time_usec = time_usec; packet.angle_x = angle_x; packet.angle_y = angle_y; packet.distance = distance; packet.size_x = size_x; packet.size_y = size_y; packet.target_num = target_num; packet.frame = frame; _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LANDING_TARGET, (const char *)&packet, MAVLINK_MSG_ID_LANDING_TARGET_MIN_LEN, MAVLINK_MSG_ID_LANDING_TARGET_LEN, MAVLINK_MSG_ID_LANDING_TARGET_CRC); #endif } /** * @brief Send a landing_target message * @param chan MAVLink channel to send the message * @param struct The MAVLink struct to serialize */ static inline void mavlink_msg_landing_target_send_struct(mavlink_channel_t chan, const mavlink_landing_target_t* landing_target) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS mavlink_msg_landing_target_send(chan, landing_target->time_usec, landing_target->target_num, landing_target->frame, landing_target->angle_x, landing_target->angle_y, landing_target->distance, landing_target->size_x, landing_target->size_y); #else _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LANDING_TARGET, (const char *)landing_target, MAVLINK_MSG_ID_LANDING_TARGET_MIN_LEN, MAVLINK_MSG_ID_LANDING_TARGET_LEN, MAVLINK_MSG_ID_LANDING_TARGET_CRC); #endif } #if MAVLINK_MSG_ID_LANDING_TARGET_LEN <= MAVLINK_MAX_PAYLOAD_LEN /* This varient of _send() can be used to save stack space by re-using memory from the receive buffer. The caller provides a mavlink_message_t which is the size of a full mavlink message. This is usually the receive buffer for the channel, and allows a reply to an incoming message with minimum stack space usage. */ static inline void mavlink_msg_landing_target_send_buf(mavlink_message_t *msgbuf, mavlink_channel_t chan, uint64_t time_usec, uint8_t target_num, uint8_t frame, float angle_x, float angle_y, float distance, float size_x, float size_y) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS char *buf = (char *)msgbuf; _mav_put_uint64_t(buf, 0, time_usec); _mav_put_float(buf, 8, angle_x); _mav_put_float(buf, 12, angle_y); _mav_put_float(buf, 16, distance); _mav_put_float(buf, 20, size_x); _mav_put_float(buf, 24, size_y); _mav_put_uint8_t(buf, 28, target_num); _mav_put_uint8_t(buf, 29, frame); _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LANDING_TARGET, buf, MAVLINK_MSG_ID_LANDING_TARGET_MIN_LEN, MAVLINK_MSG_ID_LANDING_TARGET_LEN, MAVLINK_MSG_ID_LANDING_TARGET_CRC); #else mavlink_landing_target_t *packet = (mavlink_landing_target_t *)msgbuf; packet->time_usec = time_usec; packet->angle_x = angle_x; packet->angle_y = angle_y; packet->distance = distance; packet->size_x = size_x; packet->size_y = size_y; packet->target_num = target_num; packet->frame = frame; _mav_finalize_message_chan_send(chan, MAVLINK_MSG_ID_LANDING_TARGET, (const char *)packet, MAVLINK_MSG_ID_LANDING_TARGET_MIN_LEN, MAVLINK_MSG_ID_LANDING_TARGET_LEN, MAVLINK_MSG_ID_LANDING_TARGET_CRC); #endif } #endif #endif // MESSAGE LANDING_TARGET UNPACKING /** * @brief Get field time_usec from landing_target message * * @return Timestamp (micros since boot or Unix epoch) */ static inline uint64_t mavlink_msg_landing_target_get_time_usec(const mavlink_message_t* msg) { return _MAV_RETURN_uint64_t(msg, 0); } /** * @brief Get field target_num from landing_target message * * @return The ID of the target if multiple targets are present */ static inline uint8_t mavlink_msg_landing_target_get_target_num(const mavlink_message_t* msg) { return _MAV_RETURN_uint8_t(msg, 28); } /** * @brief Get field frame from landing_target message * * @return MAV_FRAME enum specifying the whether the following feilds are earth-frame, body-frame, etc. */ static inline uint8_t mavlink_msg_landing_target_get_frame(const mavlink_message_t* msg) { return _MAV_RETURN_uint8_t(msg, 29); } /** * @brief Get field angle_x from landing_target message * * @return X-axis angular offset (in radians) of the target from the center of the image */ static inline float mavlink_msg_landing_target_get_angle_x(const mavlink_message_t* msg) { return _MAV_RETURN_float(msg, 8); } /** * @brief Get field angle_y from landing_target message * * @return Y-axis angular offset (in radians) of the target from the center of the image */ static inline float mavlink_msg_landing_target_get_angle_y(const mavlink_message_t* msg) { return _MAV_RETURN_float(msg, 12); } /** * @brief Get field distance from landing_target message * * @return Distance to the target from the vehicle in meters */ static inline float mavlink_msg_landing_target_get_distance(const mavlink_message_t* msg) { return _MAV_RETURN_float(msg, 16); } /** * @brief Get field size_x from landing_target message * * @return Size in radians of target along x-axis */ static inline float mavlink_msg_landing_target_get_size_x(const mavlink_message_t* msg) { return _MAV_RETURN_float(msg, 20); } /** * @brief Get field size_y from landing_target message * * @return Size in radians of target along y-axis */ static inline float mavlink_msg_landing_target_get_size_y(const mavlink_message_t* msg) { return _MAV_RETURN_float(msg, 24); } /** * @brief Decode a landing_target message into a struct * * @param msg The message to decode * @param landing_target C-struct to decode the message contents into */ static inline void mavlink_msg_landing_target_decode(const mavlink_message_t* msg, mavlink_landing_target_t* landing_target) { #if MAVLINK_NEED_BYTE_SWAP || !MAVLINK_ALIGNED_FIELDS landing_target->time_usec = mavlink_msg_landing_target_get_time_usec(msg); landing_target->angle_x = mavlink_msg_landing_target_get_angle_x(msg); landing_target->angle_y = mavlink_msg_landing_target_get_angle_y(msg); landing_target->distance = mavlink_msg_landing_target_get_distance(msg); landing_target->size_x = mavlink_msg_landing_target_get_size_x(msg); landing_target->size_y = mavlink_msg_landing_target_get_size_y(msg); landing_target->target_num = mavlink_msg_landing_target_get_target_num(msg); landing_target->frame = mavlink_msg_landing_target_get_frame(msg); #else uint8_t len = msg->len < MAVLINK_MSG_ID_LANDING_TARGET_LEN? msg->len : MAVLINK_MSG_ID_LANDING_TARGET_LEN; memset(landing_target, 0, MAVLINK_MSG_ID_LANDING_TARGET_LEN); memcpy(landing_target, _MAV_PAYLOAD(msg), len); #endif }
{ "language": "C" }
/* * Copyright (C) 1999 - 2010 Intel Corporation. * Copyright (C) 2010 OKI SEMICONDUCTOR Co., LTD. * * This code was derived from the Intel e1000e Linux driver. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; version 2 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, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. */ #include "pch_gbe.h" #include "pch_gbe_api.h" /** * pch_gbe_stats - Stats item information */ struct pch_gbe_stats { char string[ETH_GSTRING_LEN]; size_t size; size_t offset; }; #define PCH_GBE_STAT(m) \ { \ .string = #m, \ .size = FIELD_SIZEOF(struct pch_gbe_hw_stats, m), \ .offset = offsetof(struct pch_gbe_hw_stats, m), \ } /** * pch_gbe_gstrings_stats - ethtool information status name list */ static const struct pch_gbe_stats pch_gbe_gstrings_stats[] = { PCH_GBE_STAT(rx_packets), PCH_GBE_STAT(tx_packets), PCH_GBE_STAT(rx_bytes), PCH_GBE_STAT(tx_bytes), PCH_GBE_STAT(rx_errors), PCH_GBE_STAT(tx_errors), PCH_GBE_STAT(rx_dropped), PCH_GBE_STAT(tx_dropped), PCH_GBE_STAT(multicast), PCH_GBE_STAT(collisions), PCH_GBE_STAT(rx_crc_errors), PCH_GBE_STAT(rx_frame_errors), PCH_GBE_STAT(rx_alloc_buff_failed), PCH_GBE_STAT(tx_length_errors), PCH_GBE_STAT(tx_aborted_errors), PCH_GBE_STAT(tx_carrier_errors), PCH_GBE_STAT(tx_timeout_count), PCH_GBE_STAT(tx_restart_count), PCH_GBE_STAT(intr_rx_dsc_empty_count), PCH_GBE_STAT(intr_rx_frame_err_count), PCH_GBE_STAT(intr_rx_fifo_err_count), PCH_GBE_STAT(intr_rx_dma_err_count), PCH_GBE_STAT(intr_tx_fifo_err_count), PCH_GBE_STAT(intr_tx_dma_err_count), PCH_GBE_STAT(intr_tcpip_err_count) }; #define PCH_GBE_QUEUE_STATS_LEN 0 #define PCH_GBE_GLOBAL_STATS_LEN ARRAY_SIZE(pch_gbe_gstrings_stats) #define PCH_GBE_STATS_LEN (PCH_GBE_GLOBAL_STATS_LEN + PCH_GBE_QUEUE_STATS_LEN) #define PCH_GBE_MAC_REGS_LEN (sizeof(struct pch_gbe_regs) / 4) #define PCH_GBE_REGS_LEN (PCH_GBE_MAC_REGS_LEN + PCH_GBE_PHY_REGS_LEN) /** * pch_gbe_get_settings - Get device-specific settings * @netdev: Network interface device structure * @ecmd: Ethtool command * Returns * 0: Successful. * Negative value: Failed. */ static int pch_gbe_get_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); int ret; ret = mii_ethtool_gset(&adapter->mii, ecmd); ecmd->supported &= ~(SUPPORTED_TP | SUPPORTED_1000baseT_Half); ecmd->advertising &= ~(ADVERTISED_TP | ADVERTISED_1000baseT_Half); if (!netif_carrier_ok(adapter->netdev)) ethtool_cmd_speed_set(ecmd, -1); return ret; } /** * pch_gbe_set_settings - Set device-specific settings * @netdev: Network interface device structure * @ecmd: Ethtool command * Returns * 0: Successful. * Negative value: Failed. */ static int pch_gbe_set_settings(struct net_device *netdev, struct ethtool_cmd *ecmd) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); struct pch_gbe_hw *hw = &adapter->hw; u32 speed = ethtool_cmd_speed(ecmd); int ret; pch_gbe_hal_write_phy_reg(hw, MII_BMCR, BMCR_RESET); /* when set_settings() is called with a ethtool_cmd previously * filled by get_settings() on a down link, speed is -1: */ if (speed == UINT_MAX) { speed = SPEED_1000; ecmd->duplex = DUPLEX_FULL; } ret = mii_ethtool_sset(&adapter->mii, ecmd); if (ret) { pr_err("Error: mii_ethtool_sset\n"); return ret; } hw->mac.link_speed = speed; hw->mac.link_duplex = ecmd->duplex; hw->phy.autoneg_advertised = ecmd->advertising; hw->mac.autoneg = ecmd->autoneg; pch_gbe_hal_phy_sw_reset(hw); /* reset the link */ if (netif_running(adapter->netdev)) { pch_gbe_down(adapter); ret = pch_gbe_up(adapter); } else { pch_gbe_reset(adapter); } return ret; } /** * pch_gbe_get_regs_len - Report the size of device registers * @netdev: Network interface device structure * Returns: the size of device registers. */ static int pch_gbe_get_regs_len(struct net_device *netdev) { return PCH_GBE_REGS_LEN * (int)sizeof(u32); } /** * pch_gbe_get_drvinfo - Report driver information * @netdev: Network interface device structure * @drvinfo: Driver information structure */ static void pch_gbe_get_drvinfo(struct net_device *netdev, struct ethtool_drvinfo *drvinfo) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); strlcpy(drvinfo->driver, KBUILD_MODNAME, sizeof(drvinfo->driver)); strlcpy(drvinfo->version, pch_driver_version, sizeof(drvinfo->version)); strlcpy(drvinfo->bus_info, pci_name(adapter->pdev), sizeof(drvinfo->bus_info)); drvinfo->regdump_len = pch_gbe_get_regs_len(netdev); } /** * pch_gbe_get_regs - Get device registers * @netdev: Network interface device structure * @regs: Ethtool register structure * @p: Buffer pointer of read device register date */ static void pch_gbe_get_regs(struct net_device *netdev, struct ethtool_regs *regs, void *p) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); struct pch_gbe_hw *hw = &adapter->hw; struct pci_dev *pdev = adapter->pdev; u32 *regs_buff = p; u16 i, tmp; regs->version = 0x1000000 | (__u32)pdev->revision << 16 | pdev->device; for (i = 0; i < PCH_GBE_MAC_REGS_LEN; i++) *regs_buff++ = ioread32(&hw->reg->INT_ST + i); /* PHY register */ for (i = 0; i < PCH_GBE_PHY_REGS_LEN; i++) { pch_gbe_hal_read_phy_reg(&adapter->hw, i, &tmp); *regs_buff++ = tmp; } } /** * pch_gbe_get_wol - Report whether Wake-on-Lan is enabled * @netdev: Network interface device structure * @wol: Wake-on-Lan information */ static void pch_gbe_get_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); wol->supported = WAKE_UCAST | WAKE_MCAST | WAKE_BCAST | WAKE_MAGIC; wol->wolopts = 0; if ((adapter->wake_up_evt & PCH_GBE_WLC_IND)) wol->wolopts |= WAKE_UCAST; if ((adapter->wake_up_evt & PCH_GBE_WLC_MLT)) wol->wolopts |= WAKE_MCAST; if ((adapter->wake_up_evt & PCH_GBE_WLC_BR)) wol->wolopts |= WAKE_BCAST; if ((adapter->wake_up_evt & PCH_GBE_WLC_MP)) wol->wolopts |= WAKE_MAGIC; } /** * pch_gbe_set_wol - Turn Wake-on-Lan on or off * @netdev: Network interface device structure * @wol: Pointer of wake-on-Lan information straucture * Returns * 0: Successful. * Negative value: Failed. */ static int pch_gbe_set_wol(struct net_device *netdev, struct ethtool_wolinfo *wol) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); if ((wol->wolopts & (WAKE_PHY | WAKE_ARP | WAKE_MAGICSECURE))) return -EOPNOTSUPP; /* these settings will always override what we currently have */ adapter->wake_up_evt = 0; if ((wol->wolopts & WAKE_UCAST)) adapter->wake_up_evt |= PCH_GBE_WLC_IND; if ((wol->wolopts & WAKE_MCAST)) adapter->wake_up_evt |= PCH_GBE_WLC_MLT; if ((wol->wolopts & WAKE_BCAST)) adapter->wake_up_evt |= PCH_GBE_WLC_BR; if ((wol->wolopts & WAKE_MAGIC)) adapter->wake_up_evt |= PCH_GBE_WLC_MP; return 0; } /** * pch_gbe_nway_reset - Restart autonegotiation * @netdev: Network interface device structure * Returns * 0: Successful. * Negative value: Failed. */ static int pch_gbe_nway_reset(struct net_device *netdev) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); return mii_nway_restart(&adapter->mii); } /** * pch_gbe_get_ringparam - Report ring sizes * @netdev: Network interface device structure * @ring: Ring param structure */ static void pch_gbe_get_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); struct pch_gbe_tx_ring *txdr = adapter->tx_ring; struct pch_gbe_rx_ring *rxdr = adapter->rx_ring; ring->rx_max_pending = PCH_GBE_MAX_RXD; ring->tx_max_pending = PCH_GBE_MAX_TXD; ring->rx_pending = rxdr->count; ring->tx_pending = txdr->count; } /** * pch_gbe_set_ringparam - Set ring sizes * @netdev: Network interface device structure * @ring: Ring param structure * Returns * 0: Successful. * Negative value: Failed. */ static int pch_gbe_set_ringparam(struct net_device *netdev, struct ethtool_ringparam *ring) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); struct pch_gbe_tx_ring *txdr, *tx_old; struct pch_gbe_rx_ring *rxdr, *rx_old; int tx_ring_size, rx_ring_size; int err = 0; if ((ring->rx_mini_pending) || (ring->rx_jumbo_pending)) return -EINVAL; tx_ring_size = (int)sizeof(struct pch_gbe_tx_ring); rx_ring_size = (int)sizeof(struct pch_gbe_rx_ring); if ((netif_running(adapter->netdev))) pch_gbe_down(adapter); tx_old = adapter->tx_ring; rx_old = adapter->rx_ring; txdr = kzalloc(tx_ring_size, GFP_KERNEL); if (!txdr) { err = -ENOMEM; goto err_alloc_tx; } rxdr = kzalloc(rx_ring_size, GFP_KERNEL); if (!rxdr) { err = -ENOMEM; goto err_alloc_rx; } adapter->tx_ring = txdr; adapter->rx_ring = rxdr; rxdr->count = clamp_val(ring->rx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD); rxdr->count = roundup(rxdr->count, PCH_GBE_RX_DESC_MULTIPLE); txdr->count = clamp_val(ring->tx_pending, PCH_GBE_MIN_RXD, PCH_GBE_MAX_RXD); txdr->count = roundup(txdr->count, PCH_GBE_TX_DESC_MULTIPLE); if ((netif_running(adapter->netdev))) { /* Try to get new resources before deleting old */ err = pch_gbe_setup_rx_resources(adapter, adapter->rx_ring); if (err) goto err_setup_rx; err = pch_gbe_setup_tx_resources(adapter, adapter->tx_ring); if (err) goto err_setup_tx; /* save the new, restore the old in order to free it, * then restore the new back again */ #ifdef RINGFREE adapter->rx_ring = rx_old; adapter->tx_ring = tx_old; pch_gbe_free_rx_resources(adapter, adapter->rx_ring); pch_gbe_free_tx_resources(adapter, adapter->tx_ring); kfree(tx_old); kfree(rx_old); adapter->rx_ring = rxdr; adapter->tx_ring = txdr; #else pch_gbe_free_rx_resources(adapter, rx_old); pch_gbe_free_tx_resources(adapter, tx_old); kfree(tx_old); kfree(rx_old); adapter->rx_ring = rxdr; adapter->tx_ring = txdr; #endif err = pch_gbe_up(adapter); } return err; err_setup_tx: pch_gbe_free_rx_resources(adapter, adapter->rx_ring); err_setup_rx: adapter->rx_ring = rx_old; adapter->tx_ring = tx_old; kfree(rxdr); err_alloc_rx: kfree(txdr); err_alloc_tx: if (netif_running(adapter->netdev)) pch_gbe_up(adapter); return err; } /** * pch_gbe_get_pauseparam - Report pause parameters * @netdev: Network interface device structure * @pause: Pause parameters structure */ static void pch_gbe_get_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); struct pch_gbe_hw *hw = &adapter->hw; pause->autoneg = ((hw->mac.fc_autoneg) ? AUTONEG_ENABLE : AUTONEG_DISABLE); if (hw->mac.fc == PCH_GBE_FC_RX_PAUSE) { pause->rx_pause = 1; } else if (hw->mac.fc == PCH_GBE_FC_TX_PAUSE) { pause->tx_pause = 1; } else if (hw->mac.fc == PCH_GBE_FC_FULL) { pause->rx_pause = 1; pause->tx_pause = 1; } } /** * pch_gbe_set_pauseparam - Set pause paramters * @netdev: Network interface device structure * @pause: Pause parameters structure * Returns * 0: Successful. * Negative value: Failed. */ static int pch_gbe_set_pauseparam(struct net_device *netdev, struct ethtool_pauseparam *pause) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); struct pch_gbe_hw *hw = &adapter->hw; int ret = 0; hw->mac.fc_autoneg = pause->autoneg; if ((pause->rx_pause) && (pause->tx_pause)) hw->mac.fc = PCH_GBE_FC_FULL; else if ((pause->rx_pause) && (!pause->tx_pause)) hw->mac.fc = PCH_GBE_FC_RX_PAUSE; else if ((!pause->rx_pause) && (pause->tx_pause)) hw->mac.fc = PCH_GBE_FC_TX_PAUSE; else if ((!pause->rx_pause) && (!pause->tx_pause)) hw->mac.fc = PCH_GBE_FC_NONE; if (hw->mac.fc_autoneg == AUTONEG_ENABLE) { if ((netif_running(adapter->netdev))) { pch_gbe_down(adapter); ret = pch_gbe_up(adapter); } else { pch_gbe_reset(adapter); } } else { ret = pch_gbe_mac_force_mac_fc(hw); } return ret; } /** * pch_gbe_get_strings - Return a set of strings that describe the requested * objects * @netdev: Network interface device structure * @stringset: Select the stringset. [ETH_SS_TEST] [ETH_SS_STATS] * @data: Pointer of read string data. */ static void pch_gbe_get_strings(struct net_device *netdev, u32 stringset, u8 *data) { u8 *p = data; int i; switch (stringset) { case (u32) ETH_SS_STATS: for (i = 0; i < PCH_GBE_GLOBAL_STATS_LEN; i++) { memcpy(p, pch_gbe_gstrings_stats[i].string, ETH_GSTRING_LEN); p += ETH_GSTRING_LEN; } break; } } /** * pch_gbe_get_ethtool_stats - Return statistics about the device * @netdev: Network interface device structure * @stats: Ethtool statue structure * @data: Pointer of read status area */ static void pch_gbe_get_ethtool_stats(struct net_device *netdev, struct ethtool_stats *stats, u64 *data) { struct pch_gbe_adapter *adapter = netdev_priv(netdev); int i; const struct pch_gbe_stats *gstats = pch_gbe_gstrings_stats; char *hw_stats = (char *)&adapter->stats; pch_gbe_update_stats(adapter); for (i = 0; i < PCH_GBE_GLOBAL_STATS_LEN; i++) { char *p = hw_stats + gstats->offset; data[i] = gstats->size == sizeof(u64) ? *(u64 *)p:(*(u32 *)p); gstats++; } } static int pch_gbe_get_sset_count(struct net_device *netdev, int sset) { switch (sset) { case ETH_SS_STATS: return PCH_GBE_STATS_LEN; default: return -EOPNOTSUPP; } } static const struct ethtool_ops pch_gbe_ethtool_ops = { .get_settings = pch_gbe_get_settings, .set_settings = pch_gbe_set_settings, .get_drvinfo = pch_gbe_get_drvinfo, .get_regs_len = pch_gbe_get_regs_len, .get_regs = pch_gbe_get_regs, .get_wol = pch_gbe_get_wol, .set_wol = pch_gbe_set_wol, .nway_reset = pch_gbe_nway_reset, .get_link = ethtool_op_get_link, .get_ringparam = pch_gbe_get_ringparam, .set_ringparam = pch_gbe_set_ringparam, .get_pauseparam = pch_gbe_get_pauseparam, .set_pauseparam = pch_gbe_set_pauseparam, .get_strings = pch_gbe_get_strings, .get_ethtool_stats = pch_gbe_get_ethtool_stats, .get_sset_count = pch_gbe_get_sset_count, }; void pch_gbe_set_ethtool_ops(struct net_device *netdev) { SET_ETHTOOL_OPS(netdev, &pch_gbe_ethtool_ops); }
{ "language": "C" }
/* * * Copyright 2016 gRPC 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. * */ #ifndef GRPC_CORE_LIB_SLICE_SLICE_INTERNAL_H #define GRPC_CORE_LIB_SLICE_SLICE_INTERNAL_H #include <grpc/support/port_platform.h> #include <grpc/slice.h> #include <grpc/slice_buffer.h> grpc_slice grpc_slice_ref_internal(grpc_slice slice); void grpc_slice_unref_internal(grpc_slice slice); void grpc_slice_buffer_reset_and_unref_internal(grpc_slice_buffer* sb); void grpc_slice_buffer_partial_unref_internal(grpc_slice_buffer* sb, size_t idx); void grpc_slice_buffer_destroy_internal(grpc_slice_buffer* sb); /* Check if a slice is interned */ bool grpc_slice_is_interned(grpc_slice slice); void grpc_slice_intern_init(void); void grpc_slice_intern_shutdown(void); void grpc_test_only_set_slice_hash_seed(uint32_t key); // if slice matches a static slice, returns the static slice // otherwise returns the passed in slice (without reffing it) // used for surface boundaries where we might receive an un-interned static // string grpc_slice grpc_slice_maybe_static_intern(grpc_slice slice, bool* returned_slice_is_different); uint32_t grpc_static_slice_hash(grpc_slice s); int grpc_static_slice_eq(grpc_slice a, grpc_slice b); // Returns the memory used by this slice, not counting the slice structure // itself. This means that inlined and slices from static strings will return // 0. All other slices will return the size of the allocated chars. size_t grpc_slice_memory_usage(grpc_slice s); #endif /* GRPC_CORE_LIB_SLICE_SLICE_INTERNAL_H */
{ "language": "C" }
/* Write a program to find the node at which the intersection of two singly linked lists begins. For example, the following two linked lists: A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3 begin to intersect at node c1. Notes: If the two linked lists have no intersection at all, return null. The linked lists must retain their original structure after the function returns. You may assume there are no cycles anywhere in the entire linked structure. Your code should preferably run in O(n) time and use only O(1) memory. */ /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */ #include <common.hpp> class Solution1 { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { if (headA == NULL || headB == NULL) { return NULL; } std::unordered_set<int> cache; for (ListNode *p = headA; p != NULL; p = p->next) { cache.insert(p->val); } for (ListNode *p = headB; p != NULL; p = p->next) { if (cache.find(p->val) != cache.end()) { return p; } } return NULL; } }; //time:O(N) //space:O(N) class Solution2 { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { if (headA == NULL || headB == NULL) { return NULL; } std::unordered_set<int> cache; for (ListNode *p = headA; p != NULL; p = p->next) { cache.insert(p->val); } for (ListNode *p = headB; p != NULL; p = p->next) { if (cache.find(p->val) != cache.end()) { return p; } } return NULL; } }; //solution2 /* 1.get length of two lists 2.if listB is longer, p2 move forward lenB-lenA 3.move p1 and p2, until get the same node or NULL p1 👇 A: a1 → a2 ↘ c1 → c2 → c3 ↗ B: b1 → b2 → b3 👆 p2 time:O(N) space:O(1) */ //solution3 /* connect A and B, B and A the same nodes will be the last several nodes A->B : a1->a2->c1->c2->c3->b1->b2->b3->c1->c2->c3 B->A : b1->b2->b3->c1->c2->c3->a1->a2->c1->c2->c3 👆 👆 👆 time:O(N) space:O(1) */ class Solution3 { public: ListNode *getIntersectionNode(ListNode *headA, ListNode *headB) { ListNode *cur1 = headA, *cur2 = headB; while (cur1 != cur2) { cur1 = cur1 ? cur1->next : headB; cur2 = cur2 ? cur2->next : headA; } return cur1; } }; //What if the list has circle?
{ "language": "C" }
//-------------------------------------------------------------------------- // Copyright (C) 2015-2020 Cisco and/or its affiliates. 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. You may not use, modify or distribute // this program under any other version of the GNU General Public 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, write to the Free Software Foundation, Inc., // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. //-------------------------------------------------------------------------- // piglet_plugins.h author Joel Cornett <jocornet@cisco.com> #ifndef PIGLET_PLUGINS_H #define PIGLET_PLUGINS_H void load_piglets(); #endif
{ "language": "C" }
/* * ===================== esrc_gameArchive.h ==================== * -- tpr -- * CREATE -- 2019.05.02 * MODIFY -- * ---------------------------------------------------------- */ #ifndef TPR_ESRC_GAME_ARCHIVE_H #define TPR_ESRC_GAME_ARCHIVE_H //-------------------- Engine --------------------// #include "GameArchive.h" namespace esrc {//------------------ namespace: esrc -------------------------// void init_gameArchive(); GameArchive &get_gameArchive(); }//---------------------- namespace: esrc -------------------------// #endif
{ "language": "C" }
/* * This file is part of wl18xx * * Copyright (C) 2011 Texas Instruments Inc. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA * 02110-1301 USA * */ #include "../wlcore/cmd.h" #include "../wlcore/debug.h" #include "../wlcore/hw_ops.h" #include "cmd.h" int wl18xx_cmd_channel_switch(struct wl1271 *wl, struct wl12xx_vif *wlvif, struct ieee80211_channel_switch *ch_switch) { struct wl18xx_cmd_channel_switch *cmd; u32 supported_rates; int ret; wl1271_debug(DEBUG_ACX, "cmd channel switch"); cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); if (!cmd) { ret = -ENOMEM; goto out; } cmd->role_id = wlvif->role_id; cmd->channel = ch_switch->chandef.chan->hw_value; cmd->switch_time = ch_switch->count; cmd->stop_tx = ch_switch->block_tx; switch (ch_switch->chandef.chan->band) { case IEEE80211_BAND_2GHZ: cmd->band = WLCORE_BAND_2_4GHZ; break; case IEEE80211_BAND_5GHZ: cmd->band = WLCORE_BAND_5GHZ; break; default: wl1271_error("invalid channel switch band: %d", ch_switch->chandef.chan->band); ret = -EINVAL; goto out_free; } supported_rates = CONF_TX_ENABLED_RATES | CONF_TX_MCS_RATES | wlcore_hw_sta_get_ap_rate_mask(wl, wlvif); if (wlvif->p2p) supported_rates &= ~CONF_TX_CCK_RATES; cmd->local_supported_rates = cpu_to_le32(supported_rates); cmd->channel_type = wlvif->channel_type; ret = wl1271_cmd_send(wl, CMD_CHANNEL_SWITCH, cmd, sizeof(*cmd), 0); if (ret < 0) { wl1271_error("failed to send channel switch command"); goto out_free; } out_free: kfree(cmd); out: return ret; }
{ "language": "C" }
/* * OpenAL Helpers * * Copyright (c) 2011 by Chris Robinson <chris.kcat@gmail.com> * * 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. */ /* This file contains routines to help with some menial OpenAL-related tasks, * such as opening a device and setting up a context, closing the device and * destroying its context, converting between frame counts and byte lengths, * finding an appropriate buffer format, and getting readable strings for * channel configs and sample types. */ #include <stdio.h> #include <string.h> #include "AL/al.h" #include "AL/alc.h" #include "AL/alext.h" #include "alhelpers.h" /* InitAL opens a device and sets up a context using default attributes, making * the program ready to call OpenAL functions. */ int InitAL(char ***argv, int *argc) { const ALCchar *name; ALCdevice *device; ALCcontext *ctx; /* Open and initialize a device */ device = NULL; if(argc && argv && *argc > 1 && strcmp((*argv)[0], "-device") == 0) { device = alcOpenDevice((*argv)[1]); if(!device) fprintf(stderr, "Failed to open \"%s\", trying default\n", (*argv)[1]); (*argv) += 2; (*argc) -= 2; } if(!device) device = alcOpenDevice(NULL); if(!device) { fprintf(stderr, "Could not open a device!\n"); return 1; } ctx = alcCreateContext(device, NULL); if(ctx == NULL || alcMakeContextCurrent(ctx) == ALC_FALSE) { if(ctx != NULL) alcDestroyContext(ctx); alcCloseDevice(device); fprintf(stderr, "Could not set a context!\n"); return 1; } name = NULL; if(alcIsExtensionPresent(device, "ALC_ENUMERATE_ALL_EXT")) name = alcGetString(device, ALC_ALL_DEVICES_SPECIFIER); if(!name || alcGetError(device) != AL_NO_ERROR) name = alcGetString(device, ALC_DEVICE_SPECIFIER); printf("Opened \"%s\"\n", name); return 0; } /* CloseAL closes the device belonging to the current context, and destroys the * context. */ void CloseAL(void) { ALCdevice *device; ALCcontext *ctx; ctx = alcGetCurrentContext(); if(ctx == NULL) return; device = alcGetContextsDevice(ctx); alcMakeContextCurrent(NULL); alcDestroyContext(ctx); alcCloseDevice(device); } const char *FormatName(ALenum format) { switch(format) { case AL_FORMAT_MONO8: return "Mono, U8"; case AL_FORMAT_MONO16: return "Mono, S16"; case AL_FORMAT_STEREO8: return "Stereo, U8"; case AL_FORMAT_STEREO16: return "Stereo, S16"; } return "Unknown Format"; }
{ "language": "C" }
/*- * Copyright (c) 2010 Juli Mallett <jmallett@FreeBSD.org> * 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. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR 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 AUTHOR 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. * * $FreeBSD$ */ #ifndef _MIPS_CAVIUM_OCTOPCIVAR_H #define _MIPS_CAVIUM_OCTOPCIVAR_H DECLARE_BUS_SPACE_PROTOTYPES(octopci); extern bus_space_tag_t octopci_bus_space; #endif /* !_MIPS_CAVIUM_OCTOPCIVAR_H */
{ "language": "C" }
/*------------------------------------------------------------------------- * * nodeGroup.h * prototypes for nodeGroup.c * * * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * src/include/executor/nodeGroup.h * *------------------------------------------------------------------------- */ #ifndef NODEGROUP_H #define NODEGROUP_H #include "nodes/execnodes.h" extern GroupState *ExecInitGroup(Group *node, EState *estate, int eflags); extern void ExecEndGroup(GroupState *node); extern void ExecReScanGroup(GroupState *node); #endif /* NODEGROUP_H */
{ "language": "C" }
#ifndef ABYSS_TOKEN_H_INCLUDED #define ABYSS_TOKEN_H_INCLUDED void NextToken(const char ** const pP); char * GetToken(char ** const pP); void GetTokenConst(char ** const pP, const char ** const tokenP); #endif
{ "language": "C" }
/** * \addtogroup uip * @{ */ /** * \addtogroup uiparp * @{ */ /** * \file * Macros and definitions for the ARP module. * \author Adam Dunkels <adam@dunkels.com> */ /* * Copyright (c) 2001-2003, Adam Dunkels. * 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. The name of the author may not be used to endorse or promote * products derived from this software without specific prior * written permission. * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE * GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. * * This file is part of the uIP TCP/IP stack. * * $Id: uip_arp.h,v 1.3.2.2 2003/10/06 15:10:22 adam Exp $ * */ #ifndef __UIP_ARP_H__ #define __UIP_ARP_H__ #include "uip.h" /** * Representation of a 48-bit Ethernet address. */ struct uip_eth_addr { u8_t addr[6]; }; extern struct uip_eth_addr uip_ethaddr; /** * The Ethernet header. */ struct uip_eth_hdr { struct uip_eth_addr dest; struct uip_eth_addr src; u16_t type; }; #define UIP_ETHTYPE_ARP 0x0806 #define UIP_ETHTYPE_IP 0x0800 #define UIP_ETHTYPE_IP6 0x86dd /* The uip_arp_init() function must be called before any of the other ARP functions. */ void uip_arp_init(void); /* The uip_arp_ipin() function should be called whenever an IP packet arrives from the Ethernet. This function refreshes the ARP table or inserts a new mapping if none exists. The function assumes that an IP packet with an Ethernet header is present in the uip_buf buffer and that the length of the packet is in the uip_len variable. */ void uip_arp_ipin(void); /* The uip_arp_arpin() should be called when an ARP packet is received by the Ethernet driver. This function also assumes that the Ethernet frame is present in the uip_buf buffer. When the uip_arp_arpin() function returns, the contents of the uip_buf buffer should be sent out on the Ethernet if the uip_len variable is > 0. */ void uip_arp_arpin(void); /* The uip_arp_out() function should be called when an IP packet should be sent out on the Ethernet. This function creates an Ethernet header before the IP header in the uip_buf buffer. The Ethernet header will have the correct Ethernet MAC destination address filled in if an ARP table entry for the destination IP address (or the IP address of the default router) is present. If no such table entry is found, the IP packet is overwritten with an ARP request and we rely on TCP to retransmit the packet that was overwritten. In any case, the uip_len variable holds the length of the Ethernet frame that should be transmitted. */ void uip_arp_out(void); /* The uip_arp_timer() function should be called every ten seconds. It is responsible for flushing old entries in the ARP table. */ void uip_arp_timer(void); /** @} */ /** * \addtogroup uipconffunc * @{ */ /** * Set the default router's IP address. * * \param addr A pointer to a 4-byte array containing the IP address * of the default router. * * \hideinitializer */ #define uip_setdraddr(addr) do { uip_arp_draddr[0] = addr[0]; \ uip_arp_draddr[1] = addr[1]; } while(0) /** * Set the netmask. * * \param addr A pointer to a 4-byte array containing the IP address * of the netmask. * * \hideinitializer */ #define uip_setnetmask(addr) do { uip_arp_netmask[0] = addr[0]; \ uip_arp_netmask[1] = addr[1]; } while(0) /** * Get the default router's IP address. * * \param addr A pointer to a 4-byte array that will be filled in with * the IP address of the default router. * * \hideinitializer */ #define uip_getdraddr(addr) do { addr[0] = uip_arp_draddr[0]; \ addr[1] = uip_arp_draddr[1]; } while(0) /** * Get the netmask. * * \param addr A pointer to a 4-byte array that will be filled in with * the value of the netmask. * * \hideinitializer */ #define uip_getnetmask(addr) do { addr[0] = uip_arp_netmask[0]; \ addr[1] = uip_arp_netmask[1]; } while(0) /** * Specifiy the Ethernet MAC address. * * The ARP code needs to know the MAC address of the Ethernet card in * order to be able to respond to ARP queries and to generate working * Ethernet headers. * * \note This macro only specifies the Ethernet MAC address to the ARP * code. It cannot be used to change the MAC address of the Ethernet * card. * * \param eaddr A pointer to a struct uip_eth_addr containing the * Ethernet MAC address of the Ethernet card. * * \hideinitializer */ #define uip_setethaddr(eaddr) do {uip_ethaddr.addr[0] = eaddr.addr[0]; \ uip_ethaddr.addr[1] = eaddr.addr[1];\ uip_ethaddr.addr[2] = eaddr.addr[2];\ uip_ethaddr.addr[3] = eaddr.addr[3];\ uip_ethaddr.addr[4] = eaddr.addr[4];\ uip_ethaddr.addr[5] = eaddr.addr[5];} while(0) /** @} */ /** * \internal Internal variables that are set using the macros * uip_setdraddr and uip_setnetmask. */ extern u16_t uip_arp_draddr[2], uip_arp_netmask[2]; #endif /* __UIP_ARP_H__ */
{ "language": "C" }
/* * Copyright (c) 2006-2008 Intel Corporation * Copyright (c) 2007 Dave Airlie <airlied@linux.ie> * * DRM core CRTC related functions * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, 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 copyright holders not be used in advertising or * publicity pertaining to distribution of the software without specific, * written prior permission. The copyright holders make no representations * about the suitability of this software for any purpose. It is provided "as * is" without express or implied warranty. * * THE COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO * EVENT SHALL THE COPYRIGHT HOLDERS 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. * * Authors: * Keith Packard * Eric Anholt <eric@anholt.net> * Dave Airlie <airlied@linux.ie> * Jesse Barnes <jesse.barnes@intel.com> */ #include <linux/export.h> #include <linux/moduleparam.h> #include <drm/drmP.h> #include <drm/drm_crtc.h> #include <drm/drm_fourcc.h> #include <drm/drm_crtc_helper.h> #include <drm/drm_fb_helper.h> #include <drm/drm_edid.h> #include <drm/drm_modeset_helper_vtables.h> #include "drm_crtc_helper_internal.h" /** * DOC: output probing helper overview * * This library provides some helper code for output probing. It provides an * implementation of the core &drm_connector_funcs.fill_modes interface with * drm_helper_probe_single_connector_modes(). * * It also provides support for polling connectors with a work item and for * generic hotplug interrupt handling where the driver doesn't or cannot keep * track of a per-connector hpd interrupt. * * This helper library can be used independently of the modeset helper library. * Drivers can also overwrite different parts e.g. use their own hotplug * handling code to avoid probing unrelated outputs. * * The probe helpers share the function table structures with other display * helper libraries. See &struct drm_connector_helper_funcs for the details. */ static bool drm_kms_helper_poll = true; module_param_named(poll, drm_kms_helper_poll, bool, 0600); static enum drm_mode_status drm_mode_validate_flag(const struct drm_display_mode *mode, int flags) { if ((mode->flags & DRM_MODE_FLAG_INTERLACE) && !(flags & DRM_MODE_FLAG_INTERLACE)) return MODE_NO_INTERLACE; if ((mode->flags & DRM_MODE_FLAG_DBLSCAN) && !(flags & DRM_MODE_FLAG_DBLSCAN)) return MODE_NO_DBLESCAN; if ((mode->flags & DRM_MODE_FLAG_3D_MASK) && !(flags & DRM_MODE_FLAG_3D_MASK)) return MODE_NO_STEREO; return MODE_OK; } static enum drm_mode_status drm_mode_validate_pipeline(struct drm_display_mode *mode, struct drm_connector *connector) { struct drm_device *dev = connector->dev; uint32_t *ids = connector->encoder_ids; enum drm_mode_status ret = MODE_OK; unsigned int i; /* Step 1: Validate against connector */ ret = drm_connector_mode_valid(connector, mode); if (ret != MODE_OK) return ret; /* Step 2: Validate against encoders and crtcs */ for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { struct drm_encoder *encoder = drm_encoder_find(dev, NULL, ids[i]); struct drm_crtc *crtc; if (!encoder) continue; ret = drm_encoder_mode_valid(encoder, mode); if (ret != MODE_OK) { /* No point in continuing for crtc check as this encoder * will not accept the mode anyway. If all encoders * reject the mode then, at exit, ret will not be * MODE_OK. */ continue; } ret = drm_bridge_mode_valid(encoder->bridge, mode); if (ret != MODE_OK) { /* There is also no point in continuing for crtc check * here. */ continue; } drm_for_each_crtc(crtc, dev) { if (!drm_encoder_crtc_ok(encoder, crtc)) continue; ret = drm_crtc_mode_valid(crtc, mode); if (ret == MODE_OK) { /* If we get to this point there is at least * one combination of encoder+crtc that works * for this mode. Lets return now. */ return ret; } } } return ret; } static int drm_helper_probe_add_cmdline_mode(struct drm_connector *connector) { struct drm_cmdline_mode *cmdline_mode; struct drm_display_mode *mode; cmdline_mode = &connector->cmdline_mode; if (!cmdline_mode->specified) return 0; /* Only add a GTF mode if we find no matching probed modes */ list_for_each_entry(mode, &connector->probed_modes, head) { if (mode->hdisplay != cmdline_mode->xres || mode->vdisplay != cmdline_mode->yres) continue; if (cmdline_mode->refresh_specified) { /* The probed mode's vrefresh is set until later */ if (drm_mode_vrefresh(mode) != cmdline_mode->refresh) continue; } return 0; } mode = drm_mode_create_from_cmdline_mode(connector->dev, cmdline_mode); if (mode == NULL) return 0; drm_mode_probed_add(connector, mode); return 1; } enum drm_mode_status drm_crtc_mode_valid(struct drm_crtc *crtc, const struct drm_display_mode *mode) { const struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; if (!crtc_funcs || !crtc_funcs->mode_valid) return MODE_OK; return crtc_funcs->mode_valid(crtc, mode); } enum drm_mode_status drm_encoder_mode_valid(struct drm_encoder *encoder, const struct drm_display_mode *mode) { const struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; if (!encoder_funcs || !encoder_funcs->mode_valid) return MODE_OK; return encoder_funcs->mode_valid(encoder, mode); } enum drm_mode_status drm_connector_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode) { const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; if (!connector_funcs || !connector_funcs->mode_valid) return MODE_OK; return connector_funcs->mode_valid(connector, mode); } #define DRM_OUTPUT_POLL_PERIOD (10*HZ) /** * drm_kms_helper_poll_enable - re-enable output polling. * @dev: drm_device * * This function re-enables the output polling work, after it has been * temporarily disabled using drm_kms_helper_poll_disable(), for example over * suspend/resume. * * Drivers can call this helper from their device resume implementation. It is * not an error to call this even when output polling isn't enabled. * * Note that calls to enable and disable polling must be strictly ordered, which * is automatically the case when they're only call from suspend/resume * callbacks. */ void drm_kms_helper_poll_enable(struct drm_device *dev) { bool poll = false; struct drm_connector *connector; struct drm_connector_list_iter conn_iter; unsigned long delay = DRM_OUTPUT_POLL_PERIOD; if (!dev->mode_config.poll_enabled || !drm_kms_helper_poll) return; drm_connector_list_iter_begin(dev, &conn_iter); drm_for_each_connector_iter(connector, &conn_iter) { if (connector->polled & (DRM_CONNECTOR_POLL_CONNECT | DRM_CONNECTOR_POLL_DISCONNECT)) poll = true; } drm_connector_list_iter_end(&conn_iter); if (dev->mode_config.delayed_event) { /* * FIXME: * * Use short (1s) delay to handle the initial delayed event. * This delay should not be needed, but Optimus/nouveau will * fail in a mysterious way if the delayed event is handled as * soon as possible like it is done in * drm_helper_probe_single_connector_modes() in case the poll * was enabled before. */ poll = true; delay = HZ; } if (poll) schedule_delayed_work(&dev->mode_config.output_poll_work, delay); } EXPORT_SYMBOL(drm_kms_helper_poll_enable); static enum drm_connector_status drm_helper_probe_detect_ctx(struct drm_connector *connector, bool force) { const struct drm_connector_helper_funcs *funcs = connector->helper_private; struct drm_modeset_acquire_ctx ctx; int ret; drm_modeset_acquire_init(&ctx, 0); retry: ret = drm_modeset_lock(&connector->dev->mode_config.connection_mutex, &ctx); if (!ret) { if (funcs->detect_ctx) ret = funcs->detect_ctx(connector, &ctx, force); else if (connector->funcs->detect) ret = connector->funcs->detect(connector, force); else ret = connector_status_connected; } if (ret == -EDEADLK) { drm_modeset_backoff(&ctx); goto retry; } if (WARN_ON(ret < 0)) ret = connector_status_unknown; drm_modeset_drop_locks(&ctx); drm_modeset_acquire_fini(&ctx); return ret; } /** * drm_helper_probe_detect - probe connector status * @connector: connector to probe * @ctx: acquire_ctx, or NULL to let this function handle locking. * @force: Whether destructive probe operations should be performed. * * This function calls the detect callbacks of the connector. * This function returns &drm_connector_status, or * if @ctx is set, it might also return -EDEADLK. */ int drm_helper_probe_detect(struct drm_connector *connector, struct drm_modeset_acquire_ctx *ctx, bool force) { const struct drm_connector_helper_funcs *funcs = connector->helper_private; struct drm_device *dev = connector->dev; int ret; if (!ctx) return drm_helper_probe_detect_ctx(connector, force); ret = drm_modeset_lock(&dev->mode_config.connection_mutex, ctx); if (ret) return ret; if (funcs->detect_ctx) return funcs->detect_ctx(connector, ctx, force); else if (connector->funcs->detect) return connector->funcs->detect(connector, force); else return connector_status_connected; } EXPORT_SYMBOL(drm_helper_probe_detect); /** * drm_helper_probe_single_connector_modes - get complete set of display modes * @connector: connector to probe * @maxX: max width for modes * @maxY: max height for modes * * Based on the helper callbacks implemented by @connector in struct * &drm_connector_helper_funcs try to detect all valid modes. Modes will first * be added to the connector's probed_modes list, then culled (based on validity * and the @maxX, @maxY parameters) and put into the normal modes list. * * Intended to be used as a generic implementation of the * &drm_connector_funcs.fill_modes() vfunc for drivers that use the CRTC helpers * for output mode filtering and detection. * * The basic procedure is as follows * * 1. All modes currently on the connector's modes list are marked as stale * * 2. New modes are added to the connector's probed_modes list with * drm_mode_probed_add(). New modes start their life with status as OK. * Modes are added from a single source using the following priority order. * * - &drm_connector_helper_funcs.get_modes vfunc * - if the connector status is connector_status_connected, standard * VESA DMT modes up to 1024x768 are automatically added * (drm_add_modes_noedid()) * * Finally modes specified via the kernel command line (video=...) are * added in addition to what the earlier probes produced * (drm_helper_probe_add_cmdline_mode()). These modes are generated * using the VESA GTF/CVT formulas. * * 3. Modes are moved from the probed_modes list to the modes list. Potential * duplicates are merged together (see drm_mode_connector_list_update()). * After this step the probed_modes list will be empty again. * * 4. Any non-stale mode on the modes list then undergoes validation * * - drm_mode_validate_basic() performs basic sanity checks * - drm_mode_validate_size() filters out modes larger than @maxX and @maxY * (if specified) * - drm_mode_validate_flag() checks the modes against basic connector * capabilities (interlace_allowed,doublescan_allowed,stereo_allowed) * - the optional &drm_connector_helper_funcs.mode_valid helper can perform * driver and/or sink specific checks * - the optional &drm_crtc_helper_funcs.mode_valid, * &drm_bridge_funcs.mode_valid and &drm_encoder_helper_funcs.mode_valid * helpers can perform driver and/or source specific checks which are also * enforced by the modeset/atomic helpers * * 5. Any mode whose status is not OK is pruned from the connector's modes list, * accompanied by a debug message indicating the reason for the mode's * rejection (see drm_mode_prune_invalid()). * * Returns: * The number of modes found on @connector. */ int drm_helper_probe_single_connector_modes(struct drm_connector *connector, uint32_t maxX, uint32_t maxY) { struct drm_device *dev = connector->dev; struct drm_display_mode *mode; const struct drm_connector_helper_funcs *connector_funcs = connector->helper_private; int count = 0, ret; int mode_flags = 0; bool verbose_prune = true; enum drm_connector_status old_status; struct drm_modeset_acquire_ctx ctx; WARN_ON(!mutex_is_locked(&dev->mode_config.mutex)); drm_modeset_acquire_init(&ctx, 0); DRM_DEBUG_KMS("[CONNECTOR:%d:%s]\n", connector->base.id, connector->name); retry: ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx); if (ret == -EDEADLK) { drm_modeset_backoff(&ctx); goto retry; } else WARN_ON(ret < 0); /* set all old modes to the stale state */ list_for_each_entry(mode, &connector->modes, head) mode->status = MODE_STALE; old_status = connector->status; if (connector->force) { if (connector->force == DRM_FORCE_ON || connector->force == DRM_FORCE_ON_DIGITAL) connector->status = connector_status_connected; else connector->status = connector_status_disconnected; if (connector->funcs->force) connector->funcs->force(connector); } else { ret = drm_helper_probe_detect(connector, &ctx, true); if (ret == -EDEADLK) { drm_modeset_backoff(&ctx); goto retry; } else if (WARN(ret < 0, "Invalid return value %i for connector detection\n", ret)) ret = connector_status_unknown; connector->status = ret; } /* * Normally either the driver's hpd code or the poll loop should * pick up any changes and fire the hotplug event. But if * userspace sneaks in a probe, we might miss a change. Hence * check here, and if anything changed start the hotplug code. */ if (old_status != connector->status) { DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n", connector->base.id, connector->name, drm_get_connector_status_name(old_status), drm_get_connector_status_name(connector->status)); /* * The hotplug event code might call into the fb * helpers, and so expects that we do not hold any * locks. Fire up the poll struct instead, it will * disable itself again. */ dev->mode_config.delayed_event = true; if (dev->mode_config.poll_enabled) schedule_delayed_work(&dev->mode_config.output_poll_work, 0); } /* Re-enable polling in case the global poll config changed. */ if (drm_kms_helper_poll != dev->mode_config.poll_running) drm_kms_helper_poll_enable(dev); dev->mode_config.poll_running = drm_kms_helper_poll; if (connector->status == connector_status_disconnected) { DRM_DEBUG_KMS("[CONNECTOR:%d:%s] disconnected\n", connector->base.id, connector->name); drm_mode_connector_update_edid_property(connector, NULL); verbose_prune = false; goto prune; } count = (*connector_funcs->get_modes)(connector); if (count == 0 && connector->status == connector_status_connected) count = drm_add_modes_noedid(connector, 1024, 768); count += drm_helper_probe_add_cmdline_mode(connector); if (count == 0) goto prune; drm_mode_connector_list_update(connector); if (connector->interlace_allowed) mode_flags |= DRM_MODE_FLAG_INTERLACE; if (connector->doublescan_allowed) mode_flags |= DRM_MODE_FLAG_DBLSCAN; if (connector->stereo_allowed) mode_flags |= DRM_MODE_FLAG_3D_MASK; list_for_each_entry(mode, &connector->modes, head) { if (mode->status == MODE_OK) mode->status = drm_mode_validate_driver(dev, mode); if (mode->status == MODE_OK) mode->status = drm_mode_validate_size(mode, maxX, maxY); if (mode->status == MODE_OK) mode->status = drm_mode_validate_flag(mode, mode_flags); if (mode->status == MODE_OK) mode->status = drm_mode_validate_pipeline(mode, connector); if (mode->status == MODE_OK) mode->status = drm_mode_validate_ycbcr420(mode, connector); } prune: drm_mode_prune_invalid(dev, &connector->modes, verbose_prune); drm_modeset_drop_locks(&ctx); drm_modeset_acquire_fini(&ctx); if (list_empty(&connector->modes)) return 0; list_for_each_entry(mode, &connector->modes, head) mode->vrefresh = drm_mode_vrefresh(mode); drm_mode_sort(&connector->modes); DRM_DEBUG_KMS("[CONNECTOR:%d:%s] probed modes :\n", connector->base.id, connector->name); list_for_each_entry(mode, &connector->modes, head) { drm_mode_set_crtcinfo(mode, CRTC_INTERLACE_HALVE_V); drm_mode_debug_printmodeline(mode); } return count; } EXPORT_SYMBOL(drm_helper_probe_single_connector_modes); /** * drm_kms_helper_hotplug_event - fire off KMS hotplug events * @dev: drm_device whose connector state changed * * This function fires off the uevent for userspace and also calls the * output_poll_changed function, which is most commonly used to inform the fbdev * emulation code and allow it to update the fbcon output configuration. * * Drivers should call this from their hotplug handling code when a change is * detected. Note that this function does not do any output detection of its * own, like drm_helper_hpd_irq_event() does - this is assumed to be done by the * driver already. * * This function must be called from process context with no mode * setting locks held. */ void drm_kms_helper_hotplug_event(struct drm_device *dev) { /* send a uevent + call fbdev */ drm_sysfs_hotplug_event(dev); if (dev->mode_config.funcs->output_poll_changed) dev->mode_config.funcs->output_poll_changed(dev); } EXPORT_SYMBOL(drm_kms_helper_hotplug_event); static void output_poll_execute(struct work_struct *work) { struct delayed_work *delayed_work = to_delayed_work(work); struct drm_device *dev = container_of(delayed_work, struct drm_device, mode_config.output_poll_work); struct drm_connector *connector; struct drm_connector_list_iter conn_iter; enum drm_connector_status old_status; bool repoll = false, changed; /* Pick up any changes detected by the probe functions. */ changed = dev->mode_config.delayed_event; dev->mode_config.delayed_event = false; if (!drm_kms_helper_poll) goto out; if (!mutex_trylock(&dev->mode_config.mutex)) { repoll = true; goto out; } drm_connector_list_iter_begin(dev, &conn_iter); drm_for_each_connector_iter(connector, &conn_iter) { /* Ignore forced connectors. */ if (connector->force) continue; /* Ignore HPD capable connectors and connectors where we don't * want any hotplug detection at all for polling. */ if (!connector->polled || connector->polled == DRM_CONNECTOR_POLL_HPD) continue; old_status = connector->status; /* if we are connected and don't want to poll for disconnect skip it */ if (old_status == connector_status_connected && !(connector->polled & DRM_CONNECTOR_POLL_DISCONNECT)) continue; repoll = true; connector->status = drm_helper_probe_detect(connector, NULL, false); if (old_status != connector->status) { const char *old, *new; /* * The poll work sets force=false when calling detect so * that drivers can avoid to do disruptive tests (e.g. * when load detect cycles could cause flickering on * other, running displays). This bears the risk that we * flip-flop between unknown here in the poll work and * the real state when userspace forces a full detect * call after receiving a hotplug event due to this * change. * * Hence clamp an unknown detect status to the old * value. */ if (connector->status == connector_status_unknown) { connector->status = old_status; continue; } old = drm_get_connector_status_name(old_status); new = drm_get_connector_status_name(connector->status); DRM_DEBUG_KMS("[CONNECTOR:%d:%s] " "status updated from %s to %s\n", connector->base.id, connector->name, old, new); changed = true; } } drm_connector_list_iter_end(&conn_iter); mutex_unlock(&dev->mode_config.mutex); out: if (changed) drm_kms_helper_hotplug_event(dev); if (repoll) schedule_delayed_work(delayed_work, DRM_OUTPUT_POLL_PERIOD); } /** * drm_kms_helper_is_poll_worker - is %current task an output poll worker? * * Determine if %current task is an output poll worker. This can be used * to select distinct code paths for output polling versus other contexts. * * One use case is to avoid a deadlock between the output poll worker and * the autosuspend worker wherein the latter waits for polling to finish * upon calling drm_kms_helper_poll_disable(), while the former waits for * runtime suspend to finish upon calling pm_runtime_get_sync() in a * connector ->detect hook. */ bool drm_kms_helper_is_poll_worker(void) { struct work_struct *work = current_work(); return work && work->func == output_poll_execute; } EXPORT_SYMBOL(drm_kms_helper_is_poll_worker); /** * drm_kms_helper_poll_disable - disable output polling * @dev: drm_device * * This function disables the output polling work. * * Drivers can call this helper from their device suspend implementation. It is * not an error to call this even when output polling isn't enabled or already * disabled. Polling is re-enabled by calling drm_kms_helper_poll_enable(). * * Note that calls to enable and disable polling must be strictly ordered, which * is automatically the case when they're only call from suspend/resume * callbacks. */ void drm_kms_helper_poll_disable(struct drm_device *dev) { if (!dev->mode_config.poll_enabled) return; cancel_delayed_work_sync(&dev->mode_config.output_poll_work); } EXPORT_SYMBOL(drm_kms_helper_poll_disable); /** * drm_kms_helper_poll_init - initialize and enable output polling * @dev: drm_device * * This function intializes and then also enables output polling support for * @dev. Drivers which do not have reliable hotplug support in hardware can use * this helper infrastructure to regularly poll such connectors for changes in * their connection state. * * Drivers can control which connectors are polled by setting the * DRM_CONNECTOR_POLL_CONNECT and DRM_CONNECTOR_POLL_DISCONNECT flags. On * connectors where probing live outputs can result in visual distortion drivers * should not set the DRM_CONNECTOR_POLL_DISCONNECT flag to avoid this. * Connectors which have no flag or only DRM_CONNECTOR_POLL_HPD set are * completely ignored by the polling logic. * * Note that a connector can be both polled and probed from the hotplug handler, * in case the hotplug interrupt is known to be unreliable. */ void drm_kms_helper_poll_init(struct drm_device *dev) { INIT_DELAYED_WORK(&dev->mode_config.output_poll_work, output_poll_execute); dev->mode_config.poll_enabled = true; drm_kms_helper_poll_enable(dev); } EXPORT_SYMBOL(drm_kms_helper_poll_init); /** * drm_kms_helper_poll_fini - disable output polling and clean it up * @dev: drm_device */ void drm_kms_helper_poll_fini(struct drm_device *dev) { drm_kms_helper_poll_disable(dev); } EXPORT_SYMBOL(drm_kms_helper_poll_fini); /** * drm_helper_hpd_irq_event - hotplug processing * @dev: drm_device * * Drivers can use this helper function to run a detect cycle on all connectors * which have the DRM_CONNECTOR_POLL_HPD flag set in their &polled member. All * other connectors are ignored, which is useful to avoid reprobing fixed * panels. * * This helper function is useful for drivers which can't or don't track hotplug * interrupts for each connector. * * Drivers which support hotplug interrupts for each connector individually and * which have a more fine-grained detect logic should bypass this code and * directly call drm_kms_helper_hotplug_event() in case the connector state * changed. * * This function must be called from process context with no mode * setting locks held. * * Note that a connector can be both polled and probed from the hotplug handler, * in case the hotplug interrupt is known to be unreliable. */ bool drm_helper_hpd_irq_event(struct drm_device *dev) { struct drm_connector *connector; struct drm_connector_list_iter conn_iter; enum drm_connector_status old_status; bool changed = false; if (!dev->mode_config.poll_enabled) return false; mutex_lock(&dev->mode_config.mutex); drm_connector_list_iter_begin(dev, &conn_iter); drm_for_each_connector_iter(connector, &conn_iter) { /* Only handle HPD capable connectors. */ if (!(connector->polled & DRM_CONNECTOR_POLL_HPD)) continue; old_status = connector->status; connector->status = drm_helper_probe_detect(connector, NULL, false); DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n", connector->base.id, connector->name, drm_get_connector_status_name(old_status), drm_get_connector_status_name(connector->status)); if (old_status != connector->status) changed = true; } drm_connector_list_iter_end(&conn_iter); mutex_unlock(&dev->mode_config.mutex); if (changed) drm_kms_helper_hotplug_event(dev); return changed; } EXPORT_SYMBOL(drm_helper_hpd_irq_event);
{ "language": "C" }
/* * Copyright (c) 2016 Rockchip Electronics Co. Ltd. * Author: Xing Zheng <zhengxing@rock-chips.com> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #include <linux/clk-provider.h> #include <linux/of.h> #include <linux/of_address.h> #include <linux/platform_device.h> #include <linux/regmap.h> #include <dt-bindings/clock/rk3399-cru.h> #include "clk.h" enum rk3399_plls { lpll, bpll, dpll, cpll, gpll, npll, vpll, }; enum rk3399_pmu_plls { ppll, }; static struct rockchip_pll_rate_table rk3399_pll_rates[] = { /* _mhz, _refdiv, _fbdiv, _postdiv1, _postdiv2, _dsmpd, _frac */ RK3036_PLL_RATE(2208000000, 1, 92, 1, 1, 1, 0), RK3036_PLL_RATE(2184000000, 1, 91, 1, 1, 1, 0), RK3036_PLL_RATE(2160000000, 1, 90, 1, 1, 1, 0), RK3036_PLL_RATE(2136000000, 1, 89, 1, 1, 1, 0), RK3036_PLL_RATE(2112000000, 1, 88, 1, 1, 1, 0), RK3036_PLL_RATE(2088000000, 1, 87, 1, 1, 1, 0), RK3036_PLL_RATE(2064000000, 1, 86, 1, 1, 1, 0), RK3036_PLL_RATE(2040000000, 1, 85, 1, 1, 1, 0), RK3036_PLL_RATE(2016000000, 1, 84, 1, 1, 1, 0), RK3036_PLL_RATE(1992000000, 1, 83, 1, 1, 1, 0), RK3036_PLL_RATE(1968000000, 1, 82, 1, 1, 1, 0), RK3036_PLL_RATE(1944000000, 1, 81, 1, 1, 1, 0), RK3036_PLL_RATE(1920000000, 1, 80, 1, 1, 1, 0), RK3036_PLL_RATE(1896000000, 1, 79, 1, 1, 1, 0), RK3036_PLL_RATE(1872000000, 1, 78, 1, 1, 1, 0), RK3036_PLL_RATE(1848000000, 1, 77, 1, 1, 1, 0), RK3036_PLL_RATE(1824000000, 1, 76, 1, 1, 1, 0), RK3036_PLL_RATE(1800000000, 1, 75, 1, 1, 1, 0), RK3036_PLL_RATE(1776000000, 1, 74, 1, 1, 1, 0), RK3036_PLL_RATE(1752000000, 1, 73, 1, 1, 1, 0), RK3036_PLL_RATE(1728000000, 1, 72, 1, 1, 1, 0), RK3036_PLL_RATE(1704000000, 1, 71, 1, 1, 1, 0), RK3036_PLL_RATE(1680000000, 1, 70, 1, 1, 1, 0), RK3036_PLL_RATE(1656000000, 1, 69, 1, 1, 1, 0), RK3036_PLL_RATE(1632000000, 1, 68, 1, 1, 1, 0), RK3036_PLL_RATE(1608000000, 1, 67, 1, 1, 1, 0), RK3036_PLL_RATE(1600000000, 3, 200, 1, 1, 1, 0), RK3036_PLL_RATE(1584000000, 1, 66, 1, 1, 1, 0), RK3036_PLL_RATE(1560000000, 1, 65, 1, 1, 1, 0), RK3036_PLL_RATE(1536000000, 1, 64, 1, 1, 1, 0), RK3036_PLL_RATE(1512000000, 1, 63, 1, 1, 1, 0), RK3036_PLL_RATE(1488000000, 1, 62, 1, 1, 1, 0), RK3036_PLL_RATE(1464000000, 1, 61, 1, 1, 1, 0), RK3036_PLL_RATE(1440000000, 1, 60, 1, 1, 1, 0), RK3036_PLL_RATE(1416000000, 1, 59, 1, 1, 1, 0), RK3036_PLL_RATE(1392000000, 1, 58, 1, 1, 1, 0), RK3036_PLL_RATE(1368000000, 1, 57, 1, 1, 1, 0), RK3036_PLL_RATE(1344000000, 1, 56, 1, 1, 1, 0), RK3036_PLL_RATE(1320000000, 1, 55, 1, 1, 1, 0), RK3036_PLL_RATE(1296000000, 1, 54, 1, 1, 1, 0), RK3036_PLL_RATE(1272000000, 1, 53, 1, 1, 1, 0), RK3036_PLL_RATE(1248000000, 1, 52, 1, 1, 1, 0), RK3036_PLL_RATE(1200000000, 1, 50, 1, 1, 1, 0), RK3036_PLL_RATE(1188000000, 2, 99, 1, 1, 1, 0), RK3036_PLL_RATE(1104000000, 1, 46, 1, 1, 1, 0), RK3036_PLL_RATE(1100000000, 12, 550, 1, 1, 1, 0), RK3036_PLL_RATE(1008000000, 1, 84, 2, 1, 1, 0), RK3036_PLL_RATE(1000000000, 1, 125, 3, 1, 1, 0), RK3036_PLL_RATE( 984000000, 1, 82, 2, 1, 1, 0), RK3036_PLL_RATE( 960000000, 1, 80, 2, 1, 1, 0), RK3036_PLL_RATE( 936000000, 1, 78, 2, 1, 1, 0), RK3036_PLL_RATE( 912000000, 1, 76, 2, 1, 1, 0), RK3036_PLL_RATE( 900000000, 4, 300, 2, 1, 1, 0), RK3036_PLL_RATE( 888000000, 1, 74, 2, 1, 1, 0), RK3036_PLL_RATE( 864000000, 1, 72, 2, 1, 1, 0), RK3036_PLL_RATE( 840000000, 1, 70, 2, 1, 1, 0), RK3036_PLL_RATE( 816000000, 1, 68, 2, 1, 1, 0), RK3036_PLL_RATE( 800000000, 1, 100, 3, 1, 1, 0), RK3036_PLL_RATE( 700000000, 6, 350, 2, 1, 1, 0), RK3036_PLL_RATE( 696000000, 1, 58, 2, 1, 1, 0), RK3036_PLL_RATE( 676000000, 3, 169, 2, 1, 1, 0), RK3036_PLL_RATE( 600000000, 1, 75, 3, 1, 1, 0), RK3036_PLL_RATE( 594000000, 1, 99, 4, 1, 1, 0), RK3036_PLL_RATE( 533250000, 8, 711, 4, 1, 1, 0), RK3036_PLL_RATE( 504000000, 1, 63, 3, 1, 1, 0), RK3036_PLL_RATE( 500000000, 6, 250, 2, 1, 1, 0), RK3036_PLL_RATE( 408000000, 1, 68, 2, 2, 1, 0), RK3036_PLL_RATE( 312000000, 1, 52, 2, 2, 1, 0), RK3036_PLL_RATE( 297000000, 1, 99, 4, 2, 1, 0), RK3036_PLL_RATE( 216000000, 1, 72, 4, 2, 1, 0), RK3036_PLL_RATE( 148500000, 1, 99, 4, 4, 1, 0), RK3036_PLL_RATE( 106500000, 1, 71, 4, 4, 1, 0), RK3036_PLL_RATE( 96000000, 1, 64, 4, 4, 1, 0), RK3036_PLL_RATE( 74250000, 2, 99, 4, 4, 1, 0), RK3036_PLL_RATE( 65000000, 1, 65, 6, 4, 1, 0), RK3036_PLL_RATE( 54000000, 1, 54, 6, 4, 1, 0), RK3036_PLL_RATE( 27000000, 1, 27, 6, 4, 1, 0), { /* sentinel */ }, }; /* CRU parents */ PNAME(mux_pll_p) = { "xin24m", "xin32k" }; PNAME(mux_armclkl_p) = { "clk_core_l_lpll_src", "clk_core_l_bpll_src", "clk_core_l_dpll_src", "clk_core_l_gpll_src" }; PNAME(mux_armclkb_p) = { "clk_core_b_lpll_src", "clk_core_b_bpll_src", "clk_core_b_dpll_src", "clk_core_b_gpll_src" }; PNAME(mux_ddrclk_p) = { "clk_ddrc_lpll_src", "clk_ddrc_bpll_src", "clk_ddrc_dpll_src", "clk_ddrc_gpll_src" }; PNAME(mux_aclk_cci_p) = { "cpll_aclk_cci_src", "gpll_aclk_cci_src", "npll_aclk_cci_src", "vpll_aclk_cci_src" }; PNAME(mux_cci_trace_p) = { "cpll_cci_trace", "gpll_cci_trace" }; PNAME(mux_cs_p) = { "cpll_cs", "gpll_cs", "npll_cs"}; PNAME(mux_aclk_perihp_p) = { "cpll_aclk_perihp_src", "gpll_aclk_perihp_src" }; PNAME(mux_pll_src_cpll_gpll_p) = { "cpll", "gpll" }; PNAME(mux_pll_src_cpll_gpll_npll_p) = { "cpll", "gpll", "npll" }; PNAME(mux_pll_src_cpll_gpll_ppll_p) = { "cpll", "gpll", "ppll" }; PNAME(mux_pll_src_cpll_gpll_upll_p) = { "cpll", "gpll", "upll" }; PNAME(mux_pll_src_npll_cpll_gpll_p) = { "npll", "cpll", "gpll" }; PNAME(mux_pll_src_cpll_gpll_npll_ppll_p) = { "cpll", "gpll", "npll", "ppll" }; PNAME(mux_pll_src_cpll_gpll_npll_24m_p) = { "cpll", "gpll", "npll", "xin24m" }; PNAME(mux_pll_src_cpll_gpll_npll_usbphy480m_p) = { "cpll", "gpll", "npll", "clk_usbphy_480m" }; PNAME(mux_pll_src_ppll_cpll_gpll_npll_p) = { "ppll", "cpll", "gpll", "npll", "upll" }; PNAME(mux_pll_src_cpll_gpll_npll_upll_24m_p) = { "cpll", "gpll", "npll", "upll", "xin24m" }; PNAME(mux_pll_src_cpll_gpll_npll_ppll_upll_24m_p) = { "cpll", "gpll", "npll", "ppll", "upll", "xin24m" }; PNAME(mux_pll_src_vpll_cpll_gpll_p) = { "vpll", "cpll", "gpll" }; PNAME(mux_pll_src_vpll_cpll_gpll_npll_p) = { "vpll", "cpll", "gpll", "npll" }; PNAME(mux_pll_src_vpll_cpll_gpll_24m_p) = { "vpll", "cpll", "gpll", "xin24m" }; PNAME(mux_dclk_vop0_p) = { "dclk_vop0_div", "dclk_vop0_frac" }; PNAME(mux_dclk_vop1_p) = { "dclk_vop1_div", "dclk_vop1_frac" }; PNAME(mux_clk_cif_p) = { "clk_cifout_src", "xin24m" }; PNAME(mux_pll_src_24m_usbphy480m_p) = { "xin24m", "clk_usbphy_480m" }; PNAME(mux_pll_src_24m_pciephy_p) = { "xin24m", "clk_pciephy_ref100m" }; PNAME(mux_pll_src_24m_32k_cpll_gpll_p) = { "xin24m", "xin32k", "cpll", "gpll" }; PNAME(mux_pciecore_cru_phy_p) = { "clk_pcie_core_cru", "clk_pcie_core_phy" }; PNAME(mux_aclk_emmc_p) = { "cpll_aclk_emmc_src", "gpll_aclk_emmc_src" }; PNAME(mux_aclk_perilp0_p) = { "cpll_aclk_perilp0_src", "gpll_aclk_perilp0_src" }; PNAME(mux_fclk_cm0s_p) = { "cpll_fclk_cm0s_src", "gpll_fclk_cm0s_src" }; PNAME(mux_hclk_perilp1_p) = { "cpll_hclk_perilp1_src", "gpll_hclk_perilp1_src" }; PNAME(mux_clk_testout1_p) = { "clk_testout1_pll_src", "xin24m" }; PNAME(mux_clk_testout2_p) = { "clk_testout2_pll_src", "xin24m" }; PNAME(mux_usbphy_480m_p) = { "clk_usbphy0_480m_src", "clk_usbphy1_480m_src" }; PNAME(mux_aclk_gmac_p) = { "cpll_aclk_gmac_src", "gpll_aclk_gmac_src" }; PNAME(mux_rmii_p) = { "clk_gmac", "clkin_gmac" }; PNAME(mux_spdif_p) = { "clk_spdif_div", "clk_spdif_frac", "clkin_i2s", "xin12m" }; PNAME(mux_i2s0_p) = { "clk_i2s0_div", "clk_i2s0_frac", "clkin_i2s", "xin12m" }; PNAME(mux_i2s1_p) = { "clk_i2s1_div", "clk_i2s1_frac", "clkin_i2s", "xin12m" }; PNAME(mux_i2s2_p) = { "clk_i2s2_div", "clk_i2s2_frac", "clkin_i2s", "xin12m" }; PNAME(mux_i2sch_p) = { "clk_i2s0", "clk_i2s1", "clk_i2s2" }; PNAME(mux_i2sout_p) = { "clk_i2sout_src", "xin12m" }; PNAME(mux_uart0_p) = { "clk_uart0_div", "clk_uart0_frac", "xin24m" }; PNAME(mux_uart1_p) = { "clk_uart1_div", "clk_uart1_frac", "xin24m" }; PNAME(mux_uart2_p) = { "clk_uart2_div", "clk_uart2_frac", "xin24m" }; PNAME(mux_uart3_p) = { "clk_uart3_div", "clk_uart3_frac", "xin24m" }; /* PMU CRU parents */ PNAME(mux_ppll_24m_p) = { "ppll", "xin24m" }; PNAME(mux_24m_ppll_p) = { "xin24m", "ppll" }; PNAME(mux_fclk_cm0s_pmu_ppll_p) = { "fclk_cm0s_pmu_ppll_src", "xin24m" }; PNAME(mux_wifi_pmu_p) = { "clk_wifi_div", "clk_wifi_frac" }; PNAME(mux_uart4_pmu_p) = { "clk_uart4_div", "clk_uart4_frac", "xin24m" }; PNAME(mux_clk_testout2_2io_p) = { "clk_testout2", "clk_32k_suspend_pmu" }; static struct rockchip_pll_clock rk3399_pll_clks[] __initdata = { [lpll] = PLL(pll_rk3399, PLL_APLLL, "lpll", mux_pll_p, 0, RK3399_PLL_CON(0), RK3399_PLL_CON(3), 8, 31, 0, rk3399_pll_rates), [bpll] = PLL(pll_rk3399, PLL_APLLB, "bpll", mux_pll_p, 0, RK3399_PLL_CON(8), RK3399_PLL_CON(11), 8, 31, 0, rk3399_pll_rates), [dpll] = PLL(pll_rk3399, PLL_DPLL, "dpll", mux_pll_p, 0, RK3399_PLL_CON(16), RK3399_PLL_CON(19), 8, 31, 0, NULL), [cpll] = PLL(pll_rk3399, PLL_CPLL, "cpll", mux_pll_p, 0, RK3399_PLL_CON(24), RK3399_PLL_CON(27), 8, 31, ROCKCHIP_PLL_SYNC_RATE, rk3399_pll_rates), [gpll] = PLL(pll_rk3399, PLL_GPLL, "gpll", mux_pll_p, 0, RK3399_PLL_CON(32), RK3399_PLL_CON(35), 8, 31, ROCKCHIP_PLL_SYNC_RATE, rk3399_pll_rates), [npll] = PLL(pll_rk3399, PLL_NPLL, "npll", mux_pll_p, 0, RK3399_PLL_CON(40), RK3399_PLL_CON(43), 8, 31, ROCKCHIP_PLL_SYNC_RATE, rk3399_pll_rates), [vpll] = PLL(pll_rk3399, PLL_VPLL, "vpll", mux_pll_p, 0, RK3399_PLL_CON(48), RK3399_PLL_CON(51), 8, 31, ROCKCHIP_PLL_SYNC_RATE, rk3399_pll_rates), }; static struct rockchip_pll_clock rk3399_pmu_pll_clks[] __initdata = { [ppll] = PLL(pll_rk3399, PLL_PPLL, "ppll", mux_pll_p, 0, RK3399_PMU_PLL_CON(0), RK3399_PMU_PLL_CON(3), 8, 31, ROCKCHIP_PLL_SYNC_RATE, rk3399_pll_rates), }; #define MFLAGS CLK_MUX_HIWORD_MASK #define DFLAGS CLK_DIVIDER_HIWORD_MASK #define GFLAGS (CLK_GATE_HIWORD_MASK | CLK_GATE_SET_TO_DISABLE) #define IFLAGS ROCKCHIP_INVERTER_HIWORD_MASK static struct rockchip_clk_branch rk3399_spdif_fracmux __initdata = MUX(0, "clk_spdif_mux", mux_spdif_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(32), 13, 2, MFLAGS); static struct rockchip_clk_branch rk3399_i2s0_fracmux __initdata = MUX(0, "clk_i2s0_mux", mux_i2s0_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(28), 8, 2, MFLAGS); static struct rockchip_clk_branch rk3399_i2s1_fracmux __initdata = MUX(0, "clk_i2s1_mux", mux_i2s1_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(29), 8, 2, MFLAGS); static struct rockchip_clk_branch rk3399_i2s2_fracmux __initdata = MUX(0, "clk_i2s2_mux", mux_i2s2_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(30), 8, 2, MFLAGS); static struct rockchip_clk_branch rk3399_uart0_fracmux __initdata = MUX(SCLK_UART0, "clk_uart0", mux_uart0_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(33), 8, 2, MFLAGS); static struct rockchip_clk_branch rk3399_uart1_fracmux __initdata = MUX(SCLK_UART1, "clk_uart1", mux_uart1_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(34), 8, 2, MFLAGS); static struct rockchip_clk_branch rk3399_uart2_fracmux __initdata = MUX(SCLK_UART2, "clk_uart2", mux_uart2_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(35), 8, 2, MFLAGS); static struct rockchip_clk_branch rk3399_uart3_fracmux __initdata = MUX(SCLK_UART3, "clk_uart3", mux_uart3_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(36), 8, 2, MFLAGS); static struct rockchip_clk_branch rk3399_uart4_pmu_fracmux __initdata = MUX(SCLK_UART4_PMU, "clk_uart4_pmu", mux_uart4_pmu_p, CLK_SET_RATE_PARENT, RK3399_PMU_CLKSEL_CON(5), 8, 2, MFLAGS); static struct rockchip_clk_branch rk3399_dclk_vop0_fracmux __initdata = MUX(DCLK_VOP0, "dclk_vop0", mux_dclk_vop0_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(49), 11, 1, MFLAGS); static struct rockchip_clk_branch rk3399_dclk_vop1_fracmux __initdata = MUX(DCLK_VOP1, "dclk_vop1", mux_dclk_vop1_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(50), 11, 1, MFLAGS); static struct rockchip_clk_branch rk3399_pmuclk_wifi_fracmux __initdata = MUX(SCLK_WIFI_PMU, "clk_wifi_pmu", mux_wifi_pmu_p, CLK_SET_RATE_PARENT, RK3399_PMU_CLKSEL_CON(1), 14, 1, MFLAGS); static const struct rockchip_cpuclk_reg_data rk3399_cpuclkl_data = { .core_reg = RK3399_CLKSEL_CON(0), .div_core_shift = 0, .div_core_mask = 0x1f, .mux_core_alt = 3, .mux_core_main = 0, .mux_core_shift = 6, .mux_core_mask = 0x3, }; static const struct rockchip_cpuclk_reg_data rk3399_cpuclkb_data = { .core_reg = RK3399_CLKSEL_CON(2), .div_core_shift = 0, .div_core_mask = 0x1f, .mux_core_alt = 3, .mux_core_main = 1, .mux_core_shift = 6, .mux_core_mask = 0x3, }; #define RK3399_DIV_ACLKM_MASK 0x1f #define RK3399_DIV_ACLKM_SHIFT 8 #define RK3399_DIV_ATCLK_MASK 0x1f #define RK3399_DIV_ATCLK_SHIFT 0 #define RK3399_DIV_PCLK_DBG_MASK 0x1f #define RK3399_DIV_PCLK_DBG_SHIFT 8 #define RK3399_CLKSEL0(_offs, _aclkm) \ { \ .reg = RK3399_CLKSEL_CON(0 + _offs), \ .val = HIWORD_UPDATE(_aclkm, RK3399_DIV_ACLKM_MASK, \ RK3399_DIV_ACLKM_SHIFT), \ } #define RK3399_CLKSEL1(_offs, _atclk, _pdbg) \ { \ .reg = RK3399_CLKSEL_CON(1 + _offs), \ .val = HIWORD_UPDATE(_atclk, RK3399_DIV_ATCLK_MASK, \ RK3399_DIV_ATCLK_SHIFT) | \ HIWORD_UPDATE(_pdbg, RK3399_DIV_PCLK_DBG_MASK, \ RK3399_DIV_PCLK_DBG_SHIFT), \ } /* cluster_l: aclkm in clksel0, rest in clksel1 */ #define RK3399_CPUCLKL_RATE(_prate, _aclkm, _atclk, _pdbg) \ { \ .prate = _prate##U, \ .divs = { \ RK3399_CLKSEL0(0, _aclkm), \ RK3399_CLKSEL1(0, _atclk, _pdbg), \ }, \ } /* cluster_b: aclkm in clksel2, rest in clksel3 */ #define RK3399_CPUCLKB_RATE(_prate, _aclkm, _atclk, _pdbg) \ { \ .prate = _prate##U, \ .divs = { \ RK3399_CLKSEL0(2, _aclkm), \ RK3399_CLKSEL1(2, _atclk, _pdbg), \ }, \ } static struct rockchip_cpuclk_rate_table rk3399_cpuclkl_rates[] __initdata = { RK3399_CPUCLKL_RATE(1800000000, 1, 8, 8), RK3399_CPUCLKL_RATE(1704000000, 1, 8, 8), RK3399_CPUCLKL_RATE(1608000000, 1, 7, 7), RK3399_CPUCLKL_RATE(1512000000, 1, 7, 7), RK3399_CPUCLKL_RATE(1488000000, 1, 6, 6), RK3399_CPUCLKL_RATE(1416000000, 1, 6, 6), RK3399_CPUCLKL_RATE(1200000000, 1, 5, 5), RK3399_CPUCLKL_RATE(1008000000, 1, 5, 5), RK3399_CPUCLKL_RATE( 816000000, 1, 4, 4), RK3399_CPUCLKL_RATE( 696000000, 1, 3, 3), RK3399_CPUCLKL_RATE( 600000000, 1, 3, 3), RK3399_CPUCLKL_RATE( 408000000, 1, 2, 2), RK3399_CPUCLKL_RATE( 312000000, 1, 1, 1), RK3399_CPUCLKL_RATE( 216000000, 1, 1, 1), RK3399_CPUCLKL_RATE( 96000000, 1, 1, 1), }; static struct rockchip_cpuclk_rate_table rk3399_cpuclkb_rates[] __initdata = { RK3399_CPUCLKB_RATE(2208000000, 1, 11, 11), RK3399_CPUCLKB_RATE(2184000000, 1, 11, 11), RK3399_CPUCLKB_RATE(2088000000, 1, 10, 10), RK3399_CPUCLKB_RATE(2040000000, 1, 10, 10), RK3399_CPUCLKB_RATE(2016000000, 1, 9, 9), RK3399_CPUCLKB_RATE(1992000000, 1, 9, 9), RK3399_CPUCLKB_RATE(1896000000, 1, 9, 9), RK3399_CPUCLKB_RATE(1800000000, 1, 8, 8), RK3399_CPUCLKB_RATE(1704000000, 1, 8, 8), RK3399_CPUCLKB_RATE(1608000000, 1, 7, 7), RK3399_CPUCLKB_RATE(1512000000, 1, 7, 7), RK3399_CPUCLKB_RATE(1488000000, 1, 6, 6), RK3399_CPUCLKB_RATE(1416000000, 1, 6, 6), RK3399_CPUCLKB_RATE(1200000000, 1, 5, 5), RK3399_CPUCLKB_RATE(1008000000, 1, 5, 5), RK3399_CPUCLKB_RATE( 816000000, 1, 4, 4), RK3399_CPUCLKB_RATE( 696000000, 1, 3, 3), RK3399_CPUCLKB_RATE( 600000000, 1, 3, 3), RK3399_CPUCLKB_RATE( 408000000, 1, 2, 2), RK3399_CPUCLKB_RATE( 312000000, 1, 1, 1), RK3399_CPUCLKB_RATE( 216000000, 1, 1, 1), RK3399_CPUCLKB_RATE( 96000000, 1, 1, 1), }; static struct rockchip_clk_branch rk3399_clk_branches[] __initdata = { /* * CRU Clock-Architecture */ /* usbphy */ GATE(SCLK_USB2PHY0_REF, "clk_usb2phy0_ref", "xin24m", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(6), 5, GFLAGS), GATE(SCLK_USB2PHY1_REF, "clk_usb2phy1_ref", "xin24m", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(6), 6, GFLAGS), GATE(0, "clk_usbphy0_480m_src", "clk_usbphy0_480m", 0, RK3399_CLKGATE_CON(13), 12, GFLAGS), GATE(0, "clk_usbphy1_480m_src", "clk_usbphy1_480m", 0, RK3399_CLKGATE_CON(13), 12, GFLAGS), MUX(0, "clk_usbphy_480m", mux_usbphy_480m_p, 0, RK3399_CLKSEL_CON(14), 6, 1, MFLAGS), MUX(0, "upll", mux_pll_src_24m_usbphy480m_p, 0, RK3399_CLKSEL_CON(14), 15, 1, MFLAGS), COMPOSITE_NODIV(SCLK_HSICPHY, "clk_hsicphy", mux_pll_src_cpll_gpll_npll_usbphy480m_p, 0, RK3399_CLKSEL_CON(19), 0, 2, MFLAGS, RK3399_CLKGATE_CON(6), 4, GFLAGS), COMPOSITE(ACLK_USB3, "aclk_usb3", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(39), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(12), 0, GFLAGS), GATE(ACLK_USB3_NOC, "aclk_usb3_noc", "aclk_usb3", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(30), 0, GFLAGS), GATE(ACLK_USB3OTG0, "aclk_usb3otg0", "aclk_usb3", 0, RK3399_CLKGATE_CON(30), 1, GFLAGS), GATE(ACLK_USB3OTG1, "aclk_usb3otg1", "aclk_usb3", 0, RK3399_CLKGATE_CON(30), 2, GFLAGS), GATE(ACLK_USB3_RKSOC_AXI_PERF, "aclk_usb3_rksoc_axi_perf", "aclk_usb3", 0, RK3399_CLKGATE_CON(30), 3, GFLAGS), GATE(ACLK_USB3_GRF, "aclk_usb3_grf", "aclk_usb3", 0, RK3399_CLKGATE_CON(30), 4, GFLAGS), GATE(SCLK_USB3OTG0_REF, "clk_usb3otg0_ref", "xin24m", 0, RK3399_CLKGATE_CON(12), 1, GFLAGS), GATE(SCLK_USB3OTG1_REF, "clk_usb3otg1_ref", "xin24m", 0, RK3399_CLKGATE_CON(12), 2, GFLAGS), COMPOSITE(SCLK_USB3OTG0_SUSPEND, "clk_usb3otg0_suspend", mux_pll_p, 0, RK3399_CLKSEL_CON(40), 15, 1, MFLAGS, 0, 10, DFLAGS, RK3399_CLKGATE_CON(12), 3, GFLAGS), COMPOSITE(SCLK_USB3OTG1_SUSPEND, "clk_usb3otg1_suspend", mux_pll_p, 0, RK3399_CLKSEL_CON(41), 15, 1, MFLAGS, 0, 10, DFLAGS, RK3399_CLKGATE_CON(12), 4, GFLAGS), COMPOSITE(SCLK_UPHY0_TCPDPHY_REF, "clk_uphy0_tcpdphy_ref", mux_pll_p, 0, RK3399_CLKSEL_CON(64), 15, 1, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(13), 4, GFLAGS), COMPOSITE(SCLK_UPHY0_TCPDCORE, "clk_uphy0_tcpdcore", mux_pll_src_24m_32k_cpll_gpll_p, 0, RK3399_CLKSEL_CON(64), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(13), 5, GFLAGS), COMPOSITE(SCLK_UPHY1_TCPDPHY_REF, "clk_uphy1_tcpdphy_ref", mux_pll_p, 0, RK3399_CLKSEL_CON(65), 15, 1, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(13), 6, GFLAGS), COMPOSITE(SCLK_UPHY1_TCPDCORE, "clk_uphy1_tcpdcore", mux_pll_src_24m_32k_cpll_gpll_p, 0, RK3399_CLKSEL_CON(65), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(13), 7, GFLAGS), /* little core */ GATE(0, "clk_core_l_lpll_src", "lpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(0), 0, GFLAGS), GATE(0, "clk_core_l_bpll_src", "bpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(0), 1, GFLAGS), GATE(0, "clk_core_l_dpll_src", "dpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(0), 2, GFLAGS), GATE(0, "clk_core_l_gpll_src", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(0), 3, GFLAGS), COMPOSITE_NOMUX(0, "aclkm_core_l", "armclkl", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(0), 8, 5, DFLAGS | CLK_DIVIDER_READ_ONLY, RK3399_CLKGATE_CON(0), 4, GFLAGS), COMPOSITE_NOMUX(0, "atclk_core_l", "armclkl", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(1), 0, 5, DFLAGS | CLK_DIVIDER_READ_ONLY, RK3399_CLKGATE_CON(0), 5, GFLAGS), COMPOSITE_NOMUX(0, "pclk_dbg_core_l", "armclkl", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(1), 8, 5, DFLAGS | CLK_DIVIDER_READ_ONLY, RK3399_CLKGATE_CON(0), 6, GFLAGS), GATE(ACLK_CORE_ADB400_CORE_L_2_CCI500, "aclk_core_adb400_core_l_2_cci500", "aclkm_core_l", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 12, GFLAGS), GATE(ACLK_PERF_CORE_L, "aclk_perf_core_l", "aclkm_core_l", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 13, GFLAGS), GATE(0, "clk_dbg_pd_core_l", "armclkl", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 9, GFLAGS), GATE(ACLK_GIC_ADB400_GIC_2_CORE_L, "aclk_core_adb400_gic_2_core_l", "armclkl", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 10, GFLAGS), GATE(ACLK_GIC_ADB400_CORE_L_2_GIC, "aclk_core_adb400_core_l_2_gic", "armclkl", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 11, GFLAGS), GATE(SCLK_PVTM_CORE_L, "clk_pvtm_core_l", "xin24m", 0, RK3399_CLKGATE_CON(0), 7, GFLAGS), /* big core */ GATE(0, "clk_core_b_lpll_src", "lpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(1), 0, GFLAGS), GATE(0, "clk_core_b_bpll_src", "bpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(1), 1, GFLAGS), GATE(0, "clk_core_b_dpll_src", "dpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(1), 2, GFLAGS), GATE(0, "clk_core_b_gpll_src", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(1), 3, GFLAGS), COMPOSITE_NOMUX(0, "aclkm_core_b", "armclkb", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(2), 8, 5, DFLAGS | CLK_DIVIDER_READ_ONLY, RK3399_CLKGATE_CON(1), 4, GFLAGS), COMPOSITE_NOMUX(0, "atclk_core_b", "armclkb", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(3), 0, 5, DFLAGS | CLK_DIVIDER_READ_ONLY, RK3399_CLKGATE_CON(1), 5, GFLAGS), COMPOSITE_NOMUX(0, "pclk_dbg_core_b", "armclkb", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(3), 8, 5, DFLAGS | CLK_DIVIDER_READ_ONLY, RK3399_CLKGATE_CON(1), 6, GFLAGS), GATE(ACLK_CORE_ADB400_CORE_B_2_CCI500, "aclk_core_adb400_core_b_2_cci500", "aclkm_core_b", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 5, GFLAGS), GATE(ACLK_PERF_CORE_B, "aclk_perf_core_b", "aclkm_core_b", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 6, GFLAGS), GATE(0, "clk_dbg_pd_core_b", "armclkb", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 1, GFLAGS), GATE(ACLK_GIC_ADB400_GIC_2_CORE_B, "aclk_core_adb400_gic_2_core_b", "armclkb", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 3, GFLAGS), GATE(ACLK_GIC_ADB400_CORE_B_2_GIC, "aclk_core_adb400_core_b_2_gic", "armclkb", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 4, GFLAGS), DIV(0, "pclken_dbg_core_b", "pclk_dbg_core_b", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(3), 13, 2, DFLAGS | CLK_DIVIDER_READ_ONLY), GATE(0, "pclk_dbg_cxcs_pd_core_b", "pclk_dbg_core_b", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(14), 2, GFLAGS), GATE(SCLK_PVTM_CORE_B, "clk_pvtm_core_b", "xin24m", 0, RK3399_CLKGATE_CON(1), 7, GFLAGS), /* gmac */ GATE(0, "cpll_aclk_gmac_src", "cpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(6), 9, GFLAGS), GATE(0, "gpll_aclk_gmac_src", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(6), 8, GFLAGS), COMPOSITE(0, "aclk_gmac_pre", mux_aclk_gmac_p, 0, RK3399_CLKSEL_CON(20), 7, 1, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(6), 10, GFLAGS), GATE(ACLK_GMAC, "aclk_gmac", "aclk_gmac_pre", 0, RK3399_CLKGATE_CON(32), 0, GFLAGS), GATE(ACLK_GMAC_NOC, "aclk_gmac_noc", "aclk_gmac_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(32), 1, GFLAGS), GATE(ACLK_PERF_GMAC, "aclk_perf_gmac", "aclk_gmac_pre", 0, RK3399_CLKGATE_CON(32), 4, GFLAGS), COMPOSITE_NOMUX(0, "pclk_gmac_pre", "aclk_gmac_pre", 0, RK3399_CLKSEL_CON(19), 8, 3, DFLAGS, RK3399_CLKGATE_CON(6), 11, GFLAGS), GATE(PCLK_GMAC, "pclk_gmac", "pclk_gmac_pre", 0, RK3399_CLKGATE_CON(32), 2, GFLAGS), GATE(PCLK_GMAC_NOC, "pclk_gmac_noc", "pclk_gmac_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(32), 3, GFLAGS), COMPOSITE(SCLK_MAC, "clk_gmac", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(20), 14, 2, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(5), 5, GFLAGS), MUX(SCLK_RMII_SRC, "clk_rmii_src", mux_rmii_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(19), 4, 1, MFLAGS), GATE(SCLK_MACREF_OUT, "clk_mac_refout", "clk_rmii_src", 0, RK3399_CLKGATE_CON(5), 6, GFLAGS), GATE(SCLK_MACREF, "clk_mac_ref", "clk_rmii_src", 0, RK3399_CLKGATE_CON(5), 7, GFLAGS), GATE(SCLK_MAC_RX, "clk_rmii_rx", "clk_rmii_src", 0, RK3399_CLKGATE_CON(5), 8, GFLAGS), GATE(SCLK_MAC_TX, "clk_rmii_tx", "clk_rmii_src", 0, RK3399_CLKGATE_CON(5), 9, GFLAGS), /* spdif */ COMPOSITE(0, "clk_spdif_div", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(32), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(8), 13, GFLAGS), COMPOSITE_FRACMUX(0, "clk_spdif_frac", "clk_spdif_div", 0, RK3399_CLKSEL_CON(99), 0, RK3399_CLKGATE_CON(8), 14, GFLAGS, &rk3399_spdif_fracmux), GATE(SCLK_SPDIF_8CH, "clk_spdif", "clk_spdif_mux", CLK_SET_RATE_PARENT, RK3399_CLKGATE_CON(8), 15, GFLAGS), COMPOSITE(SCLK_SPDIF_REC_DPTX, "clk_spdif_rec_dptx", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(32), 15, 1, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(10), 6, GFLAGS), /* i2s */ COMPOSITE(0, "clk_i2s0_div", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(28), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(8), 3, GFLAGS), COMPOSITE_FRACMUX(0, "clk_i2s0_frac", "clk_i2s0_div", 0, RK3399_CLKSEL_CON(96), 0, RK3399_CLKGATE_CON(8), 4, GFLAGS, &rk3399_i2s0_fracmux), GATE(SCLK_I2S0_8CH, "clk_i2s0", "clk_i2s0_mux", CLK_SET_RATE_PARENT, RK3399_CLKGATE_CON(8), 5, GFLAGS), COMPOSITE(0, "clk_i2s1_div", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(29), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(8), 6, GFLAGS), COMPOSITE_FRACMUX(0, "clk_i2s1_frac", "clk_i2s1_div", 0, RK3399_CLKSEL_CON(97), 0, RK3399_CLKGATE_CON(8), 7, GFLAGS, &rk3399_i2s1_fracmux), GATE(SCLK_I2S1_8CH, "clk_i2s1", "clk_i2s1_mux", CLK_SET_RATE_PARENT, RK3399_CLKGATE_CON(8), 8, GFLAGS), COMPOSITE(0, "clk_i2s2_div", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(30), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(8), 9, GFLAGS), COMPOSITE_FRACMUX(0, "clk_i2s2_frac", "clk_i2s2_div", 0, RK3399_CLKSEL_CON(98), 0, RK3399_CLKGATE_CON(8), 10, GFLAGS, &rk3399_i2s2_fracmux), GATE(SCLK_I2S2_8CH, "clk_i2s2", "clk_i2s2_mux", CLK_SET_RATE_PARENT, RK3399_CLKGATE_CON(8), 11, GFLAGS), MUX(0, "clk_i2sout_src", mux_i2sch_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(31), 0, 2, MFLAGS), COMPOSITE_NODIV(SCLK_I2S_8CH_OUT, "clk_i2sout", mux_i2sout_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(30), 8, 2, MFLAGS, RK3399_CLKGATE_CON(8), 12, GFLAGS), /* uart */ MUX(0, "clk_uart0_src", mux_pll_src_cpll_gpll_upll_p, 0, RK3399_CLKSEL_CON(33), 12, 2, MFLAGS), COMPOSITE_NOMUX(0, "clk_uart0_div", "clk_uart0_src", 0, RK3399_CLKSEL_CON(33), 0, 7, DFLAGS, RK3399_CLKGATE_CON(9), 0, GFLAGS), COMPOSITE_FRACMUX(0, "clk_uart0_frac", "clk_uart0_div", 0, RK3399_CLKSEL_CON(100), 0, RK3399_CLKGATE_CON(9), 1, GFLAGS, &rk3399_uart0_fracmux), MUX(0, "clk_uart_src", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(33), 15, 1, MFLAGS), COMPOSITE_NOMUX(0, "clk_uart1_div", "clk_uart_src", 0, RK3399_CLKSEL_CON(34), 0, 7, DFLAGS, RK3399_CLKGATE_CON(9), 2, GFLAGS), COMPOSITE_FRACMUX(0, "clk_uart1_frac", "clk_uart1_div", 0, RK3399_CLKSEL_CON(101), 0, RK3399_CLKGATE_CON(9), 3, GFLAGS, &rk3399_uart1_fracmux), COMPOSITE_NOMUX(0, "clk_uart2_div", "clk_uart_src", 0, RK3399_CLKSEL_CON(35), 0, 7, DFLAGS, RK3399_CLKGATE_CON(9), 4, GFLAGS), COMPOSITE_FRACMUX(0, "clk_uart2_frac", "clk_uart2_div", 0, RK3399_CLKSEL_CON(102), 0, RK3399_CLKGATE_CON(9), 5, GFLAGS, &rk3399_uart2_fracmux), COMPOSITE_NOMUX(0, "clk_uart3_div", "clk_uart_src", 0, RK3399_CLKSEL_CON(36), 0, 7, DFLAGS, RK3399_CLKGATE_CON(9), 6, GFLAGS), COMPOSITE_FRACMUX(0, "clk_uart3_frac", "clk_uart3_div", 0, RK3399_CLKSEL_CON(103), 0, RK3399_CLKGATE_CON(9), 7, GFLAGS, &rk3399_uart3_fracmux), COMPOSITE(PCLK_DDR, "pclk_ddr", mux_pll_src_cpll_gpll_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(6), 15, 1, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(3), 4, GFLAGS), GATE(PCLK_CENTER_MAIN_NOC, "pclk_center_main_noc", "pclk_ddr", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(18), 10, GFLAGS), GATE(PCLK_DDR_MON, "pclk_ddr_mon", "pclk_ddr", 0, RK3399_CLKGATE_CON(18), 12, GFLAGS), GATE(PCLK_CIC, "pclk_cic", "pclk_ddr", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(18), 15, GFLAGS), GATE(PCLK_DDR_SGRF, "pclk_ddr_sgrf", "pclk_ddr", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(19), 2, GFLAGS), GATE(SCLK_PVTM_DDR, "clk_pvtm_ddr", "xin24m", 0, RK3399_CLKGATE_CON(4), 11, GFLAGS), GATE(SCLK_DFIMON0_TIMER, "clk_dfimon0_timer", "xin24m", 0, RK3399_CLKGATE_CON(3), 5, GFLAGS), GATE(SCLK_DFIMON1_TIMER, "clk_dfimon1_timer", "xin24m", 0, RK3399_CLKGATE_CON(3), 6, GFLAGS), /* cci */ GATE(0, "cpll_aclk_cci_src", "cpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(2), 0, GFLAGS), GATE(0, "gpll_aclk_cci_src", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(2), 1, GFLAGS), GATE(0, "npll_aclk_cci_src", "npll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(2), 2, GFLAGS), GATE(0, "vpll_aclk_cci_src", "vpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(2), 3, GFLAGS), COMPOSITE(0, "aclk_cci_pre", mux_aclk_cci_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(5), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(2), 4, GFLAGS), GATE(ACLK_ADB400M_PD_CORE_L, "aclk_adb400m_pd_core_l", "aclk_cci_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(15), 0, GFLAGS), GATE(ACLK_ADB400M_PD_CORE_B, "aclk_adb400m_pd_core_b", "aclk_cci_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(15), 1, GFLAGS), GATE(ACLK_CCI, "aclk_cci", "aclk_cci_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(15), 2, GFLAGS), GATE(ACLK_CCI_NOC0, "aclk_cci_noc0", "aclk_cci_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(15), 3, GFLAGS), GATE(ACLK_CCI_NOC1, "aclk_cci_noc1", "aclk_cci_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(15), 4, GFLAGS), GATE(ACLK_CCI_GRF, "aclk_cci_grf", "aclk_cci_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(15), 7, GFLAGS), GATE(0, "cpll_cci_trace", "cpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(2), 5, GFLAGS), GATE(0, "gpll_cci_trace", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(2), 6, GFLAGS), COMPOSITE(SCLK_CCI_TRACE, "clk_cci_trace", mux_cci_trace_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(5), 15, 2, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(2), 7, GFLAGS), GATE(0, "cpll_cs", "cpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(2), 8, GFLAGS), GATE(0, "gpll_cs", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(2), 9, GFLAGS), GATE(0, "npll_cs", "npll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(2), 10, GFLAGS), COMPOSITE_NOGATE(0, "clk_cs", mux_cs_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(4), 6, 2, MFLAGS, 0, 5, DFLAGS), GATE(0, "clk_dbg_cxcs", "clk_cs", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(15), 5, GFLAGS), GATE(0, "clk_dbg_noc", "clk_cs", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(15), 6, GFLAGS), /* vcodec */ COMPOSITE(0, "aclk_vcodec_pre", mux_pll_src_cpll_gpll_npll_ppll_p, 0, RK3399_CLKSEL_CON(7), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(4), 0, GFLAGS), COMPOSITE_NOMUX(0, "hclk_vcodec_pre", "aclk_vcodec_pre", 0, RK3399_CLKSEL_CON(7), 8, 5, DFLAGS, RK3399_CLKGATE_CON(4), 1, GFLAGS), GATE(HCLK_VCODEC, "hclk_vcodec", "hclk_vcodec_pre", 0, RK3399_CLKGATE_CON(17), 2, GFLAGS), GATE(0, "hclk_vcodec_noc", "hclk_vcodec_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(17), 3, GFLAGS), GATE(ACLK_VCODEC, "aclk_vcodec", "aclk_vcodec_pre", 0, RK3399_CLKGATE_CON(17), 0, GFLAGS), GATE(0, "aclk_vcodec_noc", "aclk_vcodec_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(17), 1, GFLAGS), /* vdu */ COMPOSITE(SCLK_VDU_CORE, "clk_vdu_core", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(9), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(4), 4, GFLAGS), COMPOSITE(SCLK_VDU_CA, "clk_vdu_ca", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(9), 14, 2, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(4), 5, GFLAGS), COMPOSITE(0, "aclk_vdu_pre", mux_pll_src_cpll_gpll_npll_ppll_p, 0, RK3399_CLKSEL_CON(8), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(4), 2, GFLAGS), COMPOSITE_NOMUX(0, "hclk_vdu_pre", "aclk_vdu_pre", 0, RK3399_CLKSEL_CON(8), 8, 5, DFLAGS, RK3399_CLKGATE_CON(4), 3, GFLAGS), GATE(HCLK_VDU, "hclk_vdu", "hclk_vdu_pre", 0, RK3399_CLKGATE_CON(17), 10, GFLAGS), GATE(HCLK_VDU_NOC, "hclk_vdu_noc", "hclk_vdu_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(17), 11, GFLAGS), GATE(ACLK_VDU, "aclk_vdu", "aclk_vdu_pre", 0, RK3399_CLKGATE_CON(17), 8, GFLAGS), GATE(ACLK_VDU_NOC, "aclk_vdu_noc", "aclk_vdu_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(17), 9, GFLAGS), /* iep */ COMPOSITE(0, "aclk_iep_pre", mux_pll_src_cpll_gpll_npll_ppll_p, 0, RK3399_CLKSEL_CON(10), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(4), 6, GFLAGS), COMPOSITE_NOMUX(0, "hclk_iep_pre", "aclk_iep_pre", 0, RK3399_CLKSEL_CON(10), 8, 5, DFLAGS, RK3399_CLKGATE_CON(4), 7, GFLAGS), GATE(HCLK_IEP, "hclk_iep", "hclk_iep_pre", 0, RK3399_CLKGATE_CON(16), 2, GFLAGS), GATE(HCLK_IEP_NOC, "hclk_iep_noc", "hclk_iep_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(16), 3, GFLAGS), GATE(ACLK_IEP, "aclk_iep", "aclk_iep_pre", 0, RK3399_CLKGATE_CON(16), 0, GFLAGS), GATE(ACLK_IEP_NOC, "aclk_iep_noc", "aclk_iep_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(16), 1, GFLAGS), /* rga */ COMPOSITE(SCLK_RGA_CORE, "clk_rga_core", mux_pll_src_cpll_gpll_npll_ppll_p, 0, RK3399_CLKSEL_CON(12), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(4), 10, GFLAGS), COMPOSITE(0, "aclk_rga_pre", mux_pll_src_cpll_gpll_npll_ppll_p, 0, RK3399_CLKSEL_CON(11), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(4), 8, GFLAGS), COMPOSITE_NOMUX(0, "hclk_rga_pre", "aclk_rga_pre", 0, RK3399_CLKSEL_CON(11), 8, 5, DFLAGS, RK3399_CLKGATE_CON(4), 9, GFLAGS), GATE(HCLK_RGA, "hclk_rga", "hclk_rga_pre", 0, RK3399_CLKGATE_CON(16), 10, GFLAGS), GATE(HCLK_RGA_NOC, "hclk_rga_noc", "hclk_rga_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(16), 11, GFLAGS), GATE(ACLK_RGA, "aclk_rga", "aclk_rga_pre", 0, RK3399_CLKGATE_CON(16), 8, GFLAGS), GATE(ACLK_RGA_NOC, "aclk_rga_noc", "aclk_rga_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(16), 9, GFLAGS), /* center */ COMPOSITE(0, "aclk_center", mux_pll_src_cpll_gpll_npll_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(12), 14, 2, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(3), 7, GFLAGS), GATE(ACLK_CENTER_MAIN_NOC, "aclk_center_main_noc", "aclk_center", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(19), 0, GFLAGS), GATE(ACLK_CENTER_PERI_NOC, "aclk_center_peri_noc", "aclk_center", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(19), 1, GFLAGS), /* gpu */ COMPOSITE(0, "aclk_gpu_pre", mux_pll_src_ppll_cpll_gpll_npll_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(13), 5, 3, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(13), 0, GFLAGS), GATE(ACLK_GPU, "aclk_gpu", "aclk_gpu_pre", 0, RK3399_CLKGATE_CON(30), 8, GFLAGS), GATE(ACLK_PERF_GPU, "aclk_perf_gpu", "aclk_gpu_pre", 0, RK3399_CLKGATE_CON(30), 10, GFLAGS), GATE(ACLK_GPU_GRF, "aclk_gpu_grf", "aclk_gpu_pre", 0, RK3399_CLKGATE_CON(30), 11, GFLAGS), GATE(SCLK_PVTM_GPU, "aclk_pvtm_gpu", "xin24m", 0, RK3399_CLKGATE_CON(13), 1, GFLAGS), /* perihp */ GATE(0, "cpll_aclk_perihp_src", "cpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(5), 1, GFLAGS), GATE(0, "gpll_aclk_perihp_src", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(5), 0, GFLAGS), COMPOSITE(ACLK_PERIHP, "aclk_perihp", mux_aclk_perihp_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(14), 7, 1, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(5), 2, GFLAGS), COMPOSITE_NOMUX(HCLK_PERIHP, "hclk_perihp", "aclk_perihp", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(14), 8, 2, DFLAGS, RK3399_CLKGATE_CON(5), 3, GFLAGS), COMPOSITE_NOMUX(PCLK_PERIHP, "pclk_perihp", "aclk_perihp", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(14), 12, 2, DFLAGS, RK3399_CLKGATE_CON(5), 4, GFLAGS), GATE(ACLK_PERF_PCIE, "aclk_perf_pcie", "aclk_perihp", 0, RK3399_CLKGATE_CON(20), 2, GFLAGS), GATE(ACLK_PCIE, "aclk_pcie", "aclk_perihp", 0, RK3399_CLKGATE_CON(20), 10, GFLAGS), GATE(0, "aclk_perihp_noc", "aclk_perihp", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(20), 12, GFLAGS), GATE(HCLK_HOST0, "hclk_host0", "hclk_perihp", 0, RK3399_CLKGATE_CON(20), 5, GFLAGS), GATE(HCLK_HOST0_ARB, "hclk_host0_arb", "hclk_perihp", 0, RK3399_CLKGATE_CON(20), 6, GFLAGS), GATE(HCLK_HOST1, "hclk_host1", "hclk_perihp", 0, RK3399_CLKGATE_CON(20), 7, GFLAGS), GATE(HCLK_HOST1_ARB, "hclk_host1_arb", "hclk_perihp", 0, RK3399_CLKGATE_CON(20), 8, GFLAGS), GATE(HCLK_HSIC, "hclk_hsic", "hclk_perihp", 0, RK3399_CLKGATE_CON(20), 9, GFLAGS), GATE(0, "hclk_perihp_noc", "hclk_perihp", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(20), 13, GFLAGS), GATE(0, "hclk_ahb1tom", "hclk_perihp", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(20), 15, GFLAGS), GATE(PCLK_PERIHP_GRF, "pclk_perihp_grf", "pclk_perihp", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(20), 4, GFLAGS), GATE(PCLK_PCIE, "pclk_pcie", "pclk_perihp", 0, RK3399_CLKGATE_CON(20), 11, GFLAGS), GATE(0, "pclk_perihp_noc", "pclk_perihp", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(20), 14, GFLAGS), GATE(PCLK_HSICPHY, "pclk_hsicphy", "pclk_perihp", 0, RK3399_CLKGATE_CON(31), 8, GFLAGS), /* sdio & sdmmc */ COMPOSITE(HCLK_SD, "hclk_sd", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(13), 15, 1, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(12), 13, GFLAGS), GATE(HCLK_SDMMC, "hclk_sdmmc", "hclk_sd", 0, RK3399_CLKGATE_CON(33), 8, GFLAGS), GATE(0, "hclk_sdmmc_noc", "hclk_sd", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(33), 9, GFLAGS), COMPOSITE(SCLK_SDIO, "clk_sdio", mux_pll_src_cpll_gpll_npll_ppll_upll_24m_p, 0, RK3399_CLKSEL_CON(15), 8, 3, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(6), 0, GFLAGS), COMPOSITE(SCLK_SDMMC, "clk_sdmmc", mux_pll_src_cpll_gpll_npll_ppll_upll_24m_p, 0, RK3399_CLKSEL_CON(16), 8, 3, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(6), 1, GFLAGS), MMC(SCLK_SDMMC_DRV, "sdmmc_drv", "clk_sdmmc", RK3399_SDMMC_CON0, 1), MMC(SCLK_SDMMC_SAMPLE, "sdmmc_sample", "clk_sdmmc", RK3399_SDMMC_CON1, 1), MMC(SCLK_SDIO_DRV, "sdio_drv", "clk_sdio", RK3399_SDIO_CON0, 1), MMC(SCLK_SDIO_SAMPLE, "sdio_sample", "clk_sdio", RK3399_SDIO_CON1, 1), /* pcie */ COMPOSITE(SCLK_PCIE_PM, "clk_pcie_pm", mux_pll_src_cpll_gpll_npll_24m_p, 0, RK3399_CLKSEL_CON(17), 8, 3, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(6), 2, GFLAGS), COMPOSITE_NOMUX(SCLK_PCIEPHY_REF100M, "clk_pciephy_ref100m", "npll", 0, RK3399_CLKSEL_CON(18), 11, 5, DFLAGS, RK3399_CLKGATE_CON(12), 6, GFLAGS), MUX(SCLK_PCIEPHY_REF, "clk_pciephy_ref", mux_pll_src_24m_pciephy_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(18), 10, 1, MFLAGS), COMPOSITE(0, "clk_pcie_core_cru", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(18), 8, 2, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(6), 3, GFLAGS), MUX(SCLK_PCIE_CORE, "clk_pcie_core", mux_pciecore_cru_phy_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(18), 7, 1, MFLAGS), /* emmc */ COMPOSITE(SCLK_EMMC, "clk_emmc", mux_pll_src_cpll_gpll_npll_upll_24m_p, 0, RK3399_CLKSEL_CON(22), 8, 3, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(6), 14, GFLAGS), GATE(0, "cpll_aclk_emmc_src", "cpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(6), 13, GFLAGS), GATE(0, "gpll_aclk_emmc_src", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(6), 12, GFLAGS), COMPOSITE_NOGATE(ACLK_EMMC, "aclk_emmc", mux_aclk_emmc_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(21), 7, 1, MFLAGS, 0, 5, DFLAGS), GATE(ACLK_EMMC_CORE, "aclk_emmccore", "aclk_emmc", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(32), 8, GFLAGS), GATE(ACLK_EMMC_NOC, "aclk_emmc_noc", "aclk_emmc", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(32), 9, GFLAGS), GATE(ACLK_EMMC_GRF, "aclk_emmcgrf", "aclk_emmc", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(32), 10, GFLAGS), /* perilp0 */ GATE(0, "cpll_aclk_perilp0_src", "cpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(7), 1, GFLAGS), GATE(0, "gpll_aclk_perilp0_src", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(7), 0, GFLAGS), COMPOSITE(ACLK_PERILP0, "aclk_perilp0", mux_aclk_perilp0_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(23), 7, 1, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(7), 2, GFLAGS), COMPOSITE_NOMUX(HCLK_PERILP0, "hclk_perilp0", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(23), 8, 2, DFLAGS, RK3399_CLKGATE_CON(7), 3, GFLAGS), COMPOSITE_NOMUX(PCLK_PERILP0, "pclk_perilp0", "aclk_perilp0", 0, RK3399_CLKSEL_CON(23), 12, 3, DFLAGS, RK3399_CLKGATE_CON(7), 4, GFLAGS), /* aclk_perilp0 gates */ GATE(ACLK_INTMEM, "aclk_intmem", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(23), 0, GFLAGS), GATE(ACLK_TZMA, "aclk_tzma", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(23), 1, GFLAGS), GATE(SCLK_INTMEM0, "clk_intmem0", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(23), 2, GFLAGS), GATE(SCLK_INTMEM1, "clk_intmem1", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(23), 3, GFLAGS), GATE(SCLK_INTMEM2, "clk_intmem2", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(23), 4, GFLAGS), GATE(SCLK_INTMEM3, "clk_intmem3", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(23), 5, GFLAGS), GATE(SCLK_INTMEM4, "clk_intmem4", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(23), 6, GFLAGS), GATE(SCLK_INTMEM5, "clk_intmem5", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(23), 7, GFLAGS), GATE(ACLK_DCF, "aclk_dcf", "aclk_perilp0", 0, RK3399_CLKGATE_CON(23), 8, GFLAGS), GATE(ACLK_DMAC0_PERILP, "aclk_dmac0_perilp", "aclk_perilp0", 0, RK3399_CLKGATE_CON(25), 5, GFLAGS), GATE(ACLK_DMAC1_PERILP, "aclk_dmac1_perilp", "aclk_perilp0", 0, RK3399_CLKGATE_CON(25), 6, GFLAGS), GATE(ACLK_PERILP0_NOC, "aclk_perilp0_noc", "aclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(25), 7, GFLAGS), /* hclk_perilp0 gates */ GATE(HCLK_ROM, "hclk_rom", "hclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(24), 4, GFLAGS), GATE(HCLK_M_CRYPTO0, "hclk_m_crypto0", "hclk_perilp0", 0, RK3399_CLKGATE_CON(24), 5, GFLAGS), GATE(HCLK_S_CRYPTO0, "hclk_s_crypto0", "hclk_perilp0", 0, RK3399_CLKGATE_CON(24), 6, GFLAGS), GATE(HCLK_M_CRYPTO1, "hclk_m_crypto1", "hclk_perilp0", 0, RK3399_CLKGATE_CON(24), 14, GFLAGS), GATE(HCLK_S_CRYPTO1, "hclk_s_crypto1", "hclk_perilp0", 0, RK3399_CLKGATE_CON(24), 15, GFLAGS), GATE(HCLK_PERILP0_NOC, "hclk_perilp0_noc", "hclk_perilp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(25), 8, GFLAGS), /* pclk_perilp0 gates */ GATE(PCLK_DCF, "pclk_dcf", "pclk_perilp0", 0, RK3399_CLKGATE_CON(23), 9, GFLAGS), /* crypto */ COMPOSITE(SCLK_CRYPTO0, "clk_crypto0", mux_pll_src_cpll_gpll_ppll_p, 0, RK3399_CLKSEL_CON(24), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(7), 7, GFLAGS), COMPOSITE(SCLK_CRYPTO1, "clk_crypto1", mux_pll_src_cpll_gpll_ppll_p, 0, RK3399_CLKSEL_CON(26), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(7), 8, GFLAGS), /* cm0s_perilp */ GATE(0, "cpll_fclk_cm0s_src", "cpll", 0, RK3399_CLKGATE_CON(7), 6, GFLAGS), GATE(0, "gpll_fclk_cm0s_src", "gpll", 0, RK3399_CLKGATE_CON(7), 5, GFLAGS), COMPOSITE(FCLK_CM0S, "fclk_cm0s", mux_fclk_cm0s_p, 0, RK3399_CLKSEL_CON(24), 15, 1, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(7), 9, GFLAGS), /* fclk_cm0s gates */ GATE(SCLK_M0_PERILP, "sclk_m0_perilp", "fclk_cm0s", 0, RK3399_CLKGATE_CON(24), 8, GFLAGS), GATE(HCLK_M0_PERILP, "hclk_m0_perilp", "fclk_cm0s", 0, RK3399_CLKGATE_CON(24), 9, GFLAGS), GATE(DCLK_M0_PERILP, "dclk_m0_perilp", "fclk_cm0s", 0, RK3399_CLKGATE_CON(24), 10, GFLAGS), GATE(SCLK_M0_PERILP_DEC, "clk_m0_perilp_dec", "fclk_cm0s", 0, RK3399_CLKGATE_CON(24), 11, GFLAGS), GATE(HCLK_M0_PERILP_NOC, "hclk_m0_perilp_noc", "fclk_cm0s", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(25), 11, GFLAGS), /* perilp1 */ GATE(0, "cpll_hclk_perilp1_src", "cpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(8), 1, GFLAGS), GATE(0, "gpll_hclk_perilp1_src", "gpll", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(8), 0, GFLAGS), COMPOSITE_NOGATE(HCLK_PERILP1, "hclk_perilp1", mux_hclk_perilp1_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(25), 7, 1, MFLAGS, 0, 5, DFLAGS), COMPOSITE_NOMUX(PCLK_PERILP1, "pclk_perilp1", "hclk_perilp1", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(25), 8, 3, DFLAGS, RK3399_CLKGATE_CON(8), 2, GFLAGS), /* hclk_perilp1 gates */ GATE(0, "hclk_perilp1_noc", "hclk_perilp1", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(25), 9, GFLAGS), GATE(0, "hclk_sdio_noc", "hclk_perilp1", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(25), 12, GFLAGS), GATE(HCLK_I2S0_8CH, "hclk_i2s0", "hclk_perilp1", 0, RK3399_CLKGATE_CON(34), 0, GFLAGS), GATE(HCLK_I2S1_8CH, "hclk_i2s1", "hclk_perilp1", 0, RK3399_CLKGATE_CON(34), 1, GFLAGS), GATE(HCLK_I2S2_8CH, "hclk_i2s2", "hclk_perilp1", 0, RK3399_CLKGATE_CON(34), 2, GFLAGS), GATE(HCLK_SPDIF, "hclk_spdif", "hclk_perilp1", 0, RK3399_CLKGATE_CON(34), 3, GFLAGS), GATE(HCLK_SDIO, "hclk_sdio", "hclk_perilp1", 0, RK3399_CLKGATE_CON(34), 4, GFLAGS), GATE(PCLK_SPI5, "pclk_spi5", "hclk_perilp1", 0, RK3399_CLKGATE_CON(34), 5, GFLAGS), GATE(0, "hclk_sdioaudio_noc", "hclk_perilp1", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(34), 6, GFLAGS), /* pclk_perilp1 gates */ GATE(PCLK_UART0, "pclk_uart0", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 0, GFLAGS), GATE(PCLK_UART1, "pclk_uart1", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 1, GFLAGS), GATE(PCLK_UART2, "pclk_uart2", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 2, GFLAGS), GATE(PCLK_UART3, "pclk_uart3", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 3, GFLAGS), GATE(PCLK_I2C7, "pclk_rki2c7", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 5, GFLAGS), GATE(PCLK_I2C1, "pclk_rki2c1", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 6, GFLAGS), GATE(PCLK_I2C5, "pclk_rki2c5", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 7, GFLAGS), GATE(PCLK_I2C6, "pclk_rki2c6", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 8, GFLAGS), GATE(PCLK_I2C2, "pclk_rki2c2", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 9, GFLAGS), GATE(PCLK_I2C3, "pclk_rki2c3", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 10, GFLAGS), GATE(PCLK_MAILBOX0, "pclk_mailbox0", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 11, GFLAGS), GATE(PCLK_SARADC, "pclk_saradc", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 12, GFLAGS), GATE(PCLK_TSADC, "pclk_tsadc", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 13, GFLAGS), GATE(PCLK_EFUSE1024NS, "pclk_efuse1024ns", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 14, GFLAGS), GATE(PCLK_EFUSE1024S, "pclk_efuse1024s", "pclk_perilp1", 0, RK3399_CLKGATE_CON(22), 15, GFLAGS), GATE(PCLK_SPI0, "pclk_spi0", "pclk_perilp1", 0, RK3399_CLKGATE_CON(23), 10, GFLAGS), GATE(PCLK_SPI1, "pclk_spi1", "pclk_perilp1", 0, RK3399_CLKGATE_CON(23), 11, GFLAGS), GATE(PCLK_SPI2, "pclk_spi2", "pclk_perilp1", 0, RK3399_CLKGATE_CON(23), 12, GFLAGS), GATE(PCLK_SPI4, "pclk_spi4", "pclk_perilp1", 0, RK3399_CLKGATE_CON(23), 13, GFLAGS), GATE(PCLK_PERIHP_GRF, "pclk_perilp_sgrf", "pclk_perilp1", 0, RK3399_CLKGATE_CON(24), 13, GFLAGS), GATE(0, "pclk_perilp1_noc", "pclk_perilp1", 0, RK3399_CLKGATE_CON(25), 10, GFLAGS), /* saradc */ COMPOSITE_NOMUX(SCLK_SARADC, "clk_saradc", "xin24m", 0, RK3399_CLKSEL_CON(26), 8, 8, DFLAGS, RK3399_CLKGATE_CON(9), 11, GFLAGS), /* tsadc */ COMPOSITE(SCLK_TSADC, "clk_tsadc", mux_pll_p, 0, RK3399_CLKSEL_CON(27), 15, 1, MFLAGS, 0, 10, DFLAGS, RK3399_CLKGATE_CON(9), 10, GFLAGS), /* cif_testout */ MUX(0, "clk_testout1_pll_src", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(38), 6, 2, MFLAGS), COMPOSITE(SCLK_TESTCLKOUT1, "clk_testout1", mux_clk_testout1_p, 0, RK3399_CLKSEL_CON(38), 5, 1, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(13), 14, GFLAGS), MUX(0, "clk_testout2_pll_src", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(38), 14, 2, MFLAGS), COMPOSITE(SCLK_TESTCLKOUT2, "clk_testout2", mux_clk_testout2_p, 0, RK3399_CLKSEL_CON(38), 13, 1, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(13), 15, GFLAGS), /* vio */ COMPOSITE(ACLK_VIO, "aclk_vio", mux_pll_src_cpll_gpll_ppll_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(42), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(11), 0, GFLAGS), COMPOSITE_NOMUX(PCLK_VIO, "pclk_vio", "aclk_vio", 0, RK3399_CLKSEL_CON(43), 0, 5, DFLAGS, RK3399_CLKGATE_CON(11), 1, GFLAGS), GATE(ACLK_VIO_NOC, "aclk_vio_noc", "aclk_vio", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(29), 0, GFLAGS), GATE(PCLK_MIPI_DSI0, "pclk_mipi_dsi0", "pclk_vio", 0, RK3399_CLKGATE_CON(29), 1, GFLAGS), GATE(PCLK_MIPI_DSI1, "pclk_mipi_dsi1", "pclk_vio", 0, RK3399_CLKGATE_CON(29), 2, GFLAGS), GATE(PCLK_VIO_GRF, "pclk_vio_grf", "pclk_vio", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(29), 12, GFLAGS), /* hdcp */ COMPOSITE(ACLK_HDCP, "aclk_hdcp", mux_pll_src_cpll_gpll_ppll_p, 0, RK3399_CLKSEL_CON(42), 14, 2, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(11), 12, GFLAGS), COMPOSITE_NOMUX(HCLK_HDCP, "hclk_hdcp", "aclk_hdcp", 0, RK3399_CLKSEL_CON(43), 5, 5, DFLAGS, RK3399_CLKGATE_CON(11), 3, GFLAGS), COMPOSITE_NOMUX(PCLK_HDCP, "pclk_hdcp", "aclk_hdcp", 0, RK3399_CLKSEL_CON(43), 10, 5, DFLAGS, RK3399_CLKGATE_CON(11), 10, GFLAGS), GATE(ACLK_HDCP_NOC, "aclk_hdcp_noc", "aclk_hdcp", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(29), 4, GFLAGS), GATE(ACLK_HDCP22, "aclk_hdcp22", "aclk_hdcp", 0, RK3399_CLKGATE_CON(29), 10, GFLAGS), GATE(HCLK_HDCP_NOC, "hclk_hdcp_noc", "hclk_hdcp", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(29), 5, GFLAGS), GATE(HCLK_HDCP22, "hclk_hdcp22", "hclk_hdcp", 0, RK3399_CLKGATE_CON(29), 9, GFLAGS), GATE(PCLK_HDCP_NOC, "pclk_hdcp_noc", "pclk_hdcp", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(29), 3, GFLAGS), GATE(PCLK_HDMI_CTRL, "pclk_hdmi_ctrl", "pclk_hdcp", 0, RK3399_CLKGATE_CON(29), 6, GFLAGS), GATE(PCLK_DP_CTRL, "pclk_dp_ctrl", "pclk_hdcp", 0, RK3399_CLKGATE_CON(29), 7, GFLAGS), GATE(PCLK_HDCP22, "pclk_hdcp22", "pclk_hdcp", 0, RK3399_CLKGATE_CON(29), 8, GFLAGS), GATE(PCLK_GASKET, "pclk_gasket", "pclk_hdcp", 0, RK3399_CLKGATE_CON(29), 11, GFLAGS), /* edp */ COMPOSITE(SCLK_DP_CORE, "clk_dp_core", mux_pll_src_npll_cpll_gpll_p, 0, RK3399_CLKSEL_CON(46), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(11), 8, GFLAGS), COMPOSITE(PCLK_EDP, "pclk_edp", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(44), 15, 1, MFLAGS, 8, 6, DFLAGS, RK3399_CLKGATE_CON(11), 11, GFLAGS), GATE(PCLK_EDP_NOC, "pclk_edp_noc", "pclk_edp", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(32), 12, GFLAGS), GATE(PCLK_EDP_CTRL, "pclk_edp_ctrl", "pclk_edp", 0, RK3399_CLKGATE_CON(32), 13, GFLAGS), /* hdmi */ GATE(SCLK_HDMI_SFR, "clk_hdmi_sfr", "xin24m", 0, RK3399_CLKGATE_CON(11), 6, GFLAGS), COMPOSITE(SCLK_HDMI_CEC, "clk_hdmi_cec", mux_pll_p, 0, RK3399_CLKSEL_CON(45), 15, 1, MFLAGS, 0, 10, DFLAGS, RK3399_CLKGATE_CON(11), 7, GFLAGS), /* vop0 */ COMPOSITE(ACLK_VOP0_PRE, "aclk_vop0_pre", mux_pll_src_vpll_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(47), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(10), 8, GFLAGS), COMPOSITE_NOMUX(0, "hclk_vop0_pre", "aclk_vop0_pre", 0, RK3399_CLKSEL_CON(47), 8, 5, DFLAGS, RK3399_CLKGATE_CON(10), 9, GFLAGS), GATE(ACLK_VOP0, "aclk_vop0", "aclk_vop0_pre", 0, RK3399_CLKGATE_CON(28), 3, GFLAGS), GATE(ACLK_VOP0_NOC, "aclk_vop0_noc", "aclk_vop0_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(28), 1, GFLAGS), GATE(HCLK_VOP0, "hclk_vop0", "hclk_vop0_pre", 0, RK3399_CLKGATE_CON(28), 2, GFLAGS), GATE(HCLK_VOP0_NOC, "hclk_vop0_noc", "hclk_vop0_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(28), 0, GFLAGS), COMPOSITE(DCLK_VOP0_DIV, "dclk_vop0_div", mux_pll_src_vpll_cpll_gpll_p, 0, RK3399_CLKSEL_CON(49), 8, 2, MFLAGS, 0, 8, DFLAGS, RK3399_CLKGATE_CON(10), 12, GFLAGS), COMPOSITE_FRACMUX_NOGATE(DCLK_VOP0_FRAC, "dclk_vop0_frac", "dclk_vop0_div", 0, RK3399_CLKSEL_CON(106), 0, &rk3399_dclk_vop0_fracmux), COMPOSITE(SCLK_VOP0_PWM, "clk_vop0_pwm", mux_pll_src_vpll_cpll_gpll_24m_p, 0, RK3399_CLKSEL_CON(51), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(10), 14, GFLAGS), /* vop1 */ COMPOSITE(ACLK_VOP1_PRE, "aclk_vop1_pre", mux_pll_src_vpll_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(48), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(10), 10, GFLAGS), COMPOSITE_NOMUX(0, "hclk_vop1_pre", "aclk_vop1_pre", 0, RK3399_CLKSEL_CON(48), 8, 5, DFLAGS, RK3399_CLKGATE_CON(10), 11, GFLAGS), GATE(ACLK_VOP1, "aclk_vop1", "aclk_vop1_pre", 0, RK3399_CLKGATE_CON(28), 7, GFLAGS), GATE(ACLK_VOP1_NOC, "aclk_vop1_noc", "aclk_vop1_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(28), 5, GFLAGS), GATE(HCLK_VOP1, "hclk_vop1", "hclk_vop1_pre", 0, RK3399_CLKGATE_CON(28), 6, GFLAGS), GATE(HCLK_VOP1_NOC, "hclk_vop1_noc", "hclk_vop1_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(28), 4, GFLAGS), COMPOSITE(DCLK_VOP1_DIV, "dclk_vop1_div", mux_pll_src_vpll_cpll_gpll_p, 0, RK3399_CLKSEL_CON(50), 8, 2, MFLAGS, 0, 8, DFLAGS, RK3399_CLKGATE_CON(10), 13, GFLAGS), COMPOSITE_FRACMUX_NOGATE(DCLK_VOP1_FRAC, "dclk_vop1_frac", "dclk_vop1_div", 0, RK3399_CLKSEL_CON(107), 0, &rk3399_dclk_vop1_fracmux), COMPOSITE(SCLK_VOP1_PWM, "clk_vop1_pwm", mux_pll_src_vpll_cpll_gpll_24m_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(52), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(10), 15, GFLAGS), /* isp */ COMPOSITE(ACLK_ISP0, "aclk_isp0", mux_pll_src_cpll_gpll_ppll_p, 0, RK3399_CLKSEL_CON(53), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(12), 8, GFLAGS), COMPOSITE_NOMUX(HCLK_ISP0, "hclk_isp0", "aclk_isp0", 0, RK3399_CLKSEL_CON(53), 8, 5, DFLAGS, RK3399_CLKGATE_CON(12), 9, GFLAGS), GATE(ACLK_ISP0_NOC, "aclk_isp0_noc", "aclk_isp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(27), 1, GFLAGS), GATE(ACLK_ISP0_WRAPPER, "aclk_isp0_wrapper", "aclk_isp0", 0, RK3399_CLKGATE_CON(27), 5, GFLAGS), GATE(HCLK_ISP1_WRAPPER, "hclk_isp1_wrapper", "aclk_isp0", 0, RK3399_CLKGATE_CON(27), 7, GFLAGS), GATE(HCLK_ISP0_NOC, "hclk_isp0_noc", "hclk_isp0", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(27), 0, GFLAGS), GATE(HCLK_ISP0_WRAPPER, "hclk_isp0_wrapper", "hclk_isp0", 0, RK3399_CLKGATE_CON(27), 4, GFLAGS), COMPOSITE(SCLK_ISP0, "clk_isp0", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(55), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(11), 4, GFLAGS), COMPOSITE(ACLK_ISP1, "aclk_isp1", mux_pll_src_cpll_gpll_ppll_p, 0, RK3399_CLKSEL_CON(54), 6, 2, MFLAGS, 0, 5, DFLAGS, RK3399_CLKGATE_CON(12), 10, GFLAGS), COMPOSITE_NOMUX(HCLK_ISP1, "hclk_isp1", "aclk_isp1", 0, RK3399_CLKSEL_CON(54), 8, 5, DFLAGS, RK3399_CLKGATE_CON(12), 11, GFLAGS), GATE(ACLK_ISP1_NOC, "aclk_isp1_noc", "aclk_isp1", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(27), 3, GFLAGS), GATE(HCLK_ISP1_NOC, "hclk_isp1_noc", "hclk_isp1", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(27), 2, GFLAGS), GATE(ACLK_ISP1_WRAPPER, "aclk_isp1_wrapper", "hclk_isp1", 0, RK3399_CLKGATE_CON(27), 8, GFLAGS), COMPOSITE(SCLK_ISP1, "clk_isp1", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(55), 14, 2, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(11), 5, GFLAGS), /* * We use pclkin_cifinv by default GRF_SOC_CON20[9] (GSC20_9) setting in system, * so we ignore the mux and make clocks nodes as following, * * pclkin_cifinv --|-------\ * |GSC20_9|-- pclkin_cifmux -- |G27_6| -- pclkin_isp1_wrapper * pclkin_cif --|-------/ */ GATE(PCLK_ISP1_WRAPPER, "pclkin_isp1_wrapper", "pclkin_cif", 0, RK3399_CLKGATE_CON(27), 6, GFLAGS), /* cif */ COMPOSITE_NODIV(0, "clk_cifout_src", mux_pll_src_cpll_gpll_npll_p, 0, RK3399_CLKSEL_CON(56), 6, 2, MFLAGS, RK3399_CLKGATE_CON(10), 7, GFLAGS), COMPOSITE_NOGATE(SCLK_CIF_OUT, "clk_cifout", mux_clk_cif_p, 0, RK3399_CLKSEL_CON(56), 5, 1, MFLAGS, 0, 5, DFLAGS), /* gic */ COMPOSITE(ACLK_GIC_PRE, "aclk_gic_pre", mux_pll_src_cpll_gpll_p, CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(56), 15, 1, MFLAGS, 8, 5, DFLAGS, RK3399_CLKGATE_CON(12), 12, GFLAGS), GATE(ACLK_GIC, "aclk_gic", "aclk_gic_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(33), 0, GFLAGS), GATE(ACLK_GIC_NOC, "aclk_gic_noc", "aclk_gic_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(33), 1, GFLAGS), GATE(ACLK_GIC_ADB400_CORE_L_2_GIC, "aclk_gic_adb400_core_l_2_gic", "aclk_gic_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(33), 2, GFLAGS), GATE(ACLK_GIC_ADB400_CORE_B_2_GIC, "aclk_gic_adb400_core_b_2_gic", "aclk_gic_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(33), 3, GFLAGS), GATE(ACLK_GIC_ADB400_GIC_2_CORE_L, "aclk_gic_adb400_gic_2_core_l", "aclk_gic_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(33), 4, GFLAGS), GATE(ACLK_GIC_ADB400_GIC_2_CORE_B, "aclk_gic_adb400_gic_2_core_b", "aclk_gic_pre", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(33), 5, GFLAGS), /* alive */ /* pclk_alive_gpll_src is controlled by PMUGRF_SOC_CON0[6] */ DIV(PCLK_ALIVE, "pclk_alive", "gpll", 0, RK3399_CLKSEL_CON(57), 0, 5, DFLAGS), GATE(PCLK_USBPHY_MUX_G, "pclk_usbphy_mux_g", "pclk_alive", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(21), 4, GFLAGS), GATE(PCLK_UPHY0_TCPHY_G, "pclk_uphy0_tcphy_g", "pclk_alive", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(21), 5, GFLAGS), GATE(PCLK_UPHY0_TCPD_G, "pclk_uphy0_tcpd_g", "pclk_alive", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(21), 6, GFLAGS), GATE(PCLK_UPHY1_TCPHY_G, "pclk_uphy1_tcphy_g", "pclk_alive", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(21), 8, GFLAGS), GATE(PCLK_UPHY1_TCPD_G, "pclk_uphy1_tcpd_g", "pclk_alive", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(21), 9, GFLAGS), GATE(PCLK_GRF, "pclk_grf", "pclk_alive", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(31), 1, GFLAGS), GATE(PCLK_INTR_ARB, "pclk_intr_arb", "pclk_alive", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(31), 2, GFLAGS), GATE(PCLK_GPIO2, "pclk_gpio2", "pclk_alive", 0, RK3399_CLKGATE_CON(31), 3, GFLAGS), GATE(PCLK_GPIO3, "pclk_gpio3", "pclk_alive", 0, RK3399_CLKGATE_CON(31), 4, GFLAGS), GATE(PCLK_GPIO4, "pclk_gpio4", "pclk_alive", 0, RK3399_CLKGATE_CON(31), 5, GFLAGS), GATE(PCLK_TIMER0, "pclk_timer0", "pclk_alive", 0, RK3399_CLKGATE_CON(31), 6, GFLAGS), GATE(PCLK_TIMER1, "pclk_timer1", "pclk_alive", 0, RK3399_CLKGATE_CON(31), 7, GFLAGS), GATE(PCLK_PMU_INTR_ARB, "pclk_pmu_intr_arb", "pclk_alive", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(31), 9, GFLAGS), GATE(PCLK_SGRF, "pclk_sgrf", "pclk_alive", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(31), 10, GFLAGS), GATE(SCLK_MIPIDPHY_REF, "clk_mipidphy_ref", "xin24m", 0, RK3399_CLKGATE_CON(11), 14, GFLAGS), GATE(SCLK_DPHY_PLL, "clk_dphy_pll", "clk_mipidphy_ref", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(21), 0, GFLAGS), GATE(SCLK_MIPIDPHY_CFG, "clk_mipidphy_cfg", "xin24m", 0, RK3399_CLKGATE_CON(11), 15, GFLAGS), GATE(SCLK_DPHY_TX0_CFG, "clk_dphy_tx0_cfg", "clk_mipidphy_cfg", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(21), 1, GFLAGS), GATE(SCLK_DPHY_TX1RX1_CFG, "clk_dphy_tx1rx1_cfg", "clk_mipidphy_cfg", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(21), 2, GFLAGS), GATE(SCLK_DPHY_RX0_CFG, "clk_dphy_rx0_cfg", "clk_mipidphy_cfg", CLK_IGNORE_UNUSED, RK3399_CLKGATE_CON(21), 3, GFLAGS), /* testout */ MUX(0, "clk_test_pre", mux_pll_src_cpll_gpll_p, CLK_SET_RATE_PARENT, RK3399_CLKSEL_CON(58), 7, 1, MFLAGS), COMPOSITE_FRAC(0, "clk_test_frac", "clk_test_pre", 0, RK3399_CLKSEL_CON(105), 0, RK3399_CLKGATE_CON(13), 9, GFLAGS), DIV(0, "clk_test_24m", "xin24m", 0, RK3399_CLKSEL_CON(57), 6, 10, DFLAGS), /* spi */ COMPOSITE(SCLK_SPI0, "clk_spi0", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(59), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(9), 12, GFLAGS), COMPOSITE(SCLK_SPI1, "clk_spi1", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(59), 15, 1, MFLAGS, 8, 7, DFLAGS, RK3399_CLKGATE_CON(9), 13, GFLAGS), COMPOSITE(SCLK_SPI2, "clk_spi2", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(60), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(9), 14, GFLAGS), COMPOSITE(SCLK_SPI4, "clk_spi4", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(60), 15, 1, MFLAGS, 8, 7, DFLAGS, RK3399_CLKGATE_CON(9), 15, GFLAGS), COMPOSITE(SCLK_SPI5, "clk_spi5", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(58), 15, 1, MFLAGS, 8, 7, DFLAGS, RK3399_CLKGATE_CON(13), 13, GFLAGS), /* i2c */ COMPOSITE(SCLK_I2C1, "clk_i2c1", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(61), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(10), 0, GFLAGS), COMPOSITE(SCLK_I2C2, "clk_i2c2", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(62), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(10), 2, GFLAGS), COMPOSITE(SCLK_I2C3, "clk_i2c3", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(63), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_CLKGATE_CON(10), 4, GFLAGS), COMPOSITE(SCLK_I2C5, "clk_i2c5", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(61), 15, 1, MFLAGS, 8, 7, DFLAGS, RK3399_CLKGATE_CON(10), 1, GFLAGS), COMPOSITE(SCLK_I2C6, "clk_i2c6", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(62), 15, 1, MFLAGS, 8, 7, DFLAGS, RK3399_CLKGATE_CON(10), 3, GFLAGS), COMPOSITE(SCLK_I2C7, "clk_i2c7", mux_pll_src_cpll_gpll_p, 0, RK3399_CLKSEL_CON(63), 15, 1, MFLAGS, 8, 7, DFLAGS, RK3399_CLKGATE_CON(10), 5, GFLAGS), /* timer */ GATE(SCLK_TIMER00, "clk_timer00", "xin24m", 0, RK3399_CLKGATE_CON(26), 0, GFLAGS), GATE(SCLK_TIMER01, "clk_timer01", "xin24m", 0, RK3399_CLKGATE_CON(26), 1, GFLAGS), GATE(SCLK_TIMER02, "clk_timer02", "xin24m", 0, RK3399_CLKGATE_CON(26), 2, GFLAGS), GATE(SCLK_TIMER03, "clk_timer03", "xin24m", 0, RK3399_CLKGATE_CON(26), 3, GFLAGS), GATE(SCLK_TIMER04, "clk_timer04", "xin24m", 0, RK3399_CLKGATE_CON(26), 4, GFLAGS), GATE(SCLK_TIMER05, "clk_timer05", "xin24m", 0, RK3399_CLKGATE_CON(26), 5, GFLAGS), GATE(SCLK_TIMER06, "clk_timer06", "xin24m", 0, RK3399_CLKGATE_CON(26), 6, GFLAGS), GATE(SCLK_TIMER07, "clk_timer07", "xin24m", 0, RK3399_CLKGATE_CON(26), 7, GFLAGS), GATE(SCLK_TIMER08, "clk_timer08", "xin24m", 0, RK3399_CLKGATE_CON(26), 8, GFLAGS), GATE(SCLK_TIMER09, "clk_timer09", "xin24m", 0, RK3399_CLKGATE_CON(26), 9, GFLAGS), GATE(SCLK_TIMER10, "clk_timer10", "xin24m", 0, RK3399_CLKGATE_CON(26), 10, GFLAGS), GATE(SCLK_TIMER11, "clk_timer11", "xin24m", 0, RK3399_CLKGATE_CON(26), 11, GFLAGS), /* clk_test */ /* clk_test_pre is controlled by CRU_MISC_CON[3] */ COMPOSITE_NOMUX(0, "clk_test", "clk_test_pre", CLK_IGNORE_UNUSED, RK3399_CLKSEL_CON(58), 0, 5, DFLAGS, RK3399_CLKGATE_CON(13), 11, GFLAGS), /* ddrc */ GATE(0, "clk_ddrc_lpll_src", "lpll", 0, RK3399_CLKGATE_CON(3), 0, GFLAGS), GATE(0, "clk_ddrc_bpll_src", "bpll", 0, RK3399_CLKGATE_CON(3), 1, GFLAGS), GATE(0, "clk_ddrc_dpll_src", "dpll", 0, RK3399_CLKGATE_CON(3), 2, GFLAGS), GATE(0, "clk_ddrc_gpll_src", "gpll", 0, RK3399_CLKGATE_CON(3), 3, GFLAGS), COMPOSITE_DDRCLK(SCLK_DDRC, "sclk_ddrc", mux_ddrclk_p, 0, RK3399_CLKSEL_CON(6), 4, 2, 0, 0, ROCKCHIP_DDRCLK_SIP), }; static struct rockchip_clk_branch rk3399_clk_pmu_branches[] __initdata = { /* * PMU CRU Clock-Architecture */ GATE(0, "fclk_cm0s_pmu_ppll_src", "ppll", 0, RK3399_PMU_CLKGATE_CON(0), 1, GFLAGS), COMPOSITE_NOGATE(FCLK_CM0S_SRC_PMU, "fclk_cm0s_src_pmu", mux_fclk_cm0s_pmu_ppll_p, 0, RK3399_PMU_CLKSEL_CON(0), 15, 1, MFLAGS, 8, 5, DFLAGS), COMPOSITE(SCLK_SPI3_PMU, "clk_spi3_pmu", mux_24m_ppll_p, 0, RK3399_PMU_CLKSEL_CON(1), 7, 1, MFLAGS, 0, 7, DFLAGS, RK3399_PMU_CLKGATE_CON(0), 2, GFLAGS), COMPOSITE(0, "clk_wifi_div", mux_ppll_24m_p, CLK_IGNORE_UNUSED, RK3399_PMU_CLKSEL_CON(1), 13, 1, MFLAGS, 8, 5, DFLAGS, RK3399_PMU_CLKGATE_CON(0), 8, GFLAGS), COMPOSITE_FRACMUX_NOGATE(0, "clk_wifi_frac", "clk_wifi_div", 0, RK3399_PMU_CLKSEL_CON(7), 0, &rk3399_pmuclk_wifi_fracmux), MUX(0, "clk_timer_src_pmu", mux_pll_p, CLK_IGNORE_UNUSED, RK3399_PMU_CLKSEL_CON(1), 15, 1, MFLAGS), COMPOSITE_NOMUX(SCLK_I2C0_PMU, "clk_i2c0_pmu", "ppll", 0, RK3399_PMU_CLKSEL_CON(2), 0, 7, DFLAGS, RK3399_PMU_CLKGATE_CON(0), 9, GFLAGS), COMPOSITE_NOMUX(SCLK_I2C4_PMU, "clk_i2c4_pmu", "ppll", 0, RK3399_PMU_CLKSEL_CON(3), 0, 7, DFLAGS, RK3399_PMU_CLKGATE_CON(0), 10, GFLAGS), COMPOSITE_NOMUX(SCLK_I2C8_PMU, "clk_i2c8_pmu", "ppll", 0, RK3399_PMU_CLKSEL_CON(2), 8, 7, DFLAGS, RK3399_PMU_CLKGATE_CON(0), 11, GFLAGS), DIV(0, "clk_32k_suspend_pmu", "xin24m", CLK_IGNORE_UNUSED, RK3399_PMU_CLKSEL_CON(4), 0, 10, DFLAGS), MUX(0, "clk_testout_2io", mux_clk_testout2_2io_p, CLK_IGNORE_UNUSED, RK3399_PMU_CLKSEL_CON(4), 15, 1, MFLAGS), COMPOSITE(0, "clk_uart4_div", mux_24m_ppll_p, 0, RK3399_PMU_CLKSEL_CON(5), 10, 1, MFLAGS, 0, 7, DFLAGS, RK3399_PMU_CLKGATE_CON(0), 5, GFLAGS), COMPOSITE_FRACMUX(0, "clk_uart4_frac", "clk_uart4_div", 0, RK3399_PMU_CLKSEL_CON(6), 0, RK3399_PMU_CLKGATE_CON(0), 6, GFLAGS, &rk3399_uart4_pmu_fracmux), DIV(PCLK_SRC_PMU, "pclk_pmu_src", "ppll", CLK_IGNORE_UNUSED, RK3399_PMU_CLKSEL_CON(0), 0, 5, DFLAGS), /* pmu clock gates */ GATE(SCLK_TIMER12_PMU, "clk_timer0_pmu", "clk_timer_src_pmu", 0, RK3399_PMU_CLKGATE_CON(0), 3, GFLAGS), GATE(SCLK_TIMER13_PMU, "clk_timer1_pmu", "clk_timer_src_pmu", 0, RK3399_PMU_CLKGATE_CON(0), 4, GFLAGS), GATE(SCLK_PVTM_PMU, "clk_pvtm_pmu", "xin24m", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(0), 7, GFLAGS), GATE(PCLK_PMU, "pclk_pmu", "pclk_pmu_src", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(1), 0, GFLAGS), GATE(PCLK_PMUGRF_PMU, "pclk_pmugrf_pmu", "pclk_pmu_src", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(1), 1, GFLAGS), GATE(PCLK_INTMEM1_PMU, "pclk_intmem1_pmu", "pclk_pmu_src", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(1), 2, GFLAGS), GATE(PCLK_GPIO0_PMU, "pclk_gpio0_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 3, GFLAGS), GATE(PCLK_GPIO1_PMU, "pclk_gpio1_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 4, GFLAGS), GATE(PCLK_SGRF_PMU, "pclk_sgrf_pmu", "pclk_pmu_src", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(1), 5, GFLAGS), GATE(PCLK_NOC_PMU, "pclk_noc_pmu", "pclk_pmu_src", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(1), 6, GFLAGS), GATE(PCLK_I2C0_PMU, "pclk_i2c0_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 7, GFLAGS), GATE(PCLK_I2C4_PMU, "pclk_i2c4_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 8, GFLAGS), GATE(PCLK_I2C8_PMU, "pclk_i2c8_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 9, GFLAGS), GATE(PCLK_RKPWM_PMU, "pclk_rkpwm_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 10, GFLAGS), GATE(PCLK_SPI3_PMU, "pclk_spi3_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 11, GFLAGS), GATE(PCLK_TIMER_PMU, "pclk_timer_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 12, GFLAGS), GATE(PCLK_MAILBOX_PMU, "pclk_mailbox_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 13, GFLAGS), GATE(PCLK_UART4_PMU, "pclk_uart4_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 14, GFLAGS), GATE(PCLK_WDT_M0_PMU, "pclk_wdt_m0_pmu", "pclk_pmu_src", 0, RK3399_PMU_CLKGATE_CON(1), 15, GFLAGS), GATE(FCLK_CM0S_PMU, "fclk_cm0s_pmu", "fclk_cm0s_src_pmu", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(2), 0, GFLAGS), GATE(SCLK_CM0S_PMU, "sclk_cm0s_pmu", "fclk_cm0s_src_pmu", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(2), 1, GFLAGS), GATE(HCLK_CM0S_PMU, "hclk_cm0s_pmu", "fclk_cm0s_src_pmu", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(2), 2, GFLAGS), GATE(DCLK_CM0S_PMU, "dclk_cm0s_pmu", "fclk_cm0s_src_pmu", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(2), 3, GFLAGS), GATE(HCLK_NOC_PMU, "hclk_noc_pmu", "fclk_cm0s_src_pmu", CLK_IGNORE_UNUSED, RK3399_PMU_CLKGATE_CON(2), 5, GFLAGS), }; static const char *const rk3399_cru_critical_clocks[] __initconst = { "aclk_cci_pre", "aclk_gic", "aclk_gic_noc", "aclk_hdcp_noc", "hclk_hdcp_noc", "pclk_hdcp_noc", "pclk_perilp0", "pclk_perilp0", "hclk_perilp0", "hclk_perilp0_noc", "pclk_perilp1", "pclk_perilp1_noc", "pclk_perihp", "pclk_perihp_noc", "hclk_perihp", "aclk_perihp", "aclk_perihp_noc", "aclk_perilp0", "aclk_perilp0_noc", "hclk_perilp1", "hclk_perilp1_noc", "aclk_dmac0_perilp", "aclk_emmc_noc", "gpll_hclk_perilp1_src", "gpll_aclk_perilp0_src", "gpll_aclk_perihp_src", "aclk_vio_noc", /* ddrc */ "sclk_ddrc" }; static const char *const rk3399_pmucru_critical_clocks[] __initconst = { "ppll", "pclk_pmu_src", "fclk_cm0s_src_pmu", "clk_timer_src_pmu", }; static void __init rk3399_clk_init(struct device_node *np) { struct rockchip_clk_provider *ctx; void __iomem *reg_base; struct clk *clk; reg_base = of_iomap(np, 0); if (!reg_base) { pr_err("%s: could not map cru region\n", __func__); return; } ctx = rockchip_clk_init(np, reg_base, CLK_NR_CLKS); if (IS_ERR(ctx)) { pr_err("%s: rockchip clk init failed\n", __func__); iounmap(reg_base); return; } /* Watchdog pclk is controlled by RK3399 SECURE_GRF_SOC_CON3[8]. */ clk = clk_register_fixed_factor(NULL, "pclk_wdt", "pclk_alive", 0, 1, 1); if (IS_ERR(clk)) pr_warn("%s: could not register clock pclk_wdt: %ld\n", __func__, PTR_ERR(clk)); else rockchip_clk_add_lookup(ctx, clk, PCLK_WDT); rockchip_clk_register_plls(ctx, rk3399_pll_clks, ARRAY_SIZE(rk3399_pll_clks), -1); rockchip_clk_register_branches(ctx, rk3399_clk_branches, ARRAY_SIZE(rk3399_clk_branches)); rockchip_clk_protect_critical(rk3399_cru_critical_clocks, ARRAY_SIZE(rk3399_cru_critical_clocks)); rockchip_clk_register_armclk(ctx, ARMCLKL, "armclkl", mux_armclkl_p, ARRAY_SIZE(mux_armclkl_p), &rk3399_cpuclkl_data, rk3399_cpuclkl_rates, ARRAY_SIZE(rk3399_cpuclkl_rates)); rockchip_clk_register_armclk(ctx, ARMCLKB, "armclkb", mux_armclkb_p, ARRAY_SIZE(mux_armclkb_p), &rk3399_cpuclkb_data, rk3399_cpuclkb_rates, ARRAY_SIZE(rk3399_cpuclkb_rates)); rockchip_register_softrst(np, 21, reg_base + RK3399_SOFTRST_CON(0), ROCKCHIP_SOFTRST_HIWORD_MASK); rockchip_register_restart_notifier(ctx, RK3399_GLB_SRST_FST, NULL); rockchip_clk_of_add_provider(np, ctx); } CLK_OF_DECLARE(rk3399_cru, "rockchip,rk3399-cru", rk3399_clk_init); static void __init rk3399_pmu_clk_init(struct device_node *np) { struct rockchip_clk_provider *ctx; void __iomem *reg_base; reg_base = of_iomap(np, 0); if (!reg_base) { pr_err("%s: could not map cru pmu region\n", __func__); return; } ctx = rockchip_clk_init(np, reg_base, CLKPMU_NR_CLKS); if (IS_ERR(ctx)) { pr_err("%s: rockchip pmu clk init failed\n", __func__); iounmap(reg_base); return; } rockchip_clk_register_plls(ctx, rk3399_pmu_pll_clks, ARRAY_SIZE(rk3399_pmu_pll_clks), -1); rockchip_clk_register_branches(ctx, rk3399_clk_pmu_branches, ARRAY_SIZE(rk3399_clk_pmu_branches)); rockchip_clk_protect_critical(rk3399_pmucru_critical_clocks, ARRAY_SIZE(rk3399_pmucru_critical_clocks)); rockchip_register_softrst(np, 2, reg_base + RK3399_PMU_SOFTRST_CON(0), ROCKCHIP_SOFTRST_HIWORD_MASK); rockchip_clk_of_add_provider(np, ctx); } CLK_OF_DECLARE(rk3399_cru_pmu, "rockchip,rk3399-pmucru", rk3399_pmu_clk_init);
{ "language": "C" }
/*****************************************************************************/ #define TWI_CMD_PAGEUPDATE 0x01 // TWI Command to program a flash page #define TWI_CMD_EXECUTEAPP 0x02 // TWI Command to jump to the application program #define TWI_CMD_SETREAD_ADDRESS 0x03 // TWI Command to set address to read from #define TWI_CMD_WRITE_DATA 0x04 // TWI Command send data to the application #define TWI_CMD_REBOOT 0x55 // TWI Command to restart back in the bootloader #define TWI_SUBCMD_SETDATETIME 0x74 // TWI Command to set the date and time #define TWI_SUBCMD_SETOUTPUTS 0x75 // TWI Command to set outputs //#define TWI_CMD_BVERSION 0x04 // TWI Command to get the bootloader revision identifier //#define TWI_CMD_ERASEFLASH 0x05 // TWI Command to erase the entire application section of flash memory //#define TWI_CMD_GETERRCONDN 0x07 // TWI Command to get Error condition /*****************************************************************************/ //#define BOOT_SETTLE_DELAY 100 // Debounce delay for the boot pin in MCU cycles //#define SLAVE_ADDRESS 0xb0 // The address identifier of this slave device on the TWI (I2C) bus #define INTVECT_PAGE_ADDRESS 0x000 // The location of the start of the interrupt vector table address // Select the communcation interfacing type: TWI or USI /*#if defined(__ATTINY25__) | defined(__ATTINY25V__) | \ defined(__ATTINY45__) | defined(__ATTINY45V__) | \ defined(__ATTINY85__) | defined(__ATTINY85V__) | \ defined(__ATTINY24__) | defined(__ATTINY24A__) | \ defined(__ATTINY44__) | defined(__ATTINY44A__) | \ defined(__ATTINY84__) | defined(__ATTINY84A__) | \ defined(__ATTINY2313__) | defined(__ATTINY2313A__) | \ defined(__ATTINY4313__) | defined(__ATTINY4313A__) | \ defined(__ATTINY261__) | defined(__ATTINY261A__) | \ defined(__ATTINY461__) | defined(__ATTINY461A__) | \ defined(__ATTINY861__) | defined(__ATTINY861A__) | \ defined(__ATTINY43U__) | \ defined(__ATTINY87__) | \ defined(__ATTINY167__) #define __USI__ // set the communication type as USI #endif */ #define __USI__ // set the communication type as USI /*#if defined(__ATTINY48__) | defined(__ATTINY88__) | \ defined(__ATMEGA48A__) | defined(__ATMEGA48PA__) | \ defined(__ATMEGA48__) #define __TWI__ #endif */ /***************************************************************/ // Page size selection for the controller with 2K flash /*#if defined(__ATTINY25__) | defined(__ATTINY25V__) | \ defined(__ATTINY24__) | defined(__ATTINY24A__) | \ defined(__ATTINY2313__) | defined(__ATTINY2313A__) | \ defined(__ATTINY261__) | defined(__ATTINY261A__) // The flash memory page size for these devices #define PAGE_SIZE 32 // Page 32, the start of bootloader section #define BOOT_PAGE_ADDRESS 0X0400 // 2KB of flash divided by pages of size 32 bytes #define TOTAL_NO_OF_PAGES 64 // The number of pages being used for bootloader code #define BOOTLOADER_PAGES (TOTAL_NO_OF_PAGES - BOOT_PAGE_ADDRESS/PAGE_SIZE) // For bounds check during page write/erase operation to protect the bootloader code from being corrupted #define LAST_PAGE_NO_TO_BE_ERASED (TOTAL_NO_OF_PAGES - BOOTLOADER_PAGES) #endif */ // Page size selection for the controller with 4K flash /*#if defined(__ATTINY45__) | defined(__ATTINY45V__) | \ defined(__ATTINY44__) | defined(__ATTINY44A__) | \ defined(__ATTINY4313__) | defined(__ATTINY4313A__) | \ defined(__ATTINY461__) | defined(__ATTINY461A__) | \ defined(__ATTINY43U__) | \ defined(__ATTINY48__) | \ defined(__ATMEGA48__) | \ defined(__ATMEGA48A__) | defined(__ATMEGA48PA__) // The flash memory page size for these devices #define PAGE_SIZE 64 // Page 48, the start of bootloader section #define BOOT_PAGE_ADDRESS 0X0C00 // 4KB of flash divided by pages of size 64 bytes #define TOTAL_NO_OF_PAGES 64 // The number of pages being used for bootloader code #define BOOTLOADER_PAGES (TOTAL_NO_OF_PAGES - BOOT_PAGE_ADDRESS/PAGE_SIZE) // For bounds check during page write/erase operation to protect the bootloader code from being corrupted #define LAST_PAGE_NO_TO_BE_ERASED (TOTAL_NO_OF_PAGES - BOOTLOADER_PAGES) #endif */ // Page size selection for the controller with 8K flash /*#if defined(__ATTINY85__) | defined(__ATTINY85V__) | \ defined(__ATTINY84__) | defined(__ATTINY84A__) | \ defined(__ATTINY861__) | defined(__ATTINY861A__) | \ defined(__ATTINY87__) | \ defined(__ATTINY88__) // The flash memory page size for these devices #define PAGE_SIZE 64 // Page 112, the start of bootloader section #define BOOT_PAGE_ADDRESS 0X1C00 // 8KB of flash divided by pages of size 64 bytes #define TOTAL_NO_OF_PAGES 128 // The number of pages being used for bootloader code #define BOOTLOADER_PAGES (TOTAL_NO_OF_PAGES - BOOT_PAGE_ADDRESS/PAGE_SIZE) // // For bounds check during page write/erase operation to protect the bootloader code from being corrupted // #define LAST_PAGE_NO_TO_BE_ERASED (TOTAL_NO_OF_PAGES - BOOTLOADER_PAGES) //#endif*/ // Page size selection for the controller with 16K flash //#if defined(__ATTINY167__) // The flash memory page size for Atiny167 #define PAGE_SIZE 128 // Page 120, the start of bootloader section #define BOOT_PAGE_ADDRESS 0X3800 // 16KB of flash divided by pages of size 128 bytes #define TOTAL_NO_OF_PAGES 128 // The number of pages being used for bootloader code #define BOOTLOADER_PAGES (TOTAL_NO_OF_PAGES - BOOT_PAGE_ADDRESS/PAGE_SIZE) // For bounds check during page write/erase operation to protect the bootloader code from being corrupted #define LAST_PAGE_NO_TO_BE_ERASED (TOTAL_NO_OF_PAGES - BOOTLOADER_PAGES) //#endif /*****************************************************************************/ /*****************************************************************************/ // Select the correct Bit name of to SELFPROGRAMming /*#if defined(__ATTINY48__) | defined(__ATTINY48A__) | \ defined(__ATTINY88__) | defined(__ATTINY88A__) | \ defined(__ATMEGA48__) | \ defined(__ATMEGA48A__) | defined(__ATMEGA48PA__) #define SELFPROGEN SELFPRGEN #endif */ /*****************************************************************************/ /*****************************************************************************/ /*#if defined(__ATTINY25__) | defined(__ATTINY25V__) | \ defined(__ATTINY45__) | defined(__ATTINY45V__) | \ defined(__ATTINY85__) | defined(__ATTINY85V__) | \ defined(__ATTINY87__) | defined(__ATTINY167__) */ #define SELFPROGEN SPMEN //#endif /*****************************************************************************/ /*****************************************************************************/ #define WDT_TIMEOUT_8s ( _BV( WDP3 ) | _BV( WDP0 ) ) // Watchdog timeout for inactivity in the boot section #define WDT_TIMEOUT_16ms 0 // Watchdog timeout for system reset (cleanup) before jump to application #define WDT_TIMEOUT_min WDT_TIMEOUT_16ms // The minimum watchdog reset time interval for jump to application /*****************************************************************************/ /*****************************************************************************/ #define STATUSMASK_SPMBUSY 0x01 // The mask bit for SPM busy status code #define STATUSMASK_BLSCERR 0x02 // The mask bit for attempt to override bootloader section #define STATUSMASK_TWIABORT 0x04 // The mask bit for indicating TWI abort fn called #define STATUSMASK_SLTR_BUSY 0x08 // The mask bit for slave transmit #define STATUSMASK_SLRBAA_BUSY 0x10 // The mask bit for slave receive and ack #define STATUSMASK_SLRBAN_BUSY 0x20 // The mask bit for slave receive and Nack #define STATUSMASK_EEPROM_BUSY 0x40 // The mask bit for EEPROM busy #define STATUSMASK_BOOTLOADER 0x80 // The mask bit for bootloader operations /*****************************************************************************/ /*****************************************************************************/ #define EEMEM_ADDR_AVERSION 0x05 // The address in EEPROM where application revision identifier will be stored #define BVERSION 0x96 // This bootloader revision identifier //static void UpdatePage (uint16_t); #ifndef _BV #define _BV( __BIT_POSITION__ ) ( 1 << __BIT_POSITION__ ) #endif //#ifdef _BV //#warning _BV now stands defined //#endif
{ "language": "C" }
/* * ptw32_processTerminate.c * * Description: * This translation unit implements routines which are private to * the implementation and may be used throughout it. * * -------------------------------------------------------------------------- * * Pthreads-win32 - POSIX Threads Library for Win32 * Copyright(C) 1998 John E. Bossom * Copyright(C) 1999,2003 Pthreads-win32 contributors * * Contact Email: rpj@callisto.canberra.edu.au * * The current list of contributors is contained * in the file CONTRIBUTORS included with the source * code distribution. The list can also be seen at the * following World Wide Web location: * http://sources.redhat.com/pthreads-win32/contributors.html * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library in the file COPYING.LIB; * if not, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA */ #include "pthread.h" #include "implement.h" void ptw32_processTerminate (void) /* * ------------------------------------------------------ * DOCPRIVATE * This function performs process wide termination for * the pthread library. * * PARAMETERS * N/A * * DESCRIPTION * This function performs process wide termination for * the pthread library. * This routine sets the global variable * ptw32_processInitialized to FALSE * * RESULTS * N/A * * ------------------------------------------------------ */ { pthread_t thread, nextThread; if (ptw32_processInitialized) { if (ptw32_selfThreadKey != NULL) { /* * Release ptw32_selfThreadKey */ pthread_key_delete (ptw32_selfThreadKey); ptw32_selfThreadKey = NULL; } if (ptw32_cleanupKey != NULL) { /* * Release ptw32_cleanupKey */ pthread_key_delete (ptw32_cleanupKey); ptw32_cleanupKey = NULL; } EnterCriticalSection(&ptw32_thread_reuse_lock); thread = ptw32_threadReuseTop; while (thread != PTW32_THREAD_REUSE_BOTTOM) { nextThread = thread->prevReuse; free(thread); thread = nextThread; } LeaveCriticalSection(&ptw32_thread_reuse_lock); /* * Destroy the global locks. */ DeleteCriticalSection(&ptw32_spinlock_test_init_lock); DeleteCriticalSection(&ptw32_rwlock_test_init_lock); DeleteCriticalSection(&ptw32_cond_test_init_lock); DeleteCriticalSection(&ptw32_cond_list_lock); DeleteCriticalSection(&ptw32_mutex_test_init_lock); DeleteCriticalSection(&ptw32_thread_reuse_lock); ptw32_processInitialized = PTW32_FALSE; } } /* processTerminate */
{ "language": "C" }
/** * Copyright (C) 2008, Creative Technology Ltd. All Rights Reserved. * * This source file is released under GPL v2 license (no other versions). * See the COPYING file included in the main directory of this source * distribution for the license terms and conditions. * * @File ctatc.c * * @Brief * This file contains the implementation of the device resource management * object. * * @Author Liu Chun * @Date Mar 28 2008 */ #include "ctatc.h" #include "ctpcm.h" #include "ctmixer.h" #include "ctsrc.h" #include "ctamixer.h" #include "ctdaio.h" #include "cttimer.h" #include <linux/delay.h> #include <linux/slab.h> #include <sound/pcm.h> #include <sound/control.h> #include <sound/asoundef.h> #define MONO_SUM_SCALE 0x19a8 /* 2^(-0.5) in 14-bit floating format */ #define MAX_MULTI_CHN 8 #define IEC958_DEFAULT_CON ((IEC958_AES0_NONAUDIO \ | IEC958_AES0_CON_NOT_COPYRIGHT) \ | ((IEC958_AES1_CON_MIXER \ | IEC958_AES1_CON_ORIGINAL) << 8) \ | (0x10 << 16) \ | ((IEC958_AES3_CON_FS_48000) << 24)) static struct snd_pci_quirk subsys_20k1_list[] = { SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x0022, "SB055x", CTSB055X), SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x002f, "SB055x", CTSB055X), SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x0029, "SB073x", CTSB073X), SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, 0x0031, "SB073x", CTSB073X), SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE, 0xf000, 0x6000, "UAA", CTUAA), { } /* terminator */ }; static struct snd_pci_quirk subsys_20k2_list[] = { SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB0760, "SB0760", CTSB0760), SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB1270, "SB1270", CTSB1270), SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB08801, "SB0880", CTSB0880), SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB08802, "SB0880", CTSB0880), SND_PCI_QUIRK(PCI_VENDOR_ID_CREATIVE, PCI_SUBDEVICE_ID_CREATIVE_SB08803, "SB0880", CTSB0880), SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_CREATIVE, 0xf000, PCI_SUBDEVICE_ID_CREATIVE_HENDRIX, "HENDRIX", CTHENDRIX), { } /* terminator */ }; static const char *ct_subsys_name[NUM_CTCARDS] = { /* 20k1 models */ [CTSB055X] = "SB055x", [CTSB073X] = "SB073x", [CTUAA] = "UAA", [CT20K1_UNKNOWN] = "Unknown", /* 20k2 models */ [CTSB0760] = "SB076x", [CTHENDRIX] = "Hendrix", [CTSB0880] = "SB0880", [CTSB1270] = "SB1270", [CT20K2_UNKNOWN] = "Unknown", }; static struct { int (*create)(struct ct_atc *atc, enum CTALSADEVS device, const char *device_name); int (*destroy)(void *alsa_dev); const char *public_name; } alsa_dev_funcs[NUM_CTALSADEVS] = { [FRONT] = { .create = ct_alsa_pcm_create, .destroy = NULL, .public_name = "Front/WaveIn"}, [SURROUND] = { .create = ct_alsa_pcm_create, .destroy = NULL, .public_name = "Surround"}, [CLFE] = { .create = ct_alsa_pcm_create, .destroy = NULL, .public_name = "Center/LFE"}, [SIDE] = { .create = ct_alsa_pcm_create, .destroy = NULL, .public_name = "Side"}, [IEC958] = { .create = ct_alsa_pcm_create, .destroy = NULL, .public_name = "IEC958 Non-audio"}, [MIXER] = { .create = ct_alsa_mix_create, .destroy = NULL, .public_name = "Mixer"} }; typedef int (*create_t)(struct hw *, void **); typedef int (*destroy_t)(void *); static struct { int (*create)(struct hw *hw, void **rmgr); int (*destroy)(void *mgr); } rsc_mgr_funcs[NUM_RSCTYP] = { [SRC] = { .create = (create_t)src_mgr_create, .destroy = (destroy_t)src_mgr_destroy }, [SRCIMP] = { .create = (create_t)srcimp_mgr_create, .destroy = (destroy_t)srcimp_mgr_destroy }, [AMIXER] = { .create = (create_t)amixer_mgr_create, .destroy = (destroy_t)amixer_mgr_destroy }, [SUM] = { .create = (create_t)sum_mgr_create, .destroy = (destroy_t)sum_mgr_destroy }, [DAIO] = { .create = (create_t)daio_mgr_create, .destroy = (destroy_t)daio_mgr_destroy } }; static int atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm); /* * * Only mono and interleaved modes are supported now. * Always allocates a contiguous channel block. * */ static int ct_map_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct snd_pcm_runtime *runtime; struct ct_vm *vm; if (!apcm->substream) return 0; runtime = apcm->substream->runtime; vm = atc->vm; apcm->vm_block = vm->map(vm, apcm->substream, runtime->dma_bytes); if (!apcm->vm_block) return -ENOENT; return 0; } static void ct_unmap_audio_buffer(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct ct_vm *vm; if (!apcm->vm_block) return; vm = atc->vm; vm->unmap(vm, apcm->vm_block); apcm->vm_block = NULL; } static unsigned long atc_get_ptp_phys(struct ct_atc *atc, int index) { return atc->vm->get_ptp_phys(atc->vm, index); } static unsigned int convert_format(snd_pcm_format_t snd_format, struct snd_card *card) { switch (snd_format) { case SNDRV_PCM_FORMAT_U8: return SRC_SF_U8; case SNDRV_PCM_FORMAT_S16_LE: return SRC_SF_S16; case SNDRV_PCM_FORMAT_S24_3LE: return SRC_SF_S24; case SNDRV_PCM_FORMAT_S32_LE: return SRC_SF_S32; case SNDRV_PCM_FORMAT_FLOAT_LE: return SRC_SF_F32; default: dev_err(card->dev, "not recognized snd format is %d\n", snd_format); return SRC_SF_S16; } } static unsigned int atc_get_pitch(unsigned int input_rate, unsigned int output_rate) { unsigned int pitch; int b; /* get pitch and convert to fixed-point 8.24 format. */ pitch = (input_rate / output_rate) << 24; input_rate %= output_rate; input_rate /= 100; output_rate /= 100; for (b = 31; ((b >= 0) && !(input_rate >> b)); ) b--; if (b >= 0) { input_rate <<= (31 - b); input_rate /= output_rate; b = 24 - (31 - b); if (b >= 0) input_rate <<= b; else input_rate >>= -b; pitch |= input_rate; } return pitch; } static int select_rom(unsigned int pitch) { if (pitch > 0x00428f5c && pitch < 0x01b851ec) { /* 0.26 <= pitch <= 1.72 */ return 1; } else if (pitch == 0x01d66666 || pitch == 0x01d66667) { /* pitch == 1.8375 */ return 2; } else if (pitch == 0x02000000) { /* pitch == 2 */ return 3; } else if (pitch <= 0x08000000) { /* 0 <= pitch <= 8 */ return 0; } else { return -ENOENT; } } static int atc_pcm_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; struct amixer_mgr *amixer_mgr = atc->rsc_mgrs[AMIXER]; struct src_desc desc = {0}; struct amixer_desc mix_dsc = {0}; struct src *src; struct amixer *amixer; int err; int n_amixer = apcm->substream->runtime->channels, i = 0; int device = apcm->substream->pcm->device; unsigned int pitch; /* first release old resources */ atc_pcm_release_resources(atc, apcm); /* Get SRC resource */ desc.multi = apcm->substream->runtime->channels; desc.msr = atc->msr; desc.mode = MEMRD; err = src_mgr->get_src(src_mgr, &desc, (struct src **)&apcm->src); if (err) goto error1; pitch = atc_get_pitch(apcm->substream->runtime->rate, (atc->rsr * atc->msr)); src = apcm->src; src->ops->set_pitch(src, pitch); src->ops->set_rom(src, select_rom(pitch)); src->ops->set_sf(src, convert_format(apcm->substream->runtime->format, atc->card)); src->ops->set_pm(src, (src->ops->next_interleave(src) != NULL)); /* Get AMIXER resource */ n_amixer = (n_amixer < 2) ? 2 : n_amixer; apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL); if (!apcm->amixers) { err = -ENOMEM; goto error1; } mix_dsc.msr = atc->msr; for (i = 0, apcm->n_amixer = 0; i < n_amixer; i++) { err = amixer_mgr->get_amixer(amixer_mgr, &mix_dsc, (struct amixer **)&apcm->amixers[i]); if (err) goto error1; apcm->n_amixer++; } /* Set up device virtual mem map */ err = ct_map_audio_buffer(atc, apcm); if (err < 0) goto error1; /* Connect resources */ src = apcm->src; for (i = 0; i < n_amixer; i++) { amixer = apcm->amixers[i]; mutex_lock(&atc->atc_mutex); amixer->ops->setup(amixer, &src->rsc, INIT_VOL, atc->pcm[i+device*2]); mutex_unlock(&atc->atc_mutex); src = src->ops->next_interleave(src); if (!src) src = apcm->src; } ct_timer_prepare(apcm->timer); return 0; error1: atc_pcm_release_resources(atc, apcm); return err; } static int atc_pcm_release_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; struct srcimp_mgr *srcimp_mgr = atc->rsc_mgrs[SRCIMP]; struct amixer_mgr *amixer_mgr = atc->rsc_mgrs[AMIXER]; struct sum_mgr *sum_mgr = atc->rsc_mgrs[SUM]; struct srcimp *srcimp; int i; if (apcm->srcimps) { for (i = 0; i < apcm->n_srcimp; i++) { srcimp = apcm->srcimps[i]; srcimp->ops->unmap(srcimp); srcimp_mgr->put_srcimp(srcimp_mgr, srcimp); apcm->srcimps[i] = NULL; } kfree(apcm->srcimps); apcm->srcimps = NULL; } if (apcm->srccs) { for (i = 0; i < apcm->n_srcc; i++) { src_mgr->put_src(src_mgr, apcm->srccs[i]); apcm->srccs[i] = NULL; } kfree(apcm->srccs); apcm->srccs = NULL; } if (apcm->amixers) { for (i = 0; i < apcm->n_amixer; i++) { amixer_mgr->put_amixer(amixer_mgr, apcm->amixers[i]); apcm->amixers[i] = NULL; } kfree(apcm->amixers); apcm->amixers = NULL; } if (apcm->mono) { sum_mgr->put_sum(sum_mgr, apcm->mono); apcm->mono = NULL; } if (apcm->src) { src_mgr->put_src(src_mgr, apcm->src); apcm->src = NULL; } if (apcm->vm_block) { /* Undo device virtual mem map */ ct_unmap_audio_buffer(atc, apcm); apcm->vm_block = NULL; } return 0; } static int atc_pcm_playback_start(struct ct_atc *atc, struct ct_atc_pcm *apcm) { unsigned int max_cisz; struct src *src = apcm->src; if (apcm->started) return 0; apcm->started = 1; max_cisz = src->multi * src->rsc.msr; max_cisz = 0x80 * (max_cisz < 8 ? max_cisz : 8); src->ops->set_sa(src, apcm->vm_block->addr); src->ops->set_la(src, apcm->vm_block->addr + apcm->vm_block->size); src->ops->set_ca(src, apcm->vm_block->addr + max_cisz); src->ops->set_cisz(src, max_cisz); src->ops->set_bm(src, 1); src->ops->set_state(src, SRC_STATE_INIT); src->ops->commit_write(src); ct_timer_start(apcm->timer); return 0; } static int atc_pcm_stop(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src *src; int i; ct_timer_stop(apcm->timer); src = apcm->src; src->ops->set_bm(src, 0); src->ops->set_state(src, SRC_STATE_OFF); src->ops->commit_write(src); if (apcm->srccs) { for (i = 0; i < apcm->n_srcc; i++) { src = apcm->srccs[i]; src->ops->set_bm(src, 0); src->ops->set_state(src, SRC_STATE_OFF); src->ops->commit_write(src); } } apcm->started = 0; return 0; } static int atc_pcm_playback_position(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src *src = apcm->src; u32 size, max_cisz; int position; if (!src) return 0; position = src->ops->get_ca(src); if (position < apcm->vm_block->addr) { dev_dbg(atc->card->dev, "bad ca - ca=0x%08x, vba=0x%08x, vbs=0x%08x\n", position, apcm->vm_block->addr, apcm->vm_block->size); position = apcm->vm_block->addr; } size = apcm->vm_block->size; max_cisz = src->multi * src->rsc.msr; max_cisz = 128 * (max_cisz < 8 ? max_cisz : 8); return (position + size - max_cisz - apcm->vm_block->addr) % size; } struct src_node_conf_t { unsigned int pitch; unsigned int msr:8; unsigned int mix_msr:8; unsigned int imp_msr:8; unsigned int vo:1; }; static void setup_src_node_conf(struct ct_atc *atc, struct ct_atc_pcm *apcm, struct src_node_conf_t *conf, int *n_srcc) { unsigned int pitch; /* get pitch and convert to fixed-point 8.24 format. */ pitch = atc_get_pitch((atc->rsr * atc->msr), apcm->substream->runtime->rate); *n_srcc = 0; if (1 == atc->msr) { /* FIXME: do we really need SRC here if pitch==1 */ *n_srcc = apcm->substream->runtime->channels; conf[0].pitch = pitch; conf[0].mix_msr = conf[0].imp_msr = conf[0].msr = 1; conf[0].vo = 1; } else if (2 <= atc->msr) { if (0x8000000 < pitch) { /* Need two-stage SRCs, SRCIMPs and * AMIXERs for converting format */ conf[0].pitch = (atc->msr << 24); conf[0].msr = conf[0].mix_msr = 1; conf[0].imp_msr = atc->msr; conf[0].vo = 0; conf[1].pitch = atc_get_pitch(atc->rsr, apcm->substream->runtime->rate); conf[1].msr = conf[1].mix_msr = conf[1].imp_msr = 1; conf[1].vo = 1; *n_srcc = apcm->substream->runtime->channels * 2; } else if (0x1000000 < pitch) { /* Need one-stage SRCs, SRCIMPs and * AMIXERs for converting format */ conf[0].pitch = pitch; conf[0].msr = conf[0].mix_msr = conf[0].imp_msr = atc->msr; conf[0].vo = 1; *n_srcc = apcm->substream->runtime->channels; } } } static int atc_pcm_capture_get_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; struct srcimp_mgr *srcimp_mgr = atc->rsc_mgrs[SRCIMP]; struct amixer_mgr *amixer_mgr = atc->rsc_mgrs[AMIXER]; struct sum_mgr *sum_mgr = atc->rsc_mgrs[SUM]; struct src_desc src_dsc = {0}; struct src *src; struct srcimp_desc srcimp_dsc = {0}; struct srcimp *srcimp; struct amixer_desc mix_dsc = {0}; struct sum_desc sum_dsc = {0}; unsigned int pitch; int multi, err, i; int n_srcimp, n_amixer, n_srcc, n_sum; struct src_node_conf_t src_node_conf[2] = {{0} }; /* first release old resources */ atc_pcm_release_resources(atc, apcm); /* The numbers of converting SRCs and SRCIMPs should be determined * by pitch value. */ multi = apcm->substream->runtime->channels; /* get pitch and convert to fixed-point 8.24 format. */ pitch = atc_get_pitch((atc->rsr * atc->msr), apcm->substream->runtime->rate); setup_src_node_conf(atc, apcm, src_node_conf, &n_srcc); n_sum = (1 == multi) ? 1 : 0; n_amixer = n_sum * 2 + n_srcc; n_srcimp = n_srcc; if ((multi > 1) && (0x8000000 >= pitch)) { /* Need extra AMIXERs and SRCIMPs for special treatment * of interleaved recording of conjugate channels */ n_amixer += multi * atc->msr; n_srcimp += multi * atc->msr; } else { n_srcimp += multi; } if (n_srcc) { apcm->srccs = kzalloc(sizeof(void *)*n_srcc, GFP_KERNEL); if (!apcm->srccs) return -ENOMEM; } if (n_amixer) { apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL); if (!apcm->amixers) { err = -ENOMEM; goto error1; } } apcm->srcimps = kzalloc(sizeof(void *)*n_srcimp, GFP_KERNEL); if (!apcm->srcimps) { err = -ENOMEM; goto error1; } /* Allocate SRCs for sample rate conversion if needed */ src_dsc.multi = 1; src_dsc.mode = ARCRW; for (i = 0, apcm->n_srcc = 0; i < n_srcc; i++) { src_dsc.msr = src_node_conf[i/multi].msr; err = src_mgr->get_src(src_mgr, &src_dsc, (struct src **)&apcm->srccs[i]); if (err) goto error1; src = apcm->srccs[i]; pitch = src_node_conf[i/multi].pitch; src->ops->set_pitch(src, pitch); src->ops->set_rom(src, select_rom(pitch)); src->ops->set_vo(src, src_node_conf[i/multi].vo); apcm->n_srcc++; } /* Allocate AMIXERs for routing SRCs of conversion if needed */ for (i = 0, apcm->n_amixer = 0; i < n_amixer; i++) { if (i < (n_sum*2)) mix_dsc.msr = atc->msr; else if (i < (n_sum*2+n_srcc)) mix_dsc.msr = src_node_conf[(i-n_sum*2)/multi].mix_msr; else mix_dsc.msr = 1; err = amixer_mgr->get_amixer(amixer_mgr, &mix_dsc, (struct amixer **)&apcm->amixers[i]); if (err) goto error1; apcm->n_amixer++; } /* Allocate a SUM resource to mix all input channels together */ sum_dsc.msr = atc->msr; err = sum_mgr->get_sum(sum_mgr, &sum_dsc, (struct sum **)&apcm->mono); if (err) goto error1; pitch = atc_get_pitch((atc->rsr * atc->msr), apcm->substream->runtime->rate); /* Allocate SRCIMP resources */ for (i = 0, apcm->n_srcimp = 0; i < n_srcimp; i++) { if (i < (n_srcc)) srcimp_dsc.msr = src_node_conf[i/multi].imp_msr; else if (1 == multi) srcimp_dsc.msr = (pitch <= 0x8000000) ? atc->msr : 1; else srcimp_dsc.msr = 1; err = srcimp_mgr->get_srcimp(srcimp_mgr, &srcimp_dsc, &srcimp); if (err) goto error1; apcm->srcimps[i] = srcimp; apcm->n_srcimp++; } /* Allocate a SRC for writing data to host memory */ src_dsc.multi = apcm->substream->runtime->channels; src_dsc.msr = 1; src_dsc.mode = MEMWR; err = src_mgr->get_src(src_mgr, &src_dsc, (struct src **)&apcm->src); if (err) goto error1; src = apcm->src; src->ops->set_pitch(src, pitch); /* Set up device virtual mem map */ err = ct_map_audio_buffer(atc, apcm); if (err < 0) goto error1; return 0; error1: atc_pcm_release_resources(atc, apcm); return err; } static int atc_pcm_capture_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src *src; struct amixer *amixer; struct srcimp *srcimp; struct ct_mixer *mixer = atc->mixer; struct sum *mono; struct rsc *out_ports[8] = {NULL}; int err, i, j, n_sum, multi; unsigned int pitch; int mix_base = 0, imp_base = 0; atc_pcm_release_resources(atc, apcm); /* Get needed resources. */ err = atc_pcm_capture_get_resources(atc, apcm); if (err) return err; /* Connect resources */ mixer->get_output_ports(mixer, MIX_PCMO_FRONT, &out_ports[0], &out_ports[1]); multi = apcm->substream->runtime->channels; if (1 == multi) { mono = apcm->mono; for (i = 0; i < 2; i++) { amixer = apcm->amixers[i]; amixer->ops->setup(amixer, out_ports[i], MONO_SUM_SCALE, mono); } out_ports[0] = &mono->rsc; n_sum = 1; mix_base = n_sum * 2; } for (i = 0; i < apcm->n_srcc; i++) { src = apcm->srccs[i]; srcimp = apcm->srcimps[imp_base+i]; amixer = apcm->amixers[mix_base+i]; srcimp->ops->map(srcimp, src, out_ports[i%multi]); amixer->ops->setup(amixer, &src->rsc, INIT_VOL, NULL); out_ports[i%multi] = &amixer->rsc; } pitch = atc_get_pitch((atc->rsr * atc->msr), apcm->substream->runtime->rate); if ((multi > 1) && (pitch <= 0x8000000)) { /* Special connection for interleaved * recording with conjugate channels */ for (i = 0; i < multi; i++) { out_ports[i]->ops->master(out_ports[i]); for (j = 0; j < atc->msr; j++) { amixer = apcm->amixers[apcm->n_srcc+j*multi+i]; amixer->ops->set_input(amixer, out_ports[i]); amixer->ops->set_scale(amixer, INIT_VOL); amixer->ops->set_sum(amixer, NULL); amixer->ops->commit_raw_write(amixer); out_ports[i]->ops->next_conj(out_ports[i]); srcimp = apcm->srcimps[apcm->n_srcc+j*multi+i]; srcimp->ops->map(srcimp, apcm->src, &amixer->rsc); } } } else { for (i = 0; i < multi; i++) { srcimp = apcm->srcimps[apcm->n_srcc+i]; srcimp->ops->map(srcimp, apcm->src, out_ports[i]); } } ct_timer_prepare(apcm->timer); return 0; } static int atc_pcm_capture_start(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src *src; struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; int i, multi; if (apcm->started) return 0; apcm->started = 1; multi = apcm->substream->runtime->channels; /* Set up converting SRCs */ for (i = 0; i < apcm->n_srcc; i++) { src = apcm->srccs[i]; src->ops->set_pm(src, ((i%multi) != (multi-1))); src_mgr->src_disable(src_mgr, src); } /* Set up recording SRC */ src = apcm->src; src->ops->set_sf(src, convert_format(apcm->substream->runtime->format, atc->card)); src->ops->set_sa(src, apcm->vm_block->addr); src->ops->set_la(src, apcm->vm_block->addr + apcm->vm_block->size); src->ops->set_ca(src, apcm->vm_block->addr); src_mgr->src_disable(src_mgr, src); /* Disable relevant SRCs firstly */ src_mgr->commit_write(src_mgr); /* Enable SRCs respectively */ for (i = 0; i < apcm->n_srcc; i++) { src = apcm->srccs[i]; src->ops->set_state(src, SRC_STATE_RUN); src->ops->commit_write(src); src_mgr->src_enable_s(src_mgr, src); } src = apcm->src; src->ops->set_bm(src, 1); src->ops->set_state(src, SRC_STATE_RUN); src->ops->commit_write(src); src_mgr->src_enable_s(src_mgr, src); /* Enable relevant SRCs synchronously */ src_mgr->commit_write(src_mgr); ct_timer_start(apcm->timer); return 0; } static int atc_pcm_capture_position(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src *src = apcm->src; if (!src) return 0; return src->ops->get_ca(src) - apcm->vm_block->addr; } static int spdif_passthru_playback_get_resources(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src_mgr *src_mgr = atc->rsc_mgrs[SRC]; struct amixer_mgr *amixer_mgr = atc->rsc_mgrs[AMIXER]; struct src_desc desc = {0}; struct amixer_desc mix_dsc = {0}; struct src *src; int err; int n_amixer = apcm->substream->runtime->channels, i; unsigned int pitch, rsr = atc->pll_rate; /* first release old resources */ atc_pcm_release_resources(atc, apcm); /* Get SRC resource */ desc.multi = apcm->substream->runtime->channels; desc.msr = 1; while (apcm->substream->runtime->rate > (rsr * desc.msr)) desc.msr <<= 1; desc.mode = MEMRD; err = src_mgr->get_src(src_mgr, &desc, (struct src **)&apcm->src); if (err) goto error1; pitch = atc_get_pitch(apcm->substream->runtime->rate, (rsr * desc.msr)); src = apcm->src; src->ops->set_pitch(src, pitch); src->ops->set_rom(src, select_rom(pitch)); src->ops->set_sf(src, convert_format(apcm->substream->runtime->format, atc->card)); src->ops->set_pm(src, (src->ops->next_interleave(src) != NULL)); src->ops->set_bp(src, 1); /* Get AMIXER resource */ n_amixer = (n_amixer < 2) ? 2 : n_amixer; apcm->amixers = kzalloc(sizeof(void *)*n_amixer, GFP_KERNEL); if (!apcm->amixers) { err = -ENOMEM; goto error1; } mix_dsc.msr = desc.msr; for (i = 0, apcm->n_amixer = 0; i < n_amixer; i++) { err = amixer_mgr->get_amixer(amixer_mgr, &mix_dsc, (struct amixer **)&apcm->amixers[i]); if (err) goto error1; apcm->n_amixer++; } /* Set up device virtual mem map */ err = ct_map_audio_buffer(atc, apcm); if (err < 0) goto error1; return 0; error1: atc_pcm_release_resources(atc, apcm); return err; } static int atc_pll_init(struct ct_atc *atc, int rate) { struct hw *hw = atc->hw; int err; err = hw->pll_init(hw, rate); atc->pll_rate = err ? 0 : rate; return err; } static int spdif_passthru_playback_setup(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct dao *dao = container_of(atc->daios[SPDIFOO], struct dao, daio); unsigned int rate = apcm->substream->runtime->rate; unsigned int status; int err = 0; unsigned char iec958_con_fs; switch (rate) { case 48000: iec958_con_fs = IEC958_AES3_CON_FS_48000; break; case 44100: iec958_con_fs = IEC958_AES3_CON_FS_44100; break; case 32000: iec958_con_fs = IEC958_AES3_CON_FS_32000; break; default: return -ENOENT; } mutex_lock(&atc->atc_mutex); dao->ops->get_spos(dao, &status); if (((status >> 24) & IEC958_AES3_CON_FS) != iec958_con_fs) { status &= ~(IEC958_AES3_CON_FS << 24); status |= (iec958_con_fs << 24); dao->ops->set_spos(dao, status); dao->ops->commit_write(dao); } if ((rate != atc->pll_rate) && (32000 != rate)) err = atc_pll_init(atc, rate); mutex_unlock(&atc->atc_mutex); return err; } static int spdif_passthru_playback_prepare(struct ct_atc *atc, struct ct_atc_pcm *apcm) { struct src *src; struct amixer *amixer; struct dao *dao; int err; int i; atc_pcm_release_resources(atc, apcm); /* Configure SPDIFOO and PLL to passthrough mode; * determine pll_rate. */ err = spdif_passthru_playback_setup(atc, apcm); if (err) return err; /* Get needed resources. */ err = spdif_passthru_playback_get_resources(atc, apcm); if (err) return err; /* Connect resources */ src = apcm->src; for (i = 0; i < apcm->n_amixer; i++) { amixer = apcm->amixers[i]; amixer->ops->setup(amixer, &src->rsc, INIT_VOL, NULL); src = src->ops->next_interleave(src); if (!src) src = apcm->src; } /* Connect to SPDIFOO */ mutex_lock(&atc->atc_mutex); dao = container_of(atc->daios[SPDIFOO], struct dao, daio); amixer = apcm->amixers[0]; dao->ops->set_left_input(dao, &amixer->rsc); amixer = apcm->amixers[1]; dao->ops->set_right_input(dao, &amixer->rsc); mutex_unlock(&atc->atc_mutex); ct_timer_prepare(apcm->timer); return 0; } static int atc_select_line_in(struct ct_atc *atc) { struct hw *hw = atc->hw; struct ct_mixer *mixer = atc->mixer; struct src *src; if (hw->is_adc_source_selected(hw, ADC_LINEIN)) return 0; mixer->set_input_left(mixer, MIX_MIC_IN, NULL); mixer->set_input_right(mixer, MIX_MIC_IN, NULL); hw->select_adc_source(hw, ADC_LINEIN); src = atc->srcs[2]; mixer->set_input_left(mixer, MIX_LINE_IN, &src->rsc); src = atc->srcs[3]; mixer->set_input_right(mixer, MIX_LINE_IN, &src->rsc); return 0; } static int atc_select_mic_in(struct ct_atc *atc) { struct hw *hw = atc->hw; struct ct_mixer *mixer = atc->mixer; struct src *src; if (hw->is_adc_source_selected(hw, ADC_MICIN)) return 0; mixer->set_input_left(mixer, MIX_LINE_IN, NULL); mixer->set_input_right(mixer, MIX_LINE_IN, NULL); hw->select_adc_source(hw, ADC_MICIN); src = atc->srcs[2]; mixer->set_input_left(mixer, MIX_MIC_IN, &src->rsc); src = atc->srcs[3]; mixer->set_input_right(mixer, MIX_MIC_IN, &src->rsc); return 0; } static struct capabilities atc_capabilities(struct ct_atc *atc) { struct hw *hw = atc->hw; return hw->capabilities(hw); } static int atc_output_switch_get(struct ct_atc *atc) { struct hw *hw = atc->hw; return hw->output_switch_get(hw); } static int atc_output_switch_put(struct ct_atc *atc, int position) { struct hw *hw = atc->hw; return hw->output_switch_put(hw, position); } static int atc_mic_source_switch_get(struct ct_atc *atc) { struct hw *hw = atc->hw; return hw->mic_source_switch_get(hw); } static int atc_mic_source_switch_put(struct ct_atc *atc, int position) { struct hw *hw = atc->hw; return hw->mic_source_switch_put(hw, position); } static int atc_select_digit_io(struct ct_atc *atc) { struct hw *hw = atc->hw; if (hw->is_adc_source_selected(hw, ADC_NONE)) return 0; hw->select_adc_source(hw, ADC_NONE); return 0; } static int atc_daio_unmute(struct ct_atc *atc, unsigned char state, int type) { struct daio_mgr *daio_mgr = atc->rsc_mgrs[DAIO]; if (state) daio_mgr->daio_enable(daio_mgr, atc->daios[type]); else daio_mgr->daio_disable(daio_mgr, atc->daios[type]); daio_mgr->commit_write(daio_mgr); return 0; } static int atc_dao_get_status(struct ct_atc *atc, unsigned int *status, int type) { struct dao *dao = container_of(atc->daios[type], struct dao, daio); return dao->ops->get_spos(dao, status); } static int atc_dao_set_status(struct ct_atc *atc, unsigned int status, int type) { struct dao *dao = container_of(atc->daios[type], struct dao, daio); dao->ops->set_spos(dao, status); dao->ops->commit_write(dao); return 0; } static int atc_line_front_unmute(struct ct_atc *atc, unsigned char state) { return atc_daio_unmute(atc, state, LINEO1); } static int atc_line_surround_unmute(struct ct_atc *atc, unsigned char state) { return atc_daio_unmute(atc, state, LINEO2); } static int atc_line_clfe_unmute(struct ct_atc *atc, unsigned char state) { return atc_daio_unmute(atc, state, LINEO3); } static int atc_line_rear_unmute(struct ct_atc *atc, unsigned char state) { return atc_daio_unmute(atc, state, LINEO4); } static int atc_line_in_unmute(struct ct_atc *atc, unsigned char state) { return atc_daio_unmute(atc, state, LINEIM); } static int atc_mic_unmute(struct ct_atc *atc, unsigned char state) { return atc_daio_unmute(atc, state, MIC); } static int atc_spdif_out_unmute(struct ct_atc *atc, unsigned char state) { return atc_daio_unmute(atc, state, SPDIFOO); } static int atc_spdif_in_unmute(struct ct_atc *atc, unsigned char state) { return atc_daio_unmute(atc, state, SPDIFIO); } static int atc_spdif_out_get_status(struct ct_atc *atc, unsigned int *status) { return atc_dao_get_status(atc, status, SPDIFOO); } static int atc_spdif_out_set_status(struct ct_atc *atc, unsigned int status) { return atc_dao_set_status(atc, status, SPDIFOO); } static int atc_spdif_out_passthru(struct ct_atc *atc, unsigned char state) { struct dao_desc da_dsc = {0}; struct dao *dao; int err; struct ct_mixer *mixer = atc->mixer; struct rsc *rscs[2] = {NULL}; unsigned int spos = 0; mutex_lock(&atc->atc_mutex); dao = container_of(atc->daios[SPDIFOO], struct dao, daio); da_dsc.msr = state ? 1 : atc->msr; da_dsc.passthru = state ? 1 : 0; err = dao->ops->reinit(dao, &da_dsc); if (state) { spos = IEC958_DEFAULT_CON; } else { mixer->get_output_ports(mixer, MIX_SPDIF_OUT, &rscs[0], &rscs[1]); dao->ops->set_left_input(dao, rscs[0]); dao->ops->set_right_input(dao, rscs[1]); /* Restore PLL to atc->rsr if needed. */ if (atc->pll_rate != atc->rsr) err = atc_pll_init(atc, atc->rsr); } dao->ops->set_spos(dao, spos); dao->ops->commit_write(dao); mutex_unlock(&atc->atc_mutex); return err; } static int atc_release_resources(struct ct_atc *atc) { int i; struct daio_mgr *daio_mgr = NULL; struct dao *dao = NULL; struct daio *daio = NULL; struct sum_mgr *sum_mgr = NULL; struct src_mgr *src_mgr = NULL; struct srcimp_mgr *srcimp_mgr = NULL; struct srcimp *srcimp = NULL; struct ct_mixer *mixer = NULL; /* disconnect internal mixer objects */ if (atc->mixer) { mixer = atc->mixer; mixer->set_input_left(mixer, MIX_LINE_IN, NULL); mixer->set_input_right(mixer, MIX_LINE_IN, NULL); mixer->set_input_left(mixer, MIX_MIC_IN, NULL); mixer->set_input_right(mixer, MIX_MIC_IN, NULL); mixer->set_input_left(mixer, MIX_SPDIF_IN, NULL); mixer->set_input_right(mixer, MIX_SPDIF_IN, NULL); } if (atc->daios) { daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO]; for (i = 0; i < atc->n_daio; i++) { daio = atc->daios[i]; if (daio->type < LINEIM) { dao = container_of(daio, struct dao, daio); dao->ops->clear_left_input(dao); dao->ops->clear_right_input(dao); } daio_mgr->put_daio(daio_mgr, daio); } kfree(atc->daios); atc->daios = NULL; } if (atc->pcm) { sum_mgr = atc->rsc_mgrs[SUM]; for (i = 0; i < atc->n_pcm; i++) sum_mgr->put_sum(sum_mgr, atc->pcm[i]); kfree(atc->pcm); atc->pcm = NULL; } if (atc->srcs) { src_mgr = atc->rsc_mgrs[SRC]; for (i = 0; i < atc->n_src; i++) src_mgr->put_src(src_mgr, atc->srcs[i]); kfree(atc->srcs); atc->srcs = NULL; } if (atc->srcimps) { srcimp_mgr = atc->rsc_mgrs[SRCIMP]; for (i = 0; i < atc->n_srcimp; i++) { srcimp = atc->srcimps[i]; srcimp->ops->unmap(srcimp); srcimp_mgr->put_srcimp(srcimp_mgr, atc->srcimps[i]); } kfree(atc->srcimps); atc->srcimps = NULL; } return 0; } static int ct_atc_destroy(struct ct_atc *atc) { int i = 0; if (!atc) return 0; if (atc->timer) { ct_timer_free(atc->timer); atc->timer = NULL; } atc_release_resources(atc); /* Destroy internal mixer objects */ if (atc->mixer) ct_mixer_destroy(atc->mixer); for (i = 0; i < NUM_RSCTYP; i++) { if (rsc_mgr_funcs[i].destroy && atc->rsc_mgrs[i]) rsc_mgr_funcs[i].destroy(atc->rsc_mgrs[i]); } if (atc->hw) destroy_hw_obj(atc->hw); /* Destroy device virtual memory manager object */ if (atc->vm) { ct_vm_destroy(atc->vm); atc->vm = NULL; } kfree(atc); return 0; } static int atc_dev_free(struct snd_device *dev) { struct ct_atc *atc = dev->device_data; return ct_atc_destroy(atc); } static int atc_identify_card(struct ct_atc *atc, unsigned int ssid) { const struct snd_pci_quirk *p; const struct snd_pci_quirk *list; u16 vendor_id, device_id; switch (atc->chip_type) { case ATC20K1: atc->chip_name = "20K1"; list = subsys_20k1_list; break; case ATC20K2: atc->chip_name = "20K2"; list = subsys_20k2_list; break; default: return -ENOENT; } if (ssid) { vendor_id = ssid >> 16; device_id = ssid & 0xffff; } else { vendor_id = atc->pci->subsystem_vendor; device_id = atc->pci->subsystem_device; } p = snd_pci_quirk_lookup_id(vendor_id, device_id, list); if (p) { if (p->value < 0) { dev_err(atc->card->dev, "Device %04x:%04x is black-listed\n", vendor_id, device_id); return -ENOENT; } atc->model = p->value; } else { if (atc->chip_type == ATC20K1) atc->model = CT20K1_UNKNOWN; else atc->model = CT20K2_UNKNOWN; } atc->model_name = ct_subsys_name[atc->model]; dev_info(atc->card->dev, "chip %s model %s (%04x:%04x) is found\n", atc->chip_name, atc->model_name, vendor_id, device_id); return 0; } int ct_atc_create_alsa_devs(struct ct_atc *atc) { enum CTALSADEVS i; int err; alsa_dev_funcs[MIXER].public_name = atc->chip_name; for (i = 0; i < NUM_CTALSADEVS; i++) { if (!alsa_dev_funcs[i].create) continue; err = alsa_dev_funcs[i].create(atc, i, alsa_dev_funcs[i].public_name); if (err) { dev_err(atc->card->dev, "Creating alsa device %d failed!\n", i); return err; } } return 0; } static int atc_create_hw_devs(struct ct_atc *atc) { struct hw *hw; struct card_conf info = {0}; int i, err; err = create_hw_obj(atc->pci, atc->chip_type, atc->model, &hw); if (err) { dev_err(atc->card->dev, "Failed to create hw obj!!!\n"); return err; } hw->card = atc->card; atc->hw = hw; /* Initialize card hardware. */ info.rsr = atc->rsr; info.msr = atc->msr; info.vm_pgt_phys = atc_get_ptp_phys(atc, 0); err = hw->card_init(hw, &info); if (err < 0) return err; for (i = 0; i < NUM_RSCTYP; i++) { if (!rsc_mgr_funcs[i].create) continue; err = rsc_mgr_funcs[i].create(atc->hw, &atc->rsc_mgrs[i]); if (err) { dev_err(atc->card->dev, "Failed to create rsc_mgr %d!!!\n", i); return err; } } return 0; } static int atc_get_resources(struct ct_atc *atc) { struct daio_desc da_desc = {0}; struct daio_mgr *daio_mgr; struct src_desc src_dsc = {0}; struct src_mgr *src_mgr; struct srcimp_desc srcimp_dsc = {0}; struct srcimp_mgr *srcimp_mgr; struct sum_desc sum_dsc = {0}; struct sum_mgr *sum_mgr; int err, i, num_srcs, num_daios; num_daios = ((atc->model == CTSB1270) ? 8 : 7); num_srcs = ((atc->model == CTSB1270) ? 6 : 4); atc->daios = kzalloc(sizeof(void *)*num_daios, GFP_KERNEL); if (!atc->daios) return -ENOMEM; atc->srcs = kzalloc(sizeof(void *)*num_srcs, GFP_KERNEL); if (!atc->srcs) return -ENOMEM; atc->srcimps = kzalloc(sizeof(void *)*num_srcs, GFP_KERNEL); if (!atc->srcimps) return -ENOMEM; atc->pcm = kzalloc(sizeof(void *)*(2*4), GFP_KERNEL); if (!atc->pcm) return -ENOMEM; daio_mgr = (struct daio_mgr *)atc->rsc_mgrs[DAIO]; da_desc.msr = atc->msr; for (i = 0, atc->n_daio = 0; i < num_daios; i++) { da_desc.type = (atc->model != CTSB073X) ? i : ((i == SPDIFIO) ? SPDIFI1 : i); err = daio_mgr->get_daio(daio_mgr, &da_desc, (struct daio **)&atc->daios[i]); if (err) { dev_err(atc->card->dev, "Failed to get DAIO resource %d!!!\n", i); return err; } atc->n_daio++; } src_mgr = atc->rsc_mgrs[SRC]; src_dsc.multi = 1; src_dsc.msr = atc->msr; src_dsc.mode = ARCRW; for (i = 0, atc->n_src = 0; i < num_srcs; i++) { err = src_mgr->get_src(src_mgr, &src_dsc, (struct src **)&atc->srcs[i]); if (err) return err; atc->n_src++; } srcimp_mgr = atc->rsc_mgrs[SRCIMP]; srcimp_dsc.msr = 8; for (i = 0, atc->n_srcimp = 0; i < num_srcs; i++) { err = srcimp_mgr->get_srcimp(srcimp_mgr, &srcimp_dsc, (struct srcimp **)&atc->srcimps[i]); if (err) return err; atc->n_srcimp++; } sum_mgr = atc->rsc_mgrs[SUM]; sum_dsc.msr = atc->msr; for (i = 0, atc->n_pcm = 0; i < (2*4); i++) { err = sum_mgr->get_sum(sum_mgr, &sum_dsc, (struct sum **)&atc->pcm[i]); if (err) return err; atc->n_pcm++; } return 0; } static void atc_connect_dai(struct src_mgr *src_mgr, struct dai *dai, struct src **srcs, struct srcimp **srcimps) { struct rsc *rscs[2] = {NULL}; struct src *src; struct srcimp *srcimp; int i = 0; rscs[0] = &dai->daio.rscl; rscs[1] = &dai->daio.rscr; for (i = 0; i < 2; i++) { src = srcs[i]; srcimp = srcimps[i]; srcimp->ops->map(srcimp, src, rscs[i]); src_mgr->src_disable(src_mgr, src); } src_mgr->commit_write(src_mgr); /* Actually disable SRCs */ src = srcs[0]; src->ops->set_pm(src, 1); for (i = 0; i < 2; i++) { src = srcs[i]; src->ops->set_state(src, SRC_STATE_RUN); src->ops->commit_write(src); src_mgr->src_enable_s(src_mgr, src); } dai->ops->set_srt_srcl(dai, &(srcs[0]->rsc)); dai->ops->set_srt_srcr(dai, &(srcs[1]->rsc)); dai->ops->set_enb_src(dai, 1); dai->ops->set_enb_srt(dai, 1); dai->ops->commit_write(dai); src_mgr->commit_write(src_mgr); /* Synchronously enable SRCs */ } static void atc_connect_resources(struct ct_atc *atc) { struct dai *dai; struct dao *dao; struct src *src; struct sum *sum; struct ct_mixer *mixer; struct rsc *rscs[2] = {NULL}; int i, j; mixer = atc->mixer; for (i = MIX_WAVE_FRONT, j = LINEO1; i <= MIX_SPDIF_OUT; i++, j++) { mixer->get_output_ports(mixer, i, &rscs[0], &rscs[1]); dao = container_of(atc->daios[j], struct dao, daio); dao->ops->set_left_input(dao, rscs[0]); dao->ops->set_right_input(dao, rscs[1]); } dai = container_of(atc->daios[LINEIM], struct dai, daio); atc_connect_dai(atc->rsc_mgrs[SRC], dai, (struct src **)&atc->srcs[2], (struct srcimp **)&atc->srcimps[2]); src = atc->srcs[2]; mixer->set_input_left(mixer, MIX_LINE_IN, &src->rsc); src = atc->srcs[3]; mixer->set_input_right(mixer, MIX_LINE_IN, &src->rsc); if (atc->model == CTSB1270) { /* Titanium HD has a dedicated ADC for the Mic. */ dai = container_of(atc->daios[MIC], struct dai, daio); atc_connect_dai(atc->rsc_mgrs[SRC], dai, (struct src **)&atc->srcs[4], (struct srcimp **)&atc->srcimps[4]); src = atc->srcs[4]; mixer->set_input_left(mixer, MIX_MIC_IN, &src->rsc); src = atc->srcs[5]; mixer->set_input_right(mixer, MIX_MIC_IN, &src->rsc); } dai = container_of(atc->daios[SPDIFIO], struct dai, daio); atc_connect_dai(atc->rsc_mgrs[SRC], dai, (struct src **)&atc->srcs[0], (struct srcimp **)&atc->srcimps[0]); src = atc->srcs[0]; mixer->set_input_left(mixer, MIX_SPDIF_IN, &src->rsc); src = atc->srcs[1]; mixer->set_input_right(mixer, MIX_SPDIF_IN, &src->rsc); for (i = MIX_PCMI_FRONT, j = 0; i <= MIX_PCMI_SURROUND; i++, j += 2) { sum = atc->pcm[j]; mixer->set_input_left(mixer, i, &sum->rsc); sum = atc->pcm[j+1]; mixer->set_input_right(mixer, i, &sum->rsc); } } #ifdef CONFIG_PM_SLEEP static int atc_suspend(struct ct_atc *atc) { int i; struct hw *hw = atc->hw; snd_power_change_state(atc->card, SNDRV_CTL_POWER_D3hot); for (i = FRONT; i < NUM_PCMS; i++) { if (!atc->pcms[i]) continue; snd_pcm_suspend_all(atc->pcms[i]); } atc_release_resources(atc); hw->suspend(hw); return 0; } static int atc_hw_resume(struct ct_atc *atc) { struct hw *hw = atc->hw; struct card_conf info = {0}; /* Re-initialize card hardware. */ info.rsr = atc->rsr; info.msr = atc->msr; info.vm_pgt_phys = atc_get_ptp_phys(atc, 0); return hw->resume(hw, &info); } static int atc_resources_resume(struct ct_atc *atc) { struct ct_mixer *mixer; int err = 0; /* Get resources */ err = atc_get_resources(atc); if (err < 0) { atc_release_resources(atc); return err; } /* Build topology */ atc_connect_resources(atc); mixer = atc->mixer; mixer->resume(mixer); return 0; } static int atc_resume(struct ct_atc *atc) { int err = 0; /* Do hardware resume. */ err = atc_hw_resume(atc); if (err < 0) { dev_err(atc->card->dev, "pci_enable_device failed, disabling device\n"); snd_card_disconnect(atc->card); return err; } err = atc_resources_resume(atc); if (err < 0) return err; snd_power_change_state(atc->card, SNDRV_CTL_POWER_D0); return 0; } #endif static struct ct_atc atc_preset = { .map_audio_buffer = ct_map_audio_buffer, .unmap_audio_buffer = ct_unmap_audio_buffer, .pcm_playback_prepare = atc_pcm_playback_prepare, .pcm_release_resources = atc_pcm_release_resources, .pcm_playback_start = atc_pcm_playback_start, .pcm_playback_stop = atc_pcm_stop, .pcm_playback_position = atc_pcm_playback_position, .pcm_capture_prepare = atc_pcm_capture_prepare, .pcm_capture_start = atc_pcm_capture_start, .pcm_capture_stop = atc_pcm_stop, .pcm_capture_position = atc_pcm_capture_position, .spdif_passthru_playback_prepare = spdif_passthru_playback_prepare, .get_ptp_phys = atc_get_ptp_phys, .select_line_in = atc_select_line_in, .select_mic_in = atc_select_mic_in, .select_digit_io = atc_select_digit_io, .line_front_unmute = atc_line_front_unmute, .line_surround_unmute = atc_line_surround_unmute, .line_clfe_unmute = atc_line_clfe_unmute, .line_rear_unmute = atc_line_rear_unmute, .line_in_unmute = atc_line_in_unmute, .mic_unmute = atc_mic_unmute, .spdif_out_unmute = atc_spdif_out_unmute, .spdif_in_unmute = atc_spdif_in_unmute, .spdif_out_get_status = atc_spdif_out_get_status, .spdif_out_set_status = atc_spdif_out_set_status, .spdif_out_passthru = atc_spdif_out_passthru, .capabilities = atc_capabilities, .output_switch_get = atc_output_switch_get, .output_switch_put = atc_output_switch_put, .mic_source_switch_get = atc_mic_source_switch_get, .mic_source_switch_put = atc_mic_source_switch_put, #ifdef CONFIG_PM_SLEEP .suspend = atc_suspend, .resume = atc_resume, #endif }; /** * ct_atc_create - create and initialize a hardware manager * @card: corresponding alsa card object * @pci: corresponding kernel pci device object * @ratc: return created object address in it * * Creates and initializes a hardware manager. * * Creates kmallocated ct_atc structure. Initializes hardware. * Returns 0 if succeeds, or negative error code if fails. */ int ct_atc_create(struct snd_card *card, struct pci_dev *pci, unsigned int rsr, unsigned int msr, int chip_type, unsigned int ssid, struct ct_atc **ratc) { struct ct_atc *atc; static struct snd_device_ops ops = { .dev_free = atc_dev_free, }; int err; *ratc = NULL; atc = kzalloc(sizeof(*atc), GFP_KERNEL); if (!atc) return -ENOMEM; /* Set operations */ *atc = atc_preset; atc->card = card; atc->pci = pci; atc->rsr = rsr; atc->msr = msr; atc->chip_type = chip_type; mutex_init(&atc->atc_mutex); /* Find card model */ err = atc_identify_card(atc, ssid); if (err < 0) { dev_err(card->dev, "ctatc: Card not recognised\n"); goto error1; } /* Set up device virtual memory management object */ err = ct_vm_create(&atc->vm, pci); if (err < 0) goto error1; /* Create all atc hw devices */ err = atc_create_hw_devs(atc); if (err < 0) goto error1; err = ct_mixer_create(atc, (struct ct_mixer **)&atc->mixer); if (err) { dev_err(card->dev, "Failed to create mixer obj!!!\n"); goto error1; } /* Get resources */ err = atc_get_resources(atc); if (err < 0) goto error1; /* Build topology */ atc_connect_resources(atc); atc->timer = ct_timer_new(atc); if (!atc->timer) { err = -ENOMEM; goto error1; } err = snd_device_new(card, SNDRV_DEV_LOWLEVEL, atc, &ops); if (err < 0) goto error1; *ratc = atc; return 0; error1: ct_atc_destroy(atc); dev_err(card->dev, "Something wrong!!!\n"); return err; }
{ "language": "C" }
/* SPDX-License-Identifier: GPL-2.0 */ /* * SELinux support for the XFRM LSM hooks * * Author : Trent Jaeger, <jaegert@us.ibm.com> * Updated : Venkat Yekkirala, <vyekkirala@TrustedCS.com> */ #ifndef _SELINUX_XFRM_H_ #define _SELINUX_XFRM_H_ #include <net/flow.h> int selinux_xfrm_policy_alloc(struct xfrm_sec_ctx **ctxp, struct xfrm_user_sec_ctx *uctx, gfp_t gfp); int selinux_xfrm_policy_clone(struct xfrm_sec_ctx *old_ctx, struct xfrm_sec_ctx **new_ctxp); void selinux_xfrm_policy_free(struct xfrm_sec_ctx *ctx); int selinux_xfrm_policy_delete(struct xfrm_sec_ctx *ctx); int selinux_xfrm_state_alloc(struct xfrm_state *x, struct xfrm_user_sec_ctx *uctx); int selinux_xfrm_state_alloc_acquire(struct xfrm_state *x, struct xfrm_sec_ctx *polsec, u32 secid); void selinux_xfrm_state_free(struct xfrm_state *x); int selinux_xfrm_state_delete(struct xfrm_state *x); int selinux_xfrm_policy_lookup(struct xfrm_sec_ctx *ctx, u32 fl_secid, u8 dir); int selinux_xfrm_state_pol_flow_match(struct xfrm_state *x, struct xfrm_policy *xp, const struct flowi *fl); #ifdef CONFIG_SECURITY_NETWORK_XFRM extern atomic_t selinux_xfrm_refcount; static inline int selinux_xfrm_enabled(void) { return (atomic_read(&selinux_xfrm_refcount) > 0); } int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb, struct common_audit_data *ad); int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb, struct common_audit_data *ad, u8 proto); int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall); int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid); static inline void selinux_xfrm_notify_policyload(void) { struct net *net; down_read(&net_rwsem); for_each_net(net) rt_genid_bump_all(net); up_read(&net_rwsem); } #else static inline int selinux_xfrm_enabled(void) { return 0; } static inline int selinux_xfrm_sock_rcv_skb(u32 sk_sid, struct sk_buff *skb, struct common_audit_data *ad) { return 0; } static inline int selinux_xfrm_postroute_last(u32 sk_sid, struct sk_buff *skb, struct common_audit_data *ad, u8 proto) { return 0; } static inline int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall) { *sid = SECSID_NULL; return 0; } static inline void selinux_xfrm_notify_policyload(void) { } static inline int selinux_xfrm_skb_sid(struct sk_buff *skb, u32 *sid) { *sid = SECSID_NULL; return 0; } #endif #endif /* _SELINUX_XFRM_H_ */
{ "language": "C" }
#ifndef __linux__ #error This file may be compiled on Linux only. #endif #include <unistd.h> #include <fcntl.h> #include <stdlib.h> #include <assert.h> #include <errno.h> #include <fcntl.h> #include <libgen.h> #include <limits.h> #include <stdio.h> #include <string.h> #include <time.h> #include <string.h> #include <sys/syscall.h> #include <sys/epoll.h> #include "org_apache_hadoop_mapred_CGroupEventListener.h" #define MIN(a,b) (((a)<(b))?(a):(b)) #define MAX(a,b) (((a)>(b))?(a):(b)) static int efd = -1; static int cfd = -1; static int event_control = -1; static int epollFd_ = -1; static struct epoll_event *events; JNIEXPORT jint JNICALL Java_org_apache_hadoop_mapred_CGroupEventListener_init (JNIEnv * env, jclass inclass, jstring inctlFile) { char event_control_path[PATH_MAX]; char line[LINE_MAX]; char * ctlfile = (char *)(*env)->GetStringUTFChars( env, inctlFile, NULL ) ; //setup the event files cfd = open(ctlfile, O_RDONLY); if (cfd == -1) { (*env)->ReleaseStringUTFChars(env, inctlFile, ctlfile); return -1; } if (snprintf(event_control_path, PATH_MAX, "%s/cgroup.event_control", dirname(ctlfile)) >= PATH_MAX) { (*env)->ReleaseStringUTFChars(env, inctlFile, ctlfile); return -2; } (*env)->ReleaseStringUTFChars(env, inctlFile, ctlfile); event_control = open(event_control_path, O_WRONLY); if (event_control == -1) { return -3; } efd = syscall(__NR_eventfd, 0, 0); if (efd == -1) { return -4; } if (snprintf(line, LINE_MAX, "%d %d", efd, cfd) >= LINE_MAX) { return -5; } if (write(event_control, line, strlen(line) + 1) == -1) { return -6; } epollFd_ = epoll_create(1); if (epollFd_ == -1) { return -7; } struct epoll_event ev; ev.events = EPOLLIN; ev.data.fd = efd; if (epoll_ctl(epollFd_, EPOLL_CTL_ADD, efd, &ev) == -1) { return -8; } events = (struct epoll_event*) calloc(1, sizeof(struct epoll_event)); if (events == NULL) { return -9; } return 0; } JNIEXPORT jint JNICALL Java_org_apache_hadoop_mapred_CGroupEventListener_waitForNotification (JNIEnv * env, jclass inclass, jint waitTime) { uint64_t result; int i; int nfds = epoll_wait(epollFd_, events, 1, waitTime); for (i = 0; i < nfds; i++) { read(events[i].data.fd, &result, sizeof(result)); } return nfds; } JNIEXPORT void JNICALL Java_org_apache_hadoop_mapred_CGroupEventListener_close (JNIEnv * env, jclass inclass) { if (epollFd_ >= 0) { close(epollFd_); } if (efd >= 0) { close(efd); } if (event_control >= 0) { close(event_control); } if (cfd >= 0) { close(cfd); } }
{ "language": "C" }
/* * Copyright (C) International Business Machines Corp., 2000-2004 * Portions Copyright (C) Christoph Hellwig, 2001-2002 * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See * the GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ #include <linux/fs.h> #include <linux/module.h> #include <linux/parser.h> #include <linux/completion.h> #include <linux/vfs.h> #include <linux/quotaops.h> #include <linux/mount.h> #include <linux/moduleparam.h> #include <linux/kthread.h> #include <linux/posix_acl.h> #include <linux/buffer_head.h> #include <linux/exportfs.h> #include <linux/crc32.h> #include <linux/slab.h> #include <asm/uaccess.h> #include <linux/seq_file.h> #include <linux/blkdev.h> #include "jfs_incore.h" #include "jfs_filsys.h" #include "jfs_inode.h" #include "jfs_metapage.h" #include "jfs_superblock.h" #include "jfs_dmap.h" #include "jfs_imap.h" #include "jfs_acl.h" #include "jfs_debug.h" #include "jfs_xattr.h" MODULE_DESCRIPTION("The Journaled Filesystem (JFS)"); MODULE_AUTHOR("Steve Best/Dave Kleikamp/Barry Arndt, IBM"); MODULE_LICENSE("GPL"); static struct kmem_cache *jfs_inode_cachep; static const struct super_operations jfs_super_operations; static const struct export_operations jfs_export_operations; static struct file_system_type jfs_fs_type; #define MAX_COMMIT_THREADS 64 static int commit_threads; module_param(commit_threads, int, 0); MODULE_PARM_DESC(commit_threads, "Number of commit threads"); static struct task_struct *jfsCommitThread[MAX_COMMIT_THREADS]; struct task_struct *jfsIOthread; struct task_struct *jfsSyncThread; #ifdef CONFIG_JFS_DEBUG int jfsloglevel = JFS_LOGLEVEL_WARN; module_param(jfsloglevel, int, 0644); MODULE_PARM_DESC(jfsloglevel, "Specify JFS loglevel (0, 1 or 2)"); #endif static void jfs_handle_error(struct super_block *sb) { struct jfs_sb_info *sbi = JFS_SBI(sb); if (sb->s_flags & MS_RDONLY) return; updateSuper(sb, FM_DIRTY); if (sbi->flag & JFS_ERR_PANIC) panic("JFS (device %s): panic forced after error\n", sb->s_id); else if (sbi->flag & JFS_ERR_REMOUNT_RO) { jfs_err("ERROR: (device %s): remounting filesystem as read-only", sb->s_id); sb->s_flags |= MS_RDONLY; } /* nothing is done for continue beyond marking the superblock dirty */ } void jfs_error(struct super_block *sb, const char *fmt, ...) { struct va_format vaf; va_list args; va_start(args, fmt); vaf.fmt = fmt; vaf.va = &args; pr_err("ERROR: (device %s): %ps: %pV\n", sb->s_id, __builtin_return_address(0), &vaf); va_end(args); jfs_handle_error(sb); } static struct inode *jfs_alloc_inode(struct super_block *sb) { struct jfs_inode_info *jfs_inode; jfs_inode = kmem_cache_alloc(jfs_inode_cachep, GFP_NOFS); if (!jfs_inode) return NULL; #ifdef CONFIG_QUOTA memset(&jfs_inode->i_dquot, 0, sizeof(jfs_inode->i_dquot)); #endif return &jfs_inode->vfs_inode; } static void jfs_i_callback(struct rcu_head *head) { struct inode *inode = container_of(head, struct inode, i_rcu); struct jfs_inode_info *ji = JFS_IP(inode); kmem_cache_free(jfs_inode_cachep, ji); } static void jfs_destroy_inode(struct inode *inode) { struct jfs_inode_info *ji = JFS_IP(inode); BUG_ON(!list_empty(&ji->anon_inode_list)); spin_lock_irq(&ji->ag_lock); if (ji->active_ag != -1) { struct bmap *bmap = JFS_SBI(inode->i_sb)->bmap; atomic_dec(&bmap->db_active[ji->active_ag]); ji->active_ag = -1; } spin_unlock_irq(&ji->ag_lock); call_rcu(&inode->i_rcu, jfs_i_callback); } static int jfs_statfs(struct dentry *dentry, struct kstatfs *buf) { struct jfs_sb_info *sbi = JFS_SBI(dentry->d_sb); s64 maxinodes; struct inomap *imap = JFS_IP(sbi->ipimap)->i_imap; jfs_info("In jfs_statfs"); buf->f_type = JFS_SUPER_MAGIC; buf->f_bsize = sbi->bsize; buf->f_blocks = sbi->bmap->db_mapsize; buf->f_bfree = sbi->bmap->db_nfree; buf->f_bavail = sbi->bmap->db_nfree; /* * If we really return the number of allocated & free inodes, some * applications will fail because they won't see enough free inodes. * We'll try to calculate some guess as to how many inodes we can * really allocate * * buf->f_files = atomic_read(&imap->im_numinos); * buf->f_ffree = atomic_read(&imap->im_numfree); */ maxinodes = min((s64) atomic_read(&imap->im_numinos) + ((sbi->bmap->db_nfree >> imap->im_l2nbperiext) << L2INOSPEREXT), (s64) 0xffffffffLL); buf->f_files = maxinodes; buf->f_ffree = maxinodes - (atomic_read(&imap->im_numinos) - atomic_read(&imap->im_numfree)); buf->f_fsid.val[0] = (u32)crc32_le(0, sbi->uuid, sizeof(sbi->uuid)/2); buf->f_fsid.val[1] = (u32)crc32_le(0, sbi->uuid + sizeof(sbi->uuid)/2, sizeof(sbi->uuid)/2); buf->f_namelen = JFS_NAME_MAX; return 0; } static void jfs_put_super(struct super_block *sb) { struct jfs_sb_info *sbi = JFS_SBI(sb); int rc; jfs_info("In jfs_put_super"); dquot_disable(sb, -1, DQUOT_USAGE_ENABLED | DQUOT_LIMITS_ENABLED); rc = jfs_umount(sb); if (rc) jfs_err("jfs_umount failed with return code %d", rc); unload_nls(sbi->nls_tab); truncate_inode_pages(sbi->direct_inode->i_mapping, 0); iput(sbi->direct_inode); kfree(sbi); } enum { Opt_integrity, Opt_nointegrity, Opt_iocharset, Opt_resize, Opt_resize_nosize, Opt_errors, Opt_ignore, Opt_err, Opt_quota, Opt_usrquota, Opt_grpquota, Opt_uid, Opt_gid, Opt_umask, Opt_discard, Opt_nodiscard, Opt_discard_minblk }; static const match_table_t tokens = { {Opt_integrity, "integrity"}, {Opt_nointegrity, "nointegrity"}, {Opt_iocharset, "iocharset=%s"}, {Opt_resize, "resize=%u"}, {Opt_resize_nosize, "resize"}, {Opt_errors, "errors=%s"}, {Opt_ignore, "noquota"}, {Opt_ignore, "quota"}, {Opt_usrquota, "usrquota"}, {Opt_grpquota, "grpquota"}, {Opt_uid, "uid=%u"}, {Opt_gid, "gid=%u"}, {Opt_umask, "umask=%u"}, {Opt_discard, "discard"}, {Opt_nodiscard, "nodiscard"}, {Opt_discard_minblk, "discard=%u"}, {Opt_err, NULL} }; static int parse_options(char *options, struct super_block *sb, s64 *newLVSize, int *flag) { void *nls_map = (void *)-1; /* -1: no change; NULL: none */ char *p; struct jfs_sb_info *sbi = JFS_SBI(sb); *newLVSize = 0; if (!options) return 1; while ((p = strsep(&options, ",")) != NULL) { substring_t args[MAX_OPT_ARGS]; int token; if (!*p) continue; token = match_token(p, tokens, args); switch (token) { case Opt_integrity: *flag &= ~JFS_NOINTEGRITY; break; case Opt_nointegrity: *flag |= JFS_NOINTEGRITY; break; case Opt_ignore: /* Silently ignore the quota options */ /* Don't do anything ;-) */ break; case Opt_iocharset: if (nls_map && nls_map != (void *) -1) unload_nls(nls_map); if (!strcmp(args[0].from, "none")) nls_map = NULL; else { nls_map = load_nls(args[0].from); if (!nls_map) { pr_err("JFS: charset not found\n"); goto cleanup; } } break; case Opt_resize: { char *resize = args[0].from; int rc = kstrtoll(resize, 0, newLVSize); if (rc) goto cleanup; break; } case Opt_resize_nosize: { *newLVSize = sb->s_bdev->bd_inode->i_size >> sb->s_blocksize_bits; if (*newLVSize == 0) pr_err("JFS: Cannot determine volume size\n"); break; } case Opt_errors: { char *errors = args[0].from; if (!errors || !*errors) goto cleanup; if (!strcmp(errors, "continue")) { *flag &= ~JFS_ERR_REMOUNT_RO; *flag &= ~JFS_ERR_PANIC; *flag |= JFS_ERR_CONTINUE; } else if (!strcmp(errors, "remount-ro")) { *flag &= ~JFS_ERR_CONTINUE; *flag &= ~JFS_ERR_PANIC; *flag |= JFS_ERR_REMOUNT_RO; } else if (!strcmp(errors, "panic")) { *flag &= ~JFS_ERR_CONTINUE; *flag &= ~JFS_ERR_REMOUNT_RO; *flag |= JFS_ERR_PANIC; } else { pr_err("JFS: %s is an invalid error handler\n", errors); goto cleanup; } break; } #ifdef CONFIG_QUOTA case Opt_quota: case Opt_usrquota: *flag |= JFS_USRQUOTA; break; case Opt_grpquota: *flag |= JFS_GRPQUOTA; break; #else case Opt_usrquota: case Opt_grpquota: case Opt_quota: pr_err("JFS: quota operations not supported\n"); break; #endif case Opt_uid: { char *uid = args[0].from; uid_t val; int rc = kstrtouint(uid, 0, &val); if (rc) goto cleanup; sbi->uid = make_kuid(current_user_ns(), val); if (!uid_valid(sbi->uid)) goto cleanup; break; } case Opt_gid: { char *gid = args[0].from; gid_t val; int rc = kstrtouint(gid, 0, &val); if (rc) goto cleanup; sbi->gid = make_kgid(current_user_ns(), val); if (!gid_valid(sbi->gid)) goto cleanup; break; } case Opt_umask: { char *umask = args[0].from; int rc = kstrtouint(umask, 8, &sbi->umask); if (rc) goto cleanup; if (sbi->umask & ~0777) { pr_err("JFS: Invalid value of umask\n"); goto cleanup; } break; } case Opt_discard: { struct request_queue *q = bdev_get_queue(sb->s_bdev); /* if set to 1, even copying files will cause * trimming :O * -> user has more control over the online trimming */ sbi->minblks_trim = 64; if (blk_queue_discard(q)) *flag |= JFS_DISCARD; else pr_err("JFS: discard option not supported on device\n"); break; } case Opt_nodiscard: *flag &= ~JFS_DISCARD; break; case Opt_discard_minblk: { struct request_queue *q = bdev_get_queue(sb->s_bdev); char *minblks_trim = args[0].from; int rc; if (blk_queue_discard(q)) { *flag |= JFS_DISCARD; rc = kstrtouint(minblks_trim, 0, &sbi->minblks_trim); if (rc) goto cleanup; } else pr_err("JFS: discard option not supported on device\n"); break; } default: printk("jfs: Unrecognized mount option \"%s\" or missing value\n", p); goto cleanup; } } if (nls_map != (void *) -1) { /* Discard old (if remount) */ unload_nls(sbi->nls_tab); sbi->nls_tab = nls_map; } return 1; cleanup: if (nls_map && nls_map != (void *) -1) unload_nls(nls_map); return 0; } static int jfs_remount(struct super_block *sb, int *flags, char *data) { s64 newLVSize = 0; int rc = 0; int flag = JFS_SBI(sb)->flag; int ret; sync_filesystem(sb); if (!parse_options(data, sb, &newLVSize, &flag)) return -EINVAL; if (newLVSize) { if (sb->s_flags & MS_RDONLY) { pr_err("JFS: resize requires volume to be mounted read-write\n"); return -EROFS; } rc = jfs_extendfs(sb, newLVSize, 0); if (rc) return rc; } if ((sb->s_flags & MS_RDONLY) && !(*flags & MS_RDONLY)) { /* * Invalidate any previously read metadata. fsck may have * changed the on-disk data since we mounted r/o */ truncate_inode_pages(JFS_SBI(sb)->direct_inode->i_mapping, 0); JFS_SBI(sb)->flag = flag; ret = jfs_mount_rw(sb, 1); /* mark the fs r/w for quota activity */ sb->s_flags &= ~MS_RDONLY; dquot_resume(sb, -1); return ret; } if ((!(sb->s_flags & MS_RDONLY)) && (*flags & MS_RDONLY)) { rc = dquot_suspend(sb, -1); if (rc < 0) return rc; rc = jfs_umount_rw(sb); JFS_SBI(sb)->flag = flag; return rc; } if ((JFS_SBI(sb)->flag & JFS_NOINTEGRITY) != (flag & JFS_NOINTEGRITY)) if (!(sb->s_flags & MS_RDONLY)) { rc = jfs_umount_rw(sb); if (rc) return rc; JFS_SBI(sb)->flag = flag; ret = jfs_mount_rw(sb, 1); return ret; } JFS_SBI(sb)->flag = flag; return 0; } static int jfs_fill_super(struct super_block *sb, void *data, int silent) { struct jfs_sb_info *sbi; struct inode *inode; int rc; s64 newLVSize = 0; int flag, ret = -EINVAL; jfs_info("In jfs_read_super: s_flags=0x%lx", sb->s_flags); sbi = kzalloc(sizeof(struct jfs_sb_info), GFP_KERNEL); if (!sbi) return -ENOMEM; sb->s_fs_info = sbi; sb->s_max_links = JFS_LINK_MAX; sbi->sb = sb; sbi->uid = INVALID_UID; sbi->gid = INVALID_GID; sbi->umask = -1; /* initialize the mount flag and determine the default error handler */ flag = JFS_ERR_REMOUNT_RO; if (!parse_options((char *) data, sb, &newLVSize, &flag)) goto out_kfree; sbi->flag = flag; #ifdef CONFIG_JFS_POSIX_ACL sb->s_flags |= MS_POSIXACL; #endif if (newLVSize) { pr_err("resize option for remount only\n"); goto out_kfree; } /* * Initialize blocksize to 4K. */ sb_set_blocksize(sb, PSIZE); /* * Set method vectors. */ sb->s_op = &jfs_super_operations; sb->s_export_op = &jfs_export_operations; sb->s_xattr = jfs_xattr_handlers; #ifdef CONFIG_QUOTA sb->dq_op = &dquot_operations; sb->s_qcop = &dquot_quotactl_ops; sb->s_quota_types = QTYPE_MASK_USR | QTYPE_MASK_GRP; #endif /* * Initialize direct-mapping inode/address-space */ inode = new_inode(sb); if (inode == NULL) { ret = -ENOMEM; goto out_unload; } inode->i_ino = 0; inode->i_size = sb->s_bdev->bd_inode->i_size; inode->i_mapping->a_ops = &jfs_metapage_aops; hlist_add_fake(&inode->i_hash); mapping_set_gfp_mask(inode->i_mapping, GFP_NOFS); sbi->direct_inode = inode; rc = jfs_mount(sb); if (rc) { if (!silent) jfs_err("jfs_mount failed w/return code = %d", rc); goto out_mount_failed; } if (sb->s_flags & MS_RDONLY) sbi->log = NULL; else { rc = jfs_mount_rw(sb, 0); if (rc) { if (!silent) { jfs_err("jfs_mount_rw failed, return code = %d", rc); } goto out_no_rw; } } sb->s_magic = JFS_SUPER_MAGIC; if (sbi->mntflag & JFS_OS2) sb->s_d_op = &jfs_ci_dentry_operations; inode = jfs_iget(sb, ROOT_I); if (IS_ERR(inode)) { ret = PTR_ERR(inode); goto out_no_rw; } sb->s_root = d_make_root(inode); if (!sb->s_root) goto out_no_root; /* logical blocks are represented by 40 bits in pxd_t, etc. */ sb->s_maxbytes = ((u64) sb->s_blocksize) << 40; #if BITS_PER_LONG == 32 /* * Page cache is indexed by long. * I would use MAX_LFS_FILESIZE, but it's only half as big */ sb->s_maxbytes = min(((u64) PAGE_SIZE << 32) - 1, (u64)sb->s_maxbytes); #endif sb->s_time_gran = 1; return 0; out_no_root: jfs_err("jfs_read_super: get root dentry failed"); out_no_rw: rc = jfs_umount(sb); if (rc) jfs_err("jfs_umount failed with return code %d", rc); out_mount_failed: filemap_write_and_wait(sbi->direct_inode->i_mapping); truncate_inode_pages(sbi->direct_inode->i_mapping, 0); make_bad_inode(sbi->direct_inode); iput(sbi->direct_inode); sbi->direct_inode = NULL; out_unload: unload_nls(sbi->nls_tab); out_kfree: kfree(sbi); return ret; } static int jfs_freeze(struct super_block *sb) { struct jfs_sb_info *sbi = JFS_SBI(sb); struct jfs_log *log = sbi->log; int rc = 0; if (!(sb->s_flags & MS_RDONLY)) { txQuiesce(sb); rc = lmLogShutdown(log); if (rc) { jfs_error(sb, "lmLogShutdown failed\n"); /* let operations fail rather than hang */ txResume(sb); return rc; } rc = updateSuper(sb, FM_CLEAN); if (rc) { jfs_err("jfs_freeze: updateSuper failed"); /* * Don't fail here. Everything succeeded except * marking the superblock clean, so there's really * no harm in leaving it frozen for now. */ } } return 0; } static int jfs_unfreeze(struct super_block *sb) { struct jfs_sb_info *sbi = JFS_SBI(sb); struct jfs_log *log = sbi->log; int rc = 0; if (!(sb->s_flags & MS_RDONLY)) { rc = updateSuper(sb, FM_MOUNT); if (rc) { jfs_error(sb, "updateSuper failed\n"); goto out; } rc = lmLogInit(log); if (rc) jfs_error(sb, "lmLogInit failed\n"); out: txResume(sb); } return rc; } static struct dentry *jfs_do_mount(struct file_system_type *fs_type, int flags, const char *dev_name, void *data) { return mount_bdev(fs_type, flags, dev_name, data, jfs_fill_super); } static int jfs_sync_fs(struct super_block *sb, int wait) { struct jfs_log *log = JFS_SBI(sb)->log; /* log == NULL indicates read-only mount */ if (log) { /* * Write quota structures to quota file, sync_blockdev() will * write them to disk later */ dquot_writeback_dquots(sb, -1); jfs_flush_journal(log, wait); jfs_syncpt(log, 0); } return 0; } static int jfs_show_options(struct seq_file *seq, struct dentry *root) { struct jfs_sb_info *sbi = JFS_SBI(root->d_sb); if (uid_valid(sbi->uid)) seq_printf(seq, ",uid=%d", from_kuid(&init_user_ns, sbi->uid)); if (gid_valid(sbi->gid)) seq_printf(seq, ",gid=%d", from_kgid(&init_user_ns, sbi->gid)); if (sbi->umask != -1) seq_printf(seq, ",umask=%03o", sbi->umask); if (sbi->flag & JFS_NOINTEGRITY) seq_puts(seq, ",nointegrity"); if (sbi->flag & JFS_DISCARD) seq_printf(seq, ",discard=%u", sbi->minblks_trim); if (sbi->nls_tab) seq_printf(seq, ",iocharset=%s", sbi->nls_tab->charset); if (sbi->flag & JFS_ERR_CONTINUE) seq_printf(seq, ",errors=continue"); if (sbi->flag & JFS_ERR_PANIC) seq_printf(seq, ",errors=panic"); #ifdef CONFIG_QUOTA if (sbi->flag & JFS_USRQUOTA) seq_puts(seq, ",usrquota"); if (sbi->flag & JFS_GRPQUOTA) seq_puts(seq, ",grpquota"); #endif return 0; } #ifdef CONFIG_QUOTA /* Read data from quotafile - avoid pagecache and such because we cannot afford * acquiring the locks... As quota files are never truncated and quota code * itself serializes the operations (and no one else should touch the files) * we don't have to be afraid of races */ static ssize_t jfs_quota_read(struct super_block *sb, int type, char *data, size_t len, loff_t off) { struct inode *inode = sb_dqopt(sb)->files[type]; sector_t blk = off >> sb->s_blocksize_bits; int err = 0; int offset = off & (sb->s_blocksize - 1); int tocopy; size_t toread; struct buffer_head tmp_bh; struct buffer_head *bh; loff_t i_size = i_size_read(inode); if (off > i_size) return 0; if (off+len > i_size) len = i_size-off; toread = len; while (toread > 0) { tocopy = sb->s_blocksize - offset < toread ? sb->s_blocksize - offset : toread; tmp_bh.b_state = 0; tmp_bh.b_size = 1 << inode->i_blkbits; err = jfs_get_block(inode, blk, &tmp_bh, 0); if (err) return err; if (!buffer_mapped(&tmp_bh)) /* A hole? */ memset(data, 0, tocopy); else { bh = sb_bread(sb, tmp_bh.b_blocknr); if (!bh) return -EIO; memcpy(data, bh->b_data+offset, tocopy); brelse(bh); } offset = 0; toread -= tocopy; data += tocopy; blk++; } return len; } /* Write to quotafile */ static ssize_t jfs_quota_write(struct super_block *sb, int type, const char *data, size_t len, loff_t off) { struct inode *inode = sb_dqopt(sb)->files[type]; sector_t blk = off >> sb->s_blocksize_bits; int err = 0; int offset = off & (sb->s_blocksize - 1); int tocopy; size_t towrite = len; struct buffer_head tmp_bh; struct buffer_head *bh; inode_lock(inode); while (towrite > 0) { tocopy = sb->s_blocksize - offset < towrite ? sb->s_blocksize - offset : towrite; tmp_bh.b_state = 0; tmp_bh.b_size = 1 << inode->i_blkbits; err = jfs_get_block(inode, blk, &tmp_bh, 1); if (err) goto out; if (offset || tocopy != sb->s_blocksize) bh = sb_bread(sb, tmp_bh.b_blocknr); else bh = sb_getblk(sb, tmp_bh.b_blocknr); if (!bh) { err = -EIO; goto out; } lock_buffer(bh); memcpy(bh->b_data+offset, data, tocopy); flush_dcache_page(bh->b_page); set_buffer_uptodate(bh); mark_buffer_dirty(bh); unlock_buffer(bh); brelse(bh); offset = 0; towrite -= tocopy; data += tocopy; blk++; } out: if (len == towrite) { inode_unlock(inode); return err; } if (inode->i_size < off+len-towrite) i_size_write(inode, off+len-towrite); inode->i_version++; inode->i_mtime = inode->i_ctime = CURRENT_TIME; mark_inode_dirty(inode); inode_unlock(inode); return len - towrite; } static struct dquot **jfs_get_dquots(struct inode *inode) { return JFS_IP(inode)->i_dquot; } #endif static const struct super_operations jfs_super_operations = { .alloc_inode = jfs_alloc_inode, .destroy_inode = jfs_destroy_inode, .dirty_inode = jfs_dirty_inode, .write_inode = jfs_write_inode, .evict_inode = jfs_evict_inode, .put_super = jfs_put_super, .sync_fs = jfs_sync_fs, .freeze_fs = jfs_freeze, .unfreeze_fs = jfs_unfreeze, .statfs = jfs_statfs, .remount_fs = jfs_remount, .show_options = jfs_show_options, #ifdef CONFIG_QUOTA .quota_read = jfs_quota_read, .quota_write = jfs_quota_write, .get_dquots = jfs_get_dquots, #endif }; static const struct export_operations jfs_export_operations = { .fh_to_dentry = jfs_fh_to_dentry, .fh_to_parent = jfs_fh_to_parent, .get_parent = jfs_get_parent, }; static struct file_system_type jfs_fs_type = { .owner = THIS_MODULE, .name = "jfs", .mount = jfs_do_mount, .kill_sb = kill_block_super, .fs_flags = FS_REQUIRES_DEV, }; MODULE_ALIAS_FS("jfs"); static void init_once(void *foo) { struct jfs_inode_info *jfs_ip = (struct jfs_inode_info *) foo; memset(jfs_ip, 0, sizeof(struct jfs_inode_info)); INIT_LIST_HEAD(&jfs_ip->anon_inode_list); init_rwsem(&jfs_ip->rdwrlock); mutex_init(&jfs_ip->commit_mutex); init_rwsem(&jfs_ip->xattr_sem); spin_lock_init(&jfs_ip->ag_lock); jfs_ip->active_ag = -1; inode_init_once(&jfs_ip->vfs_inode); } static int __init init_jfs_fs(void) { int i; int rc; jfs_inode_cachep = kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0, SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_ACCOUNT, init_once); if (jfs_inode_cachep == NULL) return -ENOMEM; /* * Metapage initialization */ rc = metapage_init(); if (rc) { jfs_err("metapage_init failed w/rc = %d", rc); goto free_slab; } /* * Transaction Manager initialization */ rc = txInit(); if (rc) { jfs_err("txInit failed w/rc = %d", rc); goto free_metapage; } /* * I/O completion thread (endio) */ jfsIOthread = kthread_run(jfsIOWait, NULL, "jfsIO"); if (IS_ERR(jfsIOthread)) { rc = PTR_ERR(jfsIOthread); jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); goto end_txmngr; } if (commit_threads < 1) commit_threads = num_online_cpus(); if (commit_threads > MAX_COMMIT_THREADS) commit_threads = MAX_COMMIT_THREADS; for (i = 0; i < commit_threads; i++) { jfsCommitThread[i] = kthread_run(jfs_lazycommit, NULL, "jfsCommit"); if (IS_ERR(jfsCommitThread[i])) { rc = PTR_ERR(jfsCommitThread[i]); jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); commit_threads = i; goto kill_committask; } } jfsSyncThread = kthread_run(jfs_sync, NULL, "jfsSync"); if (IS_ERR(jfsSyncThread)) { rc = PTR_ERR(jfsSyncThread); jfs_err("init_jfs_fs: fork failed w/rc = %d", rc); goto kill_committask; } #ifdef PROC_FS_JFS jfs_proc_init(); #endif rc = register_filesystem(&jfs_fs_type); if (!rc) return 0; #ifdef PROC_FS_JFS jfs_proc_clean(); #endif kthread_stop(jfsSyncThread); kill_committask: for (i = 0; i < commit_threads; i++) kthread_stop(jfsCommitThread[i]); kthread_stop(jfsIOthread); end_txmngr: txExit(); free_metapage: metapage_exit(); free_slab: kmem_cache_destroy(jfs_inode_cachep); return rc; } static void __exit exit_jfs_fs(void) { int i; jfs_info("exit_jfs_fs called"); txExit(); metapage_exit(); kthread_stop(jfsIOthread); for (i = 0; i < commit_threads; i++) kthread_stop(jfsCommitThread[i]); kthread_stop(jfsSyncThread); #ifdef PROC_FS_JFS jfs_proc_clean(); #endif unregister_filesystem(&jfs_fs_type); /* * Make sure all delayed rcu free inodes are flushed before we * destroy cache. */ rcu_barrier(); kmem_cache_destroy(jfs_inode_cachep); } module_init(init_jfs_fs) module_exit(exit_jfs_fs)
{ "language": "C" }
/** ****************************************************************************** * @file usbd_msc_data.h * @author MCD Application Team * @version V2.0.0 * @date 18-February-2014 * @brief header for the usbd_msc_data.c file ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT 2014 STMicroelectronics</center></h2> * * Licensed under MCD-ST Liberty SW License Agreement V2, (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.st.com/software_license_agreement_liberty_v2 * * 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. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef _USBD_MSC_DATA_H_ #define _USBD_MSC_DATA_H_ /* Includes ------------------------------------------------------------------*/ #include "usbd_conf.h" /** @addtogroup STM32_USB_OTG_DEVICE_LIBRARY * @{ */ /** @defgroup USB_INFO * @brief general defines for the usb device library file * @{ */ /** @defgroup USB_INFO_Exported_Defines * @{ */ #define MODE_SENSE6_LEN 8 #define MODE_SENSE10_LEN 8 #define LENGTH_INQUIRY_PAGE00 7 #define LENGTH_FORMAT_CAPACITIES 20 /** * @} */ /** @defgroup USBD_INFO_Exported_TypesDefinitions * @{ */ /** * @} */ /** @defgroup USBD_INFO_Exported_Macros * @{ */ /** * @} */ /** @defgroup USBD_INFO_Exported_Variables * @{ */ extern const uint8_t MSC_Page00_Inquiry_Data[]; extern const uint8_t MSC_Mode_Sense6_data[]; extern const uint8_t MSC_Mode_Sense10_data[] ; /** * @} */ /** @defgroup USBD_INFO_Exported_FunctionsPrototype * @{ */ /** * @} */ #endif /* _USBD_MSC_DATA_H_ */ /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
{ "language": "C" }
/* Moorestown PMIC GPIO (access through IPC) driver * Copyright (c) 2008 - 2009, Intel Corporation. * * 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., 675 Mass Ave, Cambridge, MA 02139, USA. */ /* Supports: * Moorestown platform PMIC chip */ #define pr_fmt(fmt) "%s: " fmt, __func__ #include <linux/module.h> #include <linux/kernel.h> #include <linux/interrupt.h> #include <linux/delay.h> #include <linux/stddef.h> #include <linux/slab.h> #include <linux/ioport.h> #include <linux/init.h> #include <linux/io.h> #include <linux/gpio.h> #include <asm/intel_scu_ipc.h> #include <linux/device.h> #include <linux/intel_pmic_gpio.h> #include <linux/platform_device.h> #define DRIVER_NAME "pmic_gpio" /* register offset that IPC driver should use * 8 GPIO + 8 GPOSW (6 controllable) + 8GPO */ enum pmic_gpio_register { GPIO0 = 0xE0, GPIO7 = 0xE7, GPIOINT = 0xE8, GPOSWCTL0 = 0xEC, GPOSWCTL5 = 0xF1, GPO = 0xF4, }; /* bits definition for GPIO & GPOSW */ #define GPIO_DRV 0x01 #define GPIO_DIR 0x02 #define GPIO_DIN 0x04 #define GPIO_DOU 0x08 #define GPIO_INTCTL 0x30 #define GPIO_DBC 0xc0 #define GPOSW_DRV 0x01 #define GPOSW_DOU 0x08 #define GPOSW_RDRV 0x30 #define GPIO_UPDATE_TYPE 0x80000000 #define NUM_GPIO 24 struct pmic_gpio { struct mutex buslock; struct gpio_chip chip; void *gpiointr; int irq; unsigned irq_base; unsigned int update_type; u32 trigger_type; }; static void pmic_program_irqtype(int gpio, int type) { if (type & IRQ_TYPE_EDGE_RISING) intel_scu_ipc_update_register(GPIO0 + gpio, 0x20, 0x20); else intel_scu_ipc_update_register(GPIO0 + gpio, 0x00, 0x20); if (type & IRQ_TYPE_EDGE_FALLING) intel_scu_ipc_update_register(GPIO0 + gpio, 0x10, 0x10); else intel_scu_ipc_update_register(GPIO0 + gpio, 0x00, 0x10); }; static int pmic_gpio_direction_input(struct gpio_chip *chip, unsigned offset) { if (offset >= 8) { pr_err("only pin 0-7 support input\n"); return -1;/* we only have 8 GPIO can use as input */ } return intel_scu_ipc_update_register(GPIO0 + offset, GPIO_DIR, GPIO_DIR); } static int pmic_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value) { int rc = 0; if (offset < 8)/* it is GPIO */ rc = intel_scu_ipc_update_register(GPIO0 + offset, GPIO_DRV | (value ? GPIO_DOU : 0), GPIO_DRV | GPIO_DOU | GPIO_DIR); else if (offset < 16)/* it is GPOSW */ rc = intel_scu_ipc_update_register(GPOSWCTL0 + offset - 8, GPOSW_DRV | (value ? GPOSW_DOU : 0), GPOSW_DRV | GPOSW_DOU | GPOSW_RDRV); else if (offset > 15 && offset < 24)/* it is GPO */ rc = intel_scu_ipc_update_register(GPO, value ? 1 << (offset - 16) : 0, 1 << (offset - 16)); else { pr_err("invalid PMIC GPIO pin %d!\n", offset); WARN_ON(1); } return rc; } static int pmic_gpio_get(struct gpio_chip *chip, unsigned offset) { u8 r; int ret; /* we only have 8 GPIO pins we can use as input */ if (offset >= 8) return -EOPNOTSUPP; ret = intel_scu_ipc_ioread8(GPIO0 + offset, &r); if (ret < 0) return ret; return r & GPIO_DIN; } static void pmic_gpio_set(struct gpio_chip *chip, unsigned offset, int value) { if (offset < 8)/* it is GPIO */ intel_scu_ipc_update_register(GPIO0 + offset, GPIO_DRV | (value ? GPIO_DOU : 0), GPIO_DRV | GPIO_DOU); else if (offset < 16)/* it is GPOSW */ intel_scu_ipc_update_register(GPOSWCTL0 + offset - 8, GPOSW_DRV | (value ? GPOSW_DOU : 0), GPOSW_DRV | GPOSW_DOU | GPOSW_RDRV); else if (offset > 15 && offset < 24) /* it is GPO */ intel_scu_ipc_update_register(GPO, value ? 1 << (offset - 16) : 0, 1 << (offset - 16)); } /* * This is called from genirq with pg->buslock locked and * irq_desc->lock held. We can not access the scu bus here, so we * store the change and update in the bus_sync_unlock() function below */ static int pmic_irq_type(struct irq_data *data, unsigned type) { struct pmic_gpio *pg = irq_data_get_irq_chip_data(data); u32 gpio = data->irq - pg->irq_base; if (gpio >= pg->chip.ngpio) return -EINVAL; pg->trigger_type = type; pg->update_type = gpio | GPIO_UPDATE_TYPE; return 0; } static int pmic_gpio_to_irq(struct gpio_chip *chip, unsigned offset) { struct pmic_gpio *pg = container_of(chip, struct pmic_gpio, chip); return pg->irq_base + offset; } static void pmic_bus_lock(struct irq_data *data) { struct pmic_gpio *pg = irq_data_get_irq_chip_data(data); mutex_lock(&pg->buslock); } static void pmic_bus_sync_unlock(struct irq_data *data) { struct pmic_gpio *pg = irq_data_get_irq_chip_data(data); if (pg->update_type) { unsigned int gpio = pg->update_type & ~GPIO_UPDATE_TYPE; pmic_program_irqtype(gpio, pg->trigger_type); pg->update_type = 0; } mutex_unlock(&pg->buslock); } /* the gpiointr register is read-clear, so just do nothing. */ static void pmic_irq_unmask(struct irq_data *data) { } static void pmic_irq_mask(struct irq_data *data) { } static struct irq_chip pmic_irqchip = { .name = "PMIC-GPIO", .irq_mask = pmic_irq_mask, .irq_unmask = pmic_irq_unmask, .irq_set_type = pmic_irq_type, .irq_bus_lock = pmic_bus_lock, .irq_bus_sync_unlock = pmic_bus_sync_unlock, }; static irqreturn_t pmic_irq_handler(int irq, void *data) { struct pmic_gpio *pg = data; u8 intsts = *((u8 *)pg->gpiointr + 4); int gpio; irqreturn_t ret = IRQ_NONE; for (gpio = 0; gpio < 8; gpio++) { if (intsts & (1 << gpio)) { pr_debug("pmic pin %d triggered\n", gpio); generic_handle_irq(pg->irq_base + gpio); ret = IRQ_HANDLED; } } return ret; } static int platform_pmic_gpio_probe(struct platform_device *pdev) { struct device *dev = &pdev->dev; int irq = platform_get_irq(pdev, 0); struct intel_pmic_gpio_platform_data *pdata = dev->platform_data; struct pmic_gpio *pg; int retval; int i; if (irq < 0) { dev_dbg(dev, "no IRQ line\n"); return -EINVAL; } if (!pdata || !pdata->gpio_base || !pdata->irq_base) { dev_dbg(dev, "incorrect or missing platform data\n"); return -EINVAL; } pg = kzalloc(sizeof(*pg), GFP_KERNEL); if (!pg) return -ENOMEM; dev_set_drvdata(dev, pg); pg->irq = irq; /* setting up SRAM mapping for GPIOINT register */ pg->gpiointr = ioremap_nocache(pdata->gpiointr, 8); if (!pg->gpiointr) { pr_err("Can not map GPIOINT\n"); retval = -EINVAL; goto err2; } pg->irq_base = pdata->irq_base; pg->chip.label = "intel_pmic"; pg->chip.direction_input = pmic_gpio_direction_input; pg->chip.direction_output = pmic_gpio_direction_output; pg->chip.get = pmic_gpio_get; pg->chip.set = pmic_gpio_set; pg->chip.to_irq = pmic_gpio_to_irq; pg->chip.base = pdata->gpio_base; pg->chip.ngpio = NUM_GPIO; pg->chip.can_sleep = 1; pg->chip.dev = dev; mutex_init(&pg->buslock); pg->chip.dev = dev; retval = gpiochip_add(&pg->chip); if (retval) { pr_err("Can not add pmic gpio chip\n"); goto err; } retval = request_irq(pg->irq, pmic_irq_handler, 0, "pmic", pg); if (retval) { pr_warn("Interrupt request failed\n"); goto fail_request_irq; } for (i = 0; i < 8; i++) { irq_set_chip_and_handler_name(i + pg->irq_base, &pmic_irqchip, handle_simple_irq, "demux"); irq_set_chip_data(i + pg->irq_base, pg); } return 0; fail_request_irq: gpiochip_remove(&pg->chip); err: iounmap(pg->gpiointr); err2: kfree(pg); return retval; } /* at the same time, register a platform driver * this supports the sfi 0.81 fw */ static struct platform_driver platform_pmic_gpio_driver = { .driver = { .name = DRIVER_NAME, }, .probe = platform_pmic_gpio_probe, }; static int __init platform_pmic_gpio_init(void) { return platform_driver_register(&platform_pmic_gpio_driver); } subsys_initcall(platform_pmic_gpio_init); MODULE_AUTHOR("Alek Du <alek.du@intel.com>"); MODULE_DESCRIPTION("Intel Moorestown PMIC GPIO driver"); MODULE_LICENSE("GPL v2");
{ "language": "C" }
/*! * Copyright (c) 2016 by Contributors * \file array_view.h * \brief Read only data structure to reference array */ #ifndef DMLC_ARRAY_VIEW_H_ #define DMLC_ARRAY_VIEW_H_ #include <vector> #include <array> namespace dmlc { /*! * \brief Read only data structure to reference continuous memory region of array. * Provide unified view for vector, array and C style array. * This data structure do not guarantee aliveness of referenced array. * * Make sure do not use array_view to record data in async function closures. * Also do not use array_view to create reference to temporary data structure. * * \tparam ValueType The value * * \code * std::vector<int> myvec{1,2,3}; * dmlc::array_view<int> view(myvec); * // indexed visit to the view. * LOG(INFO) << view[0]; * * for (int v : view) { * // visit each element in the view * } * \endcode */ template<typename ValueType> class array_view { public: /*! \brief default constructor */ array_view() = default; /*! * \brief default copy constructor * \param other another array view. */ array_view(const array_view<ValueType> &other) = default; // NOLINT(*) #ifndef _MSC_VER /*! * \brief default move constructor * \param other another array view. */ array_view(array_view<ValueType>&& other) = default; // NOLINT(*) #else /*! * \brief default move constructor * \param other another array view. */ array_view(array_view<ValueType>&& other) { // NOLINT(*) begin_ = other.begin_; size_ = other.size_; other.begin_ = nullptr; } #endif /*! * \brief default assign constructor * \param other another array view. * \return self. */ array_view<ValueType>& operator=(const array_view<ValueType>& other) = default; // NOLINT(*) /*! * \brief construct array view std::vector * \param other vector container */ array_view(const std::vector<ValueType>& other) { // NOLINT(*) if (other.size() != 0) { begin_ = &other[0]; size_ = other.size(); } } /*! * \brief construct array std::array * \param other another array view. */ template<std::size_t size> array_view(const std::array<ValueType, size>& other) { // NOLINT(*) if (size != 0) { begin_ = &other[0]; size_ = size; } } /*! * \brief construct array view from continuous segment * \param begin beginning pointre * \param end end pointer */ array_view(const ValueType* begin, const ValueType* end) { if (begin < end) { begin_ = begin; size_ = end - begin; } } /*! \return size of the array */ inline size_t size() const { return size_; } /*! \return begin of the array */ inline const ValueType* begin() const { return begin_; } /*! \return end point of the array */ inline const ValueType* end() const { return begin_ + size_; } /*! * \brief get i-th element from the view * \param i The index. * \return const reference to i-th element. */ inline const ValueType& operator[](size_t i) const { return begin_[i]; } private: /*! \brief the begin of the view */ const ValueType* begin_{nullptr}; /*! \brief The size of the view */ size_t size_{0}; }; } // namespace dmlc #endif // DMLC_ARRAY_VIEW_H_
{ "language": "C" }
/* * RFC 1115/1319 compliant MD2 implementation * * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved * SPDX-License-Identifier: Apache-2.0 * * 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. * * This file is part of mbed TLS (https://tls.mbed.org) */ /* * The MD2 algorithm was designed by Ron Rivest in 1989. * * http://www.ietf.org/rfc/rfc1115.txt * http://www.ietf.org/rfc/rfc1319.txt */ #if !defined(MBEDTLS_CONFIG_FILE) #include "mbedtls/config.h" #else #include MBEDTLS_CONFIG_FILE #endif #if defined(MBEDTLS_MD2_C) #include "mbedtls/md2.h" #include <string.h> #if defined(MBEDTLS_SELF_TEST) #if defined(MBEDTLS_PLATFORM_C) #include "mbedtls/platform.h" #else #include <stdio.h> #define mbedtls_printf printf #endif /* MBEDTLS_PLATFORM_C */ #endif /* MBEDTLS_SELF_TEST */ #if !defined(MBEDTLS_MD2_ALT) /* Implementation that should never be optimized out by the compiler */ static void mbedtls_zeroize( void *v, size_t n ) { volatile unsigned char *p = v; while( n-- ) *p++ = 0; } static const unsigned char PI_SUBST[256] = { 0x29, 0x2E, 0x43, 0xC9, 0xA2, 0xD8, 0x7C, 0x01, 0x3D, 0x36, 0x54, 0xA1, 0xEC, 0xF0, 0x06, 0x13, 0x62, 0xA7, 0x05, 0xF3, 0xC0, 0xC7, 0x73, 0x8C, 0x98, 0x93, 0x2B, 0xD9, 0xBC, 0x4C, 0x82, 0xCA, 0x1E, 0x9B, 0x57, 0x3C, 0xFD, 0xD4, 0xE0, 0x16, 0x67, 0x42, 0x6F, 0x18, 0x8A, 0x17, 0xE5, 0x12, 0xBE, 0x4E, 0xC4, 0xD6, 0xDA, 0x9E, 0xDE, 0x49, 0xA0, 0xFB, 0xF5, 0x8E, 0xBB, 0x2F, 0xEE, 0x7A, 0xA9, 0x68, 0x79, 0x91, 0x15, 0xB2, 0x07, 0x3F, 0x94, 0xC2, 0x10, 0x89, 0x0B, 0x22, 0x5F, 0x21, 0x80, 0x7F, 0x5D, 0x9A, 0x5A, 0x90, 0x32, 0x27, 0x35, 0x3E, 0xCC, 0xE7, 0xBF, 0xF7, 0x97, 0x03, 0xFF, 0x19, 0x30, 0xB3, 0x48, 0xA5, 0xB5, 0xD1, 0xD7, 0x5E, 0x92, 0x2A, 0xAC, 0x56, 0xAA, 0xC6, 0x4F, 0xB8, 0x38, 0xD2, 0x96, 0xA4, 0x7D, 0xB6, 0x76, 0xFC, 0x6B, 0xE2, 0x9C, 0x74, 0x04, 0xF1, 0x45, 0x9D, 0x70, 0x59, 0x64, 0x71, 0x87, 0x20, 0x86, 0x5B, 0xCF, 0x65, 0xE6, 0x2D, 0xA8, 0x02, 0x1B, 0x60, 0x25, 0xAD, 0xAE, 0xB0, 0xB9, 0xF6, 0x1C, 0x46, 0x61, 0x69, 0x34, 0x40, 0x7E, 0x0F, 0x55, 0x47, 0xA3, 0x23, 0xDD, 0x51, 0xAF, 0x3A, 0xC3, 0x5C, 0xF9, 0xCE, 0xBA, 0xC5, 0xEA, 0x26, 0x2C, 0x53, 0x0D, 0x6E, 0x85, 0x28, 0x84, 0x09, 0xD3, 0xDF, 0xCD, 0xF4, 0x41, 0x81, 0x4D, 0x52, 0x6A, 0xDC, 0x37, 0xC8, 0x6C, 0xC1, 0xAB, 0xFA, 0x24, 0xE1, 0x7B, 0x08, 0x0C, 0xBD, 0xB1, 0x4A, 0x78, 0x88, 0x95, 0x8B, 0xE3, 0x63, 0xE8, 0x6D, 0xE9, 0xCB, 0xD5, 0xFE, 0x3B, 0x00, 0x1D, 0x39, 0xF2, 0xEF, 0xB7, 0x0E, 0x66, 0x58, 0xD0, 0xE4, 0xA6, 0x77, 0x72, 0xF8, 0xEB, 0x75, 0x4B, 0x0A, 0x31, 0x44, 0x50, 0xB4, 0x8F, 0xED, 0x1F, 0x1A, 0xDB, 0x99, 0x8D, 0x33, 0x9F, 0x11, 0x83, 0x14 }; void mbedtls_md2_init( mbedtls_md2_context *ctx ) { memset( ctx, 0, sizeof( mbedtls_md2_context ) ); } void mbedtls_md2_free( mbedtls_md2_context *ctx ) { if( ctx == NULL ) return; mbedtls_zeroize( ctx, sizeof( mbedtls_md2_context ) ); } void mbedtls_md2_clone( mbedtls_md2_context *dst, const mbedtls_md2_context *src ) { *dst = *src; } /* * MD2 context setup */ void mbedtls_md2_starts( mbedtls_md2_context *ctx ) { memset( ctx->cksum, 0, 16 ); memset( ctx->state, 0, 46 ); memset( ctx->buffer, 0, 16 ); ctx->left = 0; } #if !defined(MBEDTLS_MD2_PROCESS_ALT) void mbedtls_md2_process( mbedtls_md2_context *ctx ) { int i, j; unsigned char t = 0; for( i = 0; i < 16; i++ ) { ctx->state[i + 16] = ctx->buffer[i]; ctx->state[i + 32] = (unsigned char)( ctx->buffer[i] ^ ctx->state[i]); } for( i = 0; i < 18; i++ ) { for( j = 0; j < 48; j++ ) { ctx->state[j] = (unsigned char) ( ctx->state[j] ^ PI_SUBST[t] ); t = ctx->state[j]; } t = (unsigned char)( t + i ); } t = ctx->cksum[15]; for( i = 0; i < 16; i++ ) { ctx->cksum[i] = (unsigned char) ( ctx->cksum[i] ^ PI_SUBST[ctx->buffer[i] ^ t] ); t = ctx->cksum[i]; } } #endif /* !MBEDTLS_MD2_PROCESS_ALT */ /* * MD2 process buffer */ void mbedtls_md2_update( mbedtls_md2_context *ctx, const unsigned char *input, size_t ilen ) { size_t fill; while( ilen > 0 ) { if( ilen > 16 - ctx->left ) fill = 16 - ctx->left; else fill = ilen; memcpy( ctx->buffer + ctx->left, input, fill ); ctx->left += fill; input += fill; ilen -= fill; if( ctx->left == 16 ) { ctx->left = 0; mbedtls_md2_process( ctx ); } } } /* * MD2 final digest */ void mbedtls_md2_finish( mbedtls_md2_context *ctx, unsigned char output[16] ) { size_t i; unsigned char x; x = (unsigned char)( 16 - ctx->left ); for( i = ctx->left; i < 16; i++ ) ctx->buffer[i] = x; mbedtls_md2_process( ctx ); memcpy( ctx->buffer, ctx->cksum, 16 ); mbedtls_md2_process( ctx ); memcpy( output, ctx->state, 16 ); } #endif /* !MBEDTLS_MD2_ALT */ /* * output = MD2( input buffer ) */ void mbedtls_md2( const unsigned char *input, size_t ilen, unsigned char output[16] ) { mbedtls_md2_context ctx; mbedtls_md2_init( &ctx ); mbedtls_md2_starts( &ctx ); mbedtls_md2_update( &ctx, input, ilen ); mbedtls_md2_finish( &ctx, output ); mbedtls_md2_free( &ctx ); } #if defined(MBEDTLS_SELF_TEST) /* * RFC 1319 test vectors */ static const char md2_test_str[7][81] = { { "" }, { "a" }, { "abc" }, { "message digest" }, { "abcdefghijklmnopqrstuvwxyz" }, { "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" }, { "12345678901234567890123456789012345678901234567890123456789012" \ "345678901234567890" } }; static const unsigned char md2_test_sum[7][16] = { { 0x83, 0x50, 0xE5, 0xA3, 0xE2, 0x4C, 0x15, 0x3D, 0xF2, 0x27, 0x5C, 0x9F, 0x80, 0x69, 0x27, 0x73 }, { 0x32, 0xEC, 0x01, 0xEC, 0x4A, 0x6D, 0xAC, 0x72, 0xC0, 0xAB, 0x96, 0xFB, 0x34, 0xC0, 0xB5, 0xD1 }, { 0xDA, 0x85, 0x3B, 0x0D, 0x3F, 0x88, 0xD9, 0x9B, 0x30, 0x28, 0x3A, 0x69, 0xE6, 0xDE, 0xD6, 0xBB }, { 0xAB, 0x4F, 0x49, 0x6B, 0xFB, 0x2A, 0x53, 0x0B, 0x21, 0x9F, 0xF3, 0x30, 0x31, 0xFE, 0x06, 0xB0 }, { 0x4E, 0x8D, 0xDF, 0xF3, 0x65, 0x02, 0x92, 0xAB, 0x5A, 0x41, 0x08, 0xC3, 0xAA, 0x47, 0x94, 0x0B }, { 0xDA, 0x33, 0xDE, 0xF2, 0xA4, 0x2D, 0xF1, 0x39, 0x75, 0x35, 0x28, 0x46, 0xC3, 0x03, 0x38, 0xCD }, { 0xD5, 0x97, 0x6F, 0x79, 0xD8, 0x3D, 0x3A, 0x0D, 0xC9, 0x80, 0x6C, 0x3C, 0x66, 0xF3, 0xEF, 0xD8 } }; /* * Checkup routine */ int mbedtls_md2_self_test( int verbose ) { int i; unsigned char md2sum[16]; for( i = 0; i < 7; i++ ) { if( verbose != 0 ) mbedtls_printf( " MD2 test #%d: ", i + 1 ); mbedtls_md2( (unsigned char *) md2_test_str[i], strlen( md2_test_str[i] ), md2sum ); if( memcmp( md2sum, md2_test_sum[i], 16 ) != 0 ) { if( verbose != 0 ) mbedtls_printf( "failed\n" ); return( 1 ); } if( verbose != 0 ) mbedtls_printf( "passed\n" ); } if( verbose != 0 ) mbedtls_printf( "\n" ); return( 0 ); } #endif /* MBEDTLS_SELF_TEST */ #endif /* MBEDTLS_MD2_C */
{ "language": "C" }
// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (C) 2014 Texas Instruments Incorporated - http://www.ti.com/ */ #define DSS_SUBSYS_NAME "PLL" #include <linux/delay.h> #include <linux/clk.h> #include <linux/io.h> #include <linux/kernel.h> #include <linux/regulator/consumer.h> #include <linux/sched.h> #include "omapdss.h" #include "dss.h" #define PLL_CONTROL 0x0000 #define PLL_STATUS 0x0004 #define PLL_GO 0x0008 #define PLL_CONFIGURATION1 0x000C #define PLL_CONFIGURATION2 0x0010 #define PLL_CONFIGURATION3 0x0014 #define PLL_SSC_CONFIGURATION1 0x0018 #define PLL_SSC_CONFIGURATION2 0x001C #define PLL_CONFIGURATION4 0x0020 int dss_pll_register(struct dss_device *dss, struct dss_pll *pll) { int i; for (i = 0; i < ARRAY_SIZE(dss->plls); ++i) { if (!dss->plls[i]) { dss->plls[i] = pll; pll->dss = dss; return 0; } } return -EBUSY; } void dss_pll_unregister(struct dss_pll *pll) { struct dss_device *dss = pll->dss; int i; for (i = 0; i < ARRAY_SIZE(dss->plls); ++i) { if (dss->plls[i] == pll) { dss->plls[i] = NULL; pll->dss = NULL; return; } } } struct dss_pll *dss_pll_find(struct dss_device *dss, const char *name) { int i; for (i = 0; i < ARRAY_SIZE(dss->plls); ++i) { if (dss->plls[i] && strcmp(dss->plls[i]->name, name) == 0) return dss->plls[i]; } return NULL; } struct dss_pll *dss_pll_find_by_src(struct dss_device *dss, enum dss_clk_source src) { struct dss_pll *pll; switch (src) { default: case DSS_CLK_SRC_FCK: return NULL; case DSS_CLK_SRC_HDMI_PLL: return dss_pll_find(dss, "hdmi"); case DSS_CLK_SRC_PLL1_1: case DSS_CLK_SRC_PLL1_2: case DSS_CLK_SRC_PLL1_3: pll = dss_pll_find(dss, "dsi0"); if (!pll) pll = dss_pll_find(dss, "video0"); return pll; case DSS_CLK_SRC_PLL2_1: case DSS_CLK_SRC_PLL2_2: case DSS_CLK_SRC_PLL2_3: pll = dss_pll_find(dss, "dsi1"); if (!pll) pll = dss_pll_find(dss, "video1"); return pll; } } unsigned int dss_pll_get_clkout_idx_for_src(enum dss_clk_source src) { switch (src) { case DSS_CLK_SRC_HDMI_PLL: return 0; case DSS_CLK_SRC_PLL1_1: case DSS_CLK_SRC_PLL2_1: return 0; case DSS_CLK_SRC_PLL1_2: case DSS_CLK_SRC_PLL2_2: return 1; case DSS_CLK_SRC_PLL1_3: case DSS_CLK_SRC_PLL2_3: return 2; default: return 0; } } int dss_pll_enable(struct dss_pll *pll) { int r; r = clk_prepare_enable(pll->clkin); if (r) return r; if (pll->regulator) { r = regulator_enable(pll->regulator); if (r) goto err_reg; } r = pll->ops->enable(pll); if (r) goto err_enable; return 0; err_enable: if (pll->regulator) regulator_disable(pll->regulator); err_reg: clk_disable_unprepare(pll->clkin); return r; } void dss_pll_disable(struct dss_pll *pll) { pll->ops->disable(pll); if (pll->regulator) regulator_disable(pll->regulator); clk_disable_unprepare(pll->clkin); memset(&pll->cinfo, 0, sizeof(pll->cinfo)); } int dss_pll_set_config(struct dss_pll *pll, const struct dss_pll_clock_info *cinfo) { int r; r = pll->ops->set_config(pll, cinfo); if (r) return r; pll->cinfo = *cinfo; return 0; } bool dss_pll_hsdiv_calc_a(const struct dss_pll *pll, unsigned long clkdco, unsigned long out_min, unsigned long out_max, dss_hsdiv_calc_func func, void *data) { const struct dss_pll_hw *hw = pll->hw; int m, m_start, m_stop; unsigned long out; out_min = out_min ? out_min : 1; out_max = out_max ? out_max : ULONG_MAX; m_start = max(DIV_ROUND_UP(clkdco, out_max), 1ul); m_stop = min((unsigned)(clkdco / out_min), hw->mX_max); for (m = m_start; m <= m_stop; ++m) { out = clkdco / m; if (func(m, out, data)) return true; } return false; } /* * clkdco = clkin / n * m * 2 * clkoutX = clkdco / mX */ bool dss_pll_calc_a(const struct dss_pll *pll, unsigned long clkin, unsigned long pll_min, unsigned long pll_max, dss_pll_calc_func func, void *data) { const struct dss_pll_hw *hw = pll->hw; int n, n_start, n_stop, n_inc; int m, m_start, m_stop, m_inc; unsigned long fint, clkdco; unsigned long pll_hw_max; unsigned long fint_hw_min, fint_hw_max; pll_hw_max = hw->clkdco_max; fint_hw_min = hw->fint_min; fint_hw_max = hw->fint_max; n_start = max(DIV_ROUND_UP(clkin, fint_hw_max), 1ul); n_stop = min((unsigned)(clkin / fint_hw_min), hw->n_max); n_inc = 1; if (hw->errata_i886) { swap(n_start, n_stop); n_inc = -1; } pll_max = pll_max ? pll_max : ULONG_MAX; for (n = n_start; n != n_stop; n += n_inc) { fint = clkin / n; m_start = max(DIV_ROUND_UP(DIV_ROUND_UP(pll_min, fint), 2), 1ul); m_stop = min3((unsigned)(pll_max / fint / 2), (unsigned)(pll_hw_max / fint / 2), hw->m_max); m_inc = 1; if (hw->errata_i886) { swap(m_start, m_stop); m_inc = -1; } for (m = m_start; m != m_stop; m += m_inc) { clkdco = 2 * m * fint; if (func(n, m, fint, clkdco, data)) return true; } } return false; } /* * This calculates a PLL config that will provide the target_clkout rate * for clkout. Additionally clkdco rate will be the same as clkout rate * when clkout rate is >= min_clkdco. * * clkdco = clkin / n * m + clkin / n * mf / 262144 * clkout = clkdco / m2 */ bool dss_pll_calc_b(const struct dss_pll *pll, unsigned long clkin, unsigned long target_clkout, struct dss_pll_clock_info *cinfo) { unsigned long fint, clkdco, clkout; unsigned long target_clkdco; unsigned long min_dco; unsigned int n, m, mf, m2, sd; const struct dss_pll_hw *hw = pll->hw; DSSDBG("clkin %lu, target clkout %lu\n", clkin, target_clkout); /* Fint */ n = DIV_ROUND_UP(clkin, hw->fint_max); fint = clkin / n; /* adjust m2 so that the clkdco will be high enough */ min_dco = roundup(hw->clkdco_min, fint); m2 = DIV_ROUND_UP(min_dco, target_clkout); if (m2 == 0) m2 = 1; target_clkdco = target_clkout * m2; m = target_clkdco / fint; clkdco = fint * m; /* adjust clkdco with fractional mf */ if (WARN_ON(target_clkdco - clkdco > fint)) mf = 0; else mf = (u32)div_u64(262144ull * (target_clkdco - clkdco), fint); if (mf > 0) clkdco += (u32)div_u64((u64)mf * fint, 262144); clkout = clkdco / m2; /* sigma-delta */ sd = DIV_ROUND_UP(fint * m, 250000000); DSSDBG("N = %u, M = %u, M.f = %u, M2 = %u, SD = %u\n", n, m, mf, m2, sd); DSSDBG("Fint %lu, clkdco %lu, clkout %lu\n", fint, clkdco, clkout); cinfo->n = n; cinfo->m = m; cinfo->mf = mf; cinfo->mX[0] = m2; cinfo->sd = sd; cinfo->fint = fint; cinfo->clkdco = clkdco; cinfo->clkout[0] = clkout; return true; } static int wait_for_bit_change(void __iomem *reg, int bitnum, int value) { unsigned long timeout; ktime_t wait; int t; /* first busyloop to see if the bit changes right away */ t = 100; while (t-- > 0) { if (FLD_GET(readl_relaxed(reg), bitnum, bitnum) == value) return value; } /* then loop for 500ms, sleeping for 1ms in between */ timeout = jiffies + msecs_to_jiffies(500); while (time_before(jiffies, timeout)) { if (FLD_GET(readl_relaxed(reg), bitnum, bitnum) == value) return value; wait = ns_to_ktime(1000 * 1000); set_current_state(TASK_UNINTERRUPTIBLE); schedule_hrtimeout(&wait, HRTIMER_MODE_REL); } return !value; } int dss_pll_wait_reset_done(struct dss_pll *pll) { void __iomem *base = pll->base; if (wait_for_bit_change(base + PLL_STATUS, 0, 1) != 1) return -ETIMEDOUT; else return 0; } static int dss_wait_hsdiv_ack(struct dss_pll *pll, u32 hsdiv_ack_mask) { int t = 100; while (t-- > 0) { u32 v = readl_relaxed(pll->base + PLL_STATUS); v &= hsdiv_ack_mask; if (v == hsdiv_ack_mask) return 0; } return -ETIMEDOUT; } static bool pll_is_locked(u32 stat) { /* * Required value for each bitfield listed below * * PLL_STATUS[6] = 0 PLL_BYPASS * PLL_STATUS[5] = 0 PLL_HIGHJITTER * * PLL_STATUS[3] = 0 PLL_LOSSREF * PLL_STATUS[2] = 0 PLL_RECAL * PLL_STATUS[1] = 1 PLL_LOCK * PLL_STATUS[0] = 1 PLL_CTRL_RESET_DONE */ return ((stat & 0x6f) == 0x3); } int dss_pll_write_config_type_a(struct dss_pll *pll, const struct dss_pll_clock_info *cinfo) { const struct dss_pll_hw *hw = pll->hw; void __iomem *base = pll->base; int r = 0; u32 l; l = 0; if (hw->has_stopmode) l = FLD_MOD(l, 1, 0, 0); /* PLL_STOPMODE */ l = FLD_MOD(l, cinfo->n - 1, hw->n_msb, hw->n_lsb); /* PLL_REGN */ l = FLD_MOD(l, cinfo->m, hw->m_msb, hw->m_lsb); /* PLL_REGM */ /* M4 */ l = FLD_MOD(l, cinfo->mX[0] ? cinfo->mX[0] - 1 : 0, hw->mX_msb[0], hw->mX_lsb[0]); /* M5 */ l = FLD_MOD(l, cinfo->mX[1] ? cinfo->mX[1] - 1 : 0, hw->mX_msb[1], hw->mX_lsb[1]); writel_relaxed(l, base + PLL_CONFIGURATION1); l = 0; /* M6 */ l = FLD_MOD(l, cinfo->mX[2] ? cinfo->mX[2] - 1 : 0, hw->mX_msb[2], hw->mX_lsb[2]); /* M7 */ l = FLD_MOD(l, cinfo->mX[3] ? cinfo->mX[3] - 1 : 0, hw->mX_msb[3], hw->mX_lsb[3]); writel_relaxed(l, base + PLL_CONFIGURATION3); l = readl_relaxed(base + PLL_CONFIGURATION2); if (hw->has_freqsel) { u32 f = cinfo->fint < 1000000 ? 0x3 : cinfo->fint < 1250000 ? 0x4 : cinfo->fint < 1500000 ? 0x5 : cinfo->fint < 1750000 ? 0x6 : 0x7; l = FLD_MOD(l, f, 4, 1); /* PLL_FREQSEL */ } else if (hw->has_selfreqdco) { u32 f = cinfo->clkdco < hw->clkdco_low ? 0x2 : 0x4; l = FLD_MOD(l, f, 3, 1); /* PLL_SELFREQDCO */ } l = FLD_MOD(l, 1, 13, 13); /* PLL_REFEN */ l = FLD_MOD(l, 0, 14, 14); /* PHY_CLKINEN */ l = FLD_MOD(l, 0, 16, 16); /* M4_CLOCK_EN */ l = FLD_MOD(l, 0, 18, 18); /* M5_CLOCK_EN */ l = FLD_MOD(l, 1, 20, 20); /* HSDIVBYPASS */ if (hw->has_refsel) l = FLD_MOD(l, 3, 22, 21); /* REFSEL = sysclk */ l = FLD_MOD(l, 0, 23, 23); /* M6_CLOCK_EN */ l = FLD_MOD(l, 0, 25, 25); /* M7_CLOCK_EN */ writel_relaxed(l, base + PLL_CONFIGURATION2); if (hw->errata_i932) { int cnt = 0; u32 sleep_time; const u32 max_lock_retries = 20; /* * Calculate wait time for PLL LOCK * 1000 REFCLK cycles in us. */ sleep_time = DIV_ROUND_UP(1000*1000*1000, cinfo->fint); for (cnt = 0; cnt < max_lock_retries; cnt++) { writel_relaxed(1, base + PLL_GO); /* PLL_GO */ /** * read the register back to ensure the write is * flushed */ readl_relaxed(base + PLL_GO); usleep_range(sleep_time, sleep_time + 5); l = readl_relaxed(base + PLL_STATUS); if (pll_is_locked(l) && !(readl_relaxed(base + PLL_GO) & 0x1)) break; } if (cnt == max_lock_retries) { DSSERR("cannot lock PLL\n"); r = -EIO; goto err; } } else { writel_relaxed(1, base + PLL_GO); /* PLL_GO */ if (wait_for_bit_change(base + PLL_GO, 0, 0) != 0) { DSSERR("DSS DPLL GO bit not going down.\n"); r = -EIO; goto err; } if (wait_for_bit_change(base + PLL_STATUS, 1, 1) != 1) { DSSERR("cannot lock DSS DPLL\n"); r = -EIO; goto err; } } l = readl_relaxed(base + PLL_CONFIGURATION2); l = FLD_MOD(l, 1, 14, 14); /* PHY_CLKINEN */ l = FLD_MOD(l, cinfo->mX[0] ? 1 : 0, 16, 16); /* M4_CLOCK_EN */ l = FLD_MOD(l, cinfo->mX[1] ? 1 : 0, 18, 18); /* M5_CLOCK_EN */ l = FLD_MOD(l, 0, 20, 20); /* HSDIVBYPASS */ l = FLD_MOD(l, cinfo->mX[2] ? 1 : 0, 23, 23); /* M6_CLOCK_EN */ l = FLD_MOD(l, cinfo->mX[3] ? 1 : 0, 25, 25); /* M7_CLOCK_EN */ writel_relaxed(l, base + PLL_CONFIGURATION2); r = dss_wait_hsdiv_ack(pll, (cinfo->mX[0] ? BIT(7) : 0) | (cinfo->mX[1] ? BIT(8) : 0) | (cinfo->mX[2] ? BIT(10) : 0) | (cinfo->mX[3] ? BIT(11) : 0)); if (r) { DSSERR("failed to enable HSDIV clocks\n"); goto err; } err: return r; } int dss_pll_write_config_type_b(struct dss_pll *pll, const struct dss_pll_clock_info *cinfo) { const struct dss_pll_hw *hw = pll->hw; void __iomem *base = pll->base; u32 l; l = 0; l = FLD_MOD(l, cinfo->m, 20, 9); /* PLL_REGM */ l = FLD_MOD(l, cinfo->n - 1, 8, 1); /* PLL_REGN */ writel_relaxed(l, base + PLL_CONFIGURATION1); l = readl_relaxed(base + PLL_CONFIGURATION2); l = FLD_MOD(l, 0x0, 12, 12); /* PLL_HIGHFREQ divide by 2 */ l = FLD_MOD(l, 0x1, 13, 13); /* PLL_REFEN */ l = FLD_MOD(l, 0x0, 14, 14); /* PHY_CLKINEN */ if (hw->has_refsel) l = FLD_MOD(l, 0x3, 22, 21); /* REFSEL = SYSCLK */ /* PLL_SELFREQDCO */ if (cinfo->clkdco > hw->clkdco_low) l = FLD_MOD(l, 0x4, 3, 1); else l = FLD_MOD(l, 0x2, 3, 1); writel_relaxed(l, base + PLL_CONFIGURATION2); l = readl_relaxed(base + PLL_CONFIGURATION3); l = FLD_MOD(l, cinfo->sd, 17, 10); /* PLL_REGSD */ writel_relaxed(l, base + PLL_CONFIGURATION3); l = readl_relaxed(base + PLL_CONFIGURATION4); l = FLD_MOD(l, cinfo->mX[0], 24, 18); /* PLL_REGM2 */ l = FLD_MOD(l, cinfo->mf, 17, 0); /* PLL_REGM_F */ writel_relaxed(l, base + PLL_CONFIGURATION4); writel_relaxed(1, base + PLL_GO); /* PLL_GO */ if (wait_for_bit_change(base + PLL_GO, 0, 0) != 0) { DSSERR("DSS DPLL GO bit not going down.\n"); return -EIO; } if (wait_for_bit_change(base + PLL_STATUS, 1, 1) != 1) { DSSERR("cannot lock DSS DPLL\n"); return -ETIMEDOUT; } return 0; }
{ "language": "C" }
/* * libEtPan! -- a mail stuff library * * Copyright (C) 2001, 2005 - DINH Viet Hoa * 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 the libEtPan! project 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 AUTHORS 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 AUTHORS 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. */ /* * $Id: newsnntp.h,v 1.21 2008/02/20 22:15:53 hoa Exp $ */ #ifndef NEWSNNTP_H #define NEWSNNTP_H #ifdef __cplusplus extern "C" { #endif #ifdef HAVE_INTTYPES_H # include <inttypes.h> #endif #include <sys/types.h> #include <time.h> #include <libetpan/clist.h> #include <libetpan/mailstream.h> #include <libetpan/newsnntp_socket.h> #include <libetpan/newsnntp_ssl.h> #include <libetpan/newsnntp_types.h> /* newsnntp_new() This function returns a new NNTP session. @param progr_rate When downloading messages, a function will be called each time the amount of bytes downloaded reaches a multiple of this value, this can be 0. @param progr_fun This is the function to call to notify the progress, this can be NULL. @return an NNTP session is returned. */ LIBETPAN_EXPORT newsnntp * newsnntp_new(size_t nntp_progr_rate, progress_function * nntp_progr_fun); /* newsnntp_free() This function will free the data structures associated with the NNTP session. @param session NNTP session */ LIBETPAN_EXPORT void newsnntp_free(newsnntp * session); /* newsnntp_set_logger() set a logger for the connection. @param session NNTP session @param logger logger function. See mailstream_types.h to know possible log_type values. str is the log, data received or data sent. @param logger_context parameter that is passed to the logger function. @return the value of the timeout in seconds. */ LIBETPAN_EXPORT void newsnntp_set_logger(newsnntp * session, void (* logger)(newsnntp * session, int log_type, const char * str, size_t size, void * context), void * logger_context); /* newsnntp_set_progress_callback() set NNTP progression callbacks. @param session NNTP session @param progr_fun callback function. */ LIBETPAN_EXPORT void newsnntp_set_progress_callback(newsnntp * f, mailprogress_function * progr_fun, void * context); /* newsnntp_set_timeout() set the network timeout of the NNTP session. @param session NNTP session @param timeout value of the timeout in seconds. */ LIBETPAN_EXPORT void newsnntp_set_timeout(newsnntp * session, time_t timeout); /* newsnntp_get_timeout() get the network timeout of the NNTP session. @param session NNTP session @return value of the timeout in seconds. */ LIBETPAN_EXPORT time_t newsnntp_get_timeout(newsnntp * session); /* newsnntp_connect() This function will connect the NNTP session with the given stream. @param session the NNTP session @param s stream to use @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_connect(newsnntp * session, mailstream * s); /* newsnntp_quit() disconnect the NNTP session. @param session NNTP session */ LIBETPAN_EXPORT int newsnntp_quit(newsnntp * session); /* newsnntp_head() fetch the headers of an article. @param session NNTP session @param indx index of the article to fetch. @param result the header data. @param result_len the length of the result data. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_head(newsnntp * session, uint32_t indx, char ** result, size_t * result_len); /* newsnntp_head_free() This function will free the data associated with an NNTP article header. @param str header data. */ LIBETPAN_EXPORT void newsnntp_head_free(char * str); /* newsnntp_article() fetch the header and contents of an article. @param session NNTP session @param indx index of the article to fetch. @param result the article data. @param result_len the length of the result data. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_article(newsnntp * session, uint32_t indx, char ** result, size_t * result_len); /* newsnntp_article_by_message_id() fetch the header and contents of an article by message id. @param session NNTP session @param msg_id ID of the article to fetch. @param result The article data. @param result_len The length of the result data. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_article_by_message_id(newsnntp * session, char * msg_id, char ** result, size_t * result_len); /* newsnntp_article_free() This function will free the data associated with an NNTP article. @param str article data. */ LIBETPAN_EXPORT void newsnntp_article_free(char * str); /* newsnntp_body() fetch the contents of an article. @param session NNTP session @param indx index of the article to fetch. @param result body data. @param result_len length of the result data. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_body(newsnntp * session, uint32_t indx, char ** result, size_t * result_len); /* newsnntp_body_free() This function will free the data associated with an NNTP article body. @param str article body data. */ LIBETPAN_EXPORT void newsnntp_body_free(char * str); /* newsnntp_mode_reader() switch the mode of the server to reader mode. @param session NNTP session @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_mode_reader(newsnntp * session); /* newsnntp_date() fetches the current Coordinated Universal Time from the server's perspective. @param session NNTP session @param tm server's current time. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_date(newsnntp * session, struct tm * tm); /* newsnntp_authinfo_username() sets the session's username. @param session NNTP session @param username username. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_authinfo_username(newsnntp * session, const char * username); /* newsnntp_authinfo_password() sets the session's password. @param session NNTP session @param username password. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_authinfo_password(newsnntp * session, const char * password); /* newsnntp_post() posts a message to a newsgroup. @param session NNTP session @param message the message data. @param size the size of the message. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_post(newsnntp * session, const char * message, size_t size); /******************* requests ******************************/ /* newsnntp_group() select a newsgroup and fetch info about it. @param session NNTP session @param groupname name of the newsgroup. @param info information about the group. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_group(newsnntp * session, const char * groupname, struct newsnntp_group_info ** info); /* newsnntp_group_free() This function will free the data associated with NNTP group data. @param info group info. */ LIBETPAN_EXPORT void newsnntp_group_free(struct newsnntp_group_info * info); /* newsnntp_list() select a newsgroup and fetch info about it. @param session NNTP session @param result list of struct newsnntp_group_info *. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_list(newsnntp * session, clist ** result); /* newsnntp_list_free() This function will free the data associated with a list of newsnntp_group_info *. @param l the list of group info. */ LIBETPAN_EXPORT void newsnntp_list_free(clist * l); /* newsnntp_list_overview_fmt() fetch the server's format overview. @param session NNTP session @param result string describing the server's format @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_list_overview_fmt(newsnntp * session, clist ** result); /* newsnntp_list_overview_fmt_free() This function will free the data associated with a list obtained from newsnntp_list_overview_fmt() @param l the list of format data. */ LIBETPAN_EXPORT void newsnntp_list_overview_fmt_free(clist * l); /* newsnntp_list_active() fetch groups matching a wildmat string. @param session NNTP session @param wildmat an optional wildmat pattern string @param result a list of struct newsnntp_group_info * @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_list_active(newsnntp * session, const char * wildmat, clist ** result); /* newsnntp_list_active_free() This function will free the data associated with a list obtained from newsnntp_list_active() @param l the list of group data. */ LIBETPAN_EXPORT void newsnntp_list_active_free(clist * l); /* newsnntp_list_active_times() fetches when the selected newsgroup was created. @param session NNTP session @param result a list of struct newsnntp_group_time * @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_list_active_times(newsnntp * session, clist ** result); /* newsnntp_list_active_times_free() This function will free the data associated with a list obtained from newsnntp_list_active_times() @param l the list of group time data. */ LIBETPAN_EXPORT void newsnntp_list_active_times_free(clist * l); /* newsnntp_list_distribution() fetches a list of descriptions of distributions known to the server. @param session NNTP session @param result a list of struct newsnntp_distrib_value_meaning * @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_list_distribution(newsnntp * session, clist ** result); /* newsnntp_list_distribution_free() This function will free the data associated with a list obtained from newsnntp_list_distribution() @param l the list of distribution data. */ LIBETPAN_EXPORT void newsnntp_list_distribution_free(clist * l); /* newsnntp_list_distrib_pats() fetches a list of canonical distribution values. Good for figuring out what to put in the Distribution header of an article being posted. @param session NNTP session @param result a list of struct newsnntp_distrib_default_value * @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_list_distrib_pats(newsnntp * session, clist ** result); /* newsnntp_list_distribution_free() This function will free the data associated with a list obtained from newsnntp_list_distrib_pats() @param l the list of distribution data. */ LIBETPAN_EXPORT void newsnntp_list_distrib_pats_free(clist * l); /* newsnntp_list_newsgroups() fetches a list of newsgroups and their descriptions. @param session NNTP session @param pattern an optional wildmat pattern @param result a list of struct newsnntp_group_description * @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_list_newsgroups(newsnntp * session, const char * pattern, clist ** result); /* newsnntp_list_newsgroups_free() This function will free the data associated with a list obtained from newsnntp_list_newsgroups() @param l the list of newsgroup data. */ LIBETPAN_EXPORT void newsnntp_list_newsgroups_free(clist * l); /* newsnntp_list_subscriptions() fetches a default list of subscriptions for new users of the server. @param session NNTP session @param result a list of newsgroup name strings @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_list_subscriptions(newsnntp * session, clist ** result); /* newsnntp_list_subscriptions_free() This function will free the data associated with a list of subscriptions. @param l the list of newsgroup data. */ LIBETPAN_EXPORT void newsnntp_list_subscriptions_free(clist * l); /* newsnntp_listgroup() fetches a list of all article numbers for a particular group. @param session NNTP session @param group_name the group name @param result a list of uint32_t article numbers @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_listgroup(newsnntp * session, const char * group_name, clist ** result); /* newsnntp_listgroup_free() This function will free the data associated with a list of subscriptions. @param l the list of article numbers. */ LIBETPAN_EXPORT void newsnntp_listgroup_free(clist * l); /* newsnntp_xhdr_single() retrieves specific header fields from a specific article. @param session NNTP session @param header the field name @param result a list of struct newsnntp_xhdr_resp_item *. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_xhdr_single(newsnntp * session, const char * header, uint32_t article, clist ** result); /* newsnntp_xhdr_range() retrieves specific header fields from a range of specific articles. @param session NNTP session @param header the field name @param rangeinf the lower bound of the range @param rangesup the upper bound of the range @param result a list of struct newsnntp_xhdr_resp_item *. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_xhdr_range(newsnntp * session, const char * header, uint32_t rangeinf, uint32_t rangesup, clist ** result); /* newsnntp_xhdr_free() This function will free the data associated with a list of struct newsnntp_xhdr_resp_item *. @param l the list of article header responses. */ LIBETPAN_EXPORT void newsnntp_xhdr_free(clist * l); /* newsnntp_xover_single() retrieves overview data for a specific article. @param session NNTP session @param header the field name @param result a list of struct newsnntp_xhdr_resp_item *. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_xover_single(newsnntp * session, uint32_t article, struct newsnntp_xover_resp_item ** result); /* newsnntp_xover_range() retrieves overview information for a particular range of articles. @param session NNTP session @param header the field name @param rangeinf the lower bound of the range @param rangesup the upper bound of the range @param result a list of struct newsnntp_xover_resp_item *. @return the return code is one of NEWSNNTP_ERROR_XXX or NEWSNNTP_NO_ERROR codes */ LIBETPAN_EXPORT int newsnntp_xover_range(newsnntp * session, uint32_t rangeinf, uint32_t rangesup, clist ** result); void xover_resp_item_free(struct newsnntp_xover_resp_item * n); /* newsnntp_xover_resp_list_free() This function will free the data associated with a list of struct newsnntp_xover_resp_item *. @param l the list of overview responses. */ LIBETPAN_EXPORT void newsnntp_xover_resp_list_free(clist * l); /* deprecated */ LIBETPAN_EXPORT int newsnntp_authinfo_generic(newsnntp * session, const char * authentificator, const char * arguments); #ifdef __cplusplus } #endif #endif
{ "language": "C" }
#include <stdio.h> #ifndef GC_DEBUG # define GC_DEBUG #endif #include "gc.h" #include "gc_backptr.h" struct treenode { struct treenode *x; struct treenode *y; } * root[10]; struct treenode * mktree(int i) { struct treenode * r = GC_MALLOC(sizeof(struct treenode)); if (0 == i) return 0; if (1 == i) r = GC_MALLOC_ATOMIC(sizeof(struct treenode)); r -> x = mktree(i-1); r -> y = mktree(i-1); return r; } int main(void) { int i; GC_INIT(); for (i = 0; i < 10; ++i) { root[i] = mktree(12); } GC_generate_random_backtrace(); GC_generate_random_backtrace(); GC_generate_random_backtrace(); GC_generate_random_backtrace(); return 0; }
{ "language": "C" }
/* Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. L. Peter Deutsch ghost@aladdin.com */ /* $Id: md5.c,v 1.6 2002/04/13 19:20:28 lpd Exp $ */ /* Independent implementation of MD5 (RFC 1321). This code implements the MD5 Algorithm defined in RFC 1321, whose text is available at http://www.ietf.org/rfc/rfc1321.txt The code is derived from the text of the RFC, including the test suite (section A.5) but excluding the rest of Appendix A. It does not include any code or documentation that is identified in the RFC as being copyrighted. The original and principal author of md5.c is L. Peter Deutsch <ghost@aladdin.com>. Other authors are noted in the change history that follows (in reverse chronological order): 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order either statically or dynamically; added missing #include <string.h> in library. 2002-03-11 lpd Corrected argument list for main(), and added int return type, in test program and T value program. 2002-02-21 lpd Added missing #include <stdio.h> in test program. 2000-07-03 lpd Patched to eliminate warnings about "constant is unsigned in ANSI C, signed in traditional"; made test program self-checking. 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). 1999-05-03 lpd Original version. */ #include "md5.h" #include <string.h> #include <limits.h> #undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ #ifdef ARCH_IS_BIG_ENDIAN # define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) #else # define BYTE_ORDER 0 #endif #define T_MASK ((md5_word_t)~0) #define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) #define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) #define T3 0x242070db #define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) #define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) #define T6 0x4787c62a #define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) #define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) #define T9 0x698098d8 #define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) #define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) #define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) #define T13 0x6b901122 #define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) #define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) #define T16 0x49b40821 #define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) #define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) #define T19 0x265e5a51 #define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) #define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) #define T22 0x02441453 #define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) #define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) #define T25 0x21e1cde6 #define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) #define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) #define T28 0x455a14ed #define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) #define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) #define T31 0x676f02d9 #define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) #define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) #define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) #define T35 0x6d9d6122 #define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) #define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) #define T38 0x4bdecfa9 #define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) #define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) #define T41 0x289b7ec6 #define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) #define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) #define T44 0x04881d05 #define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) #define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) #define T47 0x1fa27cf8 #define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) #define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) #define T50 0x432aff97 #define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) #define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) #define T53 0x655b59c3 #define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) #define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) #define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) #define T57 0x6fa87e4f #define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) #define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) #define T60 0x4e0811a1 #define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) #define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) #define T63 0x2ad7d2bb #define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) static void md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) { md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2], d = pms->abcd[3]; md5_word_t t; #if BYTE_ORDER > 0 /* Define storage only for big-endian CPUs. */ md5_word_t X[16]; #else /* Define storage for little-endian or both types of CPUs. */ md5_word_t xbuf[16]; const md5_word_t *X; #endif { #if BYTE_ORDER == 0 /* * Determine dynamically whether this is a big-endian or * little-endian machine, since we can use a more efficient * algorithm on the latter. */ static const int w = 1; if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ #endif #if BYTE_ORDER <= 0 /* little-endian */ { /* * On little-endian machines, we can process properly aligned * data without copying it. */ if (!((data - (const md5_byte_t *)0) & 3)) { /* data are properly aligned */ X = (const md5_word_t *)data; } else { /* not aligned */ memcpy(xbuf, data, 64); X = xbuf; } } #endif #if BYTE_ORDER == 0 else /* dynamic big-endian */ #endif #if BYTE_ORDER >= 0 /* big-endian */ { /* * On big-endian machines, we must arrange the bytes in the * right order. */ const md5_byte_t *xp = data; int i; # if BYTE_ORDER == 0 X = xbuf; /* (dynamic only) */ # else # define xbuf X /* (static only) */ # endif for (i = 0; i < 16; ++i, xp += 4) xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); } #endif } #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) /* Round 1. */ /* Let [abcd k s i] denote the operation a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ #define F(x, y, z) (((x) & (y)) | (~(x) & (z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + F(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 7, T1); SET(d, a, b, c, 1, 12, T2); SET(c, d, a, b, 2, 17, T3); SET(b, c, d, a, 3, 22, T4); SET(a, b, c, d, 4, 7, T5); SET(d, a, b, c, 5, 12, T6); SET(c, d, a, b, 6, 17, T7); SET(b, c, d, a, 7, 22, T8); SET(a, b, c, d, 8, 7, T9); SET(d, a, b, c, 9, 12, T10); SET(c, d, a, b, 10, 17, T11); SET(b, c, d, a, 11, 22, T12); SET(a, b, c, d, 12, 7, T13); SET(d, a, b, c, 13, 12, T14); SET(c, d, a, b, 14, 17, T15); SET(b, c, d, a, 15, 22, T16); #undef SET /* Round 2. */ /* Let [abcd k s i] denote the operation a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ #define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + G(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 1, 5, T17); SET(d, a, b, c, 6, 9, T18); SET(c, d, a, b, 11, 14, T19); SET(b, c, d, a, 0, 20, T20); SET(a, b, c, d, 5, 5, T21); SET(d, a, b, c, 10, 9, T22); SET(c, d, a, b, 15, 14, T23); SET(b, c, d, a, 4, 20, T24); SET(a, b, c, d, 9, 5, T25); SET(d, a, b, c, 14, 9, T26); SET(c, d, a, b, 3, 14, T27); SET(b, c, d, a, 8, 20, T28); SET(a, b, c, d, 13, 5, T29); SET(d, a, b, c, 2, 9, T30); SET(c, d, a, b, 7, 14, T31); SET(b, c, d, a, 12, 20, T32); #undef SET /* Round 3. */ /* Let [abcd k s t] denote the operation a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ #define H(x, y, z) ((x) ^ (y) ^ (z)) #define SET(a, b, c, d, k, s, Ti)\ t = a + H(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 5, 4, T33); SET(d, a, b, c, 8, 11, T34); SET(c, d, a, b, 11, 16, T35); SET(b, c, d, a, 14, 23, T36); SET(a, b, c, d, 1, 4, T37); SET(d, a, b, c, 4, 11, T38); SET(c, d, a, b, 7, 16, T39); SET(b, c, d, a, 10, 23, T40); SET(a, b, c, d, 13, 4, T41); SET(d, a, b, c, 0, 11, T42); SET(c, d, a, b, 3, 16, T43); SET(b, c, d, a, 6, 23, T44); SET(a, b, c, d, 9, 4, T45); SET(d, a, b, c, 12, 11, T46); SET(c, d, a, b, 15, 16, T47); SET(b, c, d, a, 2, 23, T48); #undef SET /* Round 4. */ /* Let [abcd k s t] denote the operation a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ #define I(x, y, z) ((y) ^ ((x) | ~(z))) #define SET(a, b, c, d, k, s, Ti)\ t = a + I(b,c,d) + X[k] + Ti;\ a = ROTATE_LEFT(t, s) + b /* Do the following 16 operations. */ SET(a, b, c, d, 0, 6, T49); SET(d, a, b, c, 7, 10, T50); SET(c, d, a, b, 14, 15, T51); SET(b, c, d, a, 5, 21, T52); SET(a, b, c, d, 12, 6, T53); SET(d, a, b, c, 3, 10, T54); SET(c, d, a, b, 10, 15, T55); SET(b, c, d, a, 1, 21, T56); SET(a, b, c, d, 8, 6, T57); SET(d, a, b, c, 15, 10, T58); SET(c, d, a, b, 6, 15, T59); SET(b, c, d, a, 13, 21, T60); SET(a, b, c, d, 4, 6, T61); SET(d, a, b, c, 11, 10, T62); SET(c, d, a, b, 2, 15, T63); SET(b, c, d, a, 9, 21, T64); #undef SET /* Then perform the following additions. (That is increment each of the four registers by the value it had before this block was started.) */ pms->abcd[0] += a; pms->abcd[1] += b; pms->abcd[2] += c; pms->abcd[3] += d; } void md5_init(md5_state_t *pms) { pms->count[0] = pms->count[1] = 0; pms->abcd[0] = 0x67452301; pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; pms->abcd[3] = 0x10325476; } void md5_append(md5_state_t *pms, const md5_byte_t *data, unsigned int nbytes) { const md5_byte_t *p = data; unsigned int left = nbytes; unsigned int offset = (pms->count[0] >> 3) & 63; md5_word_t nbits = (md5_word_t)(nbytes << 3); if (nbytes <= 0) return; /* this special case is handled recursively */ if (nbytes > INT_MAX - offset) { unsigned int overlap; /* handle the append in two steps to prevent overflow */ overlap = 64 - offset; md5_append(pms, data, overlap); md5_append(pms, data + overlap, nbytes - overlap); return; } /* Update the message length. */ pms->count[1] += nbytes >> 29; pms->count[0] += nbits; if (pms->count[0] < nbits) pms->count[1]++; /* Process an initial partial block. */ if (offset) { unsigned int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); memcpy(pms->buf + offset, p, copy); if (offset + copy < 64) return; p += copy; left -= copy; md5_process(pms, pms->buf); } /* Process full blocks. */ for (; left >= 64; p += 64, left -= 64) md5_process(pms, p); /* Process a final partial block. */ if (left) memcpy(pms->buf, p, left); } void md5_finish(md5_state_t *pms, md5_byte_t digest[16]) { static const md5_byte_t pad[64] = { 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; md5_byte_t data[8]; int i; /* Save the length before padding. */ for (i = 0; i < 8; ++i) data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); /* Pad to 56 bytes mod 64. */ md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); /* Append the length. */ md5_append(pms, data, 8); for (i = 0; i < 16; ++i) digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); }
{ "language": "C" }
/****************************************************************************** * * Copyright(c) 2009-2012 Realtek Corporation. * * 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. * * The full GNU General Public License is included in this distribution in the * file called LICENSE. * * Contact Information: * wlanfae <wlanfae@realtek.com> * Realtek Corporation, No. 2, Innovation Road II, Hsinchu Science Park, * Hsinchu 300, Taiwan. * * Larry Finger <Larry.Finger@lwfinger.net> * *****************************************************************************/ #ifndef __RTL92DE_HW_H__ #define __RTL92DE_HW_H__ void rtl92de_get_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val); void rtl92de_read_eeprom_info(struct ieee80211_hw *hw); void rtl92de_interrupt_recognized(struct ieee80211_hw *hw, u32 *p_inta, u32 *p_intb); int rtl92de_hw_init(struct ieee80211_hw *hw); void rtl92de_card_disable(struct ieee80211_hw *hw); void rtl92de_enable_interrupt(struct ieee80211_hw *hw); void rtl92de_disable_interrupt(struct ieee80211_hw *hw); int rtl92de_set_network_type(struct ieee80211_hw *hw, enum nl80211_iftype type); void rtl92de_set_check_bssid(struct ieee80211_hw *hw, bool check_bssid); void rtl92de_set_qos(struct ieee80211_hw *hw, int aci); void rtl92de_set_beacon_related_registers(struct ieee80211_hw *hw); void rtl92de_set_beacon_interval(struct ieee80211_hw *hw); void rtl92de_update_interrupt_mask(struct ieee80211_hw *hw, u32 add_msr, u32 rm_msr); void rtl92de_set_hw_reg(struct ieee80211_hw *hw, u8 variable, u8 *val); void rtl92de_update_hal_rate_tbl(struct ieee80211_hw *hw, struct ieee80211_sta *sta, u8 rssi_level); void rtl92de_update_channel_access_setting(struct ieee80211_hw *hw); bool rtl92de_gpio_radio_on_off_checking(struct ieee80211_hw *hw, u8 *valid); void rtl92de_enable_hw_security_config(struct ieee80211_hw *hw); void rtl92de_set_key(struct ieee80211_hw *hw, u32 key_index, u8 *p_macaddr, bool is_group, u8 enc_algo, bool is_wepkey, bool clear_all); void rtl92de_write_dword_dbi(struct ieee80211_hw *hw, u16 offset, u32 value, u8 direct); u32 rtl92de_read_dword_dbi(struct ieee80211_hw *hw, u16 offset, u8 direct); void rtl92de_suspend(struct ieee80211_hw *hw); void rtl92de_resume(struct ieee80211_hw *hw); void rtl92d_linked_set_reg(struct ieee80211_hw *hw); #endif
{ "language": "C" }
/* SPDX-License-Identifier: GPL-2.0-only */ /************************************************************************** * Copyright (c) 2007-2011, Intel Corporation. * All Rights Reserved. * **************************************************************************/ #ifndef _PSB_DRV_H_ #define _PSB_DRV_H_ #include <linux/kref.h> #include <linux/mm_types.h> #include <drm/drm_device.h> #include "gma_display.h" #include "gtt.h" #include "intel_bios.h" #include "mmu.h" #include "oaktrail.h" #include "opregion.h" #include "power.h" #include "psb_intel_drv.h" #include "psb_reg.h" #define DRIVER_AUTHOR "Alan Cox <alan@linux.intel.com> and others" #define DRIVER_NAME "gma500" #define DRIVER_DESC "DRM driver for the Intel GMA500, GMA600, GMA3600, GMA3650" #define DRIVER_DATE "20140314" #define DRIVER_MAJOR 1 #define DRIVER_MINOR 0 #define DRIVER_PATCHLEVEL 0 /* Append new drm mode definition here, align with libdrm definition */ #define DRM_MODE_SCALE_NO_SCALE 2 enum { CHIP_PSB_8108 = 0, /* Poulsbo */ CHIP_PSB_8109 = 1, /* Poulsbo */ CHIP_MRST_4100 = 2, /* Moorestown/Oaktrail */ CHIP_MFLD_0130 = 3, /* Medfield */ }; #define IS_PSB(dev) (((dev)->pdev->device & 0xfffe) == 0x8108) #define IS_MRST(dev) (((dev)->pdev->device & 0xfff0) == 0x4100) #define IS_MFLD(dev) (((dev)->pdev->device & 0xfff8) == 0x0130) #define IS_CDV(dev) (((dev)->pdev->device & 0xfff0) == 0x0be0) /* Hardware offsets */ #define PSB_VDC_OFFSET 0x00000000 #define PSB_VDC_SIZE 0x000080000 #define MRST_MMIO_SIZE 0x0000C0000 #define MDFLD_MMIO_SIZE 0x000100000 #define PSB_SGX_SIZE 0x8000 #define PSB_SGX_OFFSET 0x00040000 #define MRST_SGX_OFFSET 0x00080000 /* PCI resource identifiers */ #define PSB_MMIO_RESOURCE 0 #define PSB_AUX_RESOURCE 0 #define PSB_GATT_RESOURCE 2 #define PSB_GTT_RESOURCE 3 /* PCI configuration */ #define PSB_GMCH_CTRL 0x52 #define PSB_BSM 0x5C #define _PSB_GMCH_ENABLED 0x4 #define PSB_PGETBL_CTL 0x2020 #define _PSB_PGETBL_ENABLED 0x00000001 #define PSB_SGX_2D_SLAVE_PORT 0x4000 #define PSB_LPC_GBA 0x44 /* TODO: To get rid of */ #define PSB_TT_PRIV0_LIMIT (256*1024*1024) #define PSB_TT_PRIV0_PLIMIT (PSB_TT_PRIV0_LIMIT >> PAGE_SHIFT) /* SGX side MMU definitions (these can probably go) */ /* Flags for external memory type field */ #define PSB_MMU_CACHED_MEMORY 0x0001 /* Bind to MMU only */ #define PSB_MMU_RO_MEMORY 0x0002 /* MMU RO memory */ #define PSB_MMU_WO_MEMORY 0x0004 /* MMU WO memory */ /* PTE's and PDE's */ #define PSB_PDE_MASK 0x003FFFFF #define PSB_PDE_SHIFT 22 #define PSB_PTE_SHIFT 12 /* Cache control */ #define PSB_PTE_VALID 0x0001 /* PTE / PDE valid */ #define PSB_PTE_WO 0x0002 /* Write only */ #define PSB_PTE_RO 0x0004 /* Read only */ #define PSB_PTE_CACHED 0x0008 /* CPU cache coherent */ /* VDC registers and bits */ #define PSB_MSVDX_CLOCKGATING 0x2064 #define PSB_TOPAZ_CLOCKGATING 0x2068 #define PSB_HWSTAM 0x2098 #define PSB_INSTPM 0x20C0 #define PSB_INT_IDENTITY_R 0x20A4 #define _PSB_IRQ_ASLE (1<<0) #define _MDFLD_PIPEC_EVENT_FLAG (1<<2) #define _MDFLD_PIPEC_VBLANK_FLAG (1<<3) #define _PSB_DPST_PIPEB_FLAG (1<<4) #define _MDFLD_PIPEB_EVENT_FLAG (1<<4) #define _PSB_VSYNC_PIPEB_FLAG (1<<5) #define _PSB_DPST_PIPEA_FLAG (1<<6) #define _PSB_PIPEA_EVENT_FLAG (1<<6) #define _PSB_VSYNC_PIPEA_FLAG (1<<7) #define _MDFLD_MIPIA_FLAG (1<<16) #define _MDFLD_MIPIC_FLAG (1<<17) #define _PSB_IRQ_DISP_HOTSYNC (1<<17) #define _PSB_IRQ_SGX_FLAG (1<<18) #define _PSB_IRQ_MSVDX_FLAG (1<<19) #define _LNC_IRQ_TOPAZ_FLAG (1<<20) #define _PSB_PIPE_EVENT_FLAG (_PSB_VSYNC_PIPEA_FLAG | \ _PSB_VSYNC_PIPEB_FLAG) /* This flag includes all the display IRQ bits excepts the vblank irqs. */ #define _MDFLD_DISP_ALL_IRQ_FLAG (_MDFLD_PIPEC_EVENT_FLAG | \ _MDFLD_PIPEB_EVENT_FLAG | \ _PSB_PIPEA_EVENT_FLAG | \ _PSB_VSYNC_PIPEA_FLAG | \ _MDFLD_MIPIA_FLAG | \ _MDFLD_MIPIC_FLAG) #define PSB_INT_IDENTITY_R 0x20A4 #define PSB_INT_MASK_R 0x20A8 #define PSB_INT_ENABLE_R 0x20A0 #define _PSB_MMU_ER_MASK 0x0001FF00 #define _PSB_MMU_ER_HOST (1 << 16) #define GPIOA 0x5010 #define GPIOB 0x5014 #define GPIOC 0x5018 #define GPIOD 0x501c #define GPIOE 0x5020 #define GPIOF 0x5024 #define GPIOG 0x5028 #define GPIOH 0x502c #define GPIO_CLOCK_DIR_MASK (1 << 0) #define GPIO_CLOCK_DIR_IN (0 << 1) #define GPIO_CLOCK_DIR_OUT (1 << 1) #define GPIO_CLOCK_VAL_MASK (1 << 2) #define GPIO_CLOCK_VAL_OUT (1 << 3) #define GPIO_CLOCK_VAL_IN (1 << 4) #define GPIO_CLOCK_PULLUP_DISABLE (1 << 5) #define GPIO_DATA_DIR_MASK (1 << 8) #define GPIO_DATA_DIR_IN (0 << 9) #define GPIO_DATA_DIR_OUT (1 << 9) #define GPIO_DATA_VAL_MASK (1 << 10) #define GPIO_DATA_VAL_OUT (1 << 11) #define GPIO_DATA_VAL_IN (1 << 12) #define GPIO_DATA_PULLUP_DISABLE (1 << 13) #define VCLK_DIVISOR_VGA0 0x6000 #define VCLK_DIVISOR_VGA1 0x6004 #define VCLK_POST_DIV 0x6010 #define PSB_COMM_2D (PSB_ENGINE_2D << 4) #define PSB_COMM_3D (PSB_ENGINE_3D << 4) #define PSB_COMM_TA (PSB_ENGINE_TA << 4) #define PSB_COMM_HP (PSB_ENGINE_HP << 4) #define PSB_COMM_USER_IRQ (1024 >> 2) #define PSB_COMM_USER_IRQ_LOST (PSB_COMM_USER_IRQ + 1) #define PSB_COMM_FW (2048 >> 2) #define PSB_UIRQ_VISTEST 1 #define PSB_UIRQ_OOM_REPLY 2 #define PSB_UIRQ_FIRE_TA_REPLY 3 #define PSB_UIRQ_FIRE_RASTER_REPLY 4 #define PSB_2D_SIZE (256*1024*1024) #define PSB_MAX_RELOC_PAGES 1024 #define PSB_LOW_REG_OFFS 0x0204 #define PSB_HIGH_REG_OFFS 0x0600 #define PSB_NUM_VBLANKS 2 #define PSB_2D_SIZE (256*1024*1024) #define PSB_MAX_RELOC_PAGES 1024 #define PSB_LOW_REG_OFFS 0x0204 #define PSB_HIGH_REG_OFFS 0x0600 #define PSB_NUM_VBLANKS 2 #define PSB_WATCHDOG_DELAY (HZ * 2) #define PSB_LID_DELAY (HZ / 10) #define MDFLD_PNW_B0 0x04 #define MDFLD_PNW_C0 0x08 #define MDFLD_DSR_2D_3D_0 (1 << 0) #define MDFLD_DSR_2D_3D_2 (1 << 1) #define MDFLD_DSR_CURSOR_0 (1 << 2) #define MDFLD_DSR_CURSOR_2 (1 << 3) #define MDFLD_DSR_OVERLAY_0 (1 << 4) #define MDFLD_DSR_OVERLAY_2 (1 << 5) #define MDFLD_DSR_MIPI_CONTROL (1 << 6) #define MDFLD_DSR_DAMAGE_MASK_0 ((1 << 0) | (1 << 2) | (1 << 4)) #define MDFLD_DSR_DAMAGE_MASK_2 ((1 << 1) | (1 << 3) | (1 << 5)) #define MDFLD_DSR_2D_3D (MDFLD_DSR_2D_3D_0 | MDFLD_DSR_2D_3D_2) #define MDFLD_DSR_RR 45 #define MDFLD_DPU_ENABLE (1 << 31) #define MDFLD_DSR_FULLSCREEN (1 << 30) #define MDFLD_DSR_DELAY (HZ / MDFLD_DSR_RR) #define PSB_PWR_STATE_ON 1 #define PSB_PWR_STATE_OFF 2 #define PSB_PMPOLICY_NOPM 0 #define PSB_PMPOLICY_CLOCKGATING 1 #define PSB_PMPOLICY_POWERDOWN 2 #define PSB_PMSTATE_POWERUP 0 #define PSB_PMSTATE_CLOCKGATED 1 #define PSB_PMSTATE_POWERDOWN 2 #define PSB_PCIx_MSI_ADDR_LOC 0x94 #define PSB_PCIx_MSI_DATA_LOC 0x98 /* Medfield crystal settings */ #define KSEL_CRYSTAL_19 1 #define KSEL_BYPASS_19 5 #define KSEL_BYPASS_25 6 #define KSEL_BYPASS_83_100 7 struct drm_fb_helper; struct opregion_header; struct opregion_acpi; struct opregion_swsci; struct opregion_asle; struct psb_intel_opregion { struct opregion_header *header; struct opregion_acpi *acpi; struct opregion_swsci *swsci; struct opregion_asle *asle; void *vbt; u32 __iomem *lid_state; struct work_struct asle_work; }; struct sdvo_device_mapping { u8 initialized; u8 dvo_port; u8 slave_addr; u8 dvo_wiring; u8 i2c_pin; u8 i2c_speed; u8 ddc_pin; }; struct intel_gmbus { struct i2c_adapter adapter; struct i2c_adapter *force_bit; u32 reg0; }; /* Register offset maps */ struct psb_offset { u32 fp0; u32 fp1; u32 cntr; u32 conf; u32 src; u32 dpll; u32 dpll_md; u32 htotal; u32 hblank; u32 hsync; u32 vtotal; u32 vblank; u32 vsync; u32 stride; u32 size; u32 pos; u32 surf; u32 addr; u32 base; u32 status; u32 linoff; u32 tileoff; u32 palette; }; /* * Register save state. This is used to hold the context when the * device is powered off. In the case of Oaktrail this can (but does not * yet) include screen blank. Operations occuring during the save * update the register cache instead. */ /* Common status for pipes */ struct psb_pipe { u32 fp0; u32 fp1; u32 cntr; u32 conf; u32 src; u32 dpll; u32 dpll_md; u32 htotal; u32 hblank; u32 hsync; u32 vtotal; u32 vblank; u32 vsync; u32 stride; u32 size; u32 pos; u32 base; u32 surf; u32 addr; u32 status; u32 linoff; u32 tileoff; u32 palette[256]; }; struct psb_state { uint32_t saveVCLK_DIVISOR_VGA0; uint32_t saveVCLK_DIVISOR_VGA1; uint32_t saveVCLK_POST_DIV; uint32_t saveVGACNTRL; uint32_t saveADPA; uint32_t saveLVDS; uint32_t saveDVOA; uint32_t saveDVOB; uint32_t saveDVOC; uint32_t savePP_ON; uint32_t savePP_OFF; uint32_t savePP_CONTROL; uint32_t savePP_CYCLE; uint32_t savePFIT_CONTROL; uint32_t saveCLOCKGATING; uint32_t saveDSPARB; uint32_t savePFIT_AUTO_RATIOS; uint32_t savePFIT_PGM_RATIOS; uint32_t savePP_ON_DELAYS; uint32_t savePP_OFF_DELAYS; uint32_t savePP_DIVISOR; uint32_t saveBCLRPAT_A; uint32_t saveBCLRPAT_B; uint32_t savePERF_MODE; uint32_t saveDSPFW1; uint32_t saveDSPFW2; uint32_t saveDSPFW3; uint32_t saveDSPFW4; uint32_t saveDSPFW5; uint32_t saveDSPFW6; uint32_t saveCHICKENBIT; uint32_t saveDSPACURSOR_CTRL; uint32_t saveDSPBCURSOR_CTRL; uint32_t saveDSPACURSOR_BASE; uint32_t saveDSPBCURSOR_BASE; uint32_t saveDSPACURSOR_POS; uint32_t saveDSPBCURSOR_POS; uint32_t saveOV_OVADD; uint32_t saveOV_OGAMC0; uint32_t saveOV_OGAMC1; uint32_t saveOV_OGAMC2; uint32_t saveOV_OGAMC3; uint32_t saveOV_OGAMC4; uint32_t saveOV_OGAMC5; uint32_t saveOVC_OVADD; uint32_t saveOVC_OGAMC0; uint32_t saveOVC_OGAMC1; uint32_t saveOVC_OGAMC2; uint32_t saveOVC_OGAMC3; uint32_t saveOVC_OGAMC4; uint32_t saveOVC_OGAMC5; /* DPST register save */ uint32_t saveHISTOGRAM_INT_CONTROL_REG; uint32_t saveHISTOGRAM_LOGIC_CONTROL_REG; uint32_t savePWM_CONTROL_LOGIC; }; struct medfield_state { uint32_t saveMIPI; uint32_t saveMIPI_C; uint32_t savePFIT_CONTROL; uint32_t savePFIT_PGM_RATIOS; uint32_t saveHDMIPHYMISCCTL; uint32_t saveHDMIB_CONTROL; }; struct cdv_state { uint32_t saveDSPCLK_GATE_D; uint32_t saveRAMCLK_GATE_D; uint32_t saveDSPARB; uint32_t saveDSPFW[6]; uint32_t saveADPA; uint32_t savePP_CONTROL; uint32_t savePFIT_PGM_RATIOS; uint32_t saveLVDS; uint32_t savePFIT_CONTROL; uint32_t savePP_ON_DELAYS; uint32_t savePP_OFF_DELAYS; uint32_t savePP_CYCLE; uint32_t saveVGACNTRL; uint32_t saveIER; uint32_t saveIMR; u8 saveLBB; }; struct psb_save_area { struct psb_pipe pipe[3]; uint32_t saveBSM; uint32_t saveVBT; union { struct psb_state psb; struct medfield_state mdfld; struct cdv_state cdv; }; uint32_t saveBLC_PWM_CTL2; uint32_t saveBLC_PWM_CTL; }; struct psb_ops; #define PSB_NUM_PIPE 3 struct drm_psb_private { struct drm_device *dev; struct pci_dev *aux_pdev; /* Currently only used by mrst */ struct pci_dev *lpc_pdev; /* Currently only used by mrst */ const struct psb_ops *ops; const struct psb_offset *regmap; struct child_device_config *child_dev; int child_dev_num; struct psb_gtt gtt; /* GTT Memory manager */ struct psb_gtt_mm *gtt_mm; struct page *scratch_page; u32 __iomem *gtt_map; uint32_t stolen_base; u8 __iomem *vram_addr; unsigned long vram_stolen_size; int gtt_initialized; u16 gmch_ctrl; /* Saved GTT setup */ u32 pge_ctl; struct mutex gtt_mutex; struct resource *gtt_mem; /* Our PCI resource */ struct mutex mmap_mutex; struct psb_mmu_driver *mmu; struct psb_mmu_pd *pf_pd; /* Register base */ uint8_t __iomem *sgx_reg; uint8_t __iomem *vdc_reg; uint8_t __iomem *aux_reg; /* Auxillary vdc pipe regs */ uint16_t lpc_gpio_base; uint32_t gatt_free_offset; /* Fencing / irq */ uint32_t vdc_irq_mask; uint32_t pipestat[PSB_NUM_PIPE]; spinlock_t irqmask_lock; /* Power */ bool suspended; bool display_power; int display_count; /* Modesetting */ struct psb_intel_mode_device mode_dev; bool modeset; /* true if we have done the mode_device setup */ struct drm_crtc *plane_to_crtc_mapping[PSB_NUM_PIPE]; struct drm_crtc *pipe_to_crtc_mapping[PSB_NUM_PIPE]; uint32_t num_pipe; /* OSPM info (Power management base) (TODO: can go ?) */ uint32_t ospm_base; /* Sizes info */ u32 fuse_reg_value; u32 video_device_fuse; /* PCI revision ID for B0:D2:F0 */ uint8_t platform_rev_id; /* gmbus */ struct intel_gmbus *gmbus; uint8_t __iomem *gmbus_reg; /* Used by SDVO */ int crt_ddc_pin; /* FIXME: The mappings should be parsed from bios but for now we can pretend there are no mappings available */ struct sdvo_device_mapping sdvo_mappings[2]; u32 hotplug_supported_mask; struct drm_property *broadcast_rgb_property; struct drm_property *force_audio_property; /* LVDS info */ int backlight_duty_cycle; /* restore backlight to this value */ bool panel_wants_dither; struct drm_display_mode *panel_fixed_mode; struct drm_display_mode *lfp_lvds_vbt_mode; struct drm_display_mode *sdvo_lvds_vbt_mode; struct bdb_lvds_backlight *lvds_bl; /* LVDS backlight info from VBT */ struct psb_intel_i2c_chan *lvds_i2c_bus; /* FIXME: Remove this? */ /* Feature bits from the VBIOS */ unsigned int int_tv_support:1; unsigned int lvds_dither:1; unsigned int lvds_vbt:1; unsigned int int_crt_support:1; unsigned int lvds_use_ssc:1; int lvds_ssc_freq; bool is_lvds_on; bool is_mipi_on; bool lvds_enabled_in_vbt; u32 mipi_ctrl_display; unsigned int core_freq; uint32_t iLVDS_enable; /* Runtime PM state */ int rpm_enabled; /* MID specific */ bool has_gct; struct oaktrail_gct_data gct_data; /* Oaktrail HDMI state */ struct oaktrail_hdmi_dev *hdmi_priv; /* Register state */ struct psb_save_area regs; /* MSI reg save */ uint32_t msi_addr; uint32_t msi_data; /* Hotplug handling */ struct work_struct hotplug_work; /* LID-Switch */ spinlock_t lid_lock; struct timer_list lid_timer; struct psb_intel_opregion opregion; u32 lid_last_state; /* Watchdog */ uint32_t apm_reg; uint16_t apm_base; /* * Used for modifying backlight from * xrandr -- consider removing and using HAL instead */ struct backlight_device *backlight_device; struct drm_property *backlight_property; bool backlight_enabled; int backlight_level; uint32_t blc_adj1; uint32_t blc_adj2; struct drm_fb_helper *fb_helper; /* 2D acceleration */ spinlock_t lock_2d; /* Panel brightness */ int brightness; int brightness_adjusted; bool dsr_enable; u32 dsr_fb_update; bool dpi_panel_on[3]; void *dsi_configs[2]; u32 bpp; u32 bpp2; u32 pipeconf[3]; u32 dspcntr[3]; int mdfld_panel_id; bool dplla_96mhz; /* DPLL data from the VBT */ struct { int rate; int lanes; int preemphasis; int vswing; bool initialized; bool support; int bpp; struct edp_power_seq pps; } edp; uint8_t panel_type; }; /* Operations for each board type */ struct psb_ops { const char *name; unsigned int accel_2d:1; int pipes; /* Number of output pipes */ int crtcs; /* Number of CRTCs */ int sgx_offset; /* Base offset of SGX device */ int hdmi_mask; /* Mask of HDMI CRTCs */ int lvds_mask; /* Mask of LVDS CRTCs */ int sdvo_mask; /* Mask of SDVO CRTCs */ int cursor_needs_phys; /* If cursor base reg need physical address */ /* Sub functions */ struct drm_crtc_helper_funcs const *crtc_helper; struct drm_crtc_funcs const *crtc_funcs; const struct gma_clock_funcs *clock_funcs; /* Setup hooks */ int (*chip_setup)(struct drm_device *dev); void (*chip_teardown)(struct drm_device *dev); /* Optional helper caller after modeset */ void (*errata)(struct drm_device *dev); /* Display management hooks */ int (*output_init)(struct drm_device *dev); int (*hotplug)(struct drm_device *dev); void (*hotplug_enable)(struct drm_device *dev, bool on); /* Power management hooks */ void (*init_pm)(struct drm_device *dev); int (*save_regs)(struct drm_device *dev); int (*restore_regs)(struct drm_device *dev); void (*save_crtc)(struct drm_crtc *crtc); void (*restore_crtc)(struct drm_crtc *crtc); int (*power_up)(struct drm_device *dev); int (*power_down)(struct drm_device *dev); void (*update_wm)(struct drm_device *dev, struct drm_crtc *crtc); void (*disable_sr)(struct drm_device *dev); void (*lvds_bl_power)(struct drm_device *dev, bool on); #ifdef CONFIG_BACKLIGHT_CLASS_DEVICE /* Backlight */ int (*backlight_init)(struct drm_device *dev); #endif int i2c_bus; /* I2C bus identifier for Moorestown */ }; extern int drm_crtc_probe_output_modes(struct drm_device *dev, int, int); extern int drm_pick_crtcs(struct drm_device *dev); static inline struct drm_psb_private *psb_priv(struct drm_device *dev) { return (struct drm_psb_private *) dev->dev_private; } /* psb_irq.c */ extern irqreturn_t psb_irq_handler(int irq, void *arg); extern int psb_irq_enable_dpst(struct drm_device *dev); extern int psb_irq_disable_dpst(struct drm_device *dev); extern void psb_irq_preinstall(struct drm_device *dev); extern int psb_irq_postinstall(struct drm_device *dev); extern void psb_irq_uninstall(struct drm_device *dev); extern void psb_irq_turn_on_dpst(struct drm_device *dev); extern void psb_irq_turn_off_dpst(struct drm_device *dev); extern void psb_irq_uninstall_islands(struct drm_device *dev, int hw_islands); extern int psb_vblank_wait2(struct drm_device *dev, unsigned int *sequence); extern int psb_vblank_wait(struct drm_device *dev, unsigned int *sequence); extern int psb_enable_vblank(struct drm_crtc *crtc); extern void psb_disable_vblank(struct drm_crtc *crtc); void psb_enable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask); void psb_disable_pipestat(struct drm_psb_private *dev_priv, int pipe, u32 mask); extern u32 psb_get_vblank_counter(struct drm_crtc *crtc); /* framebuffer.c */ extern int psbfb_probed(struct drm_device *dev); extern int psbfb_remove(struct drm_device *dev, struct drm_framebuffer *fb); /* accel_2d.c */ extern void psbfb_copyarea(struct fb_info *info, const struct fb_copyarea *region); extern int psbfb_sync(struct fb_info *info); extern void psb_spank(struct drm_psb_private *dev_priv); /* psb_reset.c */ extern void psb_lid_timer_init(struct drm_psb_private *dev_priv); extern void psb_lid_timer_takedown(struct drm_psb_private *dev_priv); extern void psb_print_pagefault(struct drm_psb_private *dev_priv); /* modesetting */ extern void psb_modeset_init(struct drm_device *dev); extern void psb_modeset_cleanup(struct drm_device *dev); extern int psb_fbdev_init(struct drm_device *dev); /* backlight.c */ int gma_backlight_init(struct drm_device *dev); void gma_backlight_exit(struct drm_device *dev); void gma_backlight_disable(struct drm_device *dev); void gma_backlight_enable(struct drm_device *dev); void gma_backlight_set(struct drm_device *dev, int v); /* oaktrail_crtc.c */ extern const struct drm_crtc_helper_funcs oaktrail_helper_funcs; /* oaktrail_lvds.c */ extern void oaktrail_lvds_init(struct drm_device *dev, struct psb_intel_mode_device *mode_dev); /* psb_intel_display.c */ extern const struct drm_crtc_helper_funcs psb_intel_helper_funcs; extern const struct drm_crtc_funcs psb_intel_crtc_funcs; /* psb_intel_lvds.c */ extern const struct drm_connector_helper_funcs psb_intel_lvds_connector_helper_funcs; extern const struct drm_connector_funcs psb_intel_lvds_connector_funcs; /* gem.c */ extern void psb_gem_free_object(struct drm_gem_object *obj); extern int psb_gem_get_aperture(struct drm_device *dev, void *data, struct drm_file *file); extern int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args); extern vm_fault_t psb_gem_fault(struct vm_fault *vmf); /* psb_device.c */ extern const struct psb_ops psb_chip_ops; /* oaktrail_device.c */ extern const struct psb_ops oaktrail_chip_ops; /* mdlfd_device.c */ extern const struct psb_ops mdfld_chip_ops; /* cdv_device.c */ extern const struct psb_ops cdv_chip_ops; /* Debug print bits setting */ #define PSB_D_GENERAL (1 << 0) #define PSB_D_INIT (1 << 1) #define PSB_D_IRQ (1 << 2) #define PSB_D_ENTRY (1 << 3) /* debug the get H/V BP/FP count */ #define PSB_D_HV (1 << 4) #define PSB_D_DBI_BF (1 << 5) #define PSB_D_PM (1 << 6) #define PSB_D_RENDER (1 << 7) #define PSB_D_REG (1 << 8) #define PSB_D_MSVDX (1 << 9) #define PSB_D_TOPAZ (1 << 10) extern int drm_idle_check_interval; /* Utilities */ static inline u32 MRST_MSG_READ32(int domain, uint port, uint offset) { int mcr = (0xD0<<24) | (port << 16) | (offset << 8); uint32_t ret_val = 0; struct pci_dev *pci_root = pci_get_domain_bus_and_slot(domain, 0, 0); pci_write_config_dword(pci_root, 0xD0, mcr); pci_read_config_dword(pci_root, 0xD4, &ret_val); pci_dev_put(pci_root); return ret_val; } static inline void MRST_MSG_WRITE32(int domain, uint port, uint offset, u32 value) { int mcr = (0xE0<<24) | (port << 16) | (offset << 8) | 0xF0; struct pci_dev *pci_root = pci_get_domain_bus_and_slot(domain, 0, 0); pci_write_config_dword(pci_root, 0xD4, value); pci_write_config_dword(pci_root, 0xD0, mcr); pci_dev_put(pci_root); } static inline u32 MDFLD_MSG_READ32(int domain, uint port, uint offset) { int mcr = (0x10<<24) | (port << 16) | (offset << 8); uint32_t ret_val = 0; struct pci_dev *pci_root = pci_get_domain_bus_and_slot(domain, 0, 0); pci_write_config_dword(pci_root, 0xD0, mcr); pci_read_config_dword(pci_root, 0xD4, &ret_val); pci_dev_put(pci_root); return ret_val; } static inline void MDFLD_MSG_WRITE32(int domain, uint port, uint offset, u32 value) { int mcr = (0x11<<24) | (port << 16) | (offset << 8) | 0xF0; struct pci_dev *pci_root = pci_get_domain_bus_and_slot(domain, 0, 0); pci_write_config_dword(pci_root, 0xD4, value); pci_write_config_dword(pci_root, 0xD0, mcr); pci_dev_put(pci_root); } static inline uint32_t REGISTER_READ(struct drm_device *dev, uint32_t reg) { struct drm_psb_private *dev_priv = dev->dev_private; return ioread32(dev_priv->vdc_reg + reg); } static inline uint32_t REGISTER_READ_AUX(struct drm_device *dev, uint32_t reg) { struct drm_psb_private *dev_priv = dev->dev_private; return ioread32(dev_priv->aux_reg + reg); } #define REG_READ(reg) REGISTER_READ(dev, (reg)) #define REG_READ_AUX(reg) REGISTER_READ_AUX(dev, (reg)) /* Useful for post reads */ static inline uint32_t REGISTER_READ_WITH_AUX(struct drm_device *dev, uint32_t reg, int aux) { uint32_t val; if (aux) val = REG_READ_AUX(reg); else val = REG_READ(reg); return val; } #define REG_READ_WITH_AUX(reg, aux) REGISTER_READ_WITH_AUX(dev, (reg), (aux)) static inline void REGISTER_WRITE(struct drm_device *dev, uint32_t reg, uint32_t val) { struct drm_psb_private *dev_priv = dev->dev_private; iowrite32((val), dev_priv->vdc_reg + (reg)); } static inline void REGISTER_WRITE_AUX(struct drm_device *dev, uint32_t reg, uint32_t val) { struct drm_psb_private *dev_priv = dev->dev_private; iowrite32((val), dev_priv->aux_reg + (reg)); } #define REG_WRITE(reg, val) REGISTER_WRITE(dev, (reg), (val)) #define REG_WRITE_AUX(reg, val) REGISTER_WRITE_AUX(dev, (reg), (val)) static inline void REGISTER_WRITE_WITH_AUX(struct drm_device *dev, uint32_t reg, uint32_t val, int aux) { if (aux) REG_WRITE_AUX(reg, val); else REG_WRITE(reg, val); } #define REG_WRITE_WITH_AUX(reg, val, aux) REGISTER_WRITE_WITH_AUX(dev, (reg), (val), (aux)) static inline void REGISTER_WRITE16(struct drm_device *dev, uint32_t reg, uint32_t val) { struct drm_psb_private *dev_priv = dev->dev_private; iowrite16((val), dev_priv->vdc_reg + (reg)); } #define REG_WRITE16(reg, val) REGISTER_WRITE16(dev, (reg), (val)) static inline void REGISTER_WRITE8(struct drm_device *dev, uint32_t reg, uint32_t val) { struct drm_psb_private *dev_priv = dev->dev_private; iowrite8((val), dev_priv->vdc_reg + (reg)); } #define REG_WRITE8(reg, val) REGISTER_WRITE8(dev, (reg), (val)) #define PSB_WVDC32(_val, _offs) iowrite32(_val, dev_priv->vdc_reg + (_offs)) #define PSB_RVDC32(_offs) ioread32(dev_priv->vdc_reg + (_offs)) /* #define TRAP_SGX_PM_FAULT 1 */ #ifdef TRAP_SGX_PM_FAULT #define PSB_RSGX32(_offs) \ ({ \ if (inl(dev_priv->apm_base + PSB_APM_STS) & 0x3) { \ pr_err("access sgx when it's off!! (READ) %s, %d\n", \ __FILE__, __LINE__); \ melay(1000); \ } \ ioread32(dev_priv->sgx_reg + (_offs)); \ }) #else #define PSB_RSGX32(_offs) ioread32(dev_priv->sgx_reg + (_offs)) #endif #define PSB_WSGX32(_val, _offs) iowrite32(_val, dev_priv->sgx_reg + (_offs)) #define MSVDX_REG_DUMP 0 #define PSB_WMSVDX32(_val, _offs) iowrite32(_val, dev_priv->msvdx_reg + (_offs)) #define PSB_RMSVDX32(_offs) ioread32(dev_priv->msvdx_reg + (_offs)) #endif
{ "language": "C" }
/* CC0 license (public domain) - see LICENSE file for details */ #ifndef CCAN_FDPASS_H #define CCAN_FDPASS_H #include <stdbool.h> /** * fdpass_send - send a file descriptor across a socket * @sockout: socket to write to * @fd: file descriptor to pass * * On failure, sets errno and returns false. */ bool fdpass_send(int sockout, int fd); /** * fdpass_recv - receive a file descriptor from a socket * @sockin: socket to read from * * On failure, returns -1 and sets errno. Otherwise returns fd. */ int fdpass_recv(int sockin); #endif /* CCAN_FDPASS_H */
{ "language": "C" }
/* * Copyright (c) 2017-2020 Arm Limited. * * SPDX-License-Identifier: MIT * * 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. */ #include "helpers_asymm.h" #define MAX_OP(x, y, type, size) max((x), (y)) #define ADD_OP(x, y, type, size) ((x) + (y)) #define SUB_OP(x, y, type, size) ((x) - (y)) /* Number of workitems in dimension 0. */ #if !defined(GRID_SIZE) #define GRID_SIZE 1 #endif /* !defined(GRID_SIZE) */ #if VECTOR_SIZE == 2 __constant uint2 idx__ = (uint2)(0, 1); #define asymm_mult(a, b) ASYMM_MULT(a, b, 2) #define asymm_exp_on_negative_values(a, k_integer_bits) ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, 2) #define asymm_rescale(value, src_integer_bits, dst_integer_bits) ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, 2) #elif VECTOR_SIZE == 4 __constant uint4 idx__ = (uint4)(0, 1, 2, 3); #define asymm_mult(a, b) ASYMM_MULT(a, b, 4) #define asymm_exp_on_negative_values(a, k_integer_bits) ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, 4) #define asymm_rescale(value, src_integer_bits, dst_integer_bits) ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, 4) #elif VECTOR_SIZE == 8 __constant uint8 idx__ = (uint8)(0, 1, 2, 3, 4, 5, 6, 7); #define asymm_mult(a, b) ASYMM_MULT(a, b, 8) #define asymm_exp_on_negative_values(a, k_integer_bits) ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, 8) #define asymm_rescale(value, src_integer_bits, dst_integer_bits) ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, 8) #else /* VECTOR_SIZE DEFAULT */ #define VECTOR_SIZE 16 #define LOG_VECTOR_SIZE 4 __constant uint16 idx__ = (uint16)(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15); #define asymm_mult(a, b) ASYMM_MULT(a, b, 16) #define asymm_exp_on_negative_values(a, k_integer_bits) ASYMM_EXP_ON_NEGATIVE_VALUES(a, k_integer_bits, 16) #define asymm_rescale(value, src_integer_bits, dst_integer_bits) ASYMM_RESCALE(value, src_integer_bits, dst_integer_bits, 16) #endif /* VECTOR_SIZE END */ #define VEC_UCHAR VEC_DATA_TYPE(uchar, VECTOR_SIZE) #define VEC_UINT VEC_DATA_TYPE(uint, VECTOR_SIZE) #define VEC_INT VEC_DATA_TYPE(int, VECTOR_SIZE) #define VEC_BASE VEC_DATA_TYPE(DATA_TYPE, VECTOR_SIZE) #if defined(DIFF_MIN) VEC_INT mult_by_quantized_multiplier_serial(VEC_INT data) { #if defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT) if(INPUT_BETA_MULTIPLIER > 1) { return asymm_mult(data * (1 << INPUT_BETA_LEFT_SHIFT), INPUT_BETA_MULTIPLIER); } #endif /* defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT) */ return data; } int4 mult_by_quantized_multiplier_parallel(int4 data) { #if defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT) if(INPUT_BETA_MULTIPLIER > 1) { return ASYMM_MULT(data * (1 << INPUT_BETA_LEFT_SHIFT), INPUT_BETA_MULTIPLIER, 4); } #endif /* defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT) */ return data; } /** Shifts the values of the input tensor by the max calculated in softmax_layer_max kernel, * then gets the exponent of each element as sums all elements across each row. * * @note In case the input is not multiple of 16 -DNON_MULTIPLE_OF_VECTOR_SIZE must be passed. * @note Quantized beta can be optionally passed at compile time using -DINPUT_BETA_MULTIPLIER and -DINPUT_BETA_LEFT_SHIFT (if undefined, assume beta equals 1.0) * @note -DDIFF_MIN must be passed at compile time. It is threshold difference between maximum value of input data and current processed value, it defines whether the value will be taken into account or not. * * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: QASYMM8/QASYMM8_SIGNED * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor * @param[in] max_ptr Pointer to the max values tensor slice. Supported data types: same as @p src_ptr * @param[in] max_stride_x Stride of the max values tensor in X dimension (in bytes) * @param[in] max_step_x max_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] max_stride_y Stride of the max values tensor in Y dimension (in bytes) * @param[in] max_step_y max_stride_y * number of elements along Y processed per workitem(in bytes) * @param[in] max_stride_z Stride of the max values tensor in Z dimension (in bytes) * @param[in] max_step_z max_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] max_offset_first_element_in_bytes The offset of the first element in the max values tensor * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: S32 * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor * @param[out] sum_ptr Pointer to the sum values tensor slice. Supported data types: same as @p dst_ptr * @param[in] sum_stride_x Stride of the sum values tensor in X dimension (in bytes) * @param[in] sum_step_x sum_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] sum_stride_y Stride of the sum values tensor in Y dimension (in bytes) * @param[in] sum_step_y sum_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] sum_stride_z Stride of the sum values tensor in Z dimension (in bytes) * @param[in] sum_step_z sum_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] sum_offset_first_element_in_bytes The offset of the first element in the sum values tensor * @param[in] width Input image width */ __kernel void softmax_layer_max_shift_exp_sum_quantized_serial( TENSOR3D_DECLARATION(src), TENSOR3D_DECLARATION(maxo), TENSOR3D_DECLARATION(dst), TENSOR3D_DECLARATION(sum), uint width) { Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src); Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst); Image maxo = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(maxo); Image sum = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(sum); VEC_BASE max_val_vec = (VEC_BASE)(MIN_VALUE); // Calculate max of row const uint width4 = width >> LOG_VECTOR_SIZE; for(uint i = 0; i < width4; i++) { VEC_BASE data = VLOAD(VECTOR_SIZE)(0, (__global DATA_TYPE *)offset(&src, i << LOG_VECTOR_SIZE, 0)); max_val_vec = MAX_OP(data, max_val_vec, DATA_TYPE, 16); } #ifdef NON_MULTIPLE_OF_VECTOR_SIZE // Handle non multiple of 16 VEC_BASE vec_min_val = (VEC_BASE)(MIN_VALUE); VEC_BASE data = VLOAD(VECTOR_SIZE)(0, (__global DATA_TYPE *)offset(&src, width4 << LOG_VECTOR_SIZE, 0)); VEC_UCHAR widx = CONVERT(((VEC_UINT)(width4 << LOG_VECTOR_SIZE) + idx__) < width, VEC_UCHAR); max_val_vec = MAX_OP(max_val_vec, select(vec_min_val, data, widx), DATA_TYPE, 16); #endif /* NON_MULTIPLE_OF_VECTOR_SIZE */ // Perform max reduction #if VECTOR_SIZE == 16 max_val_vec.s01234567 = MAX_OP(max_val_vec.s01234567, max_val_vec.s89ABCDEF, DATA_TYPE, 8); #endif /* VECTOR SIZE 16 END */ #if VECTOR_SIZE >= 8 max_val_vec.s0123 = MAX_OP(max_val_vec.s0123, max_val_vec.s4567, DATA_TYPE, 4); #endif /* VECTOR SIZE 8 END */ #if VECTOR_SIZE >= 4 max_val_vec.s01 = MAX_OP(max_val_vec.s01, max_val_vec.s23, DATA_TYPE, 2); #endif /* VECTOR SIZE 4 END */ max_val_vec.s0 = MAX_OP(max_val_vec.s0, max_val_vec.s1, DATA_TYPE, 1); // Store result *((__global DATA_TYPE *)maxo.ptr) = max_val_vec.s0; // Second part // Load max value of 1D logits vector (row) int max_val = convert_int(*((__global DATA_TYPE *)offset(&maxo, 0, 0))); // Set sum vector, Q(EXP_ACCUMULATION_INT_BITS) VEC_INT sum1D = 0; // Shift values, exp and sum for(uint i = 0; i < width4; i++) { VEC_BASE data = VLOAD(VECTOR_SIZE)(0, (__global DATA_TYPE *)offset(&src, i << LOG_VECTOR_SIZE, 0)); VEC_INT data_fp = CONVERT(data, VEC_INT); VEC_INT data_diff = data_fp - max_val; VEC_INT data_diff_mult = mult_by_quantized_multiplier_serial(data_diff); data_fp = asymm_exp_on_negative_values(data_diff_mult, SCALED_DIFF_INT_BITS); data_fp = asymm_rescale(data_fp, 0, EXP_ACCUMULATION_INT_BITS); VSTORE(VECTOR_SIZE) (data_diff, 0, (__global int *)offset(&dst, i << LOG_VECTOR_SIZE, 0)); sum1D = sum1D + select(0, data_fp, data_diff >= (VEC_INT)(DIFF_MIN)); } #ifdef NON_MULTIPLE_OF_VECTOR_SIZE // Handle non multiple of 16 data = VLOAD(VECTOR_SIZE)(0, (__global DATA_TYPE *)offset(&src, width4 << LOG_VECTOR_SIZE, 0)); VEC_INT data_fp = CONVERT(data, VEC_INT); VEC_INT data_diff = data_fp - max_val; VEC_INT data_diff_mult = mult_by_quantized_multiplier_serial(data_diff); data_fp = asymm_exp_on_negative_values(data_diff_mult, SCALED_DIFF_INT_BITS); data_fp = asymm_rescale(data_fp, 0, EXP_ACCUMULATION_INT_BITS); VEC_INT widx_ = CONVERT(((VEC_UINT)(width4 << LOG_VECTOR_SIZE) + idx__) < width, VEC_INT); VSTORE(VECTOR_SIZE) (data_diff, 0, (__global int *)offset(&dst, width4 << LOG_VECTOR_SIZE, 0)); data_fp = select(0, data_fp, data_diff >= (VEC_INT)(DIFF_MIN)); sum1D = sum1D + select(0, data_fp, widx_); #endif /* NON_MULTIPLE_OF_VECTOR_SIZE */ // Perform sum reduction #if VECTOR_SIZE == 16 sum1D.s01234567 = ADD_OP(sum1D.s01234567, sum1D.s89ABCDEF, DATA_TYPE, 8); #endif /* VECTOR SIZE 16 END */ #if VECTOR_SIZE >= 8 sum1D.s0123 = ADD_OP(sum1D.s0123, sum1D.s4567, DATA_TYPE, 4); #endif /* VECTOR SIZE 8 END */ #if VECTOR_SIZE >= 4 sum1D.s01 = ADD_OP(sum1D.s01, sum1D.s23, DATA_TYPE, 2); #endif /* VECTOR SIZE 4 END */ sum1D.s0 = ADD_OP(sum1D.s0, sum1D.s1, DATA_TYPE, 1); // Calculate and store result *((__global int *)sum.ptr) = sum1D.s0; } /** Identifies the maximum value across the 1st dimension and shifts the values of the input tensor by this maximum value, * then gets the exponent of each element as sums all elements across each row. * * @note Datatype must be given as a preprocessor argument using -DDATA_TYPE=type. e.g. -DDATA_TYPE=short * @note In case the input is not a multiple of VECTOR_SIZE (2,4,8,16) -DNON_MULTIPLE_OF_VECTOR_SIZE must be passed. * * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: F16/F32 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor * @param[in] maxo_ptr Pointer to the max values tensor slice. Supported data types: same as @p src_ptr * @param[in] maxo_stride_x Stride of the max values tensor in X dimension (in bytes) * @param[in] maxo_step_x max_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] maxo_stride_y Stride of the max values tensor in Y dimension (in bytes) * @param[in] maxo_step_y max_stride_y * number of elements along Y processed per workitem(in bytes) * @param[in] maxo_stride_z Stride of the max values tensor in Z dimension (in bytes) * @param[in] maxo_step_z max_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] maxo_offset_first_element_in_bytes The offset of the first element in the max values tensor * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: same as @p src_ptr * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor * @param[out] sum_ptr Pointer to the sum values tensor slice. Supported data types: same as @p src_ptr * @param[in] sum_stride_x Stride of the sum values tensor in X dimension (in bytes) * @param[in] sum_step_x sum_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] sum_stride_y Stride of the sum values tensor in Y dimension (in bytes) * @param[in] sum_step_y sum_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] sum_stride_z Stride of the sum values tensor in Z dimension (in bytes) * @param[in] sum_step_z sum_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] sum_offset_first_element_in_bytes The offset of the first element in the sum values tensor * @param[in] width Input image width */ __kernel void softmax_layer_max_shift_exp_sum_quantized_parallel( TENSOR3D_DECLARATION(src), TENSOR3D_DECLARATION(maxo), TENSOR3D_DECLARATION(dst), TENSOR3D_DECLARATION(sum), uint width) { Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src); Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst); Image maxo = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(maxo); Image sum = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(sum); const uint4 idx4 = (uint4)(0, 1, 2, 3); const uint lid = get_local_id(0); // Define one temporary vector per work-item. __local int4 tmp_local[GRID_SIZE]; __local DATA_TYPE max_local; VEC_DATA_TYPE(DATA_TYPE, 4) vec_min_val = (VEC_DATA_TYPE(DATA_TYPE, 4))(MIN_VALUE); VEC_DATA_TYPE(DATA_TYPE, 4) max_val_vec = vec_min_val; // Number of elements per work-item. const uint row = width / GRID_SIZE; // Number of iterations per work-item. const uint width_ = row >> 2; // Calculate max of row uint i = 0; for(; i < width_; i++) { VEC_DATA_TYPE(DATA_TYPE, 4) data_max = vload4(0, (__global DATA_TYPE *)offset(&src, i * GRID_SIZE * 4, 0)); max_val_vec = MAX_OP(data_max, max_val_vec, DATA_TYPE, 4); } #ifdef NON_MULTIPLE_OF_GRID_SIZE // How many work-items needed to complete the computation. //TODO: Optimize this calculation (avoid %). int boundary_workitems = (width % (GRID_SIZE * 4)) / 4; if(lid < boundary_workitems) { VEC_DATA_TYPE(DATA_TYPE, 4) data_max = vload4(0, (__global DATA_TYPE *)offset(&src, i * GRID_SIZE * 4, 0)); max_val_vec = MAX_OP(data_max, max_val_vec, DATA_TYPE, 4); } #ifdef NON_MULTIPLE_OF_VECTOR_SIZE if(boundary_workitems == 0) { boundary_workitems = GRID_SIZE; i--; } if(lid == (boundary_workitems - 1)) { // Handle non multiple of 4 VEC_DATA_TYPE(DATA_TYPE, 4) data_max = vload4(0, (__global DATA_TYPE *)offset(&src, (GRID_SIZE * i * 4) + 4, 0)); VEC_DATA_TYPE(DATA_TYPE, 4) widx = CONVERT((((uint4)(GRID_SIZE * i * 4) + boundary_workitems * 4 + idx4) < width), VEC_DATA_TYPE(DATA_TYPE, 4)); max_val_vec = MAX_OP(max_val_vec, select(vec_min_val, data_max, widx), DATA_TYPE, 4); } #endif /* NON_MULTIPLE_OF_VECTOR_SIZE */ #endif /* NON_MULTIPLE_OF_GRID_SIZE */ tmp_local[lid] = convert_int4(max_val_vec); barrier(CLK_LOCAL_MEM_FENCE); if(GRID_SIZE >= 256) { if(lid < 128) { tmp_local[lid] = MAX_OP(tmp_local[lid + 128], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 128) { if(lid < 64) { tmp_local[lid] = MAX_OP(tmp_local[lid + 64], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 64) { if(lid < 32) { tmp_local[lid] = MAX_OP(tmp_local[lid + 32], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 32) { if(lid < 16) { tmp_local[lid] = MAX_OP(tmp_local[lid + 16], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 16) { if(lid < 8) { tmp_local[lid] = MAX_OP(tmp_local[lid + 8], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 8) { if(lid < 4) { tmp_local[lid] = MAX_OP(tmp_local[lid + 4], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 4) { if(lid < 2) { tmp_local[lid] = MAX_OP(tmp_local[lid + 2], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(lid == 0) { max_val_vec = MAX_OP(CONVERT((tmp_local[lid + 1]), VEC_DATA_TYPE(DATA_TYPE, 4)), CONVERT((tmp_local[lid]), VEC_DATA_TYPE(DATA_TYPE, 4)), DATA_TYPE, 4); max_val_vec.s01 = MAX_OP(max_val_vec.s01, max_val_vec.s23, DATA_TYPE, 2); max_val_vec.s0 = MAX_OP(max_val_vec.s0, max_val_vec.s1, DATA_TYPE, 1); max_local = max_val_vec.s0; } barrier(CLK_LOCAL_MEM_FENCE); /* Second section */ // Set sum vector int4 sum1D = 0; int max_val = convert_int(max_local); // Shift values, exp and sum for(i = 0; i < width_; i++) { VEC_DATA_TYPE(DATA_TYPE, 4) data = vload4(0, (__global DATA_TYPE *)offset(&src, i * GRID_SIZE * 4, 0)); int4 data_fp = convert_int4(data); int4 data_diff = data_fp - max_val; int4 data_diff_mult = mult_by_quantized_multiplier_parallel(data_diff); data_fp = ASYMM_EXP_ON_NEGATIVE_VALUES(data_diff_mult, SCALED_DIFF_INT_BITS, 4); data_fp = ASYMM_RESCALE(data_fp, 0, EXP_ACCUMULATION_INT_BITS, 4); vstore4(data_diff, 0, (__global int *)offset(&dst, i * GRID_SIZE * 4, 0)); sum1D = sum1D + select(0, data_fp, data_diff >= (int4)(DIFF_MIN)); } #ifdef NON_MULTIPLE_OF_GRID_SIZE //TODO: Optimize the calculation (avoid %). boundary_workitems = (width % (GRID_SIZE * 4)) / 4; if(lid < boundary_workitems) { VEC_DATA_TYPE(DATA_TYPE, 4) data = vload4(0, (__global DATA_TYPE *)offset(&src, i * GRID_SIZE * 4, 0)); int4 data_fp = convert_int4(data); int4 data_diff = data_fp - max_val; int4 data_diff_mult = mult_by_quantized_multiplier_parallel(data_diff); data_fp = ASYMM_EXP_ON_NEGATIVE_VALUES(data_diff_mult, SCALED_DIFF_INT_BITS, 4); data_fp = ASYMM_RESCALE(data_fp, 0, EXP_ACCUMULATION_INT_BITS, 4); vstore4(data_diff, 0, (__global int *)offset(&dst, i * GRID_SIZE * 4, 0)); sum1D = sum1D + select(0, data_fp, data_diff >= (int4)(DIFF_MIN)); } #ifdef NON_MULTIPLE_OF_VECTOR_SIZE if(boundary_workitems == 0) { boundary_workitems = GRID_SIZE; i--; } if(lid == (boundary_workitems - 1)) { // Handle non multiple of vector size ((GRID_SIZE * i * 4) + 4, 0); move 4 float positions ahead, *4 is due to the stride VEC_DATA_TYPE(DATA_TYPE, 4) data = vload4(0, (__global DATA_TYPE *)offset(&src, i * GRID_SIZE * 4 + 4, 0)); int4 data_fp = convert_int4(data); int4 data_diff = data_fp - max_val; int4 data_diff_mult = mult_by_quantized_multiplier_parallel(data_diff); data_fp = ASYMM_EXP_ON_NEGATIVE_VALUES(data_diff_mult, SCALED_DIFF_INT_BITS, 4); data_fp = ASYMM_RESCALE(data_fp, 0, EXP_ACCUMULATION_INT_BITS, 4); int4 widx = convert_int4(((uint4)(GRID_SIZE * i * 4) + boundary_workitems * 4 + idx4) < width); vstore4(data_diff, 0, (__global int *)offset(&dst, i * GRID_SIZE * 4 + 4, 0)); data_fp = select(MIN_VALUE, data_fp, data_diff >= (int4)(DIFF_MIN)); data_fp = select(0, data_fp, widx); sum1D = sum1D + data_fp; } #endif /* NON_MULTIPLE_OF_VECTOR_SIZE */ #endif /* NON_MULTIPLE_OF_GRID_SIZE */ tmp_local[lid] = sum1D; barrier(CLK_LOCAL_MEM_FENCE); if(GRID_SIZE >= 256) { if(lid < 128) { tmp_local[lid] = ADD_OP(tmp_local[lid + 128], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 128) { if(lid < 64) { tmp_local[lid] = ADD_OP(tmp_local[lid + 64], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 64) { if(lid < 32) { tmp_local[lid] = ADD_OP(tmp_local[lid + 32], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 32) { if(lid < 16) { tmp_local[lid] = ADD_OP(tmp_local[lid + 16], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 16) { if(lid < 8) { tmp_local[lid] = ADD_OP(tmp_local[lid + 8], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 8) { if(lid < 4) { tmp_local[lid] = ADD_OP(tmp_local[lid + 4], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(GRID_SIZE >= 4) { if(lid < 2) { tmp_local[lid] = ADD_OP(tmp_local[lid + 2], tmp_local[lid], int, 4); } barrier(CLK_LOCAL_MEM_FENCE); } if(lid == 0) { sum1D = ADD_OP(tmp_local[lid + 1], tmp_local[lid], int, 4); // Perform max reduction sum1D.s01 = ADD_OP(sum1D.s01, sum1D.s23, int, 2); sum1D.s0 = ADD_OP(sum1D.s0, sum1D.s1, int, 1); *((__global int *)sum.ptr) = sum1D.s0; } } /** Divides all the values of the input tensor by the sum calculated from softmax_layer_shift_exp_sum kernel. * * @note Quantized beta can be optionally passed at compile time using -DINPUT_BETA_MULTIPLIER and -DINPUT_BETA_LEFT_SHIFT (if undefined, assume beta equals 1.0) * @note -DDIFF_MIN must be passed at compile time. It is threshold difference between maximum value of input data and current processed value, it defines whether the value will be taken into account or not. * * @param[in] src_ptr Pointer to the source tensor slice. Supported data types: S32 * @param[in] src_stride_x Stride of the source tensor in X dimension (in bytes) * @param[in] src_step_x src_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] src_stride_y Stride of the source tensor in Y dimension (in bytes) * @param[in] src_step_y src_stride_y * number of elements along Y processed per workitem(in bytes) * @param[in] src_stride_z Stride of the source tensor in Z dimension (in bytes) * @param[in] src_step_z src_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] src_offset_first_element_in_bytes The offset of the first element in the source tensor * @param[in] sum_ptr Pointer to the sum values tensor slice. Supported data types: same as @p src_ptr * @param[in] sum_stride_x Stride of the sum values tensor in X dimension (in bytes) * @param[in] sum_step_x sum_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] sum_stride_y Stride of the sum values tensor in Y dimension (in bytes) * @param[in] sum_step_y sum_stride_y * number of elements along Y processed per workitem(in bytes) * @param[in] sum_stride_z Stride of the sum values tensor in Z dimension (in bytes) * @param[in] sum_step_z sum_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] sum_offset_first_element_in_bytes The offset of the first element in the sum values tensor * @param[out] dst_ptr Pointer to the destination tensor slice. Supported data types: QASYMM8/QASYMM8_SIGNED * @param[in] dst_stride_x Stride of the destination tensor in X dimension (in bytes) * @param[in] dst_step_x dst_stride_x * number of elements along X processed per workitem(in bytes) * @param[in] dst_stride_y Stride of the destination tensor in Y dimension (in bytes) * @param[in] dst_step_y dst_stride_y * number of elements along Y processed per workitem(in bytes) * @param[in] dst_stride_z Stride of the destination tensor in Z dimension (in bytes) * @param[in] dst_step_z dst_stride_z * number of elements along Z processed per workitem(in bytes) * @param[in] dst_offset_first_element_in_bytes The offset of the first element in the destination tensor */ __kernel void softmax_layer_norm_quantized( TENSOR3D_DECLARATION(src), TENSOR3D_DECLARATION(sum), TENSOR3D_DECLARATION(dst)) { Image src = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(src); Image dst = CONVERT_TENSOR3D_TO_IMAGE_STRUCT(dst); Image sum = CONVERT_TENSOR3D_TO_IMAGE_STRUCT_NO_STEP(sum); // Load max value of 1D logits vector (row) int sum_val = *((__global int *)offset(&sum, 0, get_global_id(1))); // It will be better to calculate this in prev layer and pass here as parameter uint sum_val_u = convert_uint(sum_val); int headroom_plus_one = clz(sum_val_u); int num_bits_over_unit = EXP_ACCUMULATION_INT_BITS - headroom_plus_one; int shifted_sum_minus_one_1 = convert_int((sum_val_u << headroom_plus_one) - (1u << 31)); int16 shifted_sum_minus_one = shifted_sum_minus_one_1; int16 shifted_scale = ASYMM_ONE_OVER_ONE_PLUS_X_FOR_X_IN_0_1(shifted_sum_minus_one, 16); // It was already calculated in prev layer, should be stored into tmp output and reused int16 data_diff = vload16(0, (__global int *)offset(&src, 0, 0)); int16 data_diff_mult = data_diff; #if defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT) if(INPUT_BETA_MULTIPLIER > 1) { data_diff_mult = ASYMM_MULT(data_diff * (1 << INPUT_BETA_LEFT_SHIFT), INPUT_BETA_MULTIPLIER, 16); } #endif /* defined(INPUT_BETA_MULTIPLIER) && defined(INPUT_BETA_LEFT_SHIFT) */ int16 data = ASYMM_EXP_ON_NEGATIVE_VALUES(data_diff_mult, SCALED_DIFF_INT_BITS, 16); data = ASYMM_MULT(shifted_scale, data, 16); data = ASYMM_ROUNDING_DIVIDE_BY_POW2(data, num_bits_over_unit + 31 - 8, 16); #ifdef QASYMM8_SIGNED data = ADD_OP(data, (int16)(MIN_VALUE), int, 16); #endif /* QASYMM8_SIGNED */ data = select(MIN_VALUE, data, data_diff >= (int16)(DIFF_MIN)); vstore16(CONVERT_SAT(data, VEC_DATA_TYPE(DATA_TYPE, 16)), 0, (__global DATA_TYPE *)offset(&dst, 0, 0)); } #endif /* defined(DIFF_MIN) */
{ "language": "C" }
/* * exchange.c * * Copyright (C) 2016-2020 Aerospike, Inc. * * Portions may be licensed to Aerospike, Inc. under one or more contributor * license agreements. * * This program is free software: you can redistribute it and/or modify it under * the terms of the GNU Affero General Public License as published by the Free * Software Foundation, either version 3 of the License, or (at your option) any * later version. * * This program is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more * details. * * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see http://www.gnu.org/licenses/ */ #include "fabric/exchange.h" #include <errno.h> #include <pthread.h> #include <unistd.h> #include <sys/param.h> // For MAX() and MIN(). #include "citrusleaf/alloc.h" #include "citrusleaf/cf_atomic.h" #include "citrusleaf/cf_clock.h" #include "citrusleaf/cf_queue.h" #include "cf_thread.h" #include "dynbuf.h" #include "log.h" #include "shash.h" #include "socket.h" #include "base/cfg.h" #include "base/datamodel.h" #include "base/stats.h" #include "fabric/fabric.h" #include "fabric/hb.h" #include "fabric/partition_balance.h" #include "storage/storage.h" /* * Overview * ======== * Cluster data exchange state machine. Exchanges per namespace partition * version exchange for now, after evey cluster change. * * State transition diagram * ======================== * The exchange state transition diagram responds to three events * 1. Incoming message * 2. Timer event * 3. Clustering module's cluster change event. * * There are four states * 1. Rest - the exchange is complete with all exchanged data committed. * 2. Exchanging - the cluster has changed since the last commit and new data * exchange is in progress. * 3. Ready to commit - this node has send its exchange data to all cluster * members, received corresponding acks and also exchange data from all cluster * members. * 4. Orphaned - this node is an orphan. After a timeout blocks client * transactions. * * Exchange starts by being in the orphaned state. * * Code organization * ================= * * There are different sections for each state. Each state has a dispatcher * which delegates the event handing to a state specific function. * * Locks * ===== * 1. g_exchanage_lock - protected the exchange state machine. * 2. g_exchange_info_lock - prevents update of exchanged data for a round while * exchange is in progress * 3. g_exchange_commited_cluster_lock - a higher * granularity, committed cluster r/w lock,used to allow read access to * committed cluster data even while exchange is busy and holding on to the * global exchange state machine lock. * 4. g_external_event_publisher_lock - ensure order of external events * published is maintained. * * Lock order * ========== * Locks to be obtained in the order mentioned above and relinquished in the * reverse order. */ /* * ---------------------------------------------------------------------------- * Constants * ---------------------------------------------------------------------------- */ /** * Exchange protocol version information. */ #define AS_EXCHANGE_PROTOCOL_IDENTIFIER 1 /** * A soft limit for the maximum cluster size. Meant to be optimize hash and list * data structures and not as a limit on the number of nodes. */ #define AS_EXCHANGE_CLUSTER_MAX_SIZE_SOFT 200 /** * A soft limit for the maximum number of unique vinfo's in a namespace. Meant * to be optimize hash and list data structures and not as a limit on the number * of vinfos processed. */ #define AS_EXCHANGE_UNIQUE_VINFO_MAX_SIZE_SOFT 200 /** * Average number of partitions for a version information. Used as initial * allocation size for every unique vinfo, hence a smaller value. */ #define AS_EXCHANGE_VINFO_NUM_PIDS_AVG 1024 /** * Maximum event listeners. */ #define AS_EXTERNAL_EVENT_LISTENER_MAX 7 /* * ---------------------------------------------------------------------------- * Exchange data format for namespaces payload * ---------------------------------------------------------------------------- */ /** * Partition data exchanged for each unique vinfo for a namespace. */ typedef struct as_exchange_vinfo_payload_s { /** * The partition vinfo. */ as_partition_version vinfo; /** * Count of partitions having this vinfo. */ uint32_t num_pids; /** * Partition having this vinfo. */ uint16_t pids[]; }__attribute__((__packed__)) as_exchange_vinfo_payload; /** * Information exchanged for a single namespace. */ typedef struct as_exchange_ns_vinfos_payload_s { /** * Count of version infos. */ uint32_t num_vinfos; /** * Parition version information for each unique version. */ as_exchange_vinfo_payload vinfos[]; }__attribute__((__packed__)) as_exchange_ns_vinfos_payload; /** * Received data stored per node, per namespace, before actual commit. */ typedef struct as_exchange_node_namespace_data_s { /** * Mapped local namespace. */ as_namespace* local_namespace; /** * Partition versions for this namespace. This field is reused across * exchange rounds and may not be null even if the local namespace is null. */ as_exchange_ns_vinfos_payload* partition_versions; /** * Sender's rack id. */ uint32_t rack_id; /** * Sender's roster generation. */ uint32_t roster_generation; /** * Sender's roster count. */ uint32_t roster_count; /** * Sending node's roster for this namespace. */ cf_node* roster; /** * Sending node's roster rack-ids for this namespace. */ cf_node* roster_rack_ids; /** * Sender's eventual regime for this namespace. */ uint32_t eventual_regime; /** * Sender's rebalance regime for this namespace. */ uint32_t rebalance_regime; /** * Sender's rebalance flags for this namespace. */ uint32_t rebalance_flags; } as_exchange_node_namespace_data; /** * Exchanged data for a single node. */ typedef struct as_exchange_node_data_s { /** * Used by exchange listeners during upgrades for compatibility purposes. */ uint32_t compatibility_id; /** * Number of sender's namespaces that have a matching local namespace. */ uint32_t num_namespaces; /** * Data for sender's namespaces having a matching local namespace. */ as_exchange_node_namespace_data namespace_data[AS_NAMESPACE_SZ]; } as_exchange_node_data; /* * ---------------------------------------------------------------------------- * Exchange internal data structures * ---------------------------------------------------------------------------- */ /** * Exchange subsystem status. */ typedef enum { AS_EXCHANGE_SYS_STATE_UNINITIALIZED, AS_EXCHANGE_SYS_STATE_RUNNING, AS_EXCHANGE_SYS_STATE_SHUTTING_DOWN, AS_EXCHANGE_SYS_STATE_STOPPED } as_exchange_sys_state; /** * Exchange message types. */ typedef enum { /** * Exchange data for one node. */ AS_EXCHANGE_MSG_TYPE_DATA, /** * Ack on receipt of exchanged data. */ AS_EXCHANGE_MSG_TYPE_DATA_ACK, /** * Not used. */ AS_EXCHANGE_MSG_TYPE_DATA_NACK, /** * The source is ready to commit exchanged information. */ AS_EXCHANGE_MSG_TYPE_READY_TO_COMMIT, /** * Message from the principal asking all nodes to commit the exchanged * information. */ AS_EXCHANGE_MSG_TYPE_COMMIT, /** * Sentinel value for exchange message types. */ AS_EXCHANGE_MSG_TYPE_SENTINEL } as_exchange_msg_type; /** * Internal exchange event type. */ typedef enum { /** * Cluster change event. */ AS_EXCHANGE_EVENT_CLUSTER_CHANGE, /** * Timer event. */ AS_EXCHANGE_EVENT_TIMER, /** * Incoming message event. */ AS_EXCHANGE_EVENT_MSG, } as_exchange_event_type; /** * Internal exchange event. */ typedef struct as_exchange_event_s { /** * The type of the event. */ as_exchange_event_type type; /** * Message for incoming message events. */ msg* msg; /** * Source for incoming message events. */ cf_node msg_source; /** * Clustering event instance for clustering events. */ as_clustering_event* clustering_event; } as_exchange_event; /** * Exchange subsystem state in the state transition diagram. */ typedef enum as_exchange_state_s { /** * Exchange subsystem is at rest will all data exchanged synchronized and * committed. */ AS_EXCHANGE_STATE_REST, /** * Data exchange is in progress. */ AS_EXCHANGE_STATE_EXCHANGING, /** * Data exchange is complete and this node is ready to commit data. */ AS_EXCHANGE_STATE_READY_TO_COMMIT, /** * Self node is orphaned. */ AS_EXCHANGE_STATE_ORPHANED } as_exchange_state; /** * State for a single node in the succession list. */ typedef struct as_exchange_node_state_s { /** * Inidicates if peer node has acknowledged send from self. */ bool send_acked; /** * Inidicates if self node has received data from this peer. */ bool received; /** * Inidicates if this peer node is ready to commit. Only relevant and used * by the current principal. */ bool is_ready_to_commit; /** * Exchange data received from this peer node. Member variables may be heap * allocated and hence should be freed carefully while discarding this * structure instance. */ as_exchange_node_data* data; } as_exchange_node_state; /** * State maintained by the exchange subsystem. */ typedef struct as_exchange_s { /** * Exchange subsystem status. */ as_exchange_sys_state sys_state; /** * Exchange state in the state transition diagram. */ as_exchange_state state; /** * Time when this node's exchange data was sent out. */ cf_clock send_ts; /** * Time when this node's ready to commit was sent out. */ cf_clock ready_to_commit_send_ts; /** * Thread id of the timer event generator. */ pthread_t timer_tid; /** * Nodes that are not yet ready to commit. */ cf_vector ready_to_commit_pending_nodes; /** * Current cluster key. */ as_cluster_key cluster_key; /** * Exchange's copy of the succession list. */ cf_vector succession_list; /** * The principal node in current succession list. Always the first node. */ cf_node principal; /** * Used by exchange listeners during upgrades for compatibility purposes. */ uint32_t compatibility_ids[AS_CLUSTER_SZ]; /** * Used during upgrades for compatibility purposes. */ uint32_t min_compatibility_id; /** * Used during upgrades for compatibility purposes. */ uint32_t max_compatibility_id; /** * Committed cluster generation. */ uint64_t committed_cluster_generation; /** * Last committed cluster key. */ as_cluster_key committed_cluster_key; /** * Last committed cluster size - size of the succession list. */ uint32_t committed_cluster_size; /** * Last committed exchange's succession list. */ cf_vector committed_succession_list; /** * The principal node in the committed succession list. Always the first * node. */ cf_node committed_principal; /** * The time this node entered orphan state. */ cf_clock orphan_state_start_time; /** * Indicates if transactions have already been blocked in the orphan state. */ bool orphan_state_are_transactions_blocked; /** * Will have an as_exchange_node_state entry for every node in the * succession list. */ cf_shash* nodeid_to_node_state; /** * Self node's partition version payload for current round. */ cf_dyn_buf self_data_dyn_buf[AS_NAMESPACE_SZ]; /** * This node's exchange data fabric message to send for current round. */ msg* data_msg; } as_exchange; /** * Internal storage for external event listeners. */ typedef struct as_exchange_event_listener_s { /** * The listener's calback function. */ as_exchange_cluster_changed_cb event_callback; /** * The listeners user data object passed back as is to the callback * function. */ void* udata; } as_exchange_event_listener; /** * External event publisher state. */ typedef struct as_exchange_external_event_publisher_s { /** * State of the external event publisher. */ as_exchange_sys_state sys_state; /** * Inidicates if there is an event to publish. */ bool event_queued; /** * The pending event to publish. */ as_exchange_cluster_changed_event to_publish; /** * The static succession list published with the message. */ cf_vector published_succession_list; /** * Conditional variable to signal a pending event. */ pthread_cond_t is_pending; /** * Thread id of the publisher thread. */ pthread_t event_publisher_tid; /** * Mutex to protect the conditional variable. */ pthread_mutex_t is_pending_mutex; /** * External event listeners. */ as_exchange_event_listener event_listeners[AS_EXTERNAL_EVENT_LISTENER_MAX]; /** * Event listener count. */ uint32_t event_listener_count; } as_exchange_external_event_publisher; /* * ---------------------------------------------------------------------------- * Externs * ---------------------------------------------------------------------------- */ void as_skew_monitor_update(); /* * ---------------------------------------------------------------------------- * Globals * ---------------------------------------------------------------------------- */ /** * Singleton exchange state all initialized to zero. */ static as_exchange g_exchange = { 0 }; /** * Rebalance flags. */ typedef enum { AS_EXCHANGE_REBALANCE_FLAG_UNIFORM = 0x01, AS_EXCHANGE_REBALANCE_FLAG_QUIESCE = 0x02 } as_exchange_rebalance_flags; /** * The fields in the exchange message. Should never change the order or elements * in between. */ typedef enum { AS_EXCHANGE_MSG_ID, AS_EXCHANGE_MSG_TYPE, AS_EXCHANGE_MSG_CLUSTER_KEY, AS_EXCHANGE_MSG_NAMESPACES, AS_EXCHANGE_MSG_NS_PARTITION_VERSIONS, AS_EXCHANGE_MSG_NS_RACK_IDS, AS_EXCHANGE_MSG_NS_ROSTER_GENERATIONS, AS_EXCHANGE_MSG_NS_ROSTERS, AS_EXCHANGE_MSG_NS_ROSTERS_RACK_IDS, AS_EXCHANGE_MSG_NS_EVENTUAL_REGIMES, AS_EXCHANGE_MSG_NS_REBALANCE_REGIMES, AS_EXCHANGE_MSG_NS_REBALANCE_FLAGS, AS_EXCHANGE_MSG_COMPATIBILITY_ID, NUM_EXCHANGE_MSG_FIELDS } as_exchange_msg_fields; /** * Exchange message template. */ static const msg_template exchange_msg_template[] = { { AS_EXCHANGE_MSG_ID, M_FT_UINT32 }, { AS_EXCHANGE_MSG_TYPE, M_FT_UINT32 }, { AS_EXCHANGE_MSG_CLUSTER_KEY, M_FT_UINT64 }, { AS_EXCHANGE_MSG_NAMESPACES, M_FT_MSGPACK }, { AS_EXCHANGE_MSG_NS_PARTITION_VERSIONS, M_FT_MSGPACK }, { AS_EXCHANGE_MSG_NS_RACK_IDS, M_FT_MSGPACK }, { AS_EXCHANGE_MSG_NS_ROSTER_GENERATIONS, M_FT_MSGPACK }, { AS_EXCHANGE_MSG_NS_ROSTERS, M_FT_MSGPACK }, { AS_EXCHANGE_MSG_NS_ROSTERS_RACK_IDS, M_FT_MSGPACK }, { AS_EXCHANGE_MSG_NS_EVENTUAL_REGIMES, M_FT_MSGPACK }, { AS_EXCHANGE_MSG_NS_REBALANCE_REGIMES, M_FT_MSGPACK }, { AS_EXCHANGE_MSG_NS_REBALANCE_FLAGS, M_FT_MSGPACK }, { AS_EXCHANGE_MSG_COMPATIBILITY_ID, M_FT_UINT32 } }; COMPILER_ASSERT(sizeof(exchange_msg_template) / sizeof(msg_template) == NUM_EXCHANGE_MSG_FIELDS); /** * Global lock to set or get exchanged info from other threads. */ pthread_mutex_t g_exchanged_info_lock = PTHREAD_MUTEX_INITIALIZER; /** * Global lock to serialize all reads and writes to the exchange state. */ pthread_mutex_t g_exchange_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; /** * Acquire a lock on the exchange subsystem. */ #define EXCHANGE_LOCK() \ ({ \ pthread_mutex_lock (&g_exchange_lock); \ LOCK_DEBUG("locked in %s", __FUNCTION__); \ }) /** * Relinquish the lock on the exchange subsystem. */ #define EXCHANGE_UNLOCK() \ ({ \ pthread_mutex_unlock (&g_exchange_lock); \ LOCK_DEBUG("unLocked in %s", __FUNCTION__); \ }) /** * Global lock to set or get committed exchange cluster. This is a lower * granularity lock to allow read access to committed cluster even while * exchange is busy for example rebalancing under the exchange lock. */ pthread_rwlock_t g_exchange_commited_cluster_lock = PTHREAD_RWLOCK_INITIALIZER; /** * Acquire a read lock on the committed exchange cluster. */ #define EXCHANGE_COMMITTED_CLUSTER_RLOCK() \ ({ \ pthread_rwlock_rdlock (&g_exchange_commited_cluster_lock); \ LOCK_DEBUG("committed data locked in %s", __FUNCTION__); \ }) /** * Acquire a write lock on the committed exchange cluster. */ #define EXCHANGE_COMMITTED_CLUSTER_WLOCK() \ ({ \ pthread_rwlock_wrlock (&g_exchange_commited_cluster_lock); \ LOCK_DEBUG("committed data locked in %s", __FUNCTION__); \ }) /** * Relinquish the lock on the committed exchange cluster. */ #define EXCHANGE_COMMITTED_CLUSTER_UNLOCK() \ ({ \ pthread_rwlock_unlock (&g_exchange_commited_cluster_lock); \ LOCK_DEBUG("committed data unLocked in %s", __FUNCTION__); \ }) /** * Singleton external events publisher. */ static as_exchange_external_event_publisher g_external_event_publisher; /** * The fat lock for all clustering events listener changes. */ static pthread_mutex_t g_external_event_publisher_lock = PTHREAD_RECURSIVE_MUTEX_INITIALIZER_NP; /** * Acquire a lock on the event publisher. */ #define EXTERNAL_EVENT_PUBLISHER_LOCK() \ ({ \ pthread_mutex_lock (&g_external_event_publisher_lock); \ LOCK_DEBUG("publisher locked in %s", __FUNCTION__); \ }) /** * Relinquish the lock on the external event publisher. */ #define EXTERNAL_EVENT_PUBLISHER_UNLOCK() \ ({ \ pthread_mutex_unlock (&g_external_event_publisher_lock); \ LOCK_DEBUG("publisher unLocked in %s", __FUNCTION__); \ }) /* * ---------------------------------------------------------------------------- * Logging macros. * ---------------------------------------------------------------------------- */ /** * Used to limit potentially long log lines. Includes space for NULL terminator. */ #define CRASH(format, ...) cf_crash(AS_EXCHANGE, format, ##__VA_ARGS__) #define WARNING(format, ...) cf_warning(AS_EXCHANGE, format, ##__VA_ARGS__) #define INFO(format, ...) cf_info(AS_EXCHANGE, format, ##__VA_ARGS__) #define DEBUG(format, ...) cf_debug(AS_EXCHANGE, format, ##__VA_ARGS__) #define DETAIL(format, ...) cf_detail(AS_EXCHANGE, format, ##__VA_ARGS__) #define LOG(severity, format, ...) \ ({ \ switch (severity) { \ case CF_CRITICAL: \ CRASH(format, ##__VA_ARGS__); \ break; \ case CF_WARNING: \ WARNING(format, ##__VA_ARGS__); \ break; \ case CF_INFO: \ INFO(format, ##__VA_ARGS__); \ break; \ case CF_DEBUG: \ DEBUG(format, ##__VA_ARGS__); \ break; \ case CF_DETAIL: \ DETAIL(format, ##__VA_ARGS__); \ break; \ default: \ break; \ } \ }) /** * Size of the (per-namespace) self payload dynamic buffer. */ #define AS_EXCHANGE_SELF_DYN_BUF_SIZE() (AS_EXCHANGE_UNIQUE_VINFO_MAX_SIZE_SOFT \ * ((AS_EXCHANGE_VINFO_NUM_PIDS_AVG * sizeof(uint16_t)) \ + sizeof(as_partition_version))) /** * Scratch size for exchange messages. * TODO: Compute this properly. */ #define AS_EXCHANGE_MSG_SCRATCH_SIZE 2048 #ifdef LOCK_DEBUG_ENABLED #define LOCK_DEBUG(format, ...) DEBUG(format, ##__VA_ARGS__) #else #define LOCK_DEBUG(format, ...) #endif /** * Timer event generation interval. */ #define EXCHANGE_TIMER_TICK_INTERVAL() (75) /** * Minimum timeout interval for sent exchange data. */ #define EXCHANGE_SEND_MIN_TIMEOUT() (MAX(75, as_hb_tx_interval_get() / 2)) /** * Maximum timeout interval for sent exchange data. */ #define EXCHANGE_SEND_MAX_TIMEOUT() (30000) /** * Timeout for receiving commit message after transitioning to ready to commit. */ #define EXCHANGE_READY_TO_COMMIT_TIMEOUT() (EXCHANGE_SEND_MIN_TIMEOUT()) /** * Send timeout is a step function with this value as the interval for each * step. */ #define EXCHANGE_SEND_STEP_INTERVAL() \ (MAX(EXCHANGE_SEND_MIN_TIMEOUT(), as_hb_tx_interval_get())) /** * Check if exchange is initialized. */ #define EXCHANGE_IS_INITIALIZED() \ ({ \ EXCHANGE_LOCK(); \ bool initialized = (g_exchange.sys_state \ != AS_EXCHANGE_SYS_STATE_UNINITIALIZED); \ EXCHANGE_UNLOCK(); \ initialized; \ }) /** * * Check if exchange is running. */ #define EXCHANGE_IS_RUNNING() \ ({ \ EXCHANGE_LOCK(); \ bool running = (EXCHANGE_IS_INITIALIZED() \ && g_exchange.sys_state == AS_EXCHANGE_SYS_STATE_RUNNING); \ EXCHANGE_UNLOCK(); \ running; \ }) /** * Create temporary stack variables. */ #define TOKEN_PASTE(x, y) x##y #define STACK_VAR(x, y) TOKEN_PASTE(x, y) /** * Convert a vector to a stack allocated array. */ #define cf_vector_to_stack_array(vector_p, nodes_array_p, num_nodes_p) \ ({ \ *num_nodes_p = cf_vector_size(vector_p); \ if (*num_nodes_p > 0) { \ *nodes_array_p = alloca(sizeof(cf_node) * (*num_nodes_p)); \ for (int i = 0; i < *num_nodes_p; i++) { \ cf_vector_get(vector_p, i, &(*nodes_array_p)[i]); \ } \ } \ else { \ *nodes_array_p = NULL; \ } \ }) /** * Create and initialize a lockless stack allocated vector to initially sized to * store cluster node number of elements. */ #define cf_vector_stack_create(value_type) \ ({ \ cf_vector * STACK_VAR(vector, __LINE__) = (cf_vector*)alloca( \ sizeof(cf_vector)); \ size_t buffer_size = AS_EXCHANGE_CLUSTER_MAX_SIZE_SOFT \ * sizeof(value_type); \ void* STACK_VAR(buff, __LINE__) = alloca(buffer_size); cf_vector_init_with_buf( \ STACK_VAR(vector, __LINE__), sizeof(value_type), \ AS_EXCHANGE_CLUSTER_MAX_SIZE_SOFT, (uint8_t*)STACK_VAR(buff, __LINE__), \ VECTOR_FLAG_INITZERO); \ STACK_VAR(vector, __LINE__); \ }) /* * ---------------------------------------------------------------------------- * Vector functions to be moved to cf_vector * ---------------------------------------------------------------------------- */ /** * Convert a vector to an array. */ static cf_node* vector_to_array(cf_vector* vector) { return (cf_node*)cf_vector_as_array(vector); } /** * Clear / delete all entries in a vector. */ static void vector_clear(cf_vector* vector) { cf_vector_delete_range(vector, 0, cf_vector_size(vector)); } /** * Find the index of an element in the vector. Equality is based on mem compare. * * @param vector the source vector. * @param element the element to find. * @return the index if the element is found, -1 otherwise. */ static int vector_find(cf_vector* vector, const void* element) { int element_count = cf_vector_size(vector); size_t value_len = cf_vector_element_size(vector); for (int i = 0; i < element_count; i++) { // No null check required since we are iterating under a lock and within // vector bounds. void* src_element = cf_vector_getp(vector, i); if (src_element) { if (memcmp(element, src_element, value_len) == 0) { return i; } } } return -1; } /** * Copy all elements form the source vector to the destination vector to the * destination vector. Assumes the source and destination vector are not being * modified while the copy operation is in progress. * * @param dest the destination vector. * @param src the source vector. * @return the number of elements copied. */ static int vector_copy(cf_vector* dest, cf_vector* src) { int element_count = cf_vector_size(src); int copied_count = 0; for (int i = 0; i < element_count; i++) { // No null check required since we are iterating under a lock and within // vector bounds. void* src_element = cf_vector_getp(src, i); if (src_element) { cf_vector_append(dest, src_element); copied_count++; } } return copied_count; } /** * Generate a hash code for a blob using Jenkins hash function. */ static uint32_t exchange_blob_hash(const uint8_t* value, size_t value_size) { uint32_t hash = 0; for (int i = 0; i < value_size; ++i) { hash += value[i]; hash += (hash << 10); hash ^= (hash >> 6); } hash += (hash << 3); hash ^= (hash >> 11); hash += (hash << 15); return hash; } /** * Generate a hash code for a mesh node key. */ static uint32_t exchange_vinfo_shash(const void* value) { return exchange_blob_hash((const uint8_t*)value, sizeof(as_partition_version)); } /* * ---------------------------------------------------------------------------- * Clustering external event publisher * ---------------------------------------------------------------------------- */ /** * * Check if event publisher is running. */ static bool exchange_external_event_publisher_is_running() { EXTERNAL_EVENT_PUBLISHER_LOCK(); bool running = g_external_event_publisher.sys_state == AS_EXCHANGE_SYS_STATE_RUNNING; EXTERNAL_EVENT_PUBLISHER_UNLOCK(); return running; } /** * Initialize the event publisher. */ static void exchange_external_event_publisher_init() { EXTERNAL_EVENT_PUBLISHER_LOCK(); memset(&g_external_event_publisher, 0, sizeof(g_external_event_publisher)); cf_vector_init(&g_external_event_publisher.published_succession_list, sizeof(cf_node), AS_EXCHANGE_CLUSTER_MAX_SIZE_SOFT, VECTOR_FLAG_INITZERO); pthread_mutex_init(&g_external_event_publisher.is_pending_mutex, NULL); pthread_cond_init(&g_external_event_publisher.is_pending, NULL); EXTERNAL_EVENT_PUBLISHER_UNLOCK(); } /** * Register a clustering event listener. */ static void exchange_external_event_listener_register( as_exchange_cluster_changed_cb event_callback, void* udata) { EXTERNAL_EVENT_PUBLISHER_LOCK(); if (g_external_event_publisher.event_listener_count >= AS_EXTERNAL_EVENT_LISTENER_MAX) { CRASH("cannot register more than %d event listeners", AS_EXTERNAL_EVENT_LISTENER_MAX); } g_external_event_publisher.event_listeners[g_external_event_publisher.event_listener_count].event_callback = event_callback; g_external_event_publisher.event_listeners[g_external_event_publisher.event_listener_count].udata = udata; g_external_event_publisher.event_listener_count++; EXTERNAL_EVENT_PUBLISHER_UNLOCK(); } /** * Wakeup the publisher thread. */ static void exchange_external_event_publisher_thr_wakeup() { pthread_mutex_lock(&g_external_event_publisher.is_pending_mutex); pthread_cond_signal(&g_external_event_publisher.is_pending); pthread_mutex_unlock(&g_external_event_publisher.is_pending_mutex); } /** * Queue up and external event to publish. */ static void exchange_external_event_queue(as_exchange_cluster_changed_event* event) { EXTERNAL_EVENT_PUBLISHER_LOCK(); memcpy(&g_external_event_publisher.to_publish, event, sizeof(g_external_event_publisher.to_publish)); vector_clear(&g_external_event_publisher.published_succession_list); if (event->succession) { // Use the static list for the published event, so that the input event // object can be destroyed irrespective of when the it is published. for (int i = 0; i < event->cluster_size; i++) { cf_vector_append( &g_external_event_publisher.published_succession_list, &event->succession[i]); } g_external_event_publisher.to_publish.succession = vector_to_array( &g_external_event_publisher.published_succession_list); } else { g_external_event_publisher.to_publish.succession = NULL; } g_external_event_publisher.event_queued = true; EXTERNAL_EVENT_PUBLISHER_UNLOCK(); // Wake up the publisher thread. exchange_external_event_publisher_thr_wakeup(); } /** * Publish external events if any are pending. */ static void exchange_external_events_publish() { EXTERNAL_EVENT_PUBLISHER_LOCK(); if (g_external_event_publisher.event_queued) { g_external_event_publisher.event_queued = false; for (uint32_t i = 0; i < g_external_event_publisher.event_listener_count; i++) { (g_external_event_publisher.event_listeners[i].event_callback)( &g_external_event_publisher.to_publish, g_external_event_publisher.event_listeners[i].udata); } } EXTERNAL_EVENT_PUBLISHER_UNLOCK(); } /** * External event publisher thread. */ static void* exchange_external_event_publisher_thr(void* arg) { pthread_mutex_lock(&g_external_event_publisher.is_pending_mutex); while (true) { pthread_cond_wait(&g_external_event_publisher.is_pending, &g_external_event_publisher.is_pending_mutex); if (exchange_external_event_publisher_is_running()) { exchange_external_events_publish(); } else { // Publisher stopped, exit the tread. break; } } return NULL; } /** * Start the event publisher. */ static void exchange_external_event_publisher_start() { EXTERNAL_EVENT_PUBLISHER_LOCK(); g_external_event_publisher.sys_state = AS_EXCHANGE_SYS_STATE_RUNNING; g_external_event_publisher.event_publisher_tid = cf_thread_create_joinable(exchange_external_event_publisher_thr, NULL); EXTERNAL_EVENT_PUBLISHER_UNLOCK(); } /** * Stop the event publisher. */ static void external_event_publisher_stop() { EXTERNAL_EVENT_PUBLISHER_LOCK(); g_external_event_publisher.sys_state = AS_EXCHANGE_SYS_STATE_SHUTTING_DOWN; EXTERNAL_EVENT_PUBLISHER_UNLOCK(); exchange_external_event_publisher_thr_wakeup(); cf_thread_join(g_external_event_publisher.event_publisher_tid); EXTERNAL_EVENT_PUBLISHER_LOCK(); g_external_event_publisher.sys_state = AS_EXCHANGE_SYS_STATE_STOPPED; g_external_event_publisher.event_queued = false; EXTERNAL_EVENT_PUBLISHER_UNLOCK(); } /* * ---------------------------------------------------------------------------- * Node state related * ---------------------------------------------------------------------------- */ /** * Initialize node state. */ static void exchange_node_state_init(as_exchange_node_state* node_state) { memset(node_state, 0, sizeof(*node_state)); node_state->data = cf_calloc(1, sizeof(as_exchange_node_data)); } /** * Reset node state. */ static void exchange_node_state_reset(as_exchange_node_state* node_state) { node_state->send_acked = false; node_state->received = false; node_state->is_ready_to_commit = false; node_state->data->num_namespaces = 0; for (int i = 0; i < AS_NAMESPACE_SZ; i++) { node_state->data->namespace_data[i].local_namespace = NULL; } } /** * Destroy node state. */ static void exchange_node_state_destroy(as_exchange_node_state* node_state) { for (int i = 0; i < AS_NAMESPACE_SZ; i++) { if (node_state->data->namespace_data[i].partition_versions) { cf_free(node_state->data->namespace_data[i].partition_versions); } if (node_state->data->namespace_data[i].roster) { cf_free(node_state->data->namespace_data[i].roster); } if (node_state->data->namespace_data[i].roster_rack_ids) { cf_free(node_state->data->namespace_data[i].roster_rack_ids); } } cf_free(node_state->data); } /** * Reduce function to match node -> node state hash to the succession list. * Should always be invoked under a lock over the main hash. */ static int exchange_node_states_reset_reduce(const void* key, void* data, void* udata) { const cf_node* node = (const cf_node*)key; as_exchange_node_state* node_state = (as_exchange_node_state*)data; int node_index = vector_find(&g_exchange.succession_list, node); if (node_index < 0) { // Node not in succession list exchange_node_state_destroy(node_state); return CF_SHASH_REDUCE_DELETE; } exchange_node_state_reset(node_state); return CF_SHASH_OK; } /** * Adjust the nodeid_to_node_state hash to have an entry for every node in the * succession list with state reset for a new round of exchange. Removes entries * not in the succession list. */ static void exchange_node_states_reset() { EXCHANGE_LOCK(); // Fix existing entries by reseting entries in succession and removing // entries not in succession list. cf_shash_reduce(g_exchange.nodeid_to_node_state, exchange_node_states_reset_reduce, NULL); // Add missing entries. int succession_length = cf_vector_size(&g_exchange.succession_list); as_exchange_node_state temp_state; for (int i = 0; i < succession_length; i++) { cf_node nodeid; cf_vector_get(&g_exchange.succession_list, i, &nodeid); if (cf_shash_get(g_exchange.nodeid_to_node_state, &nodeid, &temp_state) == CF_SHASH_ERR_NOT_FOUND) { exchange_node_state_init(&temp_state); cf_shash_put(g_exchange.nodeid_to_node_state, &nodeid, &temp_state); } } EXCHANGE_UNLOCK(); } /** * Reduce function to find nodes that had not acked self node's exchange data. */ static int exchange_nodes_find_send_unacked_reduce(const void* key, void* data, void* udata) { const cf_node* node = (const cf_node*)key; as_exchange_node_state* node_state = (as_exchange_node_state*)data; cf_vector* unacked = (cf_vector*)udata; if (!node_state->send_acked) { cf_vector_append(unacked, node); } return CF_SHASH_OK; } /** * Find nodes that have not acked self node's exchange data. */ static void exchange_nodes_find_send_unacked(cf_vector* unacked) { cf_shash_reduce(g_exchange.nodeid_to_node_state, exchange_nodes_find_send_unacked_reduce, unacked); } /** * Reduce function to find peer nodes from whom self node has not received * exchange data. */ static int exchange_nodes_find_not_received_reduce(const void* key, void* data, void* udata) { const cf_node* node = (const cf_node*)key; as_exchange_node_state* node_state = (as_exchange_node_state*)data; cf_vector* not_received = (cf_vector*)udata; if (!node_state->received) { cf_vector_append(not_received, node); } return CF_SHASH_OK; } /** * Find peer nodes from whom self node has not received exchange data. */ static void exchange_nodes_find_not_received(cf_vector* not_received) { cf_shash_reduce(g_exchange.nodeid_to_node_state, exchange_nodes_find_not_received_reduce, not_received); } /** * Reduce function to find peer nodes that are not ready to commit. */ static int exchange_nodes_find_not_ready_to_commit_reduce(const void* key, void* data, void* udata) { const cf_node* node = (const cf_node*)key; as_exchange_node_state* node_state = (as_exchange_node_state*)data; cf_vector* not_ready_to_commit = (cf_vector*)udata; if (!node_state->is_ready_to_commit) { cf_vector_append(not_ready_to_commit, node); } return CF_SHASH_OK; } /** * Find peer nodes that are not ready to commit. */ static void exchange_nodes_find_not_ready_to_commit(cf_vector* not_ready_to_commit) { cf_shash_reduce(g_exchange.nodeid_to_node_state, exchange_nodes_find_not_ready_to_commit_reduce, not_ready_to_commit); } /** * Update the node state for a node. */ static void exchange_node_state_update(cf_node nodeid, as_exchange_node_state* node_state) { cf_shash_put(g_exchange.nodeid_to_node_state, &nodeid, node_state); } /** * Get state of a node from the hash. If not found crash because this entry * should be present in the hash. */ static void exchange_node_state_get_safe(cf_node nodeid, as_exchange_node_state* node_state) { if (cf_shash_get(g_exchange.nodeid_to_node_state, &nodeid, node_state) == CF_SHASH_ERR_NOT_FOUND) { CRASH( "node entry for node %"PRIx64" missing from node state hash", nodeid); } } /* * ---------------------------------------------------------------------------- * Message related * ---------------------------------------------------------------------------- */ /** * Fill compulsary fields in a message common to all message types. */ static void exchange_msg_src_fill(msg* msg, as_exchange_msg_type type) { EXCHANGE_LOCK(); msg_set_uint32(msg, AS_EXCHANGE_MSG_ID, AS_EXCHANGE_PROTOCOL_IDENTIFIER); msg_set_uint64(msg, AS_EXCHANGE_MSG_CLUSTER_KEY, g_exchange.cluster_key); msg_set_uint32(msg, AS_EXCHANGE_MSG_TYPE, type); EXCHANGE_UNLOCK(); } /** * Get the msg buffer from a pool and fill in all compulsory fields. * @return the msg buff with compulsory fields filled in. */ static msg* exchange_msg_get(as_exchange_msg_type type) { msg* msg = as_fabric_msg_get(M_TYPE_EXCHANGE); exchange_msg_src_fill(msg, type); return msg; } /** * Return the message buffer back to the pool. */ static void exchange_msg_return(msg* msg) { as_fabric_msg_put(msg); } /** * Get message id. */ static int exchange_msg_id_get(msg* msg, uint32_t* msg_id) { if (msg_get_uint32(msg, AS_EXCHANGE_MSG_ID, msg_id) != 0) { return -1; } return 0; } /** * Get message type. */ static int exchange_msg_type_get(msg* msg, as_exchange_msg_type* msg_type) { if (msg_get_uint32(msg, AS_EXCHANGE_MSG_TYPE, msg_type) != 0) { return -1; } return 0; } /** * Get message cluster key. */ static int exchange_msg_cluster_key_get(msg* msg, as_cluster_key* cluster_key) { if (msg_get_uint64(msg, AS_EXCHANGE_MSG_CLUSTER_KEY, cluster_key) != 0) { return -1; } return 0; } /** * Set data payload for a message. */ static void exchange_msg_data_payload_set(msg* msg) { uint32_t ns_count = g_config.n_namespaces; cf_vector_define(namespace_list, sizeof(msg_buf_ele), ns_count, 0); cf_vector_define(partition_versions, sizeof(msg_buf_ele), ns_count, 0); uint32_t rack_ids[ns_count]; bool have_roster = false; bool have_roster_rack_ids = false; uint32_t roster_generations[ns_count]; cf_vector_define(rosters, sizeof(msg_buf_ele), ns_count, 0); cf_vector_define(rosters_rack_ids, sizeof(msg_buf_ele), ns_count, 0); bool have_regimes = false; uint32_t eventual_regimes[ns_count]; uint32_t rebalance_regimes[ns_count]; bool have_rebalance_flags = false; uint32_t rebalance_flags[ns_count]; memset(rebalance_flags, 0, sizeof(rebalance_flags)); msg_set_uint32(msg, AS_EXCHANGE_MSG_COMPATIBILITY_ID, AS_EXCHANGE_COMPATIBILITY_ID); for (uint32_t ns_ix = 0; ns_ix < ns_count; ns_ix++) { as_namespace* ns = g_config.namespaces[ns_ix]; msg_buf_ele ns_ele = { .sz = (uint32_t)strlen(ns->name), .ptr = (uint8_t*)ns->name }; msg_buf_ele pv_ele = { .sz = (uint32_t)g_exchange.self_data_dyn_buf[ns_ix].used_sz, .ptr = g_exchange.self_data_dyn_buf[ns_ix].buf }; msg_buf_ele rn_ele = { .sz = (uint32_t)(ns->smd_roster_count * sizeof(cf_node)), .ptr = (uint8_t*)ns->smd_roster }; msg_buf_ele rri_ele = { .sz = (uint32_t)(ns->smd_roster_count * sizeof(uint32_t)), .ptr = (uint8_t*)ns->smd_roster_rack_ids }; cf_vector_append(&namespace_list, &ns_ele); cf_vector_append(&partition_versions, &pv_ele); rack_ids[ns_ix] = ns->rack_id; if (ns->smd_roster_generation != 0) { have_roster = true; if (! have_roster_rack_ids) { for (uint32_t n = 0; n < ns->smd_roster_count; n++) { if (ns->smd_roster_rack_ids[n] != 0) { have_roster_rack_ids = true; break; } } } } roster_generations[ns_ix] = ns->smd_roster_generation; cf_vector_append(&rosters, &rn_ele); cf_vector_append(&rosters_rack_ids, &rri_ele); eventual_regimes[ns_ix] = ns->eventual_regime; rebalance_regimes[ns_ix] = ns->rebalance_regime; if (eventual_regimes[ns_ix] != 0 || rebalance_regimes[ns_ix] != 0) { have_regimes = true; } if (ns->cfg_prefer_uniform_balance) { rebalance_flags[ns_ix] |= AS_EXCHANGE_REBALANCE_FLAG_UNIFORM; } if (ns->pending_quiesce) { rebalance_flags[ns_ix] |= AS_EXCHANGE_REBALANCE_FLAG_QUIESCE; } if (rebalance_flags[ns_ix] != 0) { have_rebalance_flags = true; } } msg_msgpack_list_set_buf(msg, AS_EXCHANGE_MSG_NAMESPACES, &namespace_list); msg_msgpack_list_set_buf(msg, AS_EXCHANGE_MSG_NS_PARTITION_VERSIONS, &partition_versions); msg_msgpack_list_set_uint32(msg, AS_EXCHANGE_MSG_NS_RACK_IDS, rack_ids, ns_count); if (have_roster) { msg_msgpack_list_set_uint32(msg, AS_EXCHANGE_MSG_NS_ROSTER_GENERATIONS, roster_generations, ns_count); msg_msgpack_list_set_buf(msg, AS_EXCHANGE_MSG_NS_ROSTERS, &rosters); if (have_roster_rack_ids) { msg_msgpack_list_set_buf(msg, AS_EXCHANGE_MSG_NS_ROSTERS_RACK_IDS, &rosters_rack_ids); } } if (have_regimes) { msg_msgpack_list_set_uint32(msg, AS_EXCHANGE_MSG_NS_EVENTUAL_REGIMES, eventual_regimes, ns_count); msg_msgpack_list_set_uint32(msg, AS_EXCHANGE_MSG_NS_REBALANCE_REGIMES, rebalance_regimes, ns_count); } if (have_rebalance_flags) { msg_msgpack_list_set_uint32(msg, AS_EXCHANGE_MSG_NS_REBALANCE_FLAGS, rebalance_flags, ns_count); } } /** * Check sanity of an incoming message. If this check passes the message is * guaranteed to have valid protocol identifier, valid type and valid matching * cluster key with source node being a part of the cluster. * @return 0 if the message in valid, -1 if the message is invalid and should be * ignored. */ static bool exchange_msg_is_sane(cf_node source, msg* msg) { uint32_t id = 0; if (exchange_msg_id_get(msg, &id) != 0|| id != AS_EXCHANGE_PROTOCOL_IDENTIFIER) { DEBUG( "received exchange message with mismatching identifier - expected %u but was %u", AS_EXCHANGE_PROTOCOL_IDENTIFIER, id); return false; } as_exchange_msg_type msg_type = 0; if (exchange_msg_type_get(msg, &msg_type) != 0 || msg_type >= AS_EXCHANGE_MSG_TYPE_SENTINEL) { WARNING("received exchange message with invalid message type %u", msg_type); return false; } EXCHANGE_LOCK(); as_cluster_key current_cluster_key = g_exchange.cluster_key; bool is_in_cluster = vector_find(&g_exchange.succession_list, &source) >= 0; EXCHANGE_UNLOCK(); if (!is_in_cluster) { DEBUG("received exchange message from node %"PRIx64" not in cluster", source); return false; } as_cluster_key incoming_cluster_key = 0; if (exchange_msg_cluster_key_get(msg, &incoming_cluster_key) != 0 || (current_cluster_key != incoming_cluster_key) || current_cluster_key == 0) { DEBUG("received exchange message with mismatching cluster key - expected %"PRIx64" but was %"PRIx64, current_cluster_key, incoming_cluster_key); return false; } return true; } /** * Send a message over fabric. * * @param msg the message to send. * @param dest the desination node. * @param error_msg the error message. */ static void exchange_msg_send(msg* msg, cf_node dest, char* error_msg) { if (as_fabric_send(dest, msg, AS_FABRIC_CHANNEL_CTRL)) { // Fabric will not return the message to the pool. Do it ourself. exchange_msg_return(msg); WARNING("%s (dest:%"PRIx64")", error_msg, dest); } } /** * Send a message over to a list of destination nodes. * * @param msg the message to send. * @param dests the node list to send the message to. * @param num_dests the number of destination nodes. * @param error_msg the error message. */ static void exchange_msg_send_list(msg* msg, cf_node* dests, int num_dests, char* error_msg) { if (as_fabric_send_list(dests, num_dests, msg, AS_FABRIC_CHANNEL_CTRL) != 0) { // Fabric will not return the message to the pool. Do it ourself. exchange_msg_return(msg); as_clustering_log_cf_node_array(CF_WARNING, AS_EXCHANGE, error_msg, dests, num_dests); } } /** * Send a commit message to a destination node. * @param dest the destination node. */ static void exchange_commit_msg_send(cf_node dest) { msg* commit_msg = exchange_msg_get(AS_EXCHANGE_MSG_TYPE_COMMIT); DEBUG("sending commit message to node %"PRIx64, dest); exchange_msg_send(commit_msg, dest, "error sending commit message"); } /** * Send a commit message to a list of destination nodes. * @param dests the destination nodes. * @param num_dests the number of destination nodes. */ static void exchange_commit_msg_send_all(cf_node* dests, int num_dests) { msg* commit_msg = exchange_msg_get(AS_EXCHANGE_MSG_TYPE_COMMIT); as_clustering_log_cf_node_array(CF_DEBUG, AS_EXCHANGE, "sending commit message to nodes:", dests, num_dests); exchange_msg_send_list(commit_msg, dests, num_dests, "error sending commit message"); } /** * Send ready to commit message to the principal. */ static void exchange_ready_to_commit_msg_send() { EXCHANGE_LOCK(); g_exchange.ready_to_commit_send_ts = cf_getms(); cf_node principal = g_exchange.principal; EXCHANGE_UNLOCK(); msg* ready_to_commit_msg = exchange_msg_get( AS_EXCHANGE_MSG_TYPE_READY_TO_COMMIT); DEBUG("sending ready to commit message to node %"PRIx64, principal); exchange_msg_send(ready_to_commit_msg, principal, "error sending ready to commit message"); } /** * Send exchange data to all nodes that have not acked the send. */ static void exchange_data_msg_send_pending_ack() { EXCHANGE_LOCK(); g_exchange.send_ts = cf_getms(); cf_node* unacked_nodes; int num_unacked_nodes; cf_vector* unacked_nodes_vector = cf_vector_stack_create(cf_node); exchange_nodes_find_send_unacked(unacked_nodes_vector); cf_vector_to_stack_array(unacked_nodes_vector, &unacked_nodes, &num_unacked_nodes); cf_vector_destroy(unacked_nodes_vector); if (!num_unacked_nodes) { goto Exit; } // FIXME - temporary assert, until we're sure. cf_assert(g_exchange.data_msg != NULL, AS_EXCHANGE, "payload not built"); as_clustering_log_cf_node_array(CF_DEBUG, AS_EXCHANGE, "sending exchange data to nodes:", unacked_nodes, num_unacked_nodes); msg_incr_ref(g_exchange.data_msg); exchange_msg_send_list(g_exchange.data_msg, unacked_nodes, num_unacked_nodes, "error sending exchange data"); Exit: EXCHANGE_UNLOCK(); } /** * Send a commit message to a destination node. * @param dest the destination node. */ static void exchange_data_ack_msg_send(cf_node dest) { msg* ack_msg = exchange_msg_get(AS_EXCHANGE_MSG_TYPE_DATA_ACK); DEBUG("sending data ack message to node %"PRIx64, dest); exchange_msg_send(ack_msg, dest, "error sending data ack message"); } /* * ---------------------------------------------------------------------------- * Data payload related * ---------------------------------------------------------------------------- */ /** * Add a pid to the namespace hash for the input vinfo. */ static void exchange_namespace_hash_pid_add(cf_shash* ns_hash, as_partition_version* vinfo, uint16_t pid) { if (as_partition_version_is_null(vinfo)) { // Ignore NULL vinfos. return; } cf_vector* pid_vector; // Append the hash. if (cf_shash_get(ns_hash, vinfo, &pid_vector) != CF_SHASH_OK) { // We are seeing this vinfo for the first time. pid_vector = cf_vector_create(sizeof(uint16_t), AS_EXCHANGE_VINFO_NUM_PIDS_AVG, 0); cf_shash_put(ns_hash, vinfo, &pid_vector); } cf_vector_append(pid_vector, &pid); } /** * Destroy the pid vector for each vinfo. */ static int exchange_namespace_hash_destroy_reduce(const void* key, void* data, void* udata) { cf_vector* pid_vector = *(cf_vector**)data; cf_vector_destroy(pid_vector); return CF_SHASH_REDUCE_DELETE; } /** * Serialize each vinfo and accumulated pids to the input buffer. */ static int exchange_namespace_hash_serialize_reduce(const void* key, void* data, void* udata) { const as_partition_version* vinfo = (const as_partition_version*)key; cf_vector* pid_vector = *(cf_vector**)data; cf_dyn_buf* dyn_buf = (cf_dyn_buf*)udata; // Append the vinfo. cf_dyn_buf_append_buf(dyn_buf, (uint8_t*)vinfo, sizeof(*vinfo)); // Append the count of pids. uint32_t num_pids = cf_vector_size(pid_vector); cf_dyn_buf_append_buf(dyn_buf, (uint8_t*)&num_pids, sizeof(num_pids)); // Append each pid. for (int i = 0; i < num_pids; i++) { uint16_t* pid = cf_vector_getp(pid_vector, i); cf_dyn_buf_append_buf(dyn_buf, (uint8_t*)pid, sizeof(*pid)); } return CF_SHASH_OK; } /** * Append namespace payload, in as_exchange_namespace_payload format, for a * namespace to the dynamic buffer. * * @param ns the namespace. * @param dyn_buf the dynamic buffer. */ static void exchange_data_namespace_payload_add(as_namespace* ns, cf_dyn_buf* dyn_buf) { // A hash from each unique non null vinfo to a vector of partition ids // having the vinfo. cf_shash* ns_hash = cf_shash_create(exchange_vinfo_shash, sizeof(as_partition_version), sizeof(cf_vector*), AS_EXCHANGE_UNIQUE_VINFO_MAX_SIZE_SOFT, 0); as_partition* partitions = ns->partitions; // Populate the hash with one entry for each vinfo for (int i = 0; i < AS_PARTITIONS; i++) { as_partition_version* current_vinfo = &partitions[i].version; exchange_namespace_hash_pid_add(ns_hash, current_vinfo, i); } // We are ready to populate the dyn buffer with this ns's data. DEBUG("namespace %s has %d unique vinfos", ns->name, cf_shash_get_size(ns_hash)); // Append the vinfo count. uint32_t num_vinfos = cf_shash_get_size(ns_hash); cf_dyn_buf_append_buf(dyn_buf, (uint8_t*)&num_vinfos, sizeof(num_vinfos)); // Append vinfos and partitions. cf_shash_reduce(ns_hash, exchange_namespace_hash_serialize_reduce, dyn_buf); // Destroy the intermediate hash and the pid vectors. cf_shash_reduce(ns_hash, exchange_namespace_hash_destroy_reduce, NULL); cf_shash_destroy(ns_hash); } /** * Prepare the exchanged data payloads for current exchange round. */ static void exchange_data_payload_prepare() { EXCHANGE_LOCK(); // Block / abort migrations and freeze the partition version infos. as_partition_balance_disallow_migrations(); as_partition_balance_synchronize_migrations(); // Ensure ns->smd_roster is synchronized exchanged partition versions. pthread_mutex_lock(&g_exchanged_info_lock); for (uint32_t ns_ix = 0; ns_ix < g_config.n_namespaces; ns_ix++) { as_namespace* ns = g_config.namespaces[ns_ix]; // May change flags on partition versions we're about to exchange. as_partition_balance_protect_roster_set(ns); // Append payload for each namespace. // TODO - add API to reset dynbuf? g_exchange.self_data_dyn_buf[ns_ix].used_sz = 0; exchange_data_namespace_payload_add(ns, &g_exchange.self_data_dyn_buf[ns_ix]); } g_exchange.data_msg = exchange_msg_get(AS_EXCHANGE_MSG_TYPE_DATA); exchange_msg_data_payload_set(g_exchange.data_msg); pthread_mutex_unlock(&g_exchanged_info_lock); EXCHANGE_UNLOCK(); } /** * Indicates if the per-namespace fields in an incoming data message are valid. * * @return number of namespaces. */ static uint32_t exchange_data_msg_get_num_namespaces(as_exchange_event* msg_event) { uint32_t num_namespaces_sent = 0; uint32_t num_namespace_elements_sent = 0; if (!msg_msgpack_list_get_count(msg_event->msg, AS_EXCHANGE_MSG_NAMESPACES, &num_namespaces_sent) || num_namespaces_sent > AS_NAMESPACE_SZ) { WARNING("received invalid namespaces from node %"PRIx64, msg_event->msg_source); return 0; } if (!msg_msgpack_list_get_count(msg_event->msg, AS_EXCHANGE_MSG_NS_PARTITION_VERSIONS, &num_namespace_elements_sent) || num_namespaces_sent != num_namespace_elements_sent) { WARNING("received invalid partition versions from node %"PRIx64, msg_event->msg_source); return 0; } if (!msg_msgpack_list_get_count(msg_event->msg, AS_EXCHANGE_MSG_NS_RACK_IDS, &num_namespace_elements_sent) || num_namespaces_sent != num_namespace_elements_sent) { WARNING("received invalid cluster groups from node %"PRIx64, msg_event->msg_source); return 0; } if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTER_GENERATIONS) && (!msg_msgpack_list_get_count(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTER_GENERATIONS, &num_namespace_elements_sent) || num_namespaces_sent != num_namespace_elements_sent)) { WARNING("received invalid roster generations from node %"PRIx64, msg_event->msg_source); return 0; } if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTERS) && (!msg_msgpack_list_get_count(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTERS, &num_namespace_elements_sent) || num_namespaces_sent != num_namespace_elements_sent)) { WARNING("received invalid rosters from node %"PRIx64, msg_event->msg_source); return 0; } if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTERS_RACK_IDS) && (!msg_msgpack_list_get_count(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTERS_RACK_IDS, &num_namespace_elements_sent) || num_namespaces_sent != num_namespace_elements_sent)) { WARNING("received invalid rosters-rack-ids from node %"PRIx64, msg_event->msg_source); return 0; } if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_EVENTUAL_REGIMES) && (!msg_msgpack_list_get_count(msg_event->msg, AS_EXCHANGE_MSG_NS_EVENTUAL_REGIMES, &num_namespace_elements_sent) || num_namespaces_sent != num_namespace_elements_sent)) { WARNING("received invalid eventual regimes from node %"PRIx64, msg_event->msg_source); return 0; } if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_REBALANCE_REGIMES) && (!msg_msgpack_list_get_count(msg_event->msg, AS_EXCHANGE_MSG_NS_REBALANCE_REGIMES, &num_namespace_elements_sent) || num_namespaces_sent != num_namespace_elements_sent)) { WARNING("received invalid rebalance regimes from node %"PRIx64, msg_event->msg_source); return 0; } if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_REBALANCE_FLAGS) && (!msg_msgpack_list_get_count(msg_event->msg, AS_EXCHANGE_MSG_NS_REBALANCE_FLAGS, &num_namespace_elements_sent) || num_namespaces_sent != num_namespace_elements_sent)) { WARNING("received invalid rebalance flags from node %"PRIx64, msg_event->msg_source); return 0; } return num_namespaces_sent; } /** * Basic validation for incoming namespace payload. * Validates that * 1. Number of vinfos < AS_PARTITIONS. * 2. Each partition is between 0 and AS_PARTITIONS. * 3. Namespaces payload does not exceed payload_end_ptr. * * @param ns_payload pointer to start of the namespace payload. * @param ns_payload_size the size of the input namespace payload. * @return true if this is a valid payload. */ static bool exchange_namespace_payload_is_valid(as_exchange_ns_vinfos_payload* ns_payload, uint32_t ns_payload_size) { // Pointer past the last byte in the payload. uint8_t* payload_end_ptr = (uint8_t*)ns_payload + ns_payload_size; if ((uint8_t*)ns_payload->vinfos > payload_end_ptr) { return false; } if (ns_payload->num_vinfos > AS_PARTITIONS) { return false; } uint8_t* read_ptr = (uint8_t*)ns_payload->vinfos; for (uint32_t i = 0; i < ns_payload->num_vinfos; i++) { if (read_ptr >= payload_end_ptr) { return false; } as_exchange_vinfo_payload* vinfo_payload = (as_exchange_vinfo_payload*)read_ptr; if ((uint8_t*)vinfo_payload->pids > payload_end_ptr) { return false; } if (vinfo_payload->num_pids > AS_PARTITIONS) { return false; } size_t pids_size = vinfo_payload->num_pids * sizeof(uint16_t); if ((uint8_t*)vinfo_payload->pids + pids_size > payload_end_ptr) { return false; } for (uint32_t j = 0; j < vinfo_payload->num_pids; j++) { if (vinfo_payload->pids[j] >= AS_PARTITIONS) { return false; } } read_ptr += sizeof(as_exchange_vinfo_payload) + pids_size; } if (read_ptr != payload_end_ptr) { // There are unaccounted for extra bytes in the payload. return false; } return true; } /* * ---------------------------------------------------------------------------- * Common across all states * ---------------------------------------------------------------------------- */ /** * Update committed exchange cluster data. * @param cluster_key the new cluster key. * @param succession the new succession. Can be NULL, for orphan state. */ static void exchange_commited_cluster_update(as_cluster_key cluster_key, cf_vector* succession) { EXCHANGE_COMMITTED_CLUSTER_WLOCK(); g_exchange.committed_cluster_key = cluster_key; vector_clear(&g_exchange.committed_succession_list); if (succession && cf_vector_size(succession) > 0) { vector_copy(&g_exchange.committed_succession_list, &g_exchange.succession_list); g_exchange.committed_cluster_size = cf_vector_size(succession); cf_vector_get(succession, 0, &g_exchange.committed_principal); } else { g_exchange.committed_cluster_size = 0; g_exchange.committed_principal = 0; } g_exchange.committed_cluster_generation++; EXCHANGE_COMMITTED_CLUSTER_UNLOCK(); } /** * Indicates if self node is the cluster principal. */ static bool exchange_self_is_principal() { EXCHANGE_LOCK(); bool is_principal = (g_config.self_node == g_exchange.principal); EXCHANGE_UNLOCK(); return is_principal; } /** * Dump exchange state. */ static void exchange_dump(cf_log_level severity, bool verbose) { EXCHANGE_LOCK(); cf_vector* node_vector = cf_vector_stack_create(cf_node); char* state_str = ""; switch (g_exchange.state) { case AS_EXCHANGE_STATE_REST: state_str = "rest"; break; case AS_EXCHANGE_STATE_EXCHANGING: state_str = "exchanging"; break; case AS_EXCHANGE_STATE_READY_TO_COMMIT: state_str = "ready to commit"; break; case AS_EXCHANGE_STATE_ORPHANED: state_str = "orphaned"; break; } LOG(severity, "EXG: state: %s", state_str); if (g_exchange.state == AS_EXCHANGE_STATE_ORPHANED) { LOG(severity, "EXG: client transactions blocked: %s", g_exchange.orphan_state_are_transactions_blocked ? "true" : "false"); LOG(severity, "EXG: orphan since: %"PRIu64"(millis)", cf_getms() - g_exchange.orphan_state_start_time); } else { LOG(severity, "EXG: cluster key: %"PRIx64, g_exchange.cluster_key); as_clustering_log_cf_node_vector(severity, AS_EXCHANGE, "EXG: succession:", &g_exchange.succession_list); if (verbose) { vector_clear(node_vector); exchange_nodes_find_send_unacked(node_vector); as_clustering_log_cf_node_vector(severity, AS_EXCHANGE, "EXG: send pending:", node_vector); vector_clear(node_vector); exchange_nodes_find_not_received(node_vector); as_clustering_log_cf_node_vector(severity, AS_EXCHANGE, "EXG: receive pending:", node_vector); if (exchange_self_is_principal()) { vector_clear(node_vector); exchange_nodes_find_not_ready_to_commit(node_vector); as_clustering_log_cf_node_vector(severity, AS_EXCHANGE, "EXG: ready to commit pending:", node_vector); } } } cf_vector_destroy(node_vector); EXCHANGE_UNLOCK(); } /** * Reset state for new round of exchange, while reusing as mush heap allocated * space for exchanged data. * @param new_succession_list new succession list. Can be NULL for orphaned * state. * @param new_cluster_key 0 for orphaned state. */ static void exchange_reset_for_new_round(cf_vector* new_succession_list, as_cluster_key new_cluster_key) { EXCHANGE_LOCK(); vector_clear(&g_exchange.succession_list); g_exchange.principal = 0; if (new_succession_list && cf_vector_size(new_succession_list) > 0) { vector_copy(&g_exchange.succession_list, new_succession_list); // Set the principal node. cf_vector_get(&g_exchange.succession_list, 0, &g_exchange.principal); } // Reset accumulated node states. exchange_node_states_reset(); g_exchange.cluster_key = new_cluster_key; if (g_exchange.data_msg) { as_fabric_msg_put(g_exchange.data_msg); g_exchange.data_msg = NULL; } EXCHANGE_UNLOCK(); } /** * Commit exchange state to reflect self node being an orphan. */ static void exchange_orphan_commit() { EXCHANGE_LOCK(); exchange_commited_cluster_update(0, NULL); WARNING("blocking client transactions in orphan state!"); as_partition_balance_revert_to_orphan(); g_exchange.orphan_state_are_transactions_blocked = true; EXCHANGE_UNLOCK(); } /** * Receive an orphaned event and abort current round. */ static void exchange_orphaned_handle(as_clustering_event* orphaned_event) { DEBUG("got orphaned event"); EXCHANGE_LOCK(); if (g_exchange.state != AS_EXCHANGE_STATE_REST && g_exchange.state != AS_EXCHANGE_STATE_ORPHANED) { INFO("aborting partition exchange with cluster key %"PRIx64, g_exchange.cluster_key); } g_exchange.state = AS_EXCHANGE_STATE_ORPHANED; exchange_reset_for_new_round(NULL, 0); // Stop ongoing migrations if any. as_partition_balance_disallow_migrations(); as_partition_balance_synchronize_migrations(); // Update the time this node got into orphan state. g_exchange.orphan_state_start_time = cf_getms(); // Potentially temporary orphan state. We will timeout and commit orphan // state if this persists for long. g_exchange.orphan_state_are_transactions_blocked = false; EXCHANGE_UNLOCK(); } /** * Receive a cluster change event and start a new data exchange round. */ static void exchange_cluster_change_handle(as_clustering_event* clustering_event) { EXCHANGE_LOCK(); DEBUG("got cluster change event"); if (g_exchange.state != AS_EXCHANGE_STATE_REST && g_exchange.state != AS_EXCHANGE_STATE_ORPHANED) { INFO("aborting partition exchange with cluster key %"PRIx64, g_exchange.cluster_key); } exchange_reset_for_new_round(clustering_event->succession_list, clustering_event->cluster_key); g_exchange.state = AS_EXCHANGE_STATE_EXCHANGING; INFO("data exchange started with cluster key %"PRIx64, g_exchange.cluster_key); // Prepare the data payload. exchange_data_payload_prepare(); EXCHANGE_UNLOCK(); exchange_data_msg_send_pending_ack(); } /** * Handle a cluster change event. * @param cluster_change_event the cluster change event. */ static void exchange_clustering_event_handle(as_exchange_event* exchange_clustering_event) { as_clustering_event* clustering_event = exchange_clustering_event->clustering_event; switch (clustering_event->type) { case AS_CLUSTERING_ORPHANED: exchange_orphaned_handle(clustering_event); break; case AS_CLUSTERING_CLUSTER_CHANGED: exchange_cluster_change_handle(clustering_event); break; } } /* * ---------------------------------------------------------------------------- * Orphan state event handling * ---------------------------------------------------------------------------- */ /** * The wait time in orphan state after which client transactions and transaction * related interactions (e.g. valid partition map publishing) should be blocked. */ static uint32_t exchange_orphan_transaction_block_timeout() { return (uint32_t)as_clustering_quantum_interval() * AS_EXCHANGE_REVERT_ORPHAN_INTERVALS; } /** * Handle the timer event and if we have been an orphan for too long, block * client transactions. */ static void exchange_orphan_timer_event_handle() { uint32_t timeout = exchange_orphan_transaction_block_timeout(); EXCHANGE_LOCK(); if (!g_exchange.orphan_state_are_transactions_blocked && g_exchange.orphan_state_start_time + timeout < cf_getms()) { exchange_orphan_commit(); } EXCHANGE_UNLOCK(); } /** * Event processing in the orphan state. */ static void exchange_orphan_event_handle(as_exchange_event* event) { switch (event->type) { case AS_EXCHANGE_EVENT_CLUSTER_CHANGE: exchange_clustering_event_handle(event); break; case AS_EXCHANGE_EVENT_TIMER: exchange_orphan_timer_event_handle(); break; default: break; } } /* * ---------------------------------------------------------------------------- * Rest state event handling * ---------------------------------------------------------------------------- */ /** * Process a message event when in rest state. */ static void exchange_rest_msg_event_handle(as_exchange_event* msg_event) { EXCHANGE_LOCK(); if (!exchange_msg_is_sane(msg_event->msg_source, msg_event->msg)) { goto Exit; } as_exchange_msg_type msg_type; exchange_msg_type_get(msg_event->msg, &msg_type); if (exchange_self_is_principal() && msg_type == AS_EXCHANGE_MSG_TYPE_READY_TO_COMMIT) { // The commit message did not make it to the source node, hence it send // us the ready to commit message. Resend the commit message. DEBUG("received a ready to commit message from %"PRIx64, msg_event->msg_source); exchange_commit_msg_send(msg_event->msg_source); } else { DEBUG( "rest state received unexpected mesage of type %d from node %"PRIx64, msg_type, msg_event->msg_source); } Exit: EXCHANGE_UNLOCK(); } /** * Event processing in the rest state. */ static void exchange_rest_event_handle(as_exchange_event* event) { switch (event->type) { case AS_EXCHANGE_EVENT_CLUSTER_CHANGE: exchange_clustering_event_handle(event); break; case AS_EXCHANGE_EVENT_MSG: exchange_rest_msg_event_handle(event); break; default: break; } } /* * ---------------------------------------------------------------------------- * Exchanging state event handling * ---------------------------------------------------------------------------- */ /** * Commit namespace payload for a node. * Assumes the namespace vinfo and succession list have been zero set before. */ static void exchange_namespace_payload_pre_commit_for_node(cf_node node, as_exchange_node_namespace_data* namespace_data) { as_namespace* ns = namespace_data->local_namespace; uint32_t sl_ix = ns->cluster_size++; ns->succession[sl_ix] = node; as_exchange_ns_vinfos_payload* ns_payload = namespace_data->partition_versions; uint8_t* read_ptr = (uint8_t*)ns_payload->vinfos; for (int i = 0; i < ns_payload->num_vinfos; i++) { as_exchange_vinfo_payload* vinfo_payload = (as_exchange_vinfo_payload*)read_ptr; for (int j = 0; j < vinfo_payload->num_pids; j++) { memcpy(&ns->cluster_versions[sl_ix][vinfo_payload->pids[j]], &vinfo_payload->vinfo, sizeof(vinfo_payload->vinfo)); } read_ptr += sizeof(as_exchange_vinfo_payload) + vinfo_payload->num_pids * sizeof(uint16_t); } ns->rack_ids[sl_ix] = namespace_data->rack_id; if (namespace_data->roster_generation > ns->roster_generation) { ns->roster_generation = namespace_data->roster_generation; ns->roster_count = namespace_data->roster_count; memcpy(ns->roster, namespace_data->roster, ns->roster_count * sizeof(cf_node)); if (namespace_data->roster_rack_ids) { memcpy(ns->roster_rack_ids, namespace_data->roster_rack_ids, ns->roster_count * sizeof(uint32_t)); } else { memset(ns->roster_rack_ids, 0, ns->roster_count * sizeof(uint32_t)); } } if (ns->eventual_regime != 0 && namespace_data->eventual_regime > ns->eventual_regime) { ns->eventual_regime = namespace_data->eventual_regime; } ns->rebalance_regimes[sl_ix] = namespace_data->rebalance_regime; // Prefer uniform balance only if all nodes prefer it. if ((namespace_data->rebalance_flags & AS_EXCHANGE_REBALANCE_FLAG_UNIFORM) == 0) { ns->prefer_uniform_balance = false; } bool is_node_quiesced = (namespace_data->rebalance_flags & AS_EXCHANGE_REBALANCE_FLAG_QUIESCE) != 0; if (node == g_config.self_node) { ns->is_quiesced = is_node_quiesced; } ns->quiesced[sl_ix] = is_node_quiesced; } /** * Commit exchange data for a given node. */ static void exchange_data_pre_commit_for_node(cf_node node, uint32_t ix, uint32_t* min_compatibility_id, uint32_t* max_compatibility_id) { EXCHANGE_LOCK(); as_exchange_node_state node_state; exchange_node_state_get_safe(node, &node_state); g_exchange.compatibility_ids[ix] = node_state.data->compatibility_id; if (node_state.data->compatibility_id < *min_compatibility_id) { *min_compatibility_id = node_state.data->compatibility_id; } if (node_state.data->compatibility_id > *max_compatibility_id) { *max_compatibility_id = node_state.data->compatibility_id; } for (uint32_t i = 0; i < node_state.data->num_namespaces; i++) { exchange_namespace_payload_pre_commit_for_node(node, &node_state.data->namespace_data[i]); } EXCHANGE_UNLOCK(); } /** * Check that there's not a mixture of AP and CP nodes in any namespace. */ static bool exchange_data_pre_commit_ap_cp_check() { for (uint32_t i = 0; i < g_config.n_namespaces; i++) { as_namespace* ns = g_config.namespaces[i]; cf_node ap_node = (cf_node)0; cf_node cp_node = (cf_node)0; for (uint32_t n = 0; n < ns->cluster_size; n++) { if (ns->rebalance_regimes[n] == 0) { ap_node = ns->succession[n]; } else { cp_node = ns->succession[n]; } } if (ap_node != (cf_node)0 && cp_node != (cf_node)0) { WARNING("{%s} has mixture of AP and SC nodes - for example %lx is AP and %lx is SC", ns->name, ap_node, cp_node); return false; } } return true; } /** * Pre commit namespace data anticipating a successful commit from the * principal. This pre commit is to ensure regime advances in cp mode to cover * the case where the principal commits exchange data but the commit to a * non-principal is lost. */ static bool exchange_exchanging_pre_commit() { EXCHANGE_LOCK(); pthread_mutex_lock(&g_exchanged_info_lock); memset(g_exchange.compatibility_ids, 0, sizeof(g_exchange.compatibility_ids)); uint32_t min_compatibility_id = UINT32_MAX; uint32_t max_compatibility_id = 0; // Reset exchange data for all namespaces. for (int i = 0; i < g_config.n_namespaces; i++) { as_namespace* ns = g_config.namespaces[i]; memset(ns->succession, 0, sizeof(ns->succession)); // Assuming zero to represent "null" partition. memset(ns->cluster_versions, 0, sizeof(ns->cluster_versions)); memset(ns->rack_ids, 0, sizeof(ns->rack_ids)); ns->is_quiesced = false; memset(ns->quiesced, 0, sizeof(ns->quiesced)); ns->roster_generation = 0; ns->roster_count = 0; memset(ns->roster, 0, sizeof(ns->roster)); memset(ns->roster_rack_ids, 0, sizeof(ns->roster_rack_ids)); // Note - not clearing ns->eventual_regime - prior non-0 value means CP. // Note - not clearing ns->rebalance_regime - it's not set here. memset(ns->rebalance_regimes, 0, sizeof(ns->rebalance_regimes)); ns->cluster_size = 0; // Any node that does not prefer uniform balance will set this false. ns->prefer_uniform_balance = true; } // Fill the namespace partition version info in succession list order. int num_nodes = cf_vector_size(&g_exchange.succession_list); for (int i = 0; i < num_nodes; i++) { cf_node node; cf_vector_get(&g_exchange.succession_list, i, &node); exchange_data_pre_commit_for_node(node, i, &min_compatibility_id, &max_compatibility_id); } // Don't finish clustering if any nodes are pre-4.9. if (min_compatibility_id < 6) { WARNING("abandoned exchange - 5.0+ - can't cluster with pre-4.9 nodes"); pthread_mutex_unlock(&g_exchanged_info_lock); EXCHANGE_UNLOCK(); return false; } // Collected all exchanged data - do final configuration consistency checks. if (!exchange_data_pre_commit_ap_cp_check()) { WARNING("abandoned exchange - fix configuration conflict"); pthread_mutex_unlock(&g_exchanged_info_lock); EXCHANGE_UNLOCK(); return false; } INFO("exchange-compatibility-id: self %u cluster-min %u -> %u cluster-max %u -> %u", AS_EXCHANGE_COMPATIBILITY_ID, g_exchange.min_compatibility_id, min_compatibility_id, g_exchange.max_compatibility_id, max_compatibility_id); g_exchange.min_compatibility_id = min_compatibility_id; g_exchange.max_compatibility_id = max_compatibility_id; for (int i = 0; i < g_config.n_namespaces; i++) { as_namespace* ns = g_config.namespaces[i]; if (ns->eventual_regime != 0) { ns->eventual_regime += 2; as_storage_save_regime(ns); INFO("{%s} eventual-regime %u ready", ns->name, ns->eventual_regime); } } pthread_mutex_unlock(&g_exchanged_info_lock); EXCHANGE_UNLOCK(); return true; } /** * Check to see if all exchange data is sent and received. If so switch to * ready_to_commit state. */ static void exchange_exchanging_check_switch_ready_to_commit() { EXCHANGE_LOCK(); cf_vector* node_vector = cf_vector_stack_create(cf_node); if (g_exchange.state == AS_EXCHANGE_STATE_REST || g_exchange.cluster_key == 0) { goto Exit; } exchange_nodes_find_send_unacked(node_vector); if (cf_vector_size(node_vector) > 0) { // We still have unacked exchange send messages. goto Exit; } vector_clear(node_vector); exchange_nodes_find_not_received(node_vector); if (cf_vector_size(node_vector) > 0) { // We still haven't received exchange messages from all nodes in the // succession list. goto Exit; } if (!exchange_exchanging_pre_commit()) { // Pre-commit failed. We are not ready to commit. goto Exit; } g_exchange.state = AS_EXCHANGE_STATE_READY_TO_COMMIT; DEBUG("ready to commit exchange data for cluster key %"PRIx64, g_exchange.cluster_key); Exit: cf_vector_destroy(node_vector); if (g_exchange.state == AS_EXCHANGE_STATE_READY_TO_COMMIT) { exchange_ready_to_commit_msg_send(); } EXCHANGE_UNLOCK(); } /** * Handle incoming data message. * * Assumes the message has been checked for sanity. */ static void exchange_exchanging_data_msg_handle(as_exchange_event* msg_event) { EXCHANGE_LOCK(); DEBUG("received exchange data from node %"PRIx64, msg_event->msg_source); as_exchange_node_state node_state; exchange_node_state_get_safe(msg_event->msg_source, &node_state); if (!node_state.received) { node_state.data->compatibility_id = 0; msg_get_uint32(msg_event->msg, AS_EXCHANGE_MSG_COMPATIBILITY_ID, &node_state.data->compatibility_id); uint32_t num_namespaces_sent = exchange_data_msg_get_num_namespaces( msg_event); if (num_namespaces_sent == 0) { WARNING("ignoring invalid exchange data from node %"PRIx64, msg_event->msg_source); goto Exit; } cf_vector_define(namespace_list, sizeof(msg_buf_ele), num_namespaces_sent, 0); cf_vector_define(partition_versions, sizeof(msg_buf_ele), num_namespaces_sent, 0); uint32_t rack_ids[num_namespaces_sent]; uint32_t roster_generations[num_namespaces_sent]; cf_vector_define(rosters, sizeof(msg_buf_ele), num_namespaces_sent, 0); cf_vector_define(rosters_rack_ids, sizeof(msg_buf_ele), num_namespaces_sent, 0); memset(roster_generations, 0, sizeof(roster_generations)); uint32_t eventual_regimes[num_namespaces_sent]; uint32_t rebalance_regimes[num_namespaces_sent]; uint32_t rebalance_flags[num_namespaces_sent]; memset(eventual_regimes, 0, sizeof(eventual_regimes)); memset(rebalance_regimes, 0, sizeof(rebalance_regimes)); memset(rebalance_flags, 0, sizeof(rebalance_flags)); if (!msg_msgpack_list_get_buf_array_presized(msg_event->msg, AS_EXCHANGE_MSG_NAMESPACES, &namespace_list)) { WARNING("received invalid namespaces from node %"PRIx64, msg_event->msg_source); goto Exit; } if (!msg_msgpack_list_get_buf_array_presized(msg_event->msg, AS_EXCHANGE_MSG_NS_PARTITION_VERSIONS, &partition_versions)) { WARNING("received invalid partition versions from node %"PRIx64, msg_event->msg_source); goto Exit; } uint32_t num_rack_ids = num_namespaces_sent; if (!msg_msgpack_list_get_uint32_array(msg_event->msg, AS_EXCHANGE_MSG_NS_RACK_IDS, rack_ids, &num_rack_ids)) { WARNING("received invalid cluster groups from node %"PRIx64, msg_event->msg_source); goto Exit; } uint32_t num_roster_generations = num_namespaces_sent; if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTER_GENERATIONS) && !msg_msgpack_list_get_uint32_array(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTER_GENERATIONS, roster_generations, &num_roster_generations)) { WARNING("received invalid roster generations from node %"PRIx64, msg_event->msg_source); goto Exit; } if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTERS) && !msg_msgpack_list_get_buf_array_presized(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTERS, &rosters)) { WARNING("received invalid rosters from node %"PRIx64, msg_event->msg_source); goto Exit; } if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTERS_RACK_IDS) && !msg_msgpack_list_get_buf_array_presized(msg_event->msg, AS_EXCHANGE_MSG_NS_ROSTERS_RACK_IDS, &rosters_rack_ids)) { WARNING("received invalid rosters-rack-ids from node %"PRIx64, msg_event->msg_source); goto Exit; } uint32_t num_eventual_regimes = num_namespaces_sent; if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_EVENTUAL_REGIMES) && !msg_msgpack_list_get_uint32_array(msg_event->msg, AS_EXCHANGE_MSG_NS_EVENTUAL_REGIMES, eventual_regimes, &num_eventual_regimes)) { WARNING("received invalid eventual regimes from node %"PRIx64, msg_event->msg_source); goto Exit; } uint32_t num_rebalance_regimes = num_namespaces_sent; if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_REBALANCE_REGIMES) && !msg_msgpack_list_get_uint32_array(msg_event->msg, AS_EXCHANGE_MSG_NS_REBALANCE_REGIMES, rebalance_regimes, &num_rebalance_regimes)) { WARNING("received invalid rebalance regimes from node %"PRIx64, msg_event->msg_source); goto Exit; } uint32_t num_rebalance_flags = num_namespaces_sent; if (msg_is_set(msg_event->msg, AS_EXCHANGE_MSG_NS_REBALANCE_FLAGS) && !msg_msgpack_list_get_uint32_array(msg_event->msg, AS_EXCHANGE_MSG_NS_REBALANCE_FLAGS, rebalance_flags, &num_rebalance_flags)) { WARNING("received invalid rebalance flags from node %"PRIx64, msg_event->msg_source); goto Exit; } node_state.data->num_namespaces = 0; for (uint32_t i = 0; i < num_namespaces_sent; i++) { msg_buf_ele* namespace_name_element = cf_vector_getp( &namespace_list, i); // Find a match for the namespace. as_namespace* matching_namespace = as_namespace_get_bybuf( namespace_name_element->ptr, namespace_name_element->sz); if (!matching_namespace) { continue; } as_exchange_node_namespace_data* namespace_data = &node_state.data->namespace_data[node_state.data->num_namespaces]; node_state.data->num_namespaces++; namespace_data->local_namespace = matching_namespace; namespace_data->rack_id = rack_ids[i]; namespace_data->roster_generation = roster_generations[i]; namespace_data->eventual_regime = eventual_regimes[i]; namespace_data->rebalance_regime = rebalance_regimes[i]; namespace_data->rebalance_flags = rebalance_flags[i]; // Copy partition versions. msg_buf_ele* partition_versions_element = cf_vector_getp( &partition_versions, i); if (!exchange_namespace_payload_is_valid( (as_exchange_ns_vinfos_payload*)partition_versions_element->ptr, partition_versions_element->sz)) { WARNING( "received invalid partition versions for namespace %s from node %"PRIx64, matching_namespace->name, msg_event->msg_source); goto Exit; } namespace_data->partition_versions = cf_realloc( namespace_data->partition_versions, partition_versions_element->sz); memcpy(namespace_data->partition_versions, partition_versions_element->ptr, partition_versions_element->sz); // Copy rosters. // TODO - make this piece a utility function? if (namespace_data->roster_generation == 0) { namespace_data->roster_count = 0; } else { msg_buf_ele* roster_ele = cf_vector_getp(&rosters, i); namespace_data->roster_count = roster_ele->sz / sizeof(cf_node); if (namespace_data->roster_count == 0 || namespace_data->roster_count > AS_CLUSTER_SZ || roster_ele->sz % sizeof(cf_node) != 0) { WARNING( "received invalid roster for namespace %s from node %"PRIx64, matching_namespace->name, msg_event->msg_source); goto Exit; } namespace_data->roster = cf_realloc(namespace_data->roster, roster_ele->sz); memcpy(namespace_data->roster, roster_ele->ptr, roster_ele->sz); uint32_t rri_ele_sz = 0; if (cf_vector_size(&rosters_rack_ids) != 0) { msg_buf_ele* rri_ele = cf_vector_getp(&rosters_rack_ids, i); if (rri_ele->sz != 0) { rri_ele_sz = rri_ele->sz; if (rri_ele_sz != namespace_data->roster_count * sizeof(uint32_t)) { WARNING( "received invalid roster-rack-ids for namespace %s from node %"PRIx64, matching_namespace->name, msg_event->msg_source); goto Exit; } namespace_data->roster_rack_ids = cf_realloc( namespace_data->roster_rack_ids, rri_ele_sz); memcpy(namespace_data->roster_rack_ids, rri_ele->ptr, rri_ele_sz); } } if (rri_ele_sz == 0 && namespace_data->roster_rack_ids) { cf_free(namespace_data->roster_rack_ids); namespace_data->roster_rack_ids = NULL; } } } // Mark exchange data received from the source. node_state.received = true; exchange_node_state_update(msg_event->msg_source, &node_state); } else { // Duplicate pinfo received. Ignore. INFO("received duplicate exchange data from node %"PRIx64, msg_event->msg_source); } // Send an acknowledgement. exchange_data_ack_msg_send(msg_event->msg_source); // Check if we can switch to ready to commit state. exchange_exchanging_check_switch_ready_to_commit(); Exit: EXCHANGE_UNLOCK(); } /** * Handle incoming data ack message. * * Assumes the message has been checked for sanity. */ static void exchange_exchanging_data_ack_msg_handle(as_exchange_event* msg_event) { EXCHANGE_LOCK(); DEBUG("received exchange data ack from node %"PRIx64, msg_event->msg_source); as_exchange_node_state node_state; exchange_node_state_get_safe(msg_event->msg_source, &node_state); if (!node_state.send_acked) { // Mark send as acked in the node state. node_state.send_acked = true; exchange_node_state_update(msg_event->msg_source, &node_state); } else { // Duplicate ack. Ignore. DEBUG("received duplicate data ack from node %"PRIx64, msg_event->msg_source); } // We might have send and received all partition info. Check for completion. exchange_exchanging_check_switch_ready_to_commit(); EXCHANGE_UNLOCK(); } /** * Process a message event when in exchanging state. */ static void exchange_exchanging_msg_event_handle(as_exchange_event* msg_event) { EXCHANGE_LOCK(); if (!exchange_msg_is_sane(msg_event->msg_source, msg_event->msg)) { goto Exit; } as_exchange_msg_type msg_type; exchange_msg_type_get(msg_event->msg, &msg_type); switch (msg_type) { case AS_EXCHANGE_MSG_TYPE_DATA: exchange_exchanging_data_msg_handle(msg_event); break; case AS_EXCHANGE_MSG_TYPE_DATA_ACK: exchange_exchanging_data_ack_msg_handle(msg_event); break; default: DEBUG( "exchanging state received unexpected mesage of type %d from node %"PRIx64, msg_type, msg_event->msg_source); } Exit: EXCHANGE_UNLOCK(); } /** * Process a message event when in exchanging state. */ static void exchange_exchanging_timer_event_handle(as_exchange_event* msg_event) { EXCHANGE_LOCK(); bool send_data = false; cf_clock now = cf_getms(); // The timeout is a "linear" step function, where the timeout is constant // for the step interval. cf_clock min_timeout = EXCHANGE_SEND_MIN_TIMEOUT(); cf_clock max_timeout = EXCHANGE_SEND_MAX_TIMEOUT(); uint32_t step_interval = EXCHANGE_SEND_STEP_INTERVAL(); cf_clock timeout = MAX(min_timeout, MIN(max_timeout, min_timeout * ((now - g_exchange.send_ts) / step_interval))); if (g_exchange.send_ts + timeout < now) { send_data = true; } EXCHANGE_UNLOCK(); if (send_data) { exchange_data_msg_send_pending_ack(); } } /** * Event processing in the exchanging state. */ static void exchange_exchanging_event_handle(as_exchange_event* event) { switch (event->type) { case AS_EXCHANGE_EVENT_CLUSTER_CHANGE: exchange_clustering_event_handle(event); break; case AS_EXCHANGE_EVENT_MSG: exchange_exchanging_msg_event_handle(event); break; case AS_EXCHANGE_EVENT_TIMER: exchange_exchanging_timer_event_handle(event); break; } } /* * ---------------------------------------------------------------------------- * Ready_To_Commit state event handling * ---------------------------------------------------------------------------- */ /** * Handle incoming ready to commit message. * * Assumes the message has been checked for sanity. */ static void exchange_ready_to_commit_rtc_msg_handle(as_exchange_event* msg_event) { if (!exchange_self_is_principal()) { WARNING( "non-principal self received ready to commit message from %"PRIx64" - ignoring", msg_event->msg_source); return; } EXCHANGE_LOCK(); DEBUG("received ready to commit from node %"PRIx64, msg_event->msg_source); as_exchange_node_state node_state; exchange_node_state_get_safe(msg_event->msg_source, &node_state); if (!node_state.is_ready_to_commit) { // Mark as ready to commit in the node state. node_state.is_ready_to_commit = true; exchange_node_state_update(msg_event->msg_source, &node_state); } else { // Duplicate ready to commit received. Ignore. INFO("received duplicate ready to commit message from node %"PRIx64, msg_event->msg_source); } cf_vector* node_vector = cf_vector_stack_create(cf_node); exchange_nodes_find_not_ready_to_commit(node_vector); if (cf_vector_size(node_vector) <= 0) { // Send a commit message to all nodes in succession list. cf_node* node_list = NULL; int num_node_list = 0; cf_vector_to_stack_array(&g_exchange.succession_list, &node_list, &num_node_list); exchange_commit_msg_send_all(node_list, num_node_list); } cf_vector_destroy(node_vector); EXCHANGE_UNLOCK(); } /** * Commit accumulated exchange data. */ static void exchange_data_commit() { EXCHANGE_LOCK(); INFO("data exchange completed with cluster key %"PRIx64, g_exchange.cluster_key); // Exchange is done, use the current cluster details as the committed // cluster details. exchange_commited_cluster_update(g_exchange.cluster_key, &g_exchange.succession_list); // Force an update of the skew, to ensure new nodes if any have been checked // for skew. as_skew_monitor_update(); // Must cover partition balance since it may manipulate ns->cluster_size. pthread_mutex_lock(&g_exchanged_info_lock); as_partition_balance(); pthread_mutex_unlock(&g_exchanged_info_lock); EXCHANGE_UNLOCK(); } /** * Handle incoming data ack message. * * Assumes the message has been checked for sanity. */ static void exchange_ready_to_commit_commit_msg_handle(as_exchange_event* msg_event) { EXCHANGE_LOCK(); if (msg_event->msg_source != g_exchange.principal) { WARNING( "ignoring commit message from node %"PRIx64" - expected message from %"PRIx64, msg_event->msg_source, g_exchange.principal); goto Exit; } INFO("received commit command from principal node %"PRIx64, msg_event->msg_source); // Commit exchanged data. exchange_data_commit(); // Move to the rest state. g_exchange.state = AS_EXCHANGE_STATE_REST; // Queue up a cluster change event for downstream sub systems. as_exchange_cluster_changed_event cluster_change_event; EXCHANGE_COMMITTED_CLUSTER_RLOCK(); cluster_change_event.cluster_key = g_exchange.committed_cluster_key; cluster_change_event.succession = vector_to_array( &g_exchange.committed_succession_list); cluster_change_event.cluster_size = g_exchange.committed_cluster_size; exchange_external_event_queue(&cluster_change_event); EXCHANGE_COMMITTED_CLUSTER_UNLOCK(); Exit: EXCHANGE_UNLOCK(); } /** * Handle incoming data message in ready to commit stage. * * Assumes the message has been checked for sanity. */ static void exchange_ready_to_commit_data_msg_handle(as_exchange_event* msg_event) { EXCHANGE_LOCK(); DEBUG("received exchange data from node %"PRIx64, msg_event->msg_source); // The source must have missed self node's data ack. Send an // acknowledgement. exchange_data_ack_msg_send(msg_event->msg_source); EXCHANGE_UNLOCK(); } /** * Process a message event when in ready_to_commit state. */ static void exchange_ready_to_commit_msg_event_handle(as_exchange_event* msg_event) { EXCHANGE_LOCK(); if (!exchange_msg_is_sane(msg_event->msg_source, msg_event->msg)) { goto Exit; } as_exchange_msg_type msg_type; exchange_msg_type_get(msg_event->msg, &msg_type); switch (msg_type) { case AS_EXCHANGE_MSG_TYPE_READY_TO_COMMIT: exchange_ready_to_commit_rtc_msg_handle(msg_event); break; case AS_EXCHANGE_MSG_TYPE_COMMIT: exchange_ready_to_commit_commit_msg_handle(msg_event); break; case AS_EXCHANGE_MSG_TYPE_DATA: exchange_ready_to_commit_data_msg_handle(msg_event); break; default: DEBUG( "ready to commit state received unexpected message of type %d from node %"PRIx64, msg_type, msg_event->msg_source); } Exit: EXCHANGE_UNLOCK(); } /** * Process a message event when in ready_to_commit state. */ static void exchange_ready_to_commit_timer_event_handle(as_exchange_event* msg_event) { EXCHANGE_LOCK(); if (g_exchange.ready_to_commit_send_ts + EXCHANGE_READY_TO_COMMIT_TIMEOUT() < cf_getms()) { // Its been a while since ready to commit has been sent to the // principal, retransmit it so that the principal gets it this time and // supplies a commit message. exchange_ready_to_commit_msg_send(); } EXCHANGE_UNLOCK(); } /** * Event processing in the ready_to_commit state. */ static void exchange_ready_to_commit_event_handle(as_exchange_event* event) { switch (event->type) { case AS_EXCHANGE_EVENT_CLUSTER_CHANGE: exchange_clustering_event_handle(event); break; case AS_EXCHANGE_EVENT_MSG: exchange_ready_to_commit_msg_event_handle(event); break; case AS_EXCHANGE_EVENT_TIMER: exchange_ready_to_commit_timer_event_handle(event); break; } } /* * ---------------------------------------------------------------------------- * Exchange core subsystem * ---------------------------------------------------------------------------- */ /** * Dispatch an exchange event inline to the relevant state handler. */ static void exchange_event_handle(as_exchange_event* event) { EXCHANGE_LOCK(); switch (g_exchange.state) { case AS_EXCHANGE_STATE_REST: exchange_rest_event_handle(event); break; case AS_EXCHANGE_STATE_EXCHANGING: exchange_exchanging_event_handle(event); break; case AS_EXCHANGE_STATE_READY_TO_COMMIT: exchange_ready_to_commit_event_handle(event); break; case AS_EXCHANGE_STATE_ORPHANED: exchange_orphan_event_handle(event); break; } EXCHANGE_UNLOCK(); } /** * Exchange timer event generator thread, to help with retries and retransmits * across all states. */ static void* exchange_timer_thr(void* arg) { as_exchange_event timer_event; memset(&timer_event, 0, sizeof(timer_event)); timer_event.type = AS_EXCHANGE_EVENT_TIMER; while (EXCHANGE_IS_RUNNING()) { // Wait for a while and retry. usleep(EXCHANGE_TIMER_TICK_INTERVAL() * 1000); exchange_event_handle(&timer_event); } return NULL; } /** * Handle incoming messages from fabric. */ static int exchange_fabric_msg_listener(cf_node source, msg* msg, void* udata) { if (!EXCHANGE_IS_RUNNING()) { // Ignore this message. DEBUG("exchange stopped - ignoring message from %"PRIx64, source); goto Exit; } as_exchange_event msg_event; memset(&msg_event, 0, sizeof(msg_event)); msg_event.type = AS_EXCHANGE_EVENT_MSG; msg_event.msg = msg; msg_event.msg_source = source; exchange_event_handle(&msg_event); Exit: as_fabric_msg_put(msg); return 0; } /** * Listener for cluster change events from clustering layer. */ void exchange_clustering_event_listener(as_clustering_event* event) { if (!EXCHANGE_IS_RUNNING()) { // Ignore this message. DEBUG("exchange stopped - ignoring cluster change event"); return; } as_exchange_event clustering_event; memset(&clustering_event, 0, sizeof(clustering_event)); clustering_event.type = AS_EXCHANGE_EVENT_CLUSTER_CHANGE; clustering_event.clustering_event = event; // Dispatch the event. exchange_event_handle(&clustering_event); } /** * Initialize the template to be used for exchange messages. */ static void exchange_msg_init() { // Register fabric exchange msg type with no processing function. as_fabric_register_msg_fn(M_TYPE_EXCHANGE, exchange_msg_template, sizeof(exchange_msg_template), AS_EXCHANGE_MSG_SCRATCH_SIZE, exchange_fabric_msg_listener, NULL); } /** * Initialize exchange subsystem. */ static void exchange_init() { if (EXCHANGE_IS_INITIALIZED()) { return; } EXCHANGE_LOCK(); memset(&g_exchange, 0, sizeof(g_exchange)); // Start in the orphaned state. g_exchange.state = AS_EXCHANGE_STATE_ORPHANED; g_exchange.orphan_state_start_time = cf_getms(); g_exchange.orphan_state_are_transactions_blocked = true; // Initialize the adjacencies. g_exchange.nodeid_to_node_state = cf_shash_create(cf_nodeid_shash_fn, sizeof(cf_node), sizeof(as_exchange_node_state), AS_EXCHANGE_CLUSTER_MAX_SIZE_SOFT, 0); cf_vector_init(&g_exchange.succession_list, sizeof(cf_node), AS_EXCHANGE_CLUSTER_MAX_SIZE_SOFT, VECTOR_FLAG_INITZERO); EXCHANGE_COMMITTED_CLUSTER_WLOCK(); cf_vector_init(&g_exchange.committed_succession_list, sizeof(cf_node), AS_EXCHANGE_CLUSTER_MAX_SIZE_SOFT, VECTOR_FLAG_INITZERO); EXCHANGE_COMMITTED_CLUSTER_UNLOCK(); // Initialize exchange fabric messaging. exchange_msg_init(); // Initialize self exchange data dynamic buffers. for (uint32_t ns_ix = 0; ns_ix < g_config.n_namespaces; ns_ix++) { cf_dyn_buf_init_heap(&g_exchange.self_data_dyn_buf[ns_ix], AS_EXCHANGE_SELF_DYN_BUF_SIZE()); } // Initialize external event publishing. exchange_external_event_publisher_init(); // Get partition versions from storage. as_partition_balance_init(); DEBUG("exchange module initialized"); EXCHANGE_UNLOCK(); } /** * Stop exchange subsystem. */ static void exchange_stop() { if (!EXCHANGE_IS_RUNNING()) { WARNING("exchange is already stopped"); return; } // Unguarded state, but this should be ok. g_exchange.sys_state = AS_EXCHANGE_SYS_STATE_SHUTTING_DOWN; cf_thread_join(g_exchange.timer_tid); EXCHANGE_LOCK(); g_exchange.sys_state = AS_EXCHANGE_SYS_STATE_STOPPED; DEBUG("exchange module stopped"); EXCHANGE_UNLOCK(); external_event_publisher_stop(); } /** * Start the exchange subsystem. */ static void exchange_start() { EXCHANGE_LOCK(); if (EXCHANGE_IS_RUNNING()) { // Shutdown the exchange subsystem. exchange_stop(); } g_exchange.sys_state = AS_EXCHANGE_SYS_STATE_RUNNING; g_exchange.timer_tid = cf_thread_create_joinable(exchange_timer_thr, (void*)&g_exchange); DEBUG("exchange module started"); EXCHANGE_UNLOCK(); exchange_external_event_publisher_start(); } /* * ---------------------------------------------------------------------------- * Public API * ---------------------------------------------------------------------------- */ /** * Initialize exchange subsystem. */ void as_exchange_init() { exchange_init(); } /** * Start exchange subsystem. */ void as_exchange_start() { exchange_start(); } /** * Stop exchange subsystem. */ void as_exchange_stop() { } /** * Register to receive cluster-changed events. * TODO - may replace with simple static list someday. */ void as_exchange_register_listener(as_exchange_cluster_changed_cb cb, void* udata) { exchange_external_event_listener_register(cb, udata); } /** * Dump exchange state to log. */ void as_exchange_dump(bool verbose) { exchange_dump(CF_INFO, verbose); } /** * Member-access method. */ uint64_t as_exchange_cluster_key() { return (uint64_t)g_exchange.committed_cluster_key; } /** * Member-access method. */ uint32_t as_exchange_cluster_size() { return g_exchange.committed_cluster_size; } /** * Copy over the committed succession list. * Ensure the input vector has enough capacity. */ void as_exchange_succession(cf_vector* succession) { EXCHANGE_COMMITTED_CLUSTER_RLOCK(); vector_copy(succession, &g_exchange.committed_succession_list); EXCHANGE_COMMITTED_CLUSTER_UNLOCK(); } /** * Return the committed succession list. For internal use within the scope * exchange_data_commit function call. */ cf_node* as_exchange_succession_unsafe() { return vector_to_array(&g_exchange.committed_succession_list); } /** * Return the committed succession list as a string in a dyn-buf. */ void as_exchange_info_get_succession(cf_dyn_buf* db) { EXCHANGE_COMMITTED_CLUSTER_RLOCK(); cf_node* nodes = vector_to_array(&g_exchange.committed_succession_list); for (uint32_t i = 0; i < g_exchange.committed_cluster_size; i++) { cf_dyn_buf_append_uint64_x(db, nodes[i]); cf_dyn_buf_append_char(db, ','); } if (g_exchange.committed_cluster_size != 0) { cf_dyn_buf_chomp(db); } // Always succeeds. cf_dyn_buf_append_string(db, "\nok"); EXCHANGE_COMMITTED_CLUSTER_UNLOCK(); } /** * Member-access method. */ cf_node as_exchange_principal() { return g_exchange.committed_principal; } /** * Used by exchange listeners during upgrades for compatibility purposes. */ uint32_t* as_exchange_compatibility_ids(void) { return (uint32_t*)g_exchange.compatibility_ids; } /** * Used during upgrades for compatibility purposes. * Note - may be used outside exchange thread with care. */ uint32_t as_exchange_min_compatibility_id(void) { return g_exchange.min_compatibility_id; } /** * Used during upgrades for compatibility purposes. * Note - may be used outside exchange thread with care. */ uint32_t as_exchange_max_compatibility_id(void) { return g_exchange.max_compatibility_id; } /** * Exchange cluster state output for info calls. */ void as_exchange_cluster_info(cf_dyn_buf* db) { EXCHANGE_COMMITTED_CLUSTER_RLOCK(); info_append_uint32(db, "cluster_size", g_exchange.committed_cluster_size); info_append_uint64_x(db, "cluster_key", g_exchange.committed_cluster_key); info_append_uint64(db, "cluster_generation", g_exchange.committed_cluster_generation); info_append_uint64_x(db, "cluster_principal", g_exchange.committed_principal); EXCHANGE_COMMITTED_CLUSTER_UNLOCK(); } /** * Lock before setting or getting exchanged info from non-exchange thread. */ void as_exchange_info_lock() { pthread_mutex_lock(&g_exchanged_info_lock); } /** * Unlock after setting or getting exchanged info from non-exchange thread. */ void as_exchange_info_unlock() { pthread_mutex_unlock(&g_exchanged_info_lock); }
{ "language": "C" }
/***************************************************************************/ /* */ /* raster.c */ /* */ /* FreeType monochrome rasterer module component (body only). */ /* */ /* Copyright 1996-2018 by */ /* David Turner, Robert Wilhelm, and Werner Lemberg. */ /* */ /* This file is part of the FreeType project, and may only be used, */ /* modified, and distributed under the terms of the FreeType project */ /* license, LICENSE.TXT. By continuing to use, modify, or distribute */ /* this file you indicate that you have read the license and */ /* understand and accept it fully. */ /* */ /***************************************************************************/ #define FT_MAKE_OPTION_SINGLE_OBJECT #include <ft2build.h> #include "ftraster.c" #include "ftrend1.c" #include "rastpic.c" /* END */
{ "language": "C" }
/* * Copyright 1990, 1991 by Thomas Roell, Dinkelscherben, Germany * Copyright 1992 by David Dawes <dawes@XFree86.org> * Copyright 1992 by Jim Tsillas <jtsilla@damon.ccs.northeastern.edu> * Copyright 1992 by Rich Murphey <Rich@Rice.edu> * Copyright 1992 by Robert Baron <Robert.Baron@ernst.mach.cs.cmu.edu> * Copyright 1992 by Orest Zborowski <obz@eskimo.com> * Copyright 1993 by Vrije Universiteit, The Netherlands * Copyright 1993 by David Wexelblat <dwex@XFree86.org> * Copyright 1994, 1996 by Holger Veit <Holger.Veit@gmd.de> * Copyright 1997 by Takis Psarogiannakopoulos <takis@dpmms.cam.ac.uk> * Copyright 1994-2003 by The XFree86 Project, Inc * * Permission to use, copy, modify, distribute, and sell this software and its * documentation for any purpose is hereby granted without fee, 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 names of the above listed copyright holders * not be used in advertising or publicity pertaining to distribution of * the software without specific, written prior permission. The above listed * copyright holders make no representations about the suitability of this * software for any purpose. It is provided "as is" without express or * implied warranty. * * THE ABOVE LISTED COPYRIGHT HOLDERS DISCLAIM ALL WARRANTIES WITH REGARD * TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY * AND FITNESS, IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDERS 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. * */ /* * The ARM32 code here carries the following copyright: * * Copyright 1997 * Digital Equipment Corporation. All rights reserved. * This software is furnished under license and may be used and copied only in * accordance with the following terms and conditions. Subject to these * conditions, you may download, copy, install, use, modify and distribute * this software in source and/or binary form. No title or ownership is * transferred hereby. * * 1) Any source code used, modified or distributed must reproduce and retain * this copyright notice and list of conditions as they appear in the * source file. * * 2) No right is granted to use any trade name, trademark, or logo of Digital * Equipment Corporation. Neither the "Digital Equipment Corporation" * name nor any trademark or logo of Digital Equipment Corporation may be * used to endorse or promote products derived from this software without * the prior written permission of Digital Equipment Corporation. * * 3) This software is provided "AS-IS" and any express or implied warranties, * including but not limited to, any implied warranties of merchantability, * fitness for a particular purpose, or non-infringement are disclaimed. * In no event shall DIGITAL be liable for any damages whatsoever, and in * particular, DIGITAL shall not be liable for special, indirect, * consequential, or incidental damages or damages for lost profits, loss * of revenue or loss of use, whether such damages arise in contract, * negligence, tort, under statute, in equity, at law or otherwise, even * if advised of the possibility of such damage. * */ /* * This is private, and should not be included by any drivers. Drivers * may include xf86_OSproc.h to get prototypes for public interfaces. */ #ifndef _XF86_OSLIB_H #define _XF86_OSLIB_H #include <X11/Xos.h> #include <X11/Xfuncproto.h> #include <stdio.h> #include <ctype.h> #include <stddef.h> /**************************************************************************/ /* SYSV386 (SVR3, SVR4), including Solaris */ /**************************************************************************/ #if (defined(SYSV) || defined(SVR4)) && \ (defined(sun) || defined(__i386__)) # include <sys/ioctl.h> # include <signal.h> # include <termio.h> # include <sys/stat.h> # include <sys/types.h> # include <errno.h> # if defined(_NEED_SYSI86) # if !(defined (sun) && defined (SVR4)) # include <sys/immu.h> # include <sys/region.h> # endif # include <sys/proc.h> # include <sys/tss.h> # include <sys/sysi86.h> # if defined(SVR4) && !defined(sun) # include <sys/seg.h> # endif /* SVR4 && !sun */ /* V86SC_IOPL was moved to <sys/sysi86.h> on Solaris 7 and later */ # if !defined(V86SC_IOPL) /* Solaris 7 or later? */ # include <sys/v86.h> /* Nope */ # endif # if defined(sun) && (defined (__i386__) || defined(__i386) || defined(__x86)) && defined (SVR4) # include <sys/psw.h> # endif # endif /* _NEED_SYSI86 */ # if defined(HAS_SVR3_MMAPDRV) # include <sys/sysmacros.h> # if !defined(_NEED_SYSI86) # include <sys/immu.h> # include <sys/region.h> # endif # include <sys/mmap.h> /* MMAP driver header */ # endif # if !defined(sun) || defined(HAVE_SYS_VT_H) # define HAS_USL_VTS # endif # if !defined(sun) # include <sys/emap.h> # endif # if defined(HAS_USL_VTS) # if !defined(sun) # include <sys/at_ansi.h> # endif # include <sys/kd.h> # include <sys/vt.h> # endif # if defined(sun) # include <sys/fbio.h> # include <sys/kbd.h> # include <sys/kbio.h> /* undefine symbols from <sys/kbd.h> we don't need that conflict with enum definitions in parser/xf86tokens.h */ # undef STRING # undef LEFTALT # undef RIGHTALT # define LED_CAP LED_CAPS_LOCK # define LED_NUM LED_NUM_LOCK # define LED_SCR LED_SCROLL_LOCK # define LED_COMP LED_COMPOSE # endif /* sun */ # if !defined(VT_ACKACQ) # define VT_ACKACQ 2 # endif /* !VT_ACKACQ */ # if defined(SVR4) # include <sys/mman.h> # if !(defined(sun) && defined (SVR4)) # define DEV_MEM "/dev/pmem" # endif # define CLEARDTR_SUPPORT # define POSIX_TTY # endif /* SVR4 */ # if defined(sun) && defined(HAS_USL_VTS) # define USE_VT_SYSREQ # endif #endif /* (SYSV || SVR4) */ /**************************************************************************/ /* Linux or Glibc-based system */ /**************************************************************************/ #if defined(__linux__) || defined(__GLIBC__) # include <sys/ioctl.h> # include <signal.h> # include <stdlib.h> # include <sys/types.h> # include <assert.h> # ifdef __linux__ # include <termio.h> # else /* __GLIBC__ */ # include <termios.h> # endif # ifdef __sparc__ # include <sys/param.h> # endif # include <errno.h> # include <sys/stat.h> # include <sys/mman.h> # ifdef __linux__ # define HAS_USL_VTS # include <sys/kd.h> # include <sys/vt.h> # define LDGMAP GIO_SCRNMAP # define LDSMAP PIO_SCRNMAP # define LDNMAP LDSMAP # define CLEARDTR_SUPPORT # define USE_VT_SYSREQ # endif # define POSIX_TTY #endif /* __linux__ || __GLIBC__ */ /**************************************************************************/ /* 386BSD and derivatives, BSD/386 */ /**************************************************************************/ #if defined(__386BSD__) && (defined(__FreeBSD__) || defined(__NetBSD__)) # undef __386BSD__ #endif #ifdef CSRG_BASED # include <sys/ioctl.h> # include <signal.h> # include <termios.h> # define termio termios # define POSIX_TTY # include <errno.h> # include <sys/types.h> # include <sys/mman.h> # include <sys/stat.h> # if defined(__bsdi__) # include <sys/param.h> # if (_BSDI_VERSION < 199510) # include <i386/isa/vgaioctl.h> # endif # endif /* __bsdi__ */ #endif /* CSRG_BASED */ /**************************************************************************/ /* Kernel of *BSD */ /**************************************************************************/ #if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || \ defined(__NetBSD__) || defined(__OpenBSD__) || defined(__bsdi__) || defined(__DragonFly__) # include <sys/param.h> # if defined(__FreeBSD_version) && !defined(__FreeBSD_kernel_version) # define __FreeBSD_kernel_version __FreeBSD_version # endif # if !defined(LINKKIT) /* Don't need this stuff for the Link Kit */ # if defined(__bsdi__) # include <i386/isa/pcconsioctl.h> # define CONSOLE_X_MODE_ON PCCONIOCRAW # define CONSOLE_X_MODE_OFF PCCONIOCCOOK # define CONSOLE_X_BELL PCCONIOCBEEP # else /* __bsdi__ */ # ifdef SYSCONS_SUPPORT # define COMPAT_SYSCONS # if defined(__NetBSD__) || defined(__OpenBSD__) # include <machine/console.h> # else # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) # if defined(__DragonFly__) || (__FreeBSD_kernel_version >= 410000) # include <sys/consio.h> # include <sys/kbio.h> # else # include <machine/console.h> # endif /* FreeBSD 4.1 RELEASE or lator */ # else # include <sys/console.h> # endif # endif # endif /* SYSCONS_SUPPORT */ # if defined(PCVT_SUPPORT) # if !defined(SYSCONS_SUPPORT) /* no syscons, so include pcvt specific header file */ # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) # include <machine/pcvt_ioctl.h> # else # if defined(__NetBSD__) || defined(__OpenBSD__) # if !defined(WSCONS_SUPPORT) # include <machine/pcvt_ioctl.h> # endif /* WSCONS_SUPPORT */ # else # include <sys/pcvt_ioctl.h> # endif /* __NetBSD__ */ # endif /* __FreeBSD_kernel__ || __OpenBSD__ */ # else /* pcvt and syscons: hard-code the ID magic */ # define VGAPCVTID _IOWR('V',113, struct pcvtid) struct pcvtid { char name[16]; int rmajor, rminor; }; # endif /* PCVT_SUPPORT && SYSCONS_SUPPORT */ # endif /* PCVT_SUPPORT */ # ifdef WSCONS_SUPPORT # include <dev/wscons/wsconsio.h> # include <dev/wscons/wsdisplay_usl_io.h> # endif /* WSCONS_SUPPORT */ # if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__DragonFly__) # if defined(__FreeBSD_kernel_version) && (__FreeBSD_kernel_version >= 500013) # include <sys/mouse.h> # else # undef MOUSE_GETINFO # include <machine/mouse.h> # endif # endif /* Include these definitions in case ioctl_pc.h didn't get included */ # ifndef CONSOLE_X_MODE_ON # define CONSOLE_X_MODE_ON _IO('t',121) # endif # ifndef CONSOLE_X_MODE_OFF # define CONSOLE_X_MODE_OFF _IO('t',122) # endif # ifndef CONSOLE_X_BELL # define CONSOLE_X_BELL _IOW('t',123,int[2]) # endif # ifndef CONSOLE_X_TV_ON # define CONSOLE_X_TV_ON _IOW('t',155,int) # define XMODE_RGB 0 # define XMODE_NTSC 1 # define XMODE_PAL 2 # define XMODE_SECAM 3 # endif # ifndef CONSOLE_X_TV_OFF # define CONSOLE_X_TV_OFF _IO('t',156) # endif #ifndef CONSOLE_GET_LINEAR_INFO # define CONSOLE_GET_LINEAR_INFO _IOR('t',157,struct map_info) #endif #ifndef CONSOLE_GET_IO_INFO # define CONSOLE_GET_IO_INFO _IOR('t',158,struct map_info) #endif #ifndef CONSOLE_GET_MEM_INFO # define CONSOLE_GET_MEM_INFO _IOR('t',159,struct map_info) #endif # endif /* __bsdi__ */ # endif /* !LINKKIT */ #if defined(USE_I386_IOPL) || defined(USE_AMD64_IOPL) #include <machine/sysarch.h> #endif # define CLEARDTR_SUPPORT # if defined(SYSCONS_SUPPORT) || defined(PCVT_SUPPORT) || defined(WSCONS_SUPPORT) # define USE_VT_SYSREQ # endif #endif /* __FreeBSD_kernel__ || __NetBSD__ || __OpenBSD__ || __bsdi__ */ /**************************************************************************/ /* IRIX */ /**************************************************************************/ /**************************************************************************/ /* Generic */ /**************************************************************************/ #include <sys/wait.h> /* May need to adjust this for other OSs */ /* For PATH_MAX */ #include "misc.h" /* * Hack originally for ISC 2.2 POSIX headers, but may apply elsewhere, * and it's safe, so just do it. */ #if !defined(O_NDELAY) && defined(O_NONBLOCK) # define O_NDELAY O_NONBLOCK #endif /* !O_NDELAY && O_NONBLOCK */ #if !defined(MAXHOSTNAMELEN) # define MAXHOSTNAMELEN 32 #endif /* !MAXHOSTNAMELEN */ #if defined(_POSIX_SOURCE) # include <limits.h> #else # define _POSIX_SOURCE # include <limits.h> # undef _POSIX_SOURCE #endif /* _POSIX_SOURCE */ #ifndef DEV_MEM #define DEV_MEM "/dev/mem" #endif #ifndef VT_SYSREQ_DEFAULT #define VT_SYSREQ_DEFAULT FALSE #endif #define SYSCALL(call) while(((call) == -1) && (errno == EINTR)) #define XF86_OS_PRIVS #include "xf86_OSproc.h" #ifndef NO_COMPILER_H #include "compiler.h" #endif #endif /* _XF86_OSLIB_H */
{ "language": "C" }
/* SCTP kernel implementation * Copyright (c) 1999-2000 Cisco, Inc. * Copyright (c) 1999-2001 Motorola, Inc. * Copyright (c) 2001-2003 International Business Machines, Corp. * Copyright (c) 2001 Intel Corp. * Copyright (c) 2001 Nokia, Inc. * Copyright (c) 2001 La Monte H.P. Yarroll * * This file is part of the SCTP kernel implementation * * These functions handle all input from the IP layer into SCTP. * * This SCTP implementation 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 SCTP implementation 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 GNU CC; see the file COPYING. If not, write to * the Free Software Foundation, 59 Temple Place - Suite 330, * Boston, MA 02111-1307, USA. * * Please send any bug reports or fixes you make to the * email address(es): * lksctp developers <lksctp-developers@lists.sourceforge.net> * * Or submit a bug report through the following website: * http://www.sf.net/projects/lksctp * * Written or modified by: * La Monte H.P. Yarroll <piggy@acm.org> * Karl Knutson <karl@athena.chicago.il.us> * Xingang Guo <xingang.guo@intel.com> * Jon Grimm <jgrimm@us.ibm.com> * Hui Huang <hui.huang@nokia.com> * Daisy Chang <daisyc@us.ibm.com> * Sridhar Samudrala <sri@us.ibm.com> * Ardelle Fan <ardelle.fan@intel.com> * * Any bugs reported given to us we will try to fix... any fixes shared will * be incorporated into the next SCTP release. */ #include <linux/types.h> #include <linux/list.h> /* For struct list_head */ #include <linux/socket.h> #include <linux/ip.h> #include <linux/time.h> /* For struct timeval */ #include <linux/slab.h> #include <net/ip.h> #include <net/icmp.h> #include <net/snmp.h> #include <net/sock.h> #include <net/xfrm.h> #include <net/sctp/sctp.h> #include <net/sctp/sm.h> #include <net/sctp/checksum.h> #include <net/net_namespace.h> /* Forward declarations for internal helpers. */ static int sctp_rcv_ootb(struct sk_buff *); static struct sctp_association *__sctp_rcv_lookup(struct sk_buff *skb, const union sctp_addr *laddr, const union sctp_addr *paddr, struct sctp_transport **transportp); static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *laddr); static struct sctp_association *__sctp_lookup_association( const union sctp_addr *local, const union sctp_addr *peer, struct sctp_transport **pt); static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb); /* Calculate the SCTP checksum of an SCTP packet. */ static inline int sctp_rcv_checksum(struct sk_buff *skb) { struct sctphdr *sh = sctp_hdr(skb); __le32 cmp = sh->checksum; struct sk_buff *list; __le32 val; __u32 tmp = sctp_start_cksum((__u8 *)sh, skb_headlen(skb)); skb_walk_frags(skb, list) tmp = sctp_update_cksum((__u8 *)list->data, skb_headlen(list), tmp); val = sctp_end_cksum(tmp); if (val != cmp) { /* CRC failure, dump it. */ SCTP_INC_STATS_BH(SCTP_MIB_CHECKSUMERRORS); return -1; } return 0; } struct sctp_input_cb { union { struct inet_skb_parm h4; #if IS_ENABLED(CONFIG_IPV6) struct inet6_skb_parm h6; #endif } header; struct sctp_chunk *chunk; }; #define SCTP_INPUT_CB(__skb) ((struct sctp_input_cb *)&((__skb)->cb[0])) /* * This is the routine which IP calls when receiving an SCTP packet. */ int sctp_rcv(struct sk_buff *skb) { struct sock *sk; struct sctp_association *asoc; struct sctp_endpoint *ep = NULL; struct sctp_ep_common *rcvr; struct sctp_transport *transport = NULL; struct sctp_chunk *chunk; struct sctphdr *sh; union sctp_addr src; union sctp_addr dest; int family; struct sctp_af *af; if (skb->pkt_type!=PACKET_HOST) goto discard_it; SCTP_INC_STATS_BH(SCTP_MIB_INSCTPPACKS); if (skb_linearize(skb)) goto discard_it; sh = sctp_hdr(skb); /* Pull up the IP and SCTP headers. */ __skb_pull(skb, skb_transport_offset(skb)); if (skb->len < sizeof(struct sctphdr)) goto discard_it; if (!sctp_checksum_disable && !skb_csum_unnecessary(skb) && sctp_rcv_checksum(skb) < 0) goto discard_it; skb_pull(skb, sizeof(struct sctphdr)); /* Make sure we at least have chunk headers worth of data left. */ if (skb->len < sizeof(struct sctp_chunkhdr)) goto discard_it; family = ipver2af(ip_hdr(skb)->version); af = sctp_get_af_specific(family); if (unlikely(!af)) goto discard_it; /* Initialize local addresses for lookups. */ af->from_skb(&src, skb, 1); af->from_skb(&dest, skb, 0); /* If the packet is to or from a non-unicast address, * silently discard the packet. * * This is not clearly defined in the RFC except in section * 8.4 - OOTB handling. However, based on the book "Stream Control * Transmission Protocol" 2.1, "It is important to note that the * IP address of an SCTP transport address must be a routable * unicast address. In other words, IP multicast addresses and * IP broadcast addresses cannot be used in an SCTP transport * address." */ if (!af->addr_valid(&src, NULL, skb) || !af->addr_valid(&dest, NULL, skb)) goto discard_it; asoc = __sctp_rcv_lookup(skb, &src, &dest, &transport); if (!asoc) ep = __sctp_rcv_lookup_endpoint(&dest); /* Retrieve the common input handling substructure. */ rcvr = asoc ? &asoc->base : &ep->base; sk = rcvr->sk; /* * If a frame arrives on an interface and the receiving socket is * bound to another interface, via SO_BINDTODEVICE, treat it as OOTB */ if (sk->sk_bound_dev_if && (sk->sk_bound_dev_if != af->skb_iif(skb))) { if (asoc) { sctp_association_put(asoc); asoc = NULL; } else { sctp_endpoint_put(ep); ep = NULL; } sk = sctp_get_ctl_sock(); ep = sctp_sk(sk)->ep; sctp_endpoint_hold(ep); rcvr = &ep->base; } /* * RFC 2960, 8.4 - Handle "Out of the blue" Packets. * An SCTP packet is called an "out of the blue" (OOTB) * packet if it is correctly formed, i.e., passed the * receiver's checksum check, but the receiver is not * able to identify the association to which this * packet belongs. */ if (!asoc) { if (sctp_rcv_ootb(skb)) { SCTP_INC_STATS_BH(SCTP_MIB_OUTOFBLUES); goto discard_release; } } if (!xfrm_policy_check(sk, XFRM_POLICY_IN, skb, family)) goto discard_release; nf_reset(skb); if (sk_filter(sk, skb)) goto discard_release; /* Create an SCTP packet structure. */ chunk = sctp_chunkify(skb, asoc, sk); if (!chunk) goto discard_release; SCTP_INPUT_CB(skb)->chunk = chunk; /* Remember what endpoint is to handle this packet. */ chunk->rcvr = rcvr; /* Remember the SCTP header. */ chunk->sctp_hdr = sh; /* Set the source and destination addresses of the incoming chunk. */ sctp_init_addrs(chunk, &src, &dest); /* Remember where we came from. */ chunk->transport = transport; /* Acquire access to the sock lock. Note: We are safe from other * bottom halves on this lock, but a user may be in the lock too, * so check if it is busy. */ sctp_bh_lock_sock(sk); if (sk != rcvr->sk) { /* Our cached sk is different from the rcvr->sk. This is * because migrate()/accept() may have moved the association * to a new socket and released all the sockets. So now we * are holding a lock on the old socket while the user may * be doing something with the new socket. Switch our veiw * of the current sk. */ sctp_bh_unlock_sock(sk); sk = rcvr->sk; sctp_bh_lock_sock(sk); } if (sock_owned_by_user(sk)) { if (sctp_add_backlog(sk, skb)) { sctp_bh_unlock_sock(sk); sctp_chunk_free(chunk); skb = NULL; /* sctp_chunk_free already freed the skb */ goto discard_release; } SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_BACKLOG); } else { SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_SOFTIRQ); sctp_inq_push(&chunk->rcvr->inqueue, chunk); } sctp_bh_unlock_sock(sk); /* Release the asoc/ep ref we took in the lookup calls. */ if (asoc) sctp_association_put(asoc); else sctp_endpoint_put(ep); return 0; discard_it: SCTP_INC_STATS_BH(SCTP_MIB_IN_PKT_DISCARDS); kfree_skb(skb); return 0; discard_release: /* Release the asoc/ep ref we took in the lookup calls. */ if (asoc) sctp_association_put(asoc); else sctp_endpoint_put(ep); goto discard_it; } /* Process the backlog queue of the socket. Every skb on * the backlog holds a ref on an association or endpoint. * We hold this ref throughout the state machine to make * sure that the structure we need is still around. */ int sctp_backlog_rcv(struct sock *sk, struct sk_buff *skb) { struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk; struct sctp_inq *inqueue = &chunk->rcvr->inqueue; struct sctp_ep_common *rcvr = NULL; int backloged = 0; rcvr = chunk->rcvr; /* If the rcvr is dead then the association or endpoint * has been deleted and we can safely drop the chunk * and refs that we are holding. */ if (rcvr->dead) { sctp_chunk_free(chunk); goto done; } if (unlikely(rcvr->sk != sk)) { /* In this case, the association moved from one socket to * another. We are currently sitting on the backlog of the * old socket, so we need to move. * However, since we are here in the process context we * need to take make sure that the user doesn't own * the new socket when we process the packet. * If the new socket is user-owned, queue the chunk to the * backlog of the new socket without dropping any refs. * Otherwise, we can safely push the chunk on the inqueue. */ sk = rcvr->sk; sctp_bh_lock_sock(sk); if (sock_owned_by_user(sk)) { if (sk_add_backlog(sk, skb)) sctp_chunk_free(chunk); else backloged = 1; } else sctp_inq_push(inqueue, chunk); sctp_bh_unlock_sock(sk); /* If the chunk was backloged again, don't drop refs */ if (backloged) return 0; } else { sctp_inq_push(inqueue, chunk); } done: /* Release the refs we took in sctp_add_backlog */ if (SCTP_EP_TYPE_ASSOCIATION == rcvr->type) sctp_association_put(sctp_assoc(rcvr)); else if (SCTP_EP_TYPE_SOCKET == rcvr->type) sctp_endpoint_put(sctp_ep(rcvr)); else BUG(); return 0; } static int sctp_add_backlog(struct sock *sk, struct sk_buff *skb) { struct sctp_chunk *chunk = SCTP_INPUT_CB(skb)->chunk; struct sctp_ep_common *rcvr = chunk->rcvr; int ret; ret = sk_add_backlog(sk, skb); if (!ret) { /* Hold the assoc/ep while hanging on the backlog queue. * This way, we know structures we need will not disappear * from us */ if (SCTP_EP_TYPE_ASSOCIATION == rcvr->type) sctp_association_hold(sctp_assoc(rcvr)); else if (SCTP_EP_TYPE_SOCKET == rcvr->type) sctp_endpoint_hold(sctp_ep(rcvr)); else BUG(); } return ret; } /* Handle icmp frag needed error. */ void sctp_icmp_frag_needed(struct sock *sk, struct sctp_association *asoc, struct sctp_transport *t, __u32 pmtu) { if (!t || (t->pathmtu <= pmtu)) return; if (sock_owned_by_user(sk)) { asoc->pmtu_pending = 1; t->pmtu_pending = 1; return; } if (t->param_flags & SPP_PMTUD_ENABLE) { /* Update transports view of the MTU */ sctp_transport_update_pmtu(t, pmtu); /* Update association pmtu. */ sctp_assoc_sync_pmtu(asoc); } /* Retransmit with the new pmtu setting. * Normally, if PMTU discovery is disabled, an ICMP Fragmentation * Needed will never be sent, but if a message was sent before * PMTU discovery was disabled that was larger than the PMTU, it * would not be fragmented, so it must be re-transmitted fragmented. */ sctp_retransmit(&asoc->outqueue, t, SCTP_RTXR_PMTUD); } /* * SCTP Implementer's Guide, 2.37 ICMP handling procedures * * ICMP8) If the ICMP code is a "Unrecognized next header type encountered" * or a "Protocol Unreachable" treat this message as an abort * with the T bit set. * * This function sends an event to the state machine, which will abort the * association. * */ void sctp_icmp_proto_unreachable(struct sock *sk, struct sctp_association *asoc, struct sctp_transport *t) { SCTP_DEBUG_PRINTK("%s\n", __func__); if (sock_owned_by_user(sk)) { if (timer_pending(&t->proto_unreach_timer)) return; else { if (!mod_timer(&t->proto_unreach_timer, jiffies + (HZ/20))) sctp_association_hold(asoc); } } else { if (timer_pending(&t->proto_unreach_timer) && del_timer(&t->proto_unreach_timer)) sctp_association_put(asoc); sctp_do_sm(SCTP_EVENT_T_OTHER, SCTP_ST_OTHER(SCTP_EVENT_ICMP_PROTO_UNREACH), asoc->state, asoc->ep, asoc, t, GFP_ATOMIC); } } /* Common lookup code for icmp/icmpv6 error handler. */ struct sock *sctp_err_lookup(int family, struct sk_buff *skb, struct sctphdr *sctphdr, struct sctp_association **app, struct sctp_transport **tpp) { union sctp_addr saddr; union sctp_addr daddr; struct sctp_af *af; struct sock *sk = NULL; struct sctp_association *asoc; struct sctp_transport *transport = NULL; struct sctp_init_chunk *chunkhdr; __u32 vtag = ntohl(sctphdr->vtag); int len = skb->len - ((void *)sctphdr - (void *)skb->data); *app = NULL; *tpp = NULL; af = sctp_get_af_specific(family); if (unlikely(!af)) { return NULL; } /* Initialize local addresses for lookups. */ af->from_skb(&saddr, skb, 1); af->from_skb(&daddr, skb, 0); /* Look for an association that matches the incoming ICMP error * packet. */ asoc = __sctp_lookup_association(&saddr, &daddr, &transport); if (!asoc) return NULL; sk = asoc->base.sk; /* RFC 4960, Appendix C. ICMP Handling * * ICMP6) An implementation MUST validate that the Verification Tag * contained in the ICMP message matches the Verification Tag of * the peer. If the Verification Tag is not 0 and does NOT * match, discard the ICMP message. If it is 0 and the ICMP * message contains enough bytes to verify that the chunk type is * an INIT chunk and that the Initiate Tag matches the tag of the * peer, continue with ICMP7. If the ICMP message is too short * or the chunk type or the Initiate Tag does not match, silently * discard the packet. */ if (vtag == 0) { chunkhdr = (void *)sctphdr + sizeof(struct sctphdr); if (len < sizeof(struct sctphdr) + sizeof(sctp_chunkhdr_t) + sizeof(__be32) || chunkhdr->chunk_hdr.type != SCTP_CID_INIT || ntohl(chunkhdr->init_hdr.init_tag) != asoc->c.my_vtag) { goto out; } } else if (vtag != asoc->c.peer_vtag) { goto out; } sctp_bh_lock_sock(sk); /* If too many ICMPs get dropped on busy * servers this needs to be solved differently. */ if (sock_owned_by_user(sk)) NET_INC_STATS_BH(&init_net, LINUX_MIB_LOCKDROPPEDICMPS); *app = asoc; *tpp = transport; return sk; out: if (asoc) sctp_association_put(asoc); return NULL; } /* Common cleanup code for icmp/icmpv6 error handler. */ void sctp_err_finish(struct sock *sk, struct sctp_association *asoc) { sctp_bh_unlock_sock(sk); if (asoc) sctp_association_put(asoc); } /* * This routine is called by the ICMP module when it gets some * sort of error condition. If err < 0 then the socket should * be closed and the error returned to the user. If err > 0 * it's just the icmp type << 8 | icmp code. After adjustment * header points to the first 8 bytes of the sctp header. We need * to find the appropriate port. * * The locking strategy used here is very "optimistic". When * someone else accesses the socket the ICMP is just dropped * and for some paths there is no check at all. * A more general error queue to queue errors for later handling * is probably better. * */ void sctp_v4_err(struct sk_buff *skb, __u32 info) { const struct iphdr *iph = (const struct iphdr *)skb->data; const int ihlen = iph->ihl * 4; const int type = icmp_hdr(skb)->type; const int code = icmp_hdr(skb)->code; struct sock *sk; struct sctp_association *asoc = NULL; struct sctp_transport *transport; struct inet_sock *inet; sk_buff_data_t saveip, savesctp; int err; if (skb->len < ihlen + 8) { ICMP_INC_STATS_BH(&init_net, ICMP_MIB_INERRORS); return; } /* Fix up skb to look at the embedded net header. */ saveip = skb->network_header; savesctp = skb->transport_header; skb_reset_network_header(skb); skb_set_transport_header(skb, ihlen); sk = sctp_err_lookup(AF_INET, skb, sctp_hdr(skb), &asoc, &transport); /* Put back, the original values. */ skb->network_header = saveip; skb->transport_header = savesctp; if (!sk) { ICMP_INC_STATS_BH(&init_net, ICMP_MIB_INERRORS); return; } /* Warning: The sock lock is held. Remember to call * sctp_err_finish! */ switch (type) { case ICMP_PARAMETERPROB: err = EPROTO; break; case ICMP_DEST_UNREACH: if (code > NR_ICMP_UNREACH) goto out_unlock; /* PMTU discovery (RFC1191) */ if (ICMP_FRAG_NEEDED == code) { sctp_icmp_frag_needed(sk, asoc, transport, info); goto out_unlock; } else { if (ICMP_PROT_UNREACH == code) { sctp_icmp_proto_unreachable(sk, asoc, transport); goto out_unlock; } } err = icmp_err_convert[code].errno; break; case ICMP_TIME_EXCEEDED: /* Ignore any time exceeded errors due to fragment reassembly * timeouts. */ if (ICMP_EXC_FRAGTIME == code) goto out_unlock; err = EHOSTUNREACH; break; default: goto out_unlock; } inet = inet_sk(sk); if (!sock_owned_by_user(sk) && inet->recverr) { sk->sk_err = err; sk->sk_error_report(sk); } else { /* Only an error on timeout */ sk->sk_err_soft = err; } out_unlock: sctp_err_finish(sk, asoc); } /* * RFC 2960, 8.4 - Handle "Out of the blue" Packets. * * This function scans all the chunks in the OOTB packet to determine if * the packet should be discarded right away. If a response might be needed * for this packet, or, if further processing is possible, the packet will * be queued to a proper inqueue for the next phase of handling. * * Output: * Return 0 - If further processing is needed. * Return 1 - If the packet can be discarded right away. */ static int sctp_rcv_ootb(struct sk_buff *skb) { sctp_chunkhdr_t *ch; __u8 *ch_end; ch = (sctp_chunkhdr_t *) skb->data; /* Scan through all the chunks in the packet. */ do { /* Break out if chunk length is less then minimal. */ if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t)) break; ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length)); if (ch_end > skb_tail_pointer(skb)) break; /* RFC 8.4, 2) If the OOTB packet contains an ABORT chunk, the * receiver MUST silently discard the OOTB packet and take no * further action. */ if (SCTP_CID_ABORT == ch->type) goto discard; /* RFC 8.4, 6) If the packet contains a SHUTDOWN COMPLETE * chunk, the receiver should silently discard the packet * and take no further action. */ if (SCTP_CID_SHUTDOWN_COMPLETE == ch->type) goto discard; /* RFC 4460, 2.11.2 * This will discard packets with INIT chunk bundled as * subsequent chunks in the packet. When INIT is first, * the normal INIT processing will discard the chunk. */ if (SCTP_CID_INIT == ch->type && (void *)ch != skb->data) goto discard; ch = (sctp_chunkhdr_t *) ch_end; } while (ch_end < skb_tail_pointer(skb)); return 0; discard: return 1; } /* Insert endpoint into the hash table. */ static void __sctp_hash_endpoint(struct sctp_endpoint *ep) { struct sctp_ep_common *epb; struct sctp_hashbucket *head; epb = &ep->base; epb->hashent = sctp_ep_hashfn(epb->bind_addr.port); head = &sctp_ep_hashtable[epb->hashent]; sctp_write_lock(&head->lock); hlist_add_head(&epb->node, &head->chain); sctp_write_unlock(&head->lock); } /* Add an endpoint to the hash. Local BH-safe. */ void sctp_hash_endpoint(struct sctp_endpoint *ep) { sctp_local_bh_disable(); __sctp_hash_endpoint(ep); sctp_local_bh_enable(); } /* Remove endpoint from the hash table. */ static void __sctp_unhash_endpoint(struct sctp_endpoint *ep) { struct sctp_hashbucket *head; struct sctp_ep_common *epb; epb = &ep->base; if (hlist_unhashed(&epb->node)) return; epb->hashent = sctp_ep_hashfn(epb->bind_addr.port); head = &sctp_ep_hashtable[epb->hashent]; sctp_write_lock(&head->lock); __hlist_del(&epb->node); sctp_write_unlock(&head->lock); } /* Remove endpoint from the hash. Local BH-safe. */ void sctp_unhash_endpoint(struct sctp_endpoint *ep) { sctp_local_bh_disable(); __sctp_unhash_endpoint(ep); sctp_local_bh_enable(); } /* Look up an endpoint. */ static struct sctp_endpoint *__sctp_rcv_lookup_endpoint(const union sctp_addr *laddr) { struct sctp_hashbucket *head; struct sctp_ep_common *epb; struct sctp_endpoint *ep; struct hlist_node *node; int hash; hash = sctp_ep_hashfn(ntohs(laddr->v4.sin_port)); head = &sctp_ep_hashtable[hash]; read_lock(&head->lock); sctp_for_each_hentry(epb, node, &head->chain) { ep = sctp_ep(epb); if (sctp_endpoint_is_match(ep, laddr)) goto hit; } ep = sctp_sk((sctp_get_ctl_sock()))->ep; hit: sctp_endpoint_hold(ep); read_unlock(&head->lock); return ep; } /* Insert association into the hash table. */ static void __sctp_hash_established(struct sctp_association *asoc) { struct sctp_ep_common *epb; struct sctp_hashbucket *head; epb = &asoc->base; /* Calculate which chain this entry will belong to. */ epb->hashent = sctp_assoc_hashfn(epb->bind_addr.port, asoc->peer.port); head = &sctp_assoc_hashtable[epb->hashent]; sctp_write_lock(&head->lock); hlist_add_head(&epb->node, &head->chain); sctp_write_unlock(&head->lock); } /* Add an association to the hash. Local BH-safe. */ void sctp_hash_established(struct sctp_association *asoc) { if (asoc->temp) return; sctp_local_bh_disable(); __sctp_hash_established(asoc); sctp_local_bh_enable(); } /* Remove association from the hash table. */ static void __sctp_unhash_established(struct sctp_association *asoc) { struct sctp_hashbucket *head; struct sctp_ep_common *epb; epb = &asoc->base; epb->hashent = sctp_assoc_hashfn(epb->bind_addr.port, asoc->peer.port); head = &sctp_assoc_hashtable[epb->hashent]; sctp_write_lock(&head->lock); __hlist_del(&epb->node); sctp_write_unlock(&head->lock); } /* Remove association from the hash table. Local BH-safe. */ void sctp_unhash_established(struct sctp_association *asoc) { if (asoc->temp) return; sctp_local_bh_disable(); __sctp_unhash_established(asoc); sctp_local_bh_enable(); } /* Look up an association. */ static struct sctp_association *__sctp_lookup_association( const union sctp_addr *local, const union sctp_addr *peer, struct sctp_transport **pt) { struct sctp_hashbucket *head; struct sctp_ep_common *epb; struct sctp_association *asoc; struct sctp_transport *transport; struct hlist_node *node; int hash; /* Optimize here for direct hit, only listening connections can * have wildcards anyways. */ hash = sctp_assoc_hashfn(ntohs(local->v4.sin_port), ntohs(peer->v4.sin_port)); head = &sctp_assoc_hashtable[hash]; read_lock(&head->lock); sctp_for_each_hentry(epb, node, &head->chain) { asoc = sctp_assoc(epb); transport = sctp_assoc_is_match(asoc, local, peer); if (transport) goto hit; } read_unlock(&head->lock); return NULL; hit: *pt = transport; sctp_association_hold(asoc); read_unlock(&head->lock); return asoc; } /* Look up an association. BH-safe. */ SCTP_STATIC struct sctp_association *sctp_lookup_association(const union sctp_addr *laddr, const union sctp_addr *paddr, struct sctp_transport **transportp) { struct sctp_association *asoc; sctp_local_bh_disable(); asoc = __sctp_lookup_association(laddr, paddr, transportp); sctp_local_bh_enable(); return asoc; } /* Is there an association matching the given local and peer addresses? */ int sctp_has_association(const union sctp_addr *laddr, const union sctp_addr *paddr) { struct sctp_association *asoc; struct sctp_transport *transport; if ((asoc = sctp_lookup_association(laddr, paddr, &transport))) { sctp_association_put(asoc); return 1; } return 0; } /* * SCTP Implementors Guide, 2.18 Handling of address * parameters within the INIT or INIT-ACK. * * D) When searching for a matching TCB upon reception of an INIT * or INIT-ACK chunk the receiver SHOULD use not only the * source address of the packet (containing the INIT or * INIT-ACK) but the receiver SHOULD also use all valid * address parameters contained within the chunk. * * 2.18.3 Solution description * * This new text clearly specifies to an implementor the need * to look within the INIT or INIT-ACK. Any implementation that * does not do this, may not be able to establish associations * in certain circumstances. * */ static struct sctp_association *__sctp_rcv_init_lookup(struct sk_buff *skb, const union sctp_addr *laddr, struct sctp_transport **transportp) { struct sctp_association *asoc; union sctp_addr addr; union sctp_addr *paddr = &addr; struct sctphdr *sh = sctp_hdr(skb); union sctp_params params; sctp_init_chunk_t *init; struct sctp_transport *transport; struct sctp_af *af; /* * This code will NOT touch anything inside the chunk--it is * strictly READ-ONLY. * * RFC 2960 3 SCTP packet Format * * Multiple chunks can be bundled into one SCTP packet up to * the MTU size, except for the INIT, INIT ACK, and SHUTDOWN * COMPLETE chunks. These chunks MUST NOT be bundled with any * other chunk in a packet. See Section 6.10 for more details * on chunk bundling. */ /* Find the start of the TLVs and the end of the chunk. This is * the region we search for address parameters. */ init = (sctp_init_chunk_t *)skb->data; /* Walk the parameters looking for embedded addresses. */ sctp_walk_params(params, init, init_hdr.params) { /* Note: Ignoring hostname addresses. */ af = sctp_get_af_specific(param_type2af(params.p->type)); if (!af) continue; af->from_addr_param(paddr, params.addr, sh->source, 0); asoc = __sctp_lookup_association(laddr, paddr, &transport); if (asoc) return asoc; } return NULL; } /* ADD-IP, Section 5.2 * When an endpoint receives an ASCONF Chunk from the remote peer * special procedures may be needed to identify the association the * ASCONF Chunk is associated with. To properly find the association * the following procedures SHOULD be followed: * * D2) If the association is not found, use the address found in the * Address Parameter TLV combined with the port number found in the * SCTP common header. If found proceed to rule D4. * * D2-ext) If more than one ASCONF Chunks are packed together, use the * address found in the ASCONF Address Parameter TLV of each of the * subsequent ASCONF Chunks. If found, proceed to rule D4. */ static struct sctp_association *__sctp_rcv_asconf_lookup( sctp_chunkhdr_t *ch, const union sctp_addr *laddr, __be16 peer_port, struct sctp_transport **transportp) { sctp_addip_chunk_t *asconf = (struct sctp_addip_chunk *)ch; struct sctp_af *af; union sctp_addr_param *param; union sctp_addr paddr; /* Skip over the ADDIP header and find the Address parameter */ param = (union sctp_addr_param *)(asconf + 1); af = sctp_get_af_specific(param_type2af(param->p.type)); if (unlikely(!af)) return NULL; af->from_addr_param(&paddr, param, peer_port, 0); return __sctp_lookup_association(laddr, &paddr, transportp); } /* SCTP-AUTH, Section 6.3: * If the receiver does not find a STCB for a packet containing an AUTH * chunk as the first chunk and not a COOKIE-ECHO chunk as the second * chunk, it MUST use the chunks after the AUTH chunk to look up an existing * association. * * This means that any chunks that can help us identify the association need * to be looked at to find this association. */ static struct sctp_association *__sctp_rcv_walk_lookup(struct sk_buff *skb, const union sctp_addr *laddr, struct sctp_transport **transportp) { struct sctp_association *asoc = NULL; sctp_chunkhdr_t *ch; int have_auth = 0; unsigned int chunk_num = 1; __u8 *ch_end; /* Walk through the chunks looking for AUTH or ASCONF chunks * to help us find the association. */ ch = (sctp_chunkhdr_t *) skb->data; do { /* Break out if chunk length is less then minimal. */ if (ntohs(ch->length) < sizeof(sctp_chunkhdr_t)) break; ch_end = ((__u8 *)ch) + WORD_ROUND(ntohs(ch->length)); if (ch_end > skb_tail_pointer(skb)) break; switch(ch->type) { case SCTP_CID_AUTH: have_auth = chunk_num; break; case SCTP_CID_COOKIE_ECHO: /* If a packet arrives containing an AUTH chunk as * a first chunk, a COOKIE-ECHO chunk as the second * chunk, and possibly more chunks after them, and * the receiver does not have an STCB for that * packet, then authentication is based on * the contents of the COOKIE- ECHO chunk. */ if (have_auth == 1 && chunk_num == 2) return NULL; break; case SCTP_CID_ASCONF: if (have_auth || sctp_addip_noauth) asoc = __sctp_rcv_asconf_lookup(ch, laddr, sctp_hdr(skb)->source, transportp); default: break; } if (asoc) break; ch = (sctp_chunkhdr_t *) ch_end; chunk_num++; } while (ch_end < skb_tail_pointer(skb)); return asoc; } /* * There are circumstances when we need to look inside the SCTP packet * for information to help us find the association. Examples * include looking inside of INIT/INIT-ACK chunks or after the AUTH * chunks. */ static struct sctp_association *__sctp_rcv_lookup_harder(struct sk_buff *skb, const union sctp_addr *laddr, struct sctp_transport **transportp) { sctp_chunkhdr_t *ch; ch = (sctp_chunkhdr_t *) skb->data; /* The code below will attempt to walk the chunk and extract * parameter information. Before we do that, we need to verify * that the chunk length doesn't cause overflow. Otherwise, we'll * walk off the end. */ if (WORD_ROUND(ntohs(ch->length)) > skb->len) return NULL; /* If this is INIT/INIT-ACK look inside the chunk too. */ switch (ch->type) { case SCTP_CID_INIT: case SCTP_CID_INIT_ACK: return __sctp_rcv_init_lookup(skb, laddr, transportp); break; default: return __sctp_rcv_walk_lookup(skb, laddr, transportp); break; } return NULL; } /* Lookup an association for an inbound skb. */ static struct sctp_association *__sctp_rcv_lookup(struct sk_buff *skb, const union sctp_addr *paddr, const union sctp_addr *laddr, struct sctp_transport **transportp) { struct sctp_association *asoc; asoc = __sctp_lookup_association(laddr, paddr, transportp); /* Further lookup for INIT/INIT-ACK packets. * SCTP Implementors Guide, 2.18 Handling of address * parameters within the INIT or INIT-ACK. */ if (!asoc) asoc = __sctp_rcv_lookup_harder(skb, laddr, transportp); return asoc; }
{ "language": "C" }
#ifndef __ASM_AVR32_MSGBUF_H #define __ASM_AVR32_MSGBUF_H /* * The msqid64_ds structure for i386 architecture. * Note extra padding because this structure is passed back and forth * between kernel and user space. * * Pad space is left for: * - 64-bit time_t to solve y2038 problem * - 2 miscellaneous 32-bit values */ struct msqid64_ds { struct ipc64_perm msg_perm; __kernel_time_t msg_stime; /* last msgsnd time */ unsigned long __unused1; __kernel_time_t msg_rtime; /* last msgrcv time */ unsigned long __unused2; __kernel_time_t msg_ctime; /* last change time */ unsigned long __unused3; unsigned long msg_cbytes; /* current number of bytes on queue */ unsigned long msg_qnum; /* number of messages in queue */ unsigned long msg_qbytes; /* max number of bytes on queue */ __kernel_pid_t msg_lspid; /* pid of last msgsnd */ __kernel_pid_t msg_lrpid; /* last receive pid */ unsigned long __unused4; unsigned long __unused5; }; #endif /* __ASM_AVR32_MSGBUF_H */
{ "language": "C" }
/* * Copyright 1998-2003 Sun Microsystems, Inc. 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. Sun designates this * particular file as subject to the "Classpath" exception as provided * by Sun in the LICENSE file that accompanied this code. * * 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 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. */ #include "vis_proto.h" #include "mlib_image.h" #include "mlib_v_ImageLookUpFunc.h" /***************************************************************/ static void mlib_v_ImageLookUpSI_U8_U8_2_SrcOff0_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table); static void mlib_v_ImageLookUpSI_U8_U8_2_SrcOff1_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table); static void mlib_v_ImageLookUpSI_U8_U8_2_SrcOff2_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table); static void mlib_v_ImageLookUpSI_U8_U8_2_SrcOff3_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table); static void mlib_v_ImageLookUpSI_U8_U8_2_DstNonAl_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table); static void mlib_v_ImageLookUpSI_U8_U8_2_DstA8D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table); static void mlib_v_ImageLookUpSI_U8_U8_2_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table); static void mlib_v_ImageLookUpSI_U8_U8_3_SrcOff0_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_d64 *table); static void mlib_v_ImageLookUpSI_U8_U8_3_SrcOff1_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_d64 *table); static void mlib_v_ImageLookUpSI_U8_U8_3_SrcOff2_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_d64 *table); static void mlib_v_ImageLookUpSI_U8_U8_3_SrcOff3_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_d64 *table); static void mlib_v_ImageLookUpSI_U8_U8_3_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table); static void mlib_v_ImageLookUpSI_U8_U8_4_SrcOff0_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_f32 *table); static void mlib_v_ImageLookUpSI_U8_U8_4_DstNonAl_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_f32 *table); static void mlib_v_ImageLookUpSI_U8_U8_4_DstOff0_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table); static void mlib_v_ImageLookUpSI_U8_U8_4_DstOff1_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table); static void mlib_v_ImageLookUpSI_U8_U8_4_DstOff2_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table); static void mlib_v_ImageLookUpSI_U8_U8_4_DstOff3_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table); /***************************************************************/ #define VIS_LD_U8_I(X, Y) vis_ld_u8_i((void *)(X), (Y)) #define VIS_LD_U16_I(X, Y) vis_ld_u16_i((void *)(X), (Y)) /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_2_SrcOff0_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table) { mlib_u32 *sa; /* aligned pointer to source data */ mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0; /* source data */ mlib_u16 *dl; /* pointer to start of destination */ mlib_u16 *dend; /* pointer to end of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, acc; /* destination data */ mlib_s32 emask; /* edge mask */ mlib_s32 i, num; /* loop variable */ sa = (mlib_u32*)src; dl = (mlib_u16*)dst; dp = (mlib_d64 *) dl; dend = dl + xsize - 1; vis_alignaddr((void *) 0, 6); if (xsize >= 4) { s0 = sa[0]; sa ++; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, sa++) { t3 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t2 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 >> 15) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 23) & 0x1FE); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = sa[0]; *dp++ = acc; } t3 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t2 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 >> 15) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 23) & 0x1FE); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); *dp++ = acc; } sp = (mlib_u8*)sa; if ((mlib_addr) dp <= (mlib_addr) dend) { num = (mlib_u16*) dend - (mlib_u16*) dp; sp += num; num ++; #pragma pipeloop(0) for (i = 0; i < num; i ++) { s0 = (mlib_s32) *sp; sp --; t0 = VIS_LD_U16_I(table, 2*s0); acc = vis_faligndata(t0, acc); } emask = vis_edge16(dp, dend); vis_pst_16(acc, dp, emask); } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_2_SrcOff1_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table) { mlib_u32 *sa; /* aligned pointer to source data */ mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1; /* source data */ mlib_u16 *dl; /* pointer to start of destination */ mlib_u16 *dend; /* pointer to end of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, acc; /* destination data */ mlib_s32 emask; /* edge mask */ mlib_s32 i, num; /* loop variable */ sa = (mlib_u32*)(src-1); dl = (mlib_u16*)dst; dp = (mlib_d64 *) dl; dend = dl + xsize - 1; vis_alignaddr((void *) 0, 6); s0 = *sa++; if (xsize >= 4) { s1 = sa[0]; sa ++; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, sa++) { t3 = VIS_LD_U16_I(table, (s1 >> 23) & 0x1FE); t2 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 15) & 0x1FE); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s1; s1 = sa[0]; *dp++ = acc; } t3 = VIS_LD_U16_I(table, (s1 >> 23) & 0x1FE); t2 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 15) & 0x1FE); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); *dp++ = acc; } sp = (mlib_u8*)sa; sp -= 3; if ((mlib_addr) dp <= (mlib_addr) dend) { num = (mlib_u16*) dend - (mlib_u16*) dp; sp += num; num ++; #pragma pipeloop(0) for (i = 0; i < num; i ++) { s0 = (mlib_s32) *sp; sp --; t0 = VIS_LD_U16_I(table, 2*s0); acc = vis_faligndata(t0, acc); } emask = vis_edge16(dp, dend); vis_pst_16(acc, dp, emask); } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_2_SrcOff2_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table) { mlib_u32 *sa; /* pointer to source data */ mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1; /* source data */ mlib_u16 *dl; /* pointer to start of destination */ mlib_u16 *dend; /* pointer to end of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, acc; /* destination data */ mlib_s32 emask; /* edge mask */ mlib_s32 i, num; /* loop variable */ sa = (mlib_u32*)(src-2); dl = (mlib_u16*)dst; dp = (mlib_d64 *) dl; dend = dl + xsize - 1; vis_alignaddr((void *) 0, 6); s0 = *sa++; if (xsize >= 4) { s1 = sa[0]; sa ++; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, sa++) { t3 = VIS_LD_U16_I(table, (s1 >> 15) & 0x1FE); t2 = VIS_LD_U16_I(table, (s1 >> 23) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s1; s1 = sa[0]; *dp++ = acc; } t3 = VIS_LD_U16_I(table, (s1 >> 15) & 0x1FE); t2 = VIS_LD_U16_I(table, (s1 >> 23) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); *dp++ = acc; } sp = (mlib_u8*)sa; sp -= 2; if ((mlib_addr) dp <= (mlib_addr) dend) { num = (mlib_u16*) dend - (mlib_u16*) dp; sp += num; num ++; #pragma pipeloop(0) for (i = 0; i < num; i ++) { s0 = (mlib_s32) *sp; sp --; t0 = VIS_LD_U16_I(table, 2*s0); acc = vis_faligndata(t0, acc); } emask = vis_edge16(dp, dend); vis_pst_16(acc, dp, emask); } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_2_SrcOff3_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table) { mlib_u32 *sa; /* aligned pointer to source data */ mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1; /* source data */ mlib_u16 *dl; /* pointer to start of destination */ mlib_u16 *dend; /* pointer to end of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, acc; /* destination data */ mlib_s32 emask; /* edge mask */ mlib_s32 i, num; /* loop variable */ sa = (mlib_u32*)(src-3); dl = (mlib_u16*)dst; dp = (mlib_d64 *) dl; dend = dl + xsize - 1; vis_alignaddr((void *) 0, 6); s0 = *sa++; if (xsize >= 4) { s1 = sa[0]; sa ++; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, sa++) { t3 = VIS_LD_U16_I(table, (s1 >> 7) & 0x1FE); t2 = VIS_LD_U16_I(table, (s1 >> 15) & 0x1FE); t1 = VIS_LD_U16_I(table, (s1 >> 23) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s1; s1 = sa[0]; *dp++ = acc; } t3 = VIS_LD_U16_I(table, (s1 >> 7) & 0x1FE); t2 = VIS_LD_U16_I(table, (s1 >> 15) & 0x1FE); t1 = VIS_LD_U16_I(table, (s1 >> 23) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); *dp++ = acc; } sp = (mlib_u8*)sa; sp -= 1; if ((mlib_addr) dp <= (mlib_addr) dend) { num = (mlib_u16*) dend - (mlib_u16*) dp; sp += num; num ++; #pragma pipeloop(0) for (i = 0; i < num; i ++) { s0 = (mlib_s32) *sp; sp --; t0 = VIS_LD_U16_I(table, 2*s0); acc = vis_faligndata(t0, acc); } emask = vis_edge16(dp, dend); vis_pst_16(acc, dp, emask); } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_2_DstNonAl_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u16 *table) { mlib_u32 *sa; /* aligned pointer to source data */ mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1, s2, s3; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_u8 *dend; /* pointer to end of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, t4, t5; /* destination data */ mlib_d64 t6, t7, acc0; /* destination data */ mlib_d64 acc1, acc2; /* destination data */ mlib_d64 acc3, acc4; /* destination data */ mlib_s32 emask; /* edge mask */ mlib_s32 i, num; /* loop variable */ mlib_s32 off; /* offset */ sa = (mlib_u32*)src; dl = dst; sp = (void *)src; dend = dl + 2*xsize - 1; dp = (mlib_d64 *) ((mlib_addr) dl & (~7)); off = (mlib_addr) dp - (mlib_addr) dl; emask = vis_edge8(dl, dend); num = (xsize < 4) ? xsize : 4; sp += (num-1); vis_alignaddr(dp, 6); for (i = 0; i < num; i ++) { s0 = (mlib_s32) *sp; sp --; t0 = VIS_LD_U16_I(table, 2*s0); acc0 = vis_faligndata(t0, acc0); } vis_alignaddr(dp, off); vis_pst_8(vis_faligndata(acc0, acc0), dp++, emask); sa++; xsize -= 4; i = 0; if (xsize >= 16) { s0 = sa[0]; s1 = sa[1]; s2 = sa[2]; s3 = sa[3]; sa += 4; #pragma pipeloop(0) for(i = 0; i <= xsize - 32; i+=16, sa+=4) { vis_alignaddr(dp, 6); t3 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t2 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 >> 15) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 23) & 0x1FE); acc1 = vis_faligndata(t3, acc1); acc1 = vis_faligndata(t2, acc1); acc1 = vis_faligndata(t1, acc1); acc1 = vis_faligndata(t0, acc1); t7 = VIS_LD_U16_I(table, (s1 << 1) & 0x1FE); t6 = VIS_LD_U16_I(table, (s1 >> 7) & 0x1FE); t5 = VIS_LD_U16_I(table, (s1 >> 15) & 0x1FE); t4 = VIS_LD_U16_I(table, (s1 >> 23) & 0x1FE); acc2 = vis_faligndata(t7, acc2); acc2 = vis_faligndata(t6, acc2); acc2 = vis_faligndata(t5, acc2); acc2 = vis_faligndata(t4, acc2); t3 = VIS_LD_U16_I(table, (s2 << 1) & 0x1FE); t2 = VIS_LD_U16_I(table, (s2 >> 7) & 0x1FE); t1 = VIS_LD_U16_I(table, (s2 >> 15) & 0x1FE); t0 = VIS_LD_U16_I(table, (s2 >> 23) & 0x1FE); acc3 = vis_faligndata(t3, acc3); acc3 = vis_faligndata(t2, acc3); acc3 = vis_faligndata(t1, acc3); acc3 = vis_faligndata(t0, acc3); t7 = VIS_LD_U16_I(table, (s3 << 1) & 0x1FE); t6 = VIS_LD_U16_I(table, (s3 >> 7) & 0x1FE); t5 = VIS_LD_U16_I(table, (s3 >> 15) & 0x1FE); t4 = VIS_LD_U16_I(table, (s3 >> 23) & 0x1FE); acc4 = vis_faligndata(t7, acc4); acc4 = vis_faligndata(t6, acc4); acc4 = vis_faligndata(t5, acc4); acc4 = vis_faligndata(t4, acc4); vis_alignaddr(dp, off); s0 = sa[0]; s1 = sa[1]; s2 = sa[2]; s3 = sa[3]; *dp++ = vis_faligndata(acc0, acc1); *dp++ = vis_faligndata(acc1, acc2); *dp++ = vis_faligndata(acc2, acc3); *dp++ = vis_faligndata(acc3, acc4); acc0 = acc4; } vis_alignaddr(dp, 6); t3 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t2 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 >> 15) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 23) & 0x1FE); acc1 = vis_faligndata(t3, acc1); acc1 = vis_faligndata(t2, acc1); acc1 = vis_faligndata(t1, acc1); acc1 = vis_faligndata(t0, acc1); t7 = VIS_LD_U16_I(table, (s1 << 1) & 0x1FE); t6 = VIS_LD_U16_I(table, (s1 >> 7) & 0x1FE); t5 = VIS_LD_U16_I(table, (s1 >> 15) & 0x1FE); t4 = VIS_LD_U16_I(table, (s1 >> 23) & 0x1FE); acc2 = vis_faligndata(t7, acc2); acc2 = vis_faligndata(t6, acc2); acc2 = vis_faligndata(t5, acc2); acc2 = vis_faligndata(t4, acc2); t3 = VIS_LD_U16_I(table, (s2 << 1) & 0x1FE); t2 = VIS_LD_U16_I(table, (s2 >> 7) & 0x1FE); t1 = VIS_LD_U16_I(table, (s2 >> 15) & 0x1FE); t0 = VIS_LD_U16_I(table, (s2 >> 23) & 0x1FE); acc3 = vis_faligndata(t3, acc3); acc3 = vis_faligndata(t2, acc3); acc3 = vis_faligndata(t1, acc3); acc3 = vis_faligndata(t0, acc3); t7 = VIS_LD_U16_I(table, (s3 << 1) & 0x1FE); t6 = VIS_LD_U16_I(table, (s3 >> 7) & 0x1FE); t5 = VIS_LD_U16_I(table, (s3 >> 15) & 0x1FE); t4 = VIS_LD_U16_I(table, (s3 >> 23) & 0x1FE); acc4 = vis_faligndata(t7, acc4); acc4 = vis_faligndata(t6, acc4); acc4 = vis_faligndata(t5, acc4); acc4 = vis_faligndata(t4, acc4); vis_alignaddr(dp, off); *dp++ = vis_faligndata(acc0, acc1); *dp++ = vis_faligndata(acc1, acc2); *dp++ = vis_faligndata(acc2, acc3); *dp++ = vis_faligndata(acc3, acc4); acc0 = acc4; i+=16; } if (i <= xsize - 8) { s0 = sa[0]; s1 = sa[1]; vis_alignaddr(dp, 6); t3 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t2 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 >> 15) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 23) & 0x1FE); acc1 = vis_faligndata(t3, acc1); acc1 = vis_faligndata(t2, acc1); acc1 = vis_faligndata(t1, acc1); acc1 = vis_faligndata(t0, acc1); t7 = VIS_LD_U16_I(table, (s1 << 1) & 0x1FE); t6 = VIS_LD_U16_I(table, (s1 >> 7) & 0x1FE); t5 = VIS_LD_U16_I(table, (s1 >> 15) & 0x1FE); t4 = VIS_LD_U16_I(table, (s1 >> 23) & 0x1FE); acc2 = vis_faligndata(t7, acc2); acc2 = vis_faligndata(t6, acc2); acc2 = vis_faligndata(t5, acc2); acc2 = vis_faligndata(t4, acc2); vis_alignaddr(dp, off); *dp++ = vis_faligndata(acc0, acc1); *dp++ = vis_faligndata(acc1, acc2); acc0 = acc2; i += 8; sa += 2; } if (i <= xsize - 4) { s0 = *sa++; vis_alignaddr(dp, 6); t3 = VIS_LD_U16_I(table, (s0 << 1) & 0x1FE); t2 = VIS_LD_U16_I(table, (s0 >> 7) & 0x1FE); t1 = VIS_LD_U16_I(table, (s0 >> 15) & 0x1FE); t0 = VIS_LD_U16_I(table, (s0 >> 23) & 0x1FE); acc1 = vis_faligndata(t3, acc1); acc1 = vis_faligndata(t2, acc1); acc1 = vis_faligndata(t1, acc1); acc1 = vis_faligndata(t0, acc1); vis_alignaddr(dp, off); *dp++ = vis_faligndata(acc0, acc1); acc0 = acc1; } sp = (mlib_u8*)sa; if ((mlib_addr) dp <= (mlib_addr) dend) { num = (((mlib_u8*) dend - (mlib_u8*) dp) + off + 1) >> 1; sp += (num - 1); vis_alignaddr(dp, 6); #pragma pipeloop(0) for (i = 0; i < num; i ++) { s0 = (mlib_s32) *sp; sp --; t0 = VIS_LD_U16_I(table, 2*s0); acc1 = vis_faligndata(t0, acc1); } vis_alignaddr(dp, off); emask = vis_edge8(dp, dend); vis_pst_8(vis_faligndata(acc0, acc1), dp++, emask); } if ((mlib_addr) dp <= (mlib_addr) dend) { emask = vis_edge8(dp, dend); vis_pst_8(vis_faligndata(acc1, acc1), dp++, emask); } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_2_DstA8D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1, s2, s3; /* source data */ mlib_u16 *dl; /* pointer to start of destination */ mlib_u16 *dend; /* pointer to end of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, t4, t5; /* destination data */ mlib_d64 t6, t7, acc; /* destination data */ mlib_s32 emask; /* edge mask */ mlib_s32 i, num; /* loop variable */ const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; sp = (void *)src; dl = (mlib_u16*)dst; dp = (mlib_d64 *) dl; dend = dl + xsize - 1; vis_alignaddr((void *) 0, 7); if (xsize >= 4) { s0 = sp[0]; s1 = sp[1]; s2 = sp[2]; s3 = sp[3]; sp += 4; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, sp+=4) { t7 = VIS_LD_U8_I(tab1, s3); t6 = VIS_LD_U8_I(tab0, s3); t5 = VIS_LD_U8_I(tab1, s2); t4 = VIS_LD_U8_I(tab0, s2); t3 = VIS_LD_U8_I(tab1, s1); t2 = VIS_LD_U8_I(tab0, s1); t1 = VIS_LD_U8_I(tab1, s0); t0 = VIS_LD_U8_I(tab0, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = sp[0]; s1 = sp[1]; s2 = sp[2]; s3 = sp[3]; *dp++ = acc; } t7 = VIS_LD_U8_I(tab1, s3); t6 = VIS_LD_U8_I(tab0, s3); t5 = VIS_LD_U8_I(tab1, s2); t4 = VIS_LD_U8_I(tab0, s2); t3 = VIS_LD_U8_I(tab1, s1); t2 = VIS_LD_U8_I(tab0, s1); t1 = VIS_LD_U8_I(tab1, s0); t0 = VIS_LD_U8_I(tab0, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); *dp++ = acc; } if ((mlib_addr) dp <= (mlib_addr) dend) { num = (mlib_u16*) dend - (mlib_u16*) dp; sp += num; num ++; #pragma pipeloop(0) for (i = 0; i < num; i ++) { s0 = (mlib_s32) *sp; sp --; t0 = VIS_LD_U8_I(tab1, s0); acc = vis_faligndata(t0, acc); t0 = VIS_LD_U8_I(tab0, s0); acc = vis_faligndata(t0, acc); } emask = vis_edge16(dp, dend); vis_pst_16(acc, dp, emask); } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_2_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1, s2, s3, s4; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_u8 *dend; /* pointer to end of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, t4, t5; /* destination data */ mlib_d64 t6, t7, acc; /* destination data */ mlib_s32 emask; /* edge mask */ mlib_s32 i, num; /* loop variable */ const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; sp = (void *)src; dl = dst; dend = dl + 2 * xsize - 1; vis_alignaddr((void *) 0, 7); s0 = *sp++; *dl++ = tab0[s0]; dp = (mlib_d64 *) dl; xsize--; if (xsize >= 4) { s1 = sp[0]; s2 = sp[1]; s3 = sp[2]; s4 = sp[3]; sp += 4; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, sp+=4) { t7 = VIS_LD_U8_I(tab0, s4); t6 = VIS_LD_U8_I(tab1, s3); t5 = VIS_LD_U8_I(tab0, s3); t4 = VIS_LD_U8_I(tab1, s2); t3 = VIS_LD_U8_I(tab0, s2); t2 = VIS_LD_U8_I(tab1, s1); t1 = VIS_LD_U8_I(tab0, s1); t0 = VIS_LD_U8_I(tab1, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s4; s1 = sp[0]; s2 = sp[1]; s3 = sp[2]; s4 = sp[3]; *dp++ = acc; } t7 = VIS_LD_U8_I(tab0, s4); t6 = VIS_LD_U8_I(tab1, s3); t5 = VIS_LD_U8_I(tab0, s3); t4 = VIS_LD_U8_I(tab1, s2); t3 = VIS_LD_U8_I(tab0, s2); t2 = VIS_LD_U8_I(tab1, s1); t1 = VIS_LD_U8_I(tab0, s1); t0 = VIS_LD_U8_I(tab1, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s4; *dp++ = acc; } num = ((mlib_u8*) dend - (mlib_u8*) dp) >> 1; sp += num; num ++; #pragma pipeloop(0) for (i = 0; i < num; i ++) { s1 = (mlib_s32) *sp; sp --; t0 = VIS_LD_U8_I(tab1, s1); acc = vis_faligndata(t0, acc); t0 = VIS_LD_U8_I(tab0, s1); acc = vis_faligndata(t0, acc); } t0 = VIS_LD_U8_I(tab1, s0); acc = vis_faligndata(t0, acc); emask = vis_edge8(dp, dend); vis_pst_8(acc, dp, emask); } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_2(const mlib_u8 *src, mlib_s32 slb, mlib_u8 *dst, mlib_s32 dlb, mlib_s32 xsize, mlib_s32 ysize, const mlib_u8 **table) { if ((xsize * ysize) < 650) { mlib_u8 *sl; mlib_u8 *dl; mlib_s32 i, j; sl = (void *)src; dl = dst; /* row loop */ for (j = 0; j < ysize; j ++) { mlib_u8 *sp = sl; mlib_u8 *dp = dl; mlib_s32 off, s0, size = xsize; off = ((8 - ((mlib_addr)dp & 7)) & 7) >> 1; off = (off < size) ? off : size; for (i = 0; i < off; i++) { s0 = *sp++; *dp++ = table[0][s0]; *dp++ = table[1][s0]; size--; } if (size > 0) { if (((mlib_addr)dp & 1) == 0) { mlib_v_ImageLookUpSI_U8_U8_2_DstA8D1_SMALL(sp, dp, size, table); } else { mlib_v_ImageLookUpSI_U8_U8_2_D1_SMALL(sp, dp, size, table); } } sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); dl = (mlib_u8 *) ((mlib_u8 *) dl + dlb); } } else { mlib_u8 *sl; mlib_u8 *dl; mlib_u16 tab[256]; const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; mlib_s32 i, j, s0, s1, s2; s0 = tab0[0]; s1 = tab1[0]; for (i = 1; i < 256; i++) { s2 = (s0 << 8) + s1; s0 = tab0[i]; s1 = tab1[i]; tab[i-1] = (mlib_u16)s2; } s2 = (s0 << 8) + s1; tab[255] = (mlib_u16)s2; sl = (void *)src; dl = dst; /* row loop */ for (j = 0; j < ysize; j ++) { mlib_u8 *sp = sl; mlib_u8 *dp = dl; mlib_s32 off, s0, size = xsize; if (((mlib_addr)dp & 1) == 0) { off = ((8 - ((mlib_addr)dp & 7)) & 7) >> 1; off = (off < size) ? off : size; for (i = 0; i < off; i++) { *(mlib_u16*)dp = tab[(*sp)]; dp += 2; size--; sp++; } if (size > 0) { off = (mlib_addr)sp & 3; if (off == 0) { mlib_v_ImageLookUpSI_U8_U8_2_SrcOff0_D1(sp, dp, size, tab); } else if (off == 1) { mlib_v_ImageLookUpSI_U8_U8_2_SrcOff1_D1(sp, dp, size, tab); } else if (off == 2) { mlib_v_ImageLookUpSI_U8_U8_2_SrcOff2_D1(sp, dp, size, tab); } else { mlib_v_ImageLookUpSI_U8_U8_2_SrcOff3_D1(sp, dp, size, tab); } } } else { off = ((4 - ((mlib_addr)sp & 3)) & 3); off = (off < size) ? off : size; for (i = 0; i < off; i++) { s0 = tab[(*sp)]; *dp++ = (s0 >> 8); *dp++ = (s0 & 0xFF); size--; sp++; } if (size > 0) { mlib_v_ImageLookUpSI_U8_U8_2_DstNonAl_D1(sp, dp, size, tab); } } sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); dl = (mlib_u8 *) ((mlib_u8 *) dl + dlb); } } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_3_SrcOff0_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_d64 *table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 *sa; /* aligned pointer to source data */ mlib_u32 s0; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_f32 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2, t3; /* destination data */ mlib_d64 acc0, acc1; /* destination data */ mlib_s32 i; /* loop variable */ mlib_u8 *ptr; dl = dst; dp = (mlib_f32 *) dl; sp = (void *)src; sa = (mlib_u32*)sp; vis_alignaddr((void *) 0, 3); i = 0; if (xsize >= 4) { s0 = *sa++; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, dp+=3) { t0 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 21) & 0x7F8 )); t1 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 13) & 0x7F8 )); t2 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 5) & 0x7F8 )); t3 = *(mlib_d64*)((mlib_u8*)table + ((s0 << 3) & 0x7F8 )); acc0 = vis_faligndata(t0, t0); acc0 = vis_faligndata(acc0, t1); acc1 = vis_faligndata(acc0, acc0); acc0 = vis_faligndata(acc0, t2); acc1 = vis_faligndata(acc1, acc0); acc0 = vis_faligndata(acc0, t3); s0 = *sa++; dp[0] = vis_read_lo(acc1); dp[1] = vis_read_hi(acc0); dp[2] = vis_read_lo(acc0); } t0 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 21) & 0x7F8 )); t1 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 13) & 0x7F8 )); t2 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 5) & 0x7F8 )); t3 = *(mlib_d64*)((mlib_u8*)table + ((s0 << 3) & 0x7F8 )); acc0 = vis_faligndata(t0, t0); acc0 = vis_faligndata(acc0, t1); acc1 = vis_faligndata(acc0, acc0); acc0 = vis_faligndata(acc0, t2); acc1 = vis_faligndata(acc1, acc0); acc0 = vis_faligndata(acc0, t3); dp[0] = vis_read_lo(acc1); dp[1] = vis_read_hi(acc0); dp[2] = vis_read_lo(acc0); dp += 3; i += 4; } dl = (mlib_u8*)dp; #pragma pipeloop(0) for (; i < xsize; i++) { ptr = (mlib_u8*)(table + src[i]); dl[0] = ptr[0]; dl[1] = ptr[1]; dl[2] = ptr[2]; dl += 3; } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_3_SrcOff1_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_d64 *table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 *sa; /* aligned pointer to source data */ mlib_u32 s0, s1; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_f32 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2, t3; /* destination data */ mlib_d64 acc0, acc1; /* destination data */ mlib_s32 i; /* loop variable */ mlib_u8 *ptr; dl = dst; dp = (mlib_f32 *) dl; sp = (void *)src; sa = (mlib_u32*)(sp - 1); vis_alignaddr((void *) 0, 3); i = 0; s0 = *sa++; if (xsize >= 4) { s1 = *sa++; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, dp+=3) { t0 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 13) & 0x7F8 )); t1 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 5) & 0x7F8 )); t2 = *(mlib_d64*)((mlib_u8*)table + ((s0 << 3) & 0x7F8 )); t3 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 21) & 0x7F8 )); acc0 = vis_faligndata(t0, t0); acc0 = vis_faligndata(acc0, t1); acc1 = vis_faligndata(acc0, acc0); acc0 = vis_faligndata(acc0, t2); acc1 = vis_faligndata(acc1, acc0); acc0 = vis_faligndata(acc0, t3); s0 = s1; s1 = *sa++; dp[0] = vis_read_lo(acc1); dp[1] = vis_read_hi(acc0); dp[2] = vis_read_lo(acc0); } t0 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 13) & 0x7F8 )); t1 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 5) & 0x7F8 )); t2 = *(mlib_d64*)((mlib_u8*)table + ((s0 << 3) & 0x7F8 )); t3 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 21) & 0x7F8 )); acc0 = vis_faligndata(t0, t0); acc0 = vis_faligndata(acc0, t1); acc1 = vis_faligndata(acc0, acc0); acc0 = vis_faligndata(acc0, t2); acc1 = vis_faligndata(acc1, acc0); acc0 = vis_faligndata(acc0, t3); dp[0] = vis_read_lo(acc1); dp[1] = vis_read_hi(acc0); dp[2] = vis_read_lo(acc0); dp += 3; i += 4; } dl = (mlib_u8*)dp; #pragma pipeloop(0) for (; i < xsize; i++) { ptr = (mlib_u8*)(table + src[i]); dl[0] = ptr[0]; dl[1] = ptr[1]; dl[2] = ptr[2]; dl += 3; } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_3_SrcOff2_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_d64 *table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 *sa; /* aligned pointer to source data */ mlib_u32 s0, s1; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_f32 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2, t3; /* destination data */ mlib_d64 acc0, acc1; /* destination data */ mlib_s32 i; /* loop variable */ mlib_u8 *ptr; dl = dst; dp = (mlib_f32 *) dl; sp = (void *)src; sa = (mlib_u32*)(sp - 2); vis_alignaddr((void *) 0, 3); i = 0; s0 = *sa++; if (xsize >= 4) { s1 = *sa++; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, dp+=3) { t0 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 5) & 0x7F8 )); t1 = *(mlib_d64*)((mlib_u8*)table + ((s0 << 3) & 0x7F8 )); t2 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 21) & 0x7F8 )); t3 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 13) & 0x7F8 )); acc0 = vis_faligndata(t0, t0); acc0 = vis_faligndata(acc0, t1); acc1 = vis_faligndata(acc0, acc0); acc0 = vis_faligndata(acc0, t2); acc1 = vis_faligndata(acc1, acc0); acc0 = vis_faligndata(acc0, t3); s0 = s1; s1 = *sa++; dp[0] = vis_read_lo(acc1); dp[1] = vis_read_hi(acc0); dp[2] = vis_read_lo(acc0); } t0 = *(mlib_d64*)((mlib_u8*)table + ((s0 >> 5) & 0x7F8 )); t1 = *(mlib_d64*)((mlib_u8*)table + ((s0 << 3) & 0x7F8 )); t2 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 21) & 0x7F8 )); t3 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 13) & 0x7F8 )); acc0 = vis_faligndata(t0, t0); acc0 = vis_faligndata(acc0, t1); acc1 = vis_faligndata(acc0, acc0); acc0 = vis_faligndata(acc0, t2); acc1 = vis_faligndata(acc1, acc0); acc0 = vis_faligndata(acc0, t3); dp[0] = vis_read_lo(acc1); dp[1] = vis_read_hi(acc0); dp[2] = vis_read_lo(acc0); dp += 3; i += 4; } dl = (mlib_u8*)dp; #pragma pipeloop(0) for (; i < xsize; i++) { ptr = (mlib_u8*)(table + src[i]); dl[0] = ptr[0]; dl[1] = ptr[1]; dl[2] = ptr[2]; dl += 3; } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_3_SrcOff3_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_d64 *table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 *sa; /* aligned pointer to source data */ mlib_u32 s0, s1; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_f32 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2, t3; /* destination data */ mlib_d64 acc0, acc1; /* destination data */ mlib_s32 i; /* loop variable */ mlib_u8 *ptr; dl = dst; dp = (mlib_f32 *) dl; sp = (void *)src; sa = (mlib_u32*)(sp - 3); vis_alignaddr((void *) 0, 3); i = 0; s0 = *sa++; if (xsize >= 4) { s1 = *sa++; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, dp+=3) { t0 = *(mlib_d64*)((mlib_u8*)table + ((s0 << 3) & 0x7F8 )); t1 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 21) & 0x7F8 )); t2 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 13) & 0x7F8 )); t3 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 5) & 0x7F8 )); acc0 = vis_faligndata(t0, t0); acc0 = vis_faligndata(acc0, t1); acc1 = vis_faligndata(acc0, acc0); acc0 = vis_faligndata(acc0, t2); acc1 = vis_faligndata(acc1, acc0); acc0 = vis_faligndata(acc0, t3); s0 = s1; s1 = *sa++; dp[0] = vis_read_lo(acc1); dp[1] = vis_read_hi(acc0); dp[2] = vis_read_lo(acc0); } t0 = *(mlib_d64*)((mlib_u8*)table + ((s0 << 3) & 0x7F8 )); t1 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 21) & 0x7F8 )); t2 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 13) & 0x7F8 )); t3 = *(mlib_d64*)((mlib_u8*)table + ((s1 >> 5) & 0x7F8 )); acc0 = vis_faligndata(t0, t0); acc0 = vis_faligndata(acc0, t1); acc1 = vis_faligndata(acc0, acc0); acc0 = vis_faligndata(acc0, t2); acc1 = vis_faligndata(acc1, acc0); acc0 = vis_faligndata(acc0, t3); dp[0] = vis_read_lo(acc1); dp[1] = vis_read_hi(acc0); dp[2] = vis_read_lo(acc0); dp += 3; i += 4; } dl = (mlib_u8*)dp; #pragma pipeloop(0) for (; i < xsize; i++) { ptr = (mlib_u8*)(table + src[i]); dl[0] = ptr[0]; dl[1] = ptr[1]; dl[2] = ptr[2]; dl += 3; } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_3_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table) { mlib_u8 *sp; /* pointer to source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, t4, t5; /* destination data */ mlib_d64 t6, t7; /* destination data */ mlib_d64 acc0, acc1, acc2; /* destination data */ mlib_s32 i; /* loop variable */ const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; const mlib_u8 *tab2 = table[2]; mlib_u32 s00, s01, s02, s03; mlib_u32 s10, s11, s12, s13; sp = (void *)src; dl = dst; dp = (mlib_d64 *) dl; vis_alignaddr((void *) 0, 7); i = 0; if (xsize >= 8) { s00 = sp[0]; s01 = sp[1]; s02 = sp[2]; s03 = sp[3]; s10 = sp[4]; s11 = sp[5]; s12 = sp[6]; s13 = sp[7]; sp += 8; #pragma pipeloop(0) for(i = 0; i <= xsize - 16; i+=8, sp+=8) { t7 = VIS_LD_U8_I(tab1, s02); t6 = VIS_LD_U8_I(tab0, s02); t5 = VIS_LD_U8_I(tab2, s01); t4 = VIS_LD_U8_I(tab1, s01); t3 = VIS_LD_U8_I(tab0, s01); t2 = VIS_LD_U8_I(tab2, s00); t1 = VIS_LD_U8_I(tab1, s00); t0 = VIS_LD_U8_I(tab0, s00); acc0 = vis_faligndata(t7, acc0); acc0 = vis_faligndata(t6, acc0); acc0 = vis_faligndata(t5, acc0); acc0 = vis_faligndata(t4, acc0); acc0 = vis_faligndata(t3, acc0); acc0 = vis_faligndata(t2, acc0); acc0 = vis_faligndata(t1, acc0); acc0 = vis_faligndata(t0, acc0); t7 = VIS_LD_U8_I(tab0, s11); t6 = VIS_LD_U8_I(tab2, s10); t5 = VIS_LD_U8_I(tab1, s10); t4 = VIS_LD_U8_I(tab0, s10); t3 = VIS_LD_U8_I(tab2, s03); t2 = VIS_LD_U8_I(tab1, s03); t1 = VIS_LD_U8_I(tab0, s03); t0 = VIS_LD_U8_I(tab2, s02); acc1 = vis_faligndata(t7, acc1); acc1 = vis_faligndata(t6, acc1); acc1 = vis_faligndata(t5, acc1); acc1 = vis_faligndata(t4, acc1); acc1 = vis_faligndata(t3, acc1); acc1 = vis_faligndata(t2, acc1); acc1 = vis_faligndata(t1, acc1); acc1 = vis_faligndata(t0, acc1); t7 = VIS_LD_U8_I(tab2, s13); t6 = VIS_LD_U8_I(tab1, s13); t5 = VIS_LD_U8_I(tab0, s13); t4 = VIS_LD_U8_I(tab2, s12); t3 = VIS_LD_U8_I(tab1, s12); t2 = VIS_LD_U8_I(tab0, s12); t1 = VIS_LD_U8_I(tab2, s11); t0 = VIS_LD_U8_I(tab1, s11); acc2 = vis_faligndata(t7, acc2); acc2 = vis_faligndata(t6, acc2); acc2 = vis_faligndata(t5, acc2); acc2 = vis_faligndata(t4, acc2); acc2 = vis_faligndata(t3, acc2); acc2 = vis_faligndata(t2, acc2); acc2 = vis_faligndata(t1, acc2); acc2 = vis_faligndata(t0, acc2); s00 = sp[0]; s01 = sp[1]; s02 = sp[2]; s03 = sp[3]; s10 = sp[4]; s11 = sp[5]; s12 = sp[6]; s13 = sp[7]; *dp++ = acc0; *dp++ = acc1; *dp++ = acc2; } t7 = VIS_LD_U8_I(tab1, s02); t6 = VIS_LD_U8_I(tab0, s02); t5 = VIS_LD_U8_I(tab2, s01); t4 = VIS_LD_U8_I(tab1, s01); t3 = VIS_LD_U8_I(tab0, s01); t2 = VIS_LD_U8_I(tab2, s00); t1 = VIS_LD_U8_I(tab1, s00); t0 = VIS_LD_U8_I(tab0, s00); acc0 = vis_faligndata(t7, acc0); acc0 = vis_faligndata(t6, acc0); acc0 = vis_faligndata(t5, acc0); acc0 = vis_faligndata(t4, acc0); acc0 = vis_faligndata(t3, acc0); acc0 = vis_faligndata(t2, acc0); acc0 = vis_faligndata(t1, acc0); acc0 = vis_faligndata(t0, acc0); t7 = VIS_LD_U8_I(tab0, s11); t6 = VIS_LD_U8_I(tab2, s10); t5 = VIS_LD_U8_I(tab1, s10); t4 = VIS_LD_U8_I(tab0, s10); t3 = VIS_LD_U8_I(tab2, s03); t2 = VIS_LD_U8_I(tab1, s03); t1 = VIS_LD_U8_I(tab0, s03); t0 = VIS_LD_U8_I(tab2, s02); acc1 = vis_faligndata(t7, acc1); acc1 = vis_faligndata(t6, acc1); acc1 = vis_faligndata(t5, acc1); acc1 = vis_faligndata(t4, acc1); acc1 = vis_faligndata(t3, acc1); acc1 = vis_faligndata(t2, acc1); acc1 = vis_faligndata(t1, acc1); acc1 = vis_faligndata(t0, acc1); t7 = VIS_LD_U8_I(tab2, s13); t6 = VIS_LD_U8_I(tab1, s13); t5 = VIS_LD_U8_I(tab0, s13); t4 = VIS_LD_U8_I(tab2, s12); t3 = VIS_LD_U8_I(tab1, s12); t2 = VIS_LD_U8_I(tab0, s12); t1 = VIS_LD_U8_I(tab2, s11); t0 = VIS_LD_U8_I(tab1, s11); acc2 = vis_faligndata(t7, acc2); acc2 = vis_faligndata(t6, acc2); acc2 = vis_faligndata(t5, acc2); acc2 = vis_faligndata(t4, acc2); acc2 = vis_faligndata(t3, acc2); acc2 = vis_faligndata(t2, acc2); acc2 = vis_faligndata(t1, acc2); acc2 = vis_faligndata(t0, acc2); *dp++ = acc0; *dp++ = acc1; *dp++ = acc2; i += 8; } dl = (mlib_u8*)dp; #pragma pipeloop(0) for (; i < xsize; i++) { s00 = sp[0]; dl[0] = tab0[s00]; dl[1] = tab1[s00]; dl[2] = tab2[s00]; dl += 3; sp ++; } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_3(const mlib_u8 *src, mlib_s32 slb, mlib_u8 *dst, mlib_s32 dlb, mlib_s32 xsize, mlib_s32 ysize, const mlib_u8 **table) { if ((xsize * ysize) < 650) { mlib_u8 *sl; mlib_u8 *dl; mlib_s32 i, j; const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; const mlib_u8 *tab2 = table[2]; sl = (void *)src; dl = dst; /* row loop */ for (j = 0; j < ysize; j ++) { mlib_u8 *sp = sl; mlib_u8 *dp = dl; mlib_s32 off, s0, size = xsize; off = (mlib_addr)dp & 7; off = (off * 5) & 7; off = (off < size) ? off : size; for (i = 0; i < off; i++) { s0 = *sp++; *dp++ = tab0[s0]; *dp++ = tab1[s0]; *dp++ = tab2[s0]; size--; } if (size > 0) { mlib_v_ImageLookUpSI_U8_U8_3_D1_SMALL(sp, dp, size, table); } sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); dl = (mlib_u8 *) ((mlib_u8 *) dl + dlb); } } else { mlib_u8 *sl; mlib_u8 *dl; mlib_u32 tab[512]; const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; const mlib_u8 *tab2 = table[2]; mlib_s32 i, j; mlib_u32 s0, s1, s2, s3; s0 = tab0[0]; s1 = tab1[0]; s2 = tab2[0]; for (i = 1; i < 256; i++) { s3 = (s0 << 24) + (s1 << 16) + (s2 << 8); s0 = tab0[i]; s1 = tab1[i]; s2 = tab2[i]; tab[2*i-2] = s3; } s3 = (s0 << 24) + (s1 << 16) + (s2 << 8); tab[510] = s3; sl = (void *)src; dl = dst; /* row loop */ for (j = 0; j < ysize; j ++) { mlib_u8 *sp = sl; mlib_u8 *dp = dl; mlib_s32 off, size = xsize; mlib_u8 *ptr; off = ((mlib_addr)dp & 3); off = (off < size) ? off : size; #pragma pipeloop(0) for (i = 0; i < off; i++) { ptr = (mlib_u8*)(tab + 2*sp[i]); dp[0] = ptr[0]; dp[1] = ptr[1]; dp[2] = ptr[2]; dp += 3; } size -= off; sp += off; if (size > 0) { off = (mlib_addr)sp & 3; if (off == 0) { mlib_v_ImageLookUpSI_U8_U8_3_SrcOff0_D1(sp, dp, size, (mlib_d64*)tab); } else if (off == 1) { mlib_v_ImageLookUpSI_U8_U8_3_SrcOff1_D1(sp, dp, size, (mlib_d64*)tab); } else if (off == 2) { mlib_v_ImageLookUpSI_U8_U8_3_SrcOff2_D1(sp, dp, size, (mlib_d64*)tab); } else if (off == 3) { mlib_v_ImageLookUpSI_U8_U8_3_SrcOff3_D1(sp, dp, size, (mlib_d64*)tab); } } sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); dl = (mlib_u8 *) ((mlib_u8 *) dl + dlb); } } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_4_SrcOff0_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_f32 *table) { mlib_u32 *sa; /* aligned pointer to source data */ mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0; /* source data */ mlib_f32 *dp; /* aligned pointer to destination */ mlib_f32 acc0, acc1; /* destination data */ mlib_f32 acc2, acc3; /* destination data */ mlib_s32 i; /* loop variable */ mlib_u32 s00, s01, s02, s03; sa = (mlib_u32*)src; dp = (mlib_f32 *) dst; i = 0; if (xsize >= 4) { s0 = *sa++; s00 = (s0 >> 22) & 0x3FC; s01 = (s0 >> 14) & 0x3FC; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, dp += 4) { s02 = (s0 >> 6) & 0x3FC; s03 = (s0 << 2) & 0x3FC; acc0 = *(mlib_f32*)((mlib_u8*)table + s00); acc1 = *(mlib_f32*)((mlib_u8*)table + s01); acc2 = *(mlib_f32*)((mlib_u8*)table + s02); acc3 = *(mlib_f32*)((mlib_u8*)table + s03); s0 = *sa++; s00 = (s0 >> 22) & 0x3FC; s01 = (s0 >> 14) & 0x3FC; dp[0] = acc0; dp[1] = acc1; dp[2] = acc2; dp[3] = acc3; } s02 = (s0 >> 6) & 0x3FC; s03 = (s0 << 2) & 0x3FC; acc0 = *(mlib_f32*)((mlib_u8*)table + s00); acc1 = *(mlib_f32*)((mlib_u8*)table + s01); acc2 = *(mlib_f32*)((mlib_u8*)table + s02); acc3 = *(mlib_f32*)((mlib_u8*)table + s03); dp[0] = acc0; dp[1] = acc1; dp[2] = acc2; dp[3] = acc3; dp += 4; i += 4; } sp = (mlib_u8*)sa; if ( i <= xsize - 2) { *dp++ = table[sp[0]]; *dp++ = table[sp[1]]; i+=2; sp += 2; } if ( i < xsize) *dp = table[sp[0]]; } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_4_DstNonAl_D1(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_f32 *table) { mlib_u32 *sa; /* aligned pointer to source data */ mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 acc0, acc1, acc2; /* destination data */ mlib_s32 i; /* loop variable */ mlib_u8 *dend; /* pointer to end of destination */ mlib_s32 emask; /* edge mask */ mlib_s32 off; mlib_u32 s00, s01, s02, s03; sa = (mlib_u32*)src; sp = (void *)src; dl = dst; dend = dl + (xsize << 2) - 1; dp = (mlib_d64 *) ((mlib_addr) dl & (~7)); off = (mlib_addr) dp - (mlib_addr) dl; vis_alignaddr(dp, off); emask = vis_edge8(dl, dend); acc0 = vis_freg_pair(table[sp[0]], table[sp[1]]); vis_pst_8(vis_faligndata(acc0, acc0), dp++, emask); sp += 2; xsize -= 2; if (xsize >= 2) { acc1 = vis_freg_pair(table[sp[0]], table[sp[1]]); *dp++ = vis_faligndata(acc0, acc1); acc0 = acc1; sp += 2; xsize -= 2; } sa++; i = 0; if (xsize >= 4) { s0 = *sa++; s00 = (s0 >> 22) & 0x3FC; s01 = (s0 >> 14) & 0x3FC; #pragma pipeloop(0) for(i = 0; i <= xsize - 8; i+=4, dp += 2) { s02 = (s0 >> 6) & 0x3FC; s03 = (s0 << 2) & 0x3FC; acc1 = vis_freg_pair(*(mlib_f32*)((mlib_u8*)table + s00), *(mlib_f32*)((mlib_u8*)table + s01)); acc2 = vis_freg_pair(*(mlib_f32*)((mlib_u8*)table + s02), *(mlib_f32*)((mlib_u8*)table + s03)); s0 = *sa++; s00 = (s0 >> 22) & 0x3FC; s01 = (s0 >> 14) & 0x3FC; dp[0] = vis_faligndata(acc0, acc1); dp[1] = vis_faligndata(acc1, acc2); acc0 = acc2; } s02 = (s0 >> 6) & 0x3FC; s03 = (s0 << 2) & 0x3FC; acc1 = vis_freg_pair(*(mlib_f32*)((mlib_u8*)table + s00), *(mlib_f32*)((mlib_u8*)table + s01)); acc2 = vis_freg_pair(*(mlib_f32*)((mlib_u8*)table + s02), *(mlib_f32*)((mlib_u8*)table + s03)); dp[0] = vis_faligndata(acc0, acc1); dp[1] = vis_faligndata(acc1, acc2); acc0 = acc2; sp = (mlib_u8*)sa; dp += 2; i += 4; } if ( i <= xsize - 2) { acc1 = vis_freg_pair(table[sp[0]], table[sp[1]]); *dp++ = vis_faligndata(acc0, acc1); acc0 = acc1; i+=2; sp += 2; } if ((mlib_addr) dp <= (mlib_addr) dend) { emask = vis_edge8(dp, dend); acc1 = vis_freg_pair(table[sp[0]], table[sp[1]]); vis_pst_8(vis_faligndata(acc0, acc1), dp++, emask); } if ((mlib_addr) dp <= (mlib_addr) dend) { emask = vis_edge8(dp, dend); vis_pst_8(vis_faligndata(acc1, acc1), dp++, emask); } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_4_DstOff0_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, t4, t5; /* destination data */ mlib_d64 t6, t7, acc; /* destination data */ mlib_s32 i; /* loop variable */ const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; const mlib_u8 *tab2 = table[2]; const mlib_u8 *tab3 = table[3]; sp = (void *)src; dl = dst; dp = (mlib_d64 *) dl; vis_alignaddr((void *) 0, 7); if (xsize >= 2) { s0 = sp[0]; s1 = sp[1]; sp += 2; #pragma pipeloop(0) for(i = 0; i <= xsize - 4; i+=2, sp+=2) { t7 = VIS_LD_U8_I(tab3, s1); t6 = VIS_LD_U8_I(tab2, s1); t5 = VIS_LD_U8_I(tab1, s1); t4 = VIS_LD_U8_I(tab0, s1); t3 = VIS_LD_U8_I(tab3, s0); t2 = VIS_LD_U8_I(tab2, s0); t1 = VIS_LD_U8_I(tab1, s0); t0 = VIS_LD_U8_I(tab0, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = sp[0]; s1 = sp[1]; *dp++ = acc; } t7 = VIS_LD_U8_I(tab3, s1); t6 = VIS_LD_U8_I(tab2, s1); t5 = VIS_LD_U8_I(tab1, s1); t4 = VIS_LD_U8_I(tab0, s1); t3 = VIS_LD_U8_I(tab3, s0); t2 = VIS_LD_U8_I(tab2, s0); t1 = VIS_LD_U8_I(tab1, s0); t0 = VIS_LD_U8_I(tab0, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); *dp++ = acc; } if ((xsize & 1) != 0) { s0 = sp[0]; t7 = VIS_LD_U8_I(tab3, s0); t6 = VIS_LD_U8_I(tab2, s0); t5 = VIS_LD_U8_I(tab1, s0); t4 = VIS_LD_U8_I(tab0, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); *(mlib_f32*)dp = vis_read_hi(acc); } } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_4_DstOff1_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1, s2; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, t4, t5; /* destination data */ mlib_d64 t6, t7, acc; /* destination data */ mlib_s32 i; /* loop variable */ const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; const mlib_u8 *tab2 = table[2]; const mlib_u8 *tab3 = table[3]; sp = (void *)src; dl = dst; dp = (mlib_d64 *) dl; vis_alignaddr((void *) 0, 7); s0 = *sp++; if (xsize >= 2) { s1 = sp[0]; s2 = sp[1]; sp += 2; #pragma pipeloop(0) for(i = 0; i <= xsize - 4; i+=2, sp+=2) { t7 = VIS_LD_U8_I(tab0, s2); t6 = VIS_LD_U8_I(tab3, s1); t5 = VIS_LD_U8_I(tab2, s1); t4 = VIS_LD_U8_I(tab1, s1); t3 = VIS_LD_U8_I(tab0, s1); t2 = VIS_LD_U8_I(tab3, s0); t1 = VIS_LD_U8_I(tab2, s0); t0 = VIS_LD_U8_I(tab1, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s2; s1 = sp[0]; s2 = sp[1]; *dp++ = acc; } t7 = VIS_LD_U8_I(tab0, s2); t6 = VIS_LD_U8_I(tab3, s1); t5 = VIS_LD_U8_I(tab2, s1); t4 = VIS_LD_U8_I(tab1, s1); t3 = VIS_LD_U8_I(tab0, s1); t2 = VIS_LD_U8_I(tab3, s0); t1 = VIS_LD_U8_I(tab2, s0); t0 = VIS_LD_U8_I(tab1, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s2; *dp++ = acc; } dl = (mlib_u8*)dp; if ((xsize & 1) != 0) { s1 = sp[0]; t7 = VIS_LD_U8_I(tab0, s1); t6 = VIS_LD_U8_I(tab3, s0); t5 = VIS_LD_U8_I(tab2, s0); t4 = VIS_LD_U8_I(tab1, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); *(mlib_f32*)dl = vis_read_hi(acc); dl += 4; s0 = s1; } dl[0] = tab1[s0]; dl[1] = tab2[s0]; dl[2] = tab3[s0]; } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_4_DstOff2_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1, s2; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, t4, t5; /* destination data */ mlib_d64 t6, t7, acc; /* destination data */ mlib_s32 i; /* loop variable */ const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; const mlib_u8 *tab2 = table[2]; const mlib_u8 *tab3 = table[3]; sp = (void *)src; dl = dst; dp = (mlib_d64 *) dl; vis_alignaddr((void *) 0, 7); s0 = *sp++; if (xsize >= 2) { s1 = sp[0]; s2 = sp[1]; sp += 2; #pragma pipeloop(0) for(i = 0; i <= xsize - 4; i+=2, sp+=2) { t7 = VIS_LD_U8_I(tab1, s2); t6 = VIS_LD_U8_I(tab0, s2); t5 = VIS_LD_U8_I(tab3, s1); t4 = VIS_LD_U8_I(tab2, s1); t3 = VIS_LD_U8_I(tab1, s1); t2 = VIS_LD_U8_I(tab0, s1); t1 = VIS_LD_U8_I(tab3, s0); t0 = VIS_LD_U8_I(tab2, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s2; s1 = sp[0]; s2 = sp[1]; *dp++ = acc; } t7 = VIS_LD_U8_I(tab1, s2); t6 = VIS_LD_U8_I(tab0, s2); t5 = VIS_LD_U8_I(tab3, s1); t4 = VIS_LD_U8_I(tab2, s1); t3 = VIS_LD_U8_I(tab1, s1); t2 = VIS_LD_U8_I(tab0, s1); t1 = VIS_LD_U8_I(tab3, s0); t0 = VIS_LD_U8_I(tab2, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s2; *dp++ = acc; } dl = (mlib_u8*)dp; if ((xsize & 1) != 0) { s1 = sp[0]; t7 = VIS_LD_U8_I(tab1, s1); t6 = VIS_LD_U8_I(tab0, s1); t5 = VIS_LD_U8_I(tab3, s0); t4 = VIS_LD_U8_I(tab2, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); *(mlib_f32*)dl = vis_read_hi(acc); dl += 4; s0 = s1; } dl[0] = tab2[s0]; dl[1] = tab3[s0]; } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_4_DstOff3_D1_SMALL(const mlib_u8 *src, mlib_u8 *dst, mlib_s32 xsize, const mlib_u8 **table) { mlib_u8 *sp; /* pointer to source data */ mlib_u32 s0, s1, s2; /* source data */ mlib_u8 *dl; /* pointer to start of destination */ mlib_d64 *dp; /* aligned pointer to destination */ mlib_d64 t0, t1, t2; /* destination data */ mlib_d64 t3, t4, t5; /* destination data */ mlib_d64 t6, t7, acc; /* destination data */ mlib_s32 i; /* loop variable */ const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; const mlib_u8 *tab2 = table[2]; const mlib_u8 *tab3 = table[3]; sp = (void *)src; dl = dst; dp = (mlib_d64 *) dl; vis_alignaddr((void *) 0, 7); s0 = *sp++; if (xsize >= 2) { s1 = sp[0]; s2 = sp[1]; sp += 2; #pragma pipeloop(0) for(i = 0; i <= xsize - 4; i+=2, sp+=2) { t7 = VIS_LD_U8_I(tab2, s2); t6 = VIS_LD_U8_I(tab1, s2); t5 = VIS_LD_U8_I(tab0, s2); t4 = VIS_LD_U8_I(tab3, s1); t3 = VIS_LD_U8_I(tab2, s1); t2 = VIS_LD_U8_I(tab1, s1); t1 = VIS_LD_U8_I(tab0, s1); t0 = VIS_LD_U8_I(tab3, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s2; s1 = sp[0]; s2 = sp[1]; *dp++ = acc; } t7 = VIS_LD_U8_I(tab2, s2); t6 = VIS_LD_U8_I(tab1, s2); t5 = VIS_LD_U8_I(tab0, s2); t4 = VIS_LD_U8_I(tab3, s1); t3 = VIS_LD_U8_I(tab2, s1); t2 = VIS_LD_U8_I(tab1, s1); t1 = VIS_LD_U8_I(tab0, s1); t0 = VIS_LD_U8_I(tab3, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); acc = vis_faligndata(t3, acc); acc = vis_faligndata(t2, acc); acc = vis_faligndata(t1, acc); acc = vis_faligndata(t0, acc); s0 = s2; *dp++ = acc; } dl = (mlib_u8*)dp; if ((xsize & 1) != 0) { s1 = sp[0]; t7 = VIS_LD_U8_I(tab2, s1); t6 = VIS_LD_U8_I(tab1, s1); t5 = VIS_LD_U8_I(tab0, s1); t4 = VIS_LD_U8_I(tab3, s0); acc = vis_faligndata(t7, acc); acc = vis_faligndata(t6, acc); acc = vis_faligndata(t5, acc); acc = vis_faligndata(t4, acc); *(mlib_f32*)dl = vis_read_hi(acc); dl += 4; s0 = s1; } dl[0] = tab3[s0]; } /***************************************************************/ void mlib_v_ImageLookUpSI_U8_U8_4(const mlib_u8 *src, mlib_s32 slb, mlib_u8 *dst, mlib_s32 dlb, mlib_s32 xsize, mlib_s32 ysize, const mlib_u8 **table) { if ((xsize * ysize) < 500) { mlib_u8 *sl; mlib_u8 *dl; mlib_s32 j; const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; const mlib_u8 *tab2 = table[2]; const mlib_u8 *tab3 = table[3]; sl = (void *)src; dl = dst; /* row loop */ for (j = 0; j < ysize; j ++) { mlib_u8 *sp = sl; mlib_u8 *dp = dl; mlib_s32 off, s0, size = xsize; off = (8 - ((mlib_addr)dp & 7)) & 7; if ((off >= 4) && (size > 0)) { s0 = *sp++; *dp++ = tab0[s0]; *dp++ = tab1[s0]; *dp++ = tab2[s0]; *dp++ = tab3[s0]; size--; } if (size > 0) { off = (4 - ((mlib_addr)dp & 3)) & 3; if (off == 0) { mlib_v_ImageLookUpSI_U8_U8_4_DstOff0_D1_SMALL(sp, dp, size, table); } else if (off == 1) { s0 = *sp; *dp++ = tab0[s0]; size--; mlib_v_ImageLookUpSI_U8_U8_4_DstOff1_D1_SMALL(sp, dp, size, table); } else if (off == 2) { s0 = *sp; *dp++ = tab0[s0]; *dp++ = tab1[s0]; size--; mlib_v_ImageLookUpSI_U8_U8_4_DstOff2_D1_SMALL(sp, dp, size, table); } else if (off == 3) { s0 = *sp; *dp++ = tab0[s0]; *dp++ = tab1[s0]; *dp++ = tab2[s0]; size--; mlib_v_ImageLookUpSI_U8_U8_4_DstOff3_D1_SMALL(sp, dp, size, table); } } sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); dl = (mlib_u8 *) ((mlib_u8 *) dl + dlb); } } else { mlib_u8 *sl; mlib_u8 *dl; mlib_u32 tab[256]; const mlib_u8 *tab0 = table[0]; const mlib_u8 *tab1 = table[1]; const mlib_u8 *tab2 = table[2]; const mlib_u8 *tab3 = table[3]; mlib_s32 i, j; mlib_u32 s0, s1, s2, s3, s4; s0 = tab0[0]; s1 = tab1[0]; s2 = tab2[0]; s3 = tab3[0]; for (i = 1; i < 256; i++) { s4 = (s0 << 24) + (s1 << 16) + (s2 << 8) + s3; s0 = tab0[i]; s1 = tab1[i]; s2 = tab2[i]; s3 = tab3[i]; tab[i-1] = s4; } s4 = (s0 << 24) + (s1 << 16) + (s2 << 8) + s3; tab[255] = s4; sl = (void *)src; dl = dst; /* row loop */ for (j = 0; j < ysize; j ++) { mlib_u8 *sp = sl; mlib_u8 *dp = dl; mlib_s32 off, size = xsize; if (((mlib_addr)dp & 3) == 0) { off = (4 - (mlib_addr)sp & 3) & 3; off = (off < size) ? off : size; #pragma pipeloop(0) for (i = 0; i < off; i++) { *(mlib_u32*)dp = tab[(*sp)]; dp += 4; sp++; } size -= off; if (size > 0) { mlib_v_ImageLookUpSI_U8_U8_4_SrcOff0_D1(sp, dp, size, (mlib_f32*)tab); } } else { off = ((4 - ((mlib_addr)sp & 3)) & 3); off = (off < size) ? off : size; for (i = 0; i < off; i++) { s0 = tab[(*sp)]; *dp++ = (s0 >> 24); *dp++ = (s0 >> 16); *dp++ = (s0 >> 8); *dp++ = s0; size--; sp++; } if (size > 0) { mlib_v_ImageLookUpSI_U8_U8_4_DstNonAl_D1(sp, dp, size, (mlib_f32*)tab); } } sl = (mlib_u8 *) ((mlib_u8 *) sl + slb); dl = (mlib_u8 *) ((mlib_u8 *) dl + dlb); } } } /***************************************************************/
{ "language": "C" }
/* Broadcom B43 wireless driver Copyright (c) 2010 Rafał Miłecki <zajec5@gmail.com> Some parts of the code in this file are derived from the brcm80211 driver Copyright (c) 2010 Broadcom Corporation This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; 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; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Steet, Fifth Floor, Boston, MA 02110-1301, USA. */ #ifndef B43_RADIO_2056_H_ #define B43_RADIO_2056_H_ #include <linux/types.h> #include "tables_nphy.h" #define B2056_SYN (0x0 << 12) #define B2056_TX0 (0x2 << 12) #define B2056_TX1 (0x3 << 12) #define B2056_RX0 (0x6 << 12) #define B2056_RX1 (0x7 << 12) #define B2056_ALLTX (0xE << 12) #define B2056_ALLRX (0xF << 12) #define B2056_SYN_RESERVED_ADDR0 0x00 #define B2056_SYN_IDCODE 0x01 #define B2056_SYN_RESERVED_ADDR2 0x02 #define B2056_SYN_RESERVED_ADDR3 0x03 #define B2056_SYN_RESERVED_ADDR4 0x04 #define B2056_SYN_RESERVED_ADDR5 0x05 #define B2056_SYN_RESERVED_ADDR6 0x06 #define B2056_SYN_RESERVED_ADDR7 0x07 #define B2056_SYN_COM_CTRL 0x08 #define B2056_SYN_COM_PU 0x09 #define B2056_SYN_COM_OVR 0x0A #define B2056_SYN_COM_RESET 0x0B #define B2056_SYN_COM_RCAL 0x0C #define B2056_SYN_COM_RC_RXLPF 0x0D #define B2056_SYN_COM_RC_TXLPF 0x0E #define B2056_SYN_COM_RC_RXHPF 0x0F #define B2056_SYN_RESERVED_ADDR16 0x10 #define B2056_SYN_RESERVED_ADDR17 0x11 #define B2056_SYN_RESERVED_ADDR18 0x12 #define B2056_SYN_RESERVED_ADDR19 0x13 #define B2056_SYN_RESERVED_ADDR20 0x14 #define B2056_SYN_RESERVED_ADDR21 0x15 #define B2056_SYN_RESERVED_ADDR22 0x16 #define B2056_SYN_RESERVED_ADDR23 0x17 #define B2056_SYN_RESERVED_ADDR24 0x18 #define B2056_SYN_RESERVED_ADDR25 0x19 #define B2056_SYN_RESERVED_ADDR26 0x1A #define B2056_SYN_RESERVED_ADDR27 0x1B #define B2056_SYN_RESERVED_ADDR28 0x1C #define B2056_SYN_RESERVED_ADDR29 0x1D #define B2056_SYN_RESERVED_ADDR30 0x1E #define B2056_SYN_RESERVED_ADDR31 0x1F #define B2056_SYN_GPIO_MASTER1 0x20 #define B2056_SYN_GPIO_MASTER2 0x21 #define B2056_SYN_TOPBIAS_MASTER 0x22 #define B2056_SYN_TOPBIAS_RCAL 0x23 #define B2056_SYN_AFEREG 0x24 #define B2056_SYN_TEMPPROCSENSE 0x25 #define B2056_SYN_TEMPPROCSENSEIDAC 0x26 #define B2056_SYN_TEMPPROCSENSERCAL 0x27 #define B2056_SYN_LPO 0x28 #define B2056_SYN_VDDCAL_MASTER 0x29 #define B2056_SYN_VDDCAL_IDAC 0x2A #define B2056_SYN_VDDCAL_STATUS 0x2B #define B2056_SYN_RCAL_MASTER 0x2C #define B2056_SYN_RCAL_CODE_OUT 0x2D #define B2056_SYN_RCCAL_CTRL0 0x2E #define B2056_SYN_RCCAL_CTRL1 0x2F #define B2056_SYN_RCCAL_CTRL2 0x30 #define B2056_SYN_RCCAL_CTRL3 0x31 #define B2056_SYN_RCCAL_CTRL4 0x32 #define B2056_SYN_RCCAL_CTRL5 0x33 #define B2056_SYN_RCCAL_CTRL6 0x34 #define B2056_SYN_RCCAL_CTRL7 0x35 #define B2056_SYN_RCCAL_CTRL8 0x36 #define B2056_SYN_RCCAL_CTRL9 0x37 #define B2056_SYN_RCCAL_CTRL10 0x38 #define B2056_SYN_RCCAL_CTRL11 0x39 #define B2056_SYN_ZCAL_SPARE1 0x3A #define B2056_SYN_ZCAL_SPARE2 0x3B #define B2056_SYN_PLL_MAST1 0x3C #define B2056_SYN_PLL_MAST2 0x3D #define B2056_SYN_PLL_MAST3 0x3E #define B2056_SYN_PLL_BIAS_RESET 0x3F #define B2056_SYN_PLL_XTAL0 0x40 #define B2056_SYN_PLL_XTAL1 0x41 #define B2056_SYN_PLL_XTAL3 0x42 #define B2056_SYN_PLL_XTAL4 0x43 #define B2056_SYN_PLL_XTAL5 0x44 #define B2056_SYN_PLL_XTAL6 0x45 #define B2056_SYN_PLL_REFDIV 0x46 #define B2056_SYN_PLL_PFD 0x47 #define B2056_SYN_PLL_CP1 0x48 #define B2056_SYN_PLL_CP2 0x49 #define B2056_SYN_PLL_CP3 0x4A #define B2056_SYN_PLL_LOOPFILTER1 0x4B #define B2056_SYN_PLL_LOOPFILTER2 0x4C #define B2056_SYN_PLL_LOOPFILTER3 0x4D #define B2056_SYN_PLL_LOOPFILTER4 0x4E #define B2056_SYN_PLL_LOOPFILTER5 0x4F #define B2056_SYN_PLL_MMD1 0x50 #define B2056_SYN_PLL_MMD2 0x51 #define B2056_SYN_PLL_VCO1 0x52 #define B2056_SYN_PLL_VCO2 0x53 #define B2056_SYN_PLL_MONITOR1 0x54 #define B2056_SYN_PLL_MONITOR2 0x55 #define B2056_SYN_PLL_VCOCAL1 0x56 #define B2056_SYN_PLL_VCOCAL2 0x57 #define B2056_SYN_PLL_VCOCAL4 0x58 #define B2056_SYN_PLL_VCOCAL5 0x59 #define B2056_SYN_PLL_VCOCAL6 0x5A #define B2056_SYN_PLL_VCOCAL7 0x5B #define B2056_SYN_PLL_VCOCAL8 0x5C #define B2056_SYN_PLL_VCOCAL9 0x5D #define B2056_SYN_PLL_VCOCAL10 0x5E #define B2056_SYN_PLL_VCOCAL11 0x5F #define B2056_SYN_PLL_VCOCAL12 0x60 #define B2056_SYN_PLL_VCOCAL13 0x61 #define B2056_SYN_PLL_VREG 0x62 #define B2056_SYN_PLL_STATUS1 0x63 #define B2056_SYN_PLL_STATUS2 0x64 #define B2056_SYN_PLL_STATUS3 0x65 #define B2056_SYN_LOGEN_PU0 0x66 #define B2056_SYN_LOGEN_PU1 0x67 #define B2056_SYN_LOGEN_PU2 0x68 #define B2056_SYN_LOGEN_PU3 0x69 #define B2056_SYN_LOGEN_PU5 0x6A #define B2056_SYN_LOGEN_PU6 0x6B #define B2056_SYN_LOGEN_PU7 0x6C #define B2056_SYN_LOGEN_PU8 0x6D #define B2056_SYN_LOGEN_BIAS_RESET 0x6E #define B2056_SYN_LOGEN_RCCR1 0x6F #define B2056_SYN_LOGEN_VCOBUF1 0x70 #define B2056_SYN_LOGEN_MIXER1 0x71 #define B2056_SYN_LOGEN_MIXER2 0x72 #define B2056_SYN_LOGEN_BUF1 0x73 #define B2056_SYN_LOGENBUF2 0x74 #define B2056_SYN_LOGEN_BUF3 0x75 #define B2056_SYN_LOGEN_BUF4 0x76 #define B2056_SYN_LOGEN_DIV1 0x77 #define B2056_SYN_LOGEN_DIV2 0x78 #define B2056_SYN_LOGEN_DIV3 0x79 #define B2056_SYN_LOGEN_ACL1 0x7A #define B2056_SYN_LOGEN_ACL2 0x7B #define B2056_SYN_LOGEN_ACL3 0x7C #define B2056_SYN_LOGEN_ACL4 0x7D #define B2056_SYN_LOGEN_ACL5 0x7E #define B2056_SYN_LOGEN_ACL6 0x7F #define B2056_SYN_LOGEN_ACLOUT 0x80 #define B2056_SYN_LOGEN_ACLCAL1 0x81 #define B2056_SYN_LOGEN_ACLCAL2 0x82 #define B2056_SYN_LOGEN_ACLCAL3 0x83 #define B2056_SYN_CALEN 0x84 #define B2056_SYN_LOGEN_PEAKDET1 0x85 #define B2056_SYN_LOGEN_CORE_ACL_OVR 0x86 #define B2056_SYN_LOGEN_RX_DIFF_ACL_OVR 0x87 #define B2056_SYN_LOGEN_TX_DIFF_ACL_OVR 0x88 #define B2056_SYN_LOGEN_RX_CMOS_ACL_OVR 0x89 #define B2056_SYN_LOGEN_TX_CMOS_ACL_OVR 0x8A #define B2056_SYN_LOGEN_VCOBUF2 0x8B #define B2056_SYN_LOGEN_MIXER3 0x8C #define B2056_SYN_LOGEN_BUF5 0x8D #define B2056_SYN_LOGEN_BUF6 0x8E #define B2056_SYN_LOGEN_CBUFRX1 0x8F #define B2056_SYN_LOGEN_CBUFRX2 0x90 #define B2056_SYN_LOGEN_CBUFRX3 0x91 #define B2056_SYN_LOGEN_CBUFRX4 0x92 #define B2056_SYN_LOGEN_CBUFTX1 0x93 #define B2056_SYN_LOGEN_CBUFTX2 0x94 #define B2056_SYN_LOGEN_CBUFTX3 0x95 #define B2056_SYN_LOGEN_CBUFTX4 0x96 #define B2056_SYN_LOGEN_CMOSRX1 0x97 #define B2056_SYN_LOGEN_CMOSRX2 0x98 #define B2056_SYN_LOGEN_CMOSRX3 0x99 #define B2056_SYN_LOGEN_CMOSRX4 0x9A #define B2056_SYN_LOGEN_CMOSTX1 0x9B #define B2056_SYN_LOGEN_CMOSTX2 0x9C #define B2056_SYN_LOGEN_CMOSTX3 0x9D #define B2056_SYN_LOGEN_CMOSTX4 0x9E #define B2056_SYN_LOGEN_VCOBUF2_OVRVAL 0x9F #define B2056_SYN_LOGEN_MIXER3_OVRVAL 0xA0 #define B2056_SYN_LOGEN_BUF5_OVRVAL 0xA1 #define B2056_SYN_LOGEN_BUF6_OVRVAL 0xA2 #define B2056_SYN_LOGEN_CBUFRX1_OVRVAL 0xA3 #define B2056_SYN_LOGEN_CBUFRX2_OVRVAL 0xA4 #define B2056_SYN_LOGEN_CBUFRX3_OVRVAL 0xA5 #define B2056_SYN_LOGEN_CBUFRX4_OVRVAL 0xA6 #define B2056_SYN_LOGEN_CBUFTX1_OVRVAL 0xA7 #define B2056_SYN_LOGEN_CBUFTX2_OVRVAL 0xA8 #define B2056_SYN_LOGEN_CBUFTX3_OVRVAL 0xA9 #define B2056_SYN_LOGEN_CBUFTX4_OVRVAL 0xAA #define B2056_SYN_LOGEN_CMOSRX1_OVRVAL 0xAB #define B2056_SYN_LOGEN_CMOSRX2_OVRVAL 0xAC #define B2056_SYN_LOGEN_CMOSRX3_OVRVAL 0xAD #define B2056_SYN_LOGEN_CMOSRX4_OVRVAL 0xAE #define B2056_SYN_LOGEN_CMOSTX1_OVRVAL 0xAF #define B2056_SYN_LOGEN_CMOSTX2_OVRVAL 0xB0 #define B2056_SYN_LOGEN_CMOSTX3_OVRVAL 0xB1 #define B2056_SYN_LOGEN_CMOSTX4_OVRVAL 0xB2 #define B2056_SYN_LOGEN_ACL_WAITCNT 0xB3 #define B2056_SYN_LOGEN_CORE_CALVALID 0xB4 #define B2056_SYN_LOGEN_RX_CMOS_CALVALID 0xB5 #define B2056_SYN_LOGEN_TX_CMOS_VALID 0xB6 #define B2056_TX_RESERVED_ADDR0 0x00 #define B2056_TX_IDCODE 0x01 #define B2056_TX_RESERVED_ADDR2 0x02 #define B2056_TX_RESERVED_ADDR3 0x03 #define B2056_TX_RESERVED_ADDR4 0x04 #define B2056_TX_RESERVED_ADDR5 0x05 #define B2056_TX_RESERVED_ADDR6 0x06 #define B2056_TX_RESERVED_ADDR7 0x07 #define B2056_TX_COM_CTRL 0x08 #define B2056_TX_COM_PU 0x09 #define B2056_TX_COM_OVR 0x0A #define B2056_TX_COM_RESET 0x0B #define B2056_TX_COM_RCAL 0x0C #define B2056_TX_COM_RC_RXLPF 0x0D #define B2056_TX_COM_RC_TXLPF 0x0E #define B2056_TX_COM_RC_RXHPF 0x0F #define B2056_TX_RESERVED_ADDR16 0x10 #define B2056_TX_RESERVED_ADDR17 0x11 #define B2056_TX_RESERVED_ADDR18 0x12 #define B2056_TX_RESERVED_ADDR19 0x13 #define B2056_TX_RESERVED_ADDR20 0x14 #define B2056_TX_RESERVED_ADDR21 0x15 #define B2056_TX_RESERVED_ADDR22 0x16 #define B2056_TX_RESERVED_ADDR23 0x17 #define B2056_TX_RESERVED_ADDR24 0x18 #define B2056_TX_RESERVED_ADDR25 0x19 #define B2056_TX_RESERVED_ADDR26 0x1A #define B2056_TX_RESERVED_ADDR27 0x1B #define B2056_TX_RESERVED_ADDR28 0x1C #define B2056_TX_RESERVED_ADDR29 0x1D #define B2056_TX_RESERVED_ADDR30 0x1E #define B2056_TX_RESERVED_ADDR31 0x1F #define B2056_TX_IQCAL_GAIN_BW 0x20 #define B2056_TX_LOFT_FINE_I 0x21 #define B2056_TX_LOFT_FINE_Q 0x22 #define B2056_TX_LOFT_COARSE_I 0x23 #define B2056_TX_LOFT_COARSE_Q 0x24 #define B2056_TX_TX_COM_MASTER1 0x25 #define B2056_TX_TX_COM_MASTER2 0x26 #define B2056_TX_RXIQCAL_TXMUX 0x27 #define B2056_TX_TX_SSI_MASTER 0x28 #define B2056_TX_IQCAL_VCM_HG 0x29 #define B2056_TX_IQCAL_IDAC 0x2A #define B2056_TX_TSSI_VCM 0x2B #define B2056_TX_TX_AMP_DET 0x2C #define B2056_TX_TX_SSI_MUX 0x2D #define B2056_TX_TSSIA 0x2E #define B2056_TX_TSSIG 0x2F #define B2056_TX_TSSI_MISC1 0x30 #define B2056_TX_TSSI_MISC2 0x31 #define B2056_TX_TSSI_MISC3 0x32 #define B2056_TX_PA_SPARE1 0x33 #define B2056_TX_PA_SPARE2 0x34 #define B2056_TX_INTPAA_MASTER 0x35 #define B2056_TX_INTPAA_GAIN 0x36 #define B2056_TX_INTPAA_BOOST_TUNE 0x37 #define B2056_TX_INTPAA_IAUX_STAT 0x38 #define B2056_TX_INTPAA_IAUX_DYN 0x39 #define B2056_TX_INTPAA_IMAIN_STAT 0x3A #define B2056_TX_INTPAA_IMAIN_DYN 0x3B #define B2056_TX_INTPAA_CASCBIAS 0x3C #define B2056_TX_INTPAA_PASLOPE 0x3D #define B2056_TX_INTPAA_PA_MISC 0x3E #define B2056_TX_INTPAG_MASTER 0x3F #define B2056_TX_INTPAG_GAIN 0x40 #define B2056_TX_INTPAG_BOOST_TUNE 0x41 #define B2056_TX_INTPAG_IAUX_STAT 0x42 #define B2056_TX_INTPAG_IAUX_DYN 0x43 #define B2056_TX_INTPAG_IMAIN_STAT 0x44 #define B2056_TX_INTPAG_IMAIN_DYN 0x45 #define B2056_TX_INTPAG_CASCBIAS 0x46 #define B2056_TX_INTPAG_PASLOPE 0x47 #define B2056_TX_INTPAG_PA_MISC 0x48 #define B2056_TX_PADA_MASTER 0x49 #define B2056_TX_PADA_IDAC 0x4A #define B2056_TX_PADA_CASCBIAS 0x4B #define B2056_TX_PADA_GAIN 0x4C #define B2056_TX_PADA_BOOST_TUNE 0x4D #define B2056_TX_PADA_SLOPE 0x4E #define B2056_TX_PADG_MASTER 0x4F #define B2056_TX_PADG_IDAC 0x50 #define B2056_TX_PADG_CASCBIAS 0x51 #define B2056_TX_PADG_GAIN 0x52 #define B2056_TX_PADG_BOOST_TUNE 0x53 #define B2056_TX_PADG_SLOPE 0x54 #define B2056_TX_PGAA_MASTER 0x55 #define B2056_TX_PGAA_IDAC 0x56 #define B2056_TX_PGAA_GAIN 0x57 #define B2056_TX_PGAA_BOOST_TUNE 0x58 #define B2056_TX_PGAA_SLOPE 0x59 #define B2056_TX_PGAA_MISC 0x5A #define B2056_TX_PGAG_MASTER 0x5B #define B2056_TX_PGAG_IDAC 0x5C #define B2056_TX_PGAG_GAIN 0x5D #define B2056_TX_PGAG_BOOST_TUNE 0x5E #define B2056_TX_PGAG_SLOPE 0x5F #define B2056_TX_PGAG_MISC 0x60 #define B2056_TX_MIXA_MASTER 0x61 #define B2056_TX_MIXA_BOOST_TUNE 0x62 #define B2056_TX_MIXG 0x63 #define B2056_TX_MIXG_BOOST_TUNE 0x64 #define B2056_TX_BB_GM_MASTER 0x65 #define B2056_TX_GMBB_GM 0x66 #define B2056_TX_GMBB_IDAC 0x67 #define B2056_TX_TXLPF_MASTER 0x68 #define B2056_TX_TXLPF_RCCAL 0x69 #define B2056_TX_TXLPF_RCCAL_OFF0 0x6A #define B2056_TX_TXLPF_RCCAL_OFF1 0x6B #define B2056_TX_TXLPF_RCCAL_OFF2 0x6C #define B2056_TX_TXLPF_RCCAL_OFF3 0x6D #define B2056_TX_TXLPF_RCCAL_OFF4 0x6E #define B2056_TX_TXLPF_RCCAL_OFF5 0x6F #define B2056_TX_TXLPF_RCCAL_OFF6 0x70 #define B2056_TX_TXLPF_BW 0x71 #define B2056_TX_TXLPF_GAIN 0x72 #define B2056_TX_TXLPF_IDAC 0x73 #define B2056_TX_TXLPF_IDAC_0 0x74 #define B2056_TX_TXLPF_IDAC_1 0x75 #define B2056_TX_TXLPF_IDAC_2 0x76 #define B2056_TX_TXLPF_IDAC_3 0x77 #define B2056_TX_TXLPF_IDAC_4 0x78 #define B2056_TX_TXLPF_IDAC_5 0x79 #define B2056_TX_TXLPF_IDAC_6 0x7A #define B2056_TX_TXLPF_OPAMP_IDAC 0x7B #define B2056_TX_TXLPF_MISC 0x7C #define B2056_TX_TXSPARE1 0x7D #define B2056_TX_TXSPARE2 0x7E #define B2056_TX_TXSPARE3 0x7F #define B2056_TX_TXSPARE4 0x80 #define B2056_TX_TXSPARE5 0x81 #define B2056_TX_TXSPARE6 0x82 #define B2056_TX_TXSPARE7 0x83 #define B2056_TX_TXSPARE8 0x84 #define B2056_TX_TXSPARE9 0x85 #define B2056_TX_TXSPARE10 0x86 #define B2056_TX_TXSPARE11 0x87 #define B2056_TX_TXSPARE12 0x88 #define B2056_TX_TXSPARE13 0x89 #define B2056_TX_TXSPARE14 0x8A #define B2056_TX_TXSPARE15 0x8B #define B2056_TX_TXSPARE16 0x8C #define B2056_TX_STATUS_INTPA_GAIN 0x8D #define B2056_TX_STATUS_PAD_GAIN 0x8E #define B2056_TX_STATUS_PGA_GAIN 0x8F #define B2056_TX_STATUS_GM_TXLPF_GAIN 0x90 #define B2056_TX_STATUS_TXLPF_BW 0x91 #define B2056_TX_STATUS_TXLPF_RC 0x92 #define B2056_TX_GMBB_IDAC0 0x93 #define B2056_TX_GMBB_IDAC1 0x94 #define B2056_TX_GMBB_IDAC2 0x95 #define B2056_TX_GMBB_IDAC3 0x96 #define B2056_TX_GMBB_IDAC4 0x97 #define B2056_TX_GMBB_IDAC5 0x98 #define B2056_TX_GMBB_IDAC6 0x99 #define B2056_TX_GMBB_IDAC7 0x9A #define B2056_RX_RESERVED_ADDR0 0x00 #define B2056_RX_IDCODE 0x01 #define B2056_RX_RESERVED_ADDR2 0x02 #define B2056_RX_RESERVED_ADDR3 0x03 #define B2056_RX_RESERVED_ADDR4 0x04 #define B2056_RX_RESERVED_ADDR5 0x05 #define B2056_RX_RESERVED_ADDR6 0x06 #define B2056_RX_RESERVED_ADDR7 0x07 #define B2056_RX_COM_CTRL 0x08 #define B2056_RX_COM_PU 0x09 #define B2056_RX_COM_OVR 0x0A #define B2056_RX_COM_RESET 0x0B #define B2056_RX_COM_RCAL 0x0C #define B2056_RX_COM_RC_RXLPF 0x0D #define B2056_RX_COM_RC_TXLPF 0x0E #define B2056_RX_COM_RC_RXHPF 0x0F #define B2056_RX_RESERVED_ADDR16 0x10 #define B2056_RX_RESERVED_ADDR17 0x11 #define B2056_RX_RESERVED_ADDR18 0x12 #define B2056_RX_RESERVED_ADDR19 0x13 #define B2056_RX_RESERVED_ADDR20 0x14 #define B2056_RX_RESERVED_ADDR21 0x15 #define B2056_RX_RESERVED_ADDR22 0x16 #define B2056_RX_RESERVED_ADDR23 0x17 #define B2056_RX_RESERVED_ADDR24 0x18 #define B2056_RX_RESERVED_ADDR25 0x19 #define B2056_RX_RESERVED_ADDR26 0x1A #define B2056_RX_RESERVED_ADDR27 0x1B #define B2056_RX_RESERVED_ADDR28 0x1C #define B2056_RX_RESERVED_ADDR29 0x1D #define B2056_RX_RESERVED_ADDR30 0x1E #define B2056_RX_RESERVED_ADDR31 0x1F #define B2056_RX_RXIQCAL_RXMUX 0x20 #define B2056_RX_RSSI_PU 0x21 #define B2056_RX_RSSI_SEL 0x22 #define B2056_RX_RSSI_GAIN 0x23 #define B2056_RX_RSSI_NB_IDAC 0x24 #define B2056_RX_RSSI_WB2I_IDAC_1 0x25 #define B2056_RX_RSSI_WB2I_IDAC_2 0x26 #define B2056_RX_RSSI_WB2Q_IDAC_1 0x27 #define B2056_RX_RSSI_WB2Q_IDAC_2 0x28 #define B2056_RX_RSSI_POLE 0x29 #define B2056_RX_RSSI_WB1_IDAC 0x2A #define B2056_RX_RSSI_MISC 0x2B #define B2056_RX_LNAA_MASTER 0x2C #define B2056_RX_LNAA_TUNE 0x2D #define B2056_RX_LNAA_GAIN 0x2E #define B2056_RX_LNA_A_SLOPE 0x2F #define B2056_RX_BIASPOLE_LNAA1_IDAC 0x30 #define B2056_RX_LNAA2_IDAC 0x31 #define B2056_RX_LNA1A_MISC 0x32 #define B2056_RX_LNAG_MASTER 0x33 #define B2056_RX_LNAG_TUNE 0x34 #define B2056_RX_LNAG_GAIN 0x35 #define B2056_RX_LNA_G_SLOPE 0x36 #define B2056_RX_BIASPOLE_LNAG1_IDAC 0x37 #define B2056_RX_LNAG2_IDAC 0x38 #define B2056_RX_LNA1G_MISC 0x39 #define B2056_RX_MIXA_MASTER 0x3A #define B2056_RX_MIXA_VCM 0x3B #define B2056_RX_MIXA_CTRLPTAT 0x3C #define B2056_RX_MIXA_LOB_BIAS 0x3D #define B2056_RX_MIXA_CORE_IDAC 0x3E #define B2056_RX_MIXA_CMFB_IDAC 0x3F #define B2056_RX_MIXA_BIAS_AUX 0x40 #define B2056_RX_MIXA_BIAS_MAIN 0x41 #define B2056_RX_MIXA_BIAS_MISC 0x42 #define B2056_RX_MIXA_MAST_BIAS 0x43 #define B2056_RX_MIXG_MASTER 0x44 #define B2056_RX_MIXG_VCM 0x45 #define B2056_RX_MIXG_CTRLPTAT 0x46 #define B2056_RX_MIXG_LOB_BIAS 0x47 #define B2056_RX_MIXG_CORE_IDAC 0x48 #define B2056_RX_MIXG_CMFB_IDAC 0x49 #define B2056_RX_MIXG_BIAS_AUX 0x4A #define B2056_RX_MIXG_BIAS_MAIN 0x4B #define B2056_RX_MIXG_BIAS_MISC 0x4C #define B2056_RX_MIXG_MAST_BIAS 0x4D #define B2056_RX_TIA_MASTER 0x4E #define B2056_RX_TIA_IOPAMP 0x4F #define B2056_RX_TIA_QOPAMP 0x50 #define B2056_RX_TIA_IMISC 0x51 #define B2056_RX_TIA_QMISC 0x52 #define B2056_RX_TIA_GAIN 0x53 #define B2056_RX_TIA_SPARE1 0x54 #define B2056_RX_TIA_SPARE2 0x55 #define B2056_RX_BB_LPF_MASTER 0x56 #define B2056_RX_AACI_MASTER 0x57 #define B2056_RX_RXLPF_IDAC 0x58 #define B2056_RX_RXLPF_OPAMPBIAS_LOWQ 0x59 #define B2056_RX_RXLPF_OPAMPBIAS_HIGHQ 0x5A #define B2056_RX_RXLPF_BIAS_DCCANCEL 0x5B #define B2056_RX_RXLPF_OUTVCM 0x5C #define B2056_RX_RXLPF_INVCM_BODY 0x5D #define B2056_RX_RXLPF_CC_OP 0x5E #define B2056_RX_RXLPF_GAIN 0x5F #define B2056_RX_RXLPF_Q_BW 0x60 #define B2056_RX_RXLPF_HP_CORNER_BW 0x61 #define B2056_RX_RXLPF_RCCAL_HPC 0x62 #define B2056_RX_RXHPF_OFF0 0x63 #define B2056_RX_RXHPF_OFF1 0x64 #define B2056_RX_RXHPF_OFF2 0x65 #define B2056_RX_RXHPF_OFF3 0x66 #define B2056_RX_RXHPF_OFF4 0x67 #define B2056_RX_RXHPF_OFF5 0x68 #define B2056_RX_RXHPF_OFF6 0x69 #define B2056_RX_RXHPF_OFF7 0x6A #define B2056_RX_RXLPF_RCCAL_LPC 0x6B #define B2056_RX_RXLPF_OFF_0 0x6C #define B2056_RX_RXLPF_OFF_1 0x6D #define B2056_RX_RXLPF_OFF_2 0x6E #define B2056_RX_RXLPF_OFF_3 0x6F #define B2056_RX_RXLPF_OFF_4 0x70 #define B2056_RX_UNUSED 0x71 #define B2056_RX_VGA_MASTER 0x72 #define B2056_RX_VGA_BIAS 0x73 #define B2056_RX_VGA_BIAS_DCCANCEL 0x74 #define B2056_RX_VGA_GAIN 0x75 #define B2056_RX_VGA_HP_CORNER_BW 0x76 #define B2056_RX_VGABUF_BIAS 0x77 #define B2056_RX_VGABUF_GAIN_BW 0x78 #define B2056_RX_TXFBMIX_A 0x79 #define B2056_RX_TXFBMIX_G 0x7A #define B2056_RX_RXSPARE1 0x7B #define B2056_RX_RXSPARE2 0x7C #define B2056_RX_RXSPARE3 0x7D #define B2056_RX_RXSPARE4 0x7E #define B2056_RX_RXSPARE5 0x7F #define B2056_RX_RXSPARE6 0x80 #define B2056_RX_RXSPARE7 0x81 #define B2056_RX_RXSPARE8 0x82 #define B2056_RX_RXSPARE9 0x83 #define B2056_RX_RXSPARE10 0x84 #define B2056_RX_RXSPARE11 0x85 #define B2056_RX_RXSPARE12 0x86 #define B2056_RX_RXSPARE13 0x87 #define B2056_RX_RXSPARE14 0x88 #define B2056_RX_RXSPARE15 0x89 #define B2056_RX_RXSPARE16 0x8A #define B2056_RX_STATUS_LNAA_GAIN 0x8B #define B2056_RX_STATUS_LNAG_GAIN 0x8C #define B2056_RX_STATUS_MIXTIA_GAIN 0x8D #define B2056_RX_STATUS_RXLPF_GAIN 0x8E #define B2056_RX_STATUS_VGA_BUF_GAIN 0x8F #define B2056_RX_STATUS_RXLPF_Q 0x90 #define B2056_RX_STATUS_RXLPF_BUF_BW 0x91 #define B2056_RX_STATUS_RXLPF_VGA_HPC 0x92 #define B2056_RX_STATUS_RXLPF_RC 0x93 #define B2056_RX_STATUS_HPC_RC 0x94 #define B2056_LNA1_A_PU 0x01 #define B2056_LNA2_A_PU 0x02 #define B2056_LNA1_G_PU 0x01 #define B2056_LNA2_G_PU 0x02 #define B2056_MIXA_PU_I 0x01 #define B2056_MIXA_PU_Q 0x02 #define B2056_MIXA_PU_GM 0x10 #define B2056_MIXG_PU_I 0x01 #define B2056_MIXG_PU_Q 0x02 #define B2056_MIXG_PU_GM 0x10 #define B2056_TIA_PU 0x01 #define B2056_BB_LPF_PU 0x20 #define B2056_W1_PU 0x02 #define B2056_W2_PU 0x04 #define B2056_NB_PU 0x08 #define B2056_RSSI_W1_SEL 0x02 #define B2056_RSSI_W2_SEL 0x04 #define B2056_RSSI_NB_SEL 0x08 #define B2056_VCM_MASK 0x1C #define B2056_RSSI_VCM_SHIFT 0x02 #define B2056_SYN (0x0 << 12) #define B2056_TX0 (0x2 << 12) #define B2056_TX1 (0x3 << 12) #define B2056_RX0 (0x6 << 12) #define B2056_RX1 (0x7 << 12) #define B2056_ALLTX (0xE << 12) #define B2056_ALLRX (0xF << 12) #define B2056_SYN_RESERVED_ADDR0 0x00 #define B2056_SYN_IDCODE 0x01 #define B2056_SYN_RESERVED_ADDR2 0x02 #define B2056_SYN_RESERVED_ADDR3 0x03 #define B2056_SYN_RESERVED_ADDR4 0x04 #define B2056_SYN_RESERVED_ADDR5 0x05 #define B2056_SYN_RESERVED_ADDR6 0x06 #define B2056_SYN_RESERVED_ADDR7 0x07 #define B2056_SYN_COM_CTRL 0x08 #define B2056_SYN_COM_PU 0x09 #define B2056_SYN_COM_OVR 0x0A #define B2056_SYN_COM_RESET 0x0B #define B2056_SYN_COM_RCAL 0x0C #define B2056_SYN_COM_RC_RXLPF 0x0D #define B2056_SYN_COM_RC_TXLPF 0x0E #define B2056_SYN_COM_RC_RXHPF 0x0F #define B2056_SYN_RESERVED_ADDR16 0x10 #define B2056_SYN_RESERVED_ADDR17 0x11 #define B2056_SYN_RESERVED_ADDR18 0x12 #define B2056_SYN_RESERVED_ADDR19 0x13 #define B2056_SYN_RESERVED_ADDR20 0x14 #define B2056_SYN_RESERVED_ADDR21 0x15 #define B2056_SYN_RESERVED_ADDR22 0x16 #define B2056_SYN_RESERVED_ADDR23 0x17 #define B2056_SYN_RESERVED_ADDR24 0x18 #define B2056_SYN_RESERVED_ADDR25 0x19 #define B2056_SYN_RESERVED_ADDR26 0x1A #define B2056_SYN_RESERVED_ADDR27 0x1B #define B2056_SYN_RESERVED_ADDR28 0x1C #define B2056_SYN_RESERVED_ADDR29 0x1D #define B2056_SYN_RESERVED_ADDR30 0x1E #define B2056_SYN_RESERVED_ADDR31 0x1F #define B2056_SYN_GPIO_MASTER1 0x20 #define B2056_SYN_GPIO_MASTER2 0x21 #define B2056_SYN_TOPBIAS_MASTER 0x22 #define B2056_SYN_TOPBIAS_RCAL 0x23 #define B2056_SYN_AFEREG 0x24 #define B2056_SYN_TEMPPROCSENSE 0x25 #define B2056_SYN_TEMPPROCSENSEIDAC 0x26 #define B2056_SYN_TEMPPROCSENSERCAL 0x27 #define B2056_SYN_LPO 0x28 #define B2056_SYN_VDDCAL_MASTER 0x29 #define B2056_SYN_VDDCAL_IDAC 0x2A #define B2056_SYN_VDDCAL_STATUS 0x2B #define B2056_SYN_RCAL_MASTER 0x2C #define B2056_SYN_RCAL_CODE_OUT 0x2D #define B2056_SYN_RCCAL_CTRL0 0x2E #define B2056_SYN_RCCAL_CTRL1 0x2F #define B2056_SYN_RCCAL_CTRL2 0x30 #define B2056_SYN_RCCAL_CTRL3 0x31 #define B2056_SYN_RCCAL_CTRL4 0x32 #define B2056_SYN_RCCAL_CTRL5 0x33 #define B2056_SYN_RCCAL_CTRL6 0x34 #define B2056_SYN_RCCAL_CTRL7 0x35 #define B2056_SYN_RCCAL_CTRL8 0x36 #define B2056_SYN_RCCAL_CTRL9 0x37 #define B2056_SYN_RCCAL_CTRL10 0x38 #define B2056_SYN_RCCAL_CTRL11 0x39 #define B2056_SYN_ZCAL_SPARE1 0x3A #define B2056_SYN_ZCAL_SPARE2 0x3B #define B2056_SYN_PLL_MAST1 0x3C #define B2056_SYN_PLL_MAST2 0x3D #define B2056_SYN_PLL_MAST3 0x3E #define B2056_SYN_PLL_BIAS_RESET 0x3F #define B2056_SYN_PLL_XTAL0 0x40 #define B2056_SYN_PLL_XTAL1 0x41 #define B2056_SYN_PLL_XTAL3 0x42 #define B2056_SYN_PLL_XTAL4 0x43 #define B2056_SYN_PLL_XTAL5 0x44 #define B2056_SYN_PLL_XTAL6 0x45 #define B2056_SYN_PLL_REFDIV 0x46 #define B2056_SYN_PLL_PFD 0x47 #define B2056_SYN_PLL_CP1 0x48 #define B2056_SYN_PLL_CP2 0x49 #define B2056_SYN_PLL_CP3 0x4A #define B2056_SYN_PLL_LOOPFILTER1 0x4B #define B2056_SYN_PLL_LOOPFILTER2 0x4C #define B2056_SYN_PLL_LOOPFILTER3 0x4D #define B2056_SYN_PLL_LOOPFILTER4 0x4E #define B2056_SYN_PLL_LOOPFILTER5 0x4F #define B2056_SYN_PLL_MMD1 0x50 #define B2056_SYN_PLL_MMD2 0x51 #define B2056_SYN_PLL_VCO1 0x52 #define B2056_SYN_PLL_VCO2 0x53 #define B2056_SYN_PLL_MONITOR1 0x54 #define B2056_SYN_PLL_MONITOR2 0x55 #define B2056_SYN_PLL_VCOCAL1 0x56 #define B2056_SYN_PLL_VCOCAL2 0x57 #define B2056_SYN_PLL_VCOCAL4 0x58 #define B2056_SYN_PLL_VCOCAL5 0x59 #define B2056_SYN_PLL_VCOCAL6 0x5A #define B2056_SYN_PLL_VCOCAL7 0x5B #define B2056_SYN_PLL_VCOCAL8 0x5C #define B2056_SYN_PLL_VCOCAL9 0x5D #define B2056_SYN_PLL_VCOCAL10 0x5E #define B2056_SYN_PLL_VCOCAL11 0x5F #define B2056_SYN_PLL_VCOCAL12 0x60 #define B2056_SYN_PLL_VCOCAL13 0x61 #define B2056_SYN_PLL_VREG 0x62 #define B2056_SYN_PLL_STATUS1 0x63 #define B2056_SYN_PLL_STATUS2 0x64 #define B2056_SYN_PLL_STATUS3 0x65 #define B2056_SYN_LOGEN_PU0 0x66 #define B2056_SYN_LOGEN_PU1 0x67 #define B2056_SYN_LOGEN_PU2 0x68 #define B2056_SYN_LOGEN_PU3 0x69 #define B2056_SYN_LOGEN_PU5 0x6A #define B2056_SYN_LOGEN_PU6 0x6B #define B2056_SYN_LOGEN_PU7 0x6C #define B2056_SYN_LOGEN_PU8 0x6D #define B2056_SYN_LOGEN_BIAS_RESET 0x6E #define B2056_SYN_LOGEN_RCCR1 0x6F #define B2056_SYN_LOGEN_VCOBUF1 0x70 #define B2056_SYN_LOGEN_MIXER1 0x71 #define B2056_SYN_LOGEN_MIXER2 0x72 #define B2056_SYN_LOGEN_BUF1 0x73 #define B2056_SYN_LOGENBUF2 0x74 #define B2056_SYN_LOGEN_BUF3 0x75 #define B2056_SYN_LOGEN_BUF4 0x76 #define B2056_SYN_LOGEN_DIV1 0x77 #define B2056_SYN_LOGEN_DIV2 0x78 #define B2056_SYN_LOGEN_DIV3 0x79 #define B2056_SYN_LOGEN_ACL1 0x7A #define B2056_SYN_LOGEN_ACL2 0x7B #define B2056_SYN_LOGEN_ACL3 0x7C #define B2056_SYN_LOGEN_ACL4 0x7D #define B2056_SYN_LOGEN_ACL5 0x7E #define B2056_SYN_LOGEN_ACL6 0x7F #define B2056_SYN_LOGEN_ACLOUT 0x80 #define B2056_SYN_LOGEN_ACLCAL1 0x81 #define B2056_SYN_LOGEN_ACLCAL2 0x82 #define B2056_SYN_LOGEN_ACLCAL3 0x83 #define B2056_SYN_CALEN 0x84 #define B2056_SYN_LOGEN_PEAKDET1 0x85 #define B2056_SYN_LOGEN_CORE_ACL_OVR 0x86 #define B2056_SYN_LOGEN_RX_DIFF_ACL_OVR 0x87 #define B2056_SYN_LOGEN_TX_DIFF_ACL_OVR 0x88 #define B2056_SYN_LOGEN_RX_CMOS_ACL_OVR 0x89 #define B2056_SYN_LOGEN_TX_CMOS_ACL_OVR 0x8A #define B2056_SYN_LOGEN_VCOBUF2 0x8B #define B2056_SYN_LOGEN_MIXER3 0x8C #define B2056_SYN_LOGEN_BUF5 0x8D #define B2056_SYN_LOGEN_BUF6 0x8E #define B2056_SYN_LOGEN_CBUFRX1 0x8F #define B2056_SYN_LOGEN_CBUFRX2 0x90 #define B2056_SYN_LOGEN_CBUFRX3 0x91 #define B2056_SYN_LOGEN_CBUFRX4 0x92 #define B2056_SYN_LOGEN_CBUFTX1 0x93 #define B2056_SYN_LOGEN_CBUFTX2 0x94 #define B2056_SYN_LOGEN_CBUFTX3 0x95 #define B2056_SYN_LOGEN_CBUFTX4 0x96 #define B2056_SYN_LOGEN_CMOSRX1 0x97 #define B2056_SYN_LOGEN_CMOSRX2 0x98 #define B2056_SYN_LOGEN_CMOSRX3 0x99 #define B2056_SYN_LOGEN_CMOSRX4 0x9A #define B2056_SYN_LOGEN_CMOSTX1 0x9B #define B2056_SYN_LOGEN_CMOSTX2 0x9C #define B2056_SYN_LOGEN_CMOSTX3 0x9D #define B2056_SYN_LOGEN_CMOSTX4 0x9E #define B2056_SYN_LOGEN_VCOBUF2_OVRVAL 0x9F #define B2056_SYN_LOGEN_MIXER3_OVRVAL 0xA0 #define B2056_SYN_LOGEN_BUF5_OVRVAL 0xA1 #define B2056_SYN_LOGEN_BUF6_OVRVAL 0xA2 #define B2056_SYN_LOGEN_CBUFRX1_OVRVAL 0xA3 #define B2056_SYN_LOGEN_CBUFRX2_OVRVAL 0xA4 #define B2056_SYN_LOGEN_CBUFRX3_OVRVAL 0xA5 #define B2056_SYN_LOGEN_CBUFRX4_OVRVAL 0xA6 #define B2056_SYN_LOGEN_CBUFTX1_OVRVAL 0xA7 #define B2056_SYN_LOGEN_CBUFTX2_OVRVAL 0xA8 #define B2056_SYN_LOGEN_CBUFTX3_OVRVAL 0xA9 #define B2056_SYN_LOGEN_CBUFTX4_OVRVAL 0xAA #define B2056_SYN_LOGEN_CMOSRX1_OVRVAL 0xAB #define B2056_SYN_LOGEN_CMOSRX2_OVRVAL 0xAC #define B2056_SYN_LOGEN_CMOSRX3_OVRVAL 0xAD #define B2056_SYN_LOGEN_CMOSRX4_OVRVAL 0xAE #define B2056_SYN_LOGEN_CMOSTX1_OVRVAL 0xAF #define B2056_SYN_LOGEN_CMOSTX2_OVRVAL 0xB0 #define B2056_SYN_LOGEN_CMOSTX3_OVRVAL 0xB1 #define B2056_SYN_LOGEN_CMOSTX4_OVRVAL 0xB2 #define B2056_SYN_LOGEN_ACL_WAITCNT 0xB3 #define B2056_SYN_LOGEN_CORE_CALVALID 0xB4 #define B2056_SYN_LOGEN_RX_CMOS_CALVALID 0xB5 #define B2056_SYN_LOGEN_TX_CMOS_VALID 0xB6 #define B2056_TX_RESERVED_ADDR0 0x00 #define B2056_TX_IDCODE 0x01 #define B2056_TX_RESERVED_ADDR2 0x02 #define B2056_TX_RESERVED_ADDR3 0x03 #define B2056_TX_RESERVED_ADDR4 0x04 #define B2056_TX_RESERVED_ADDR5 0x05 #define B2056_TX_RESERVED_ADDR6 0x06 #define B2056_TX_RESERVED_ADDR7 0x07 #define B2056_TX_COM_CTRL 0x08 #define B2056_TX_COM_PU 0x09 #define B2056_TX_COM_OVR 0x0A #define B2056_TX_COM_RESET 0x0B #define B2056_TX_COM_RCAL 0x0C #define B2056_TX_COM_RC_RXLPF 0x0D #define B2056_TX_COM_RC_TXLPF 0x0E #define B2056_TX_COM_RC_RXHPF 0x0F #define B2056_TX_RESERVED_ADDR16 0x10 #define B2056_TX_RESERVED_ADDR17 0x11 #define B2056_TX_RESERVED_ADDR18 0x12 #define B2056_TX_RESERVED_ADDR19 0x13 #define B2056_TX_RESERVED_ADDR20 0x14 #define B2056_TX_RESERVED_ADDR21 0x15 #define B2056_TX_RESERVED_ADDR22 0x16 #define B2056_TX_RESERVED_ADDR23 0x17 #define B2056_TX_RESERVED_ADDR24 0x18 #define B2056_TX_RESERVED_ADDR25 0x19 #define B2056_TX_RESERVED_ADDR26 0x1A #define B2056_TX_RESERVED_ADDR27 0x1B #define B2056_TX_RESERVED_ADDR28 0x1C #define B2056_TX_RESERVED_ADDR29 0x1D #define B2056_TX_RESERVED_ADDR30 0x1E #define B2056_TX_RESERVED_ADDR31 0x1F #define B2056_TX_IQCAL_GAIN_BW 0x20 #define B2056_TX_LOFT_FINE_I 0x21 #define B2056_TX_LOFT_FINE_Q 0x22 #define B2056_TX_LOFT_COARSE_I 0x23 #define B2056_TX_LOFT_COARSE_Q 0x24 #define B2056_TX_TX_COM_MASTER1 0x25 #define B2056_TX_TX_COM_MASTER2 0x26 #define B2056_TX_RXIQCAL_TXMUX 0x27 #define B2056_TX_TX_SSI_MASTER 0x28 #define B2056_TX_IQCAL_VCM_HG 0x29 #define B2056_TX_IQCAL_IDAC 0x2A #define B2056_TX_TSSI_VCM 0x2B #define B2056_TX_TX_AMP_DET 0x2C #define B2056_TX_TX_SSI_MUX 0x2D #define B2056_TX_TSSIA 0x2E #define B2056_TX_TSSIG 0x2F #define B2056_TX_TSSI_MISC1 0x30 #define B2056_TX_TSSI_MISC2 0x31 #define B2056_TX_TSSI_MISC3 0x32 #define B2056_TX_PA_SPARE1 0x33 #define B2056_TX_PA_SPARE2 0x34 #define B2056_TX_INTPAA_MASTER 0x35 #define B2056_TX_INTPAA_GAIN 0x36 #define B2056_TX_INTPAA_BOOST_TUNE 0x37 #define B2056_TX_INTPAA_IAUX_STAT 0x38 #define B2056_TX_INTPAA_IAUX_DYN 0x39 #define B2056_TX_INTPAA_IMAIN_STAT 0x3A #define B2056_TX_INTPAA_IMAIN_DYN 0x3B #define B2056_TX_INTPAA_CASCBIAS 0x3C #define B2056_TX_INTPAA_PASLOPE 0x3D #define B2056_TX_INTPAA_PA_MISC 0x3E #define B2056_TX_INTPAG_MASTER 0x3F #define B2056_TX_INTPAG_GAIN 0x40 #define B2056_TX_INTPAG_BOOST_TUNE 0x41 #define B2056_TX_INTPAG_IAUX_STAT 0x42 #define B2056_TX_INTPAG_IAUX_DYN 0x43 #define B2056_TX_INTPAG_IMAIN_STAT 0x44 #define B2056_TX_INTPAG_IMAIN_DYN 0x45 #define B2056_TX_INTPAG_CASCBIAS 0x46 #define B2056_TX_INTPAG_PASLOPE 0x47 #define B2056_TX_INTPAG_PA_MISC 0x48 #define B2056_TX_PADA_MASTER 0x49 #define B2056_TX_PADA_IDAC 0x4A #define B2056_TX_PADA_CASCBIAS 0x4B #define B2056_TX_PADA_GAIN 0x4C #define B2056_TX_PADA_BOOST_TUNE 0x4D #define B2056_TX_PADA_SLOPE 0x4E #define B2056_TX_PADG_MASTER 0x4F #define B2056_TX_PADG_IDAC 0x50 #define B2056_TX_PADG_CASCBIAS 0x51 #define B2056_TX_PADG_GAIN 0x52 #define B2056_TX_PADG_BOOST_TUNE 0x53 #define B2056_TX_PADG_SLOPE 0x54 #define B2056_TX_PGAA_MASTER 0x55 #define B2056_TX_PGAA_IDAC 0x56 #define B2056_TX_PGAA_GAIN 0x57 #define B2056_TX_PGAA_BOOST_TUNE 0x58 #define B2056_TX_PGAA_SLOPE 0x59 #define B2056_TX_PGAA_MISC 0x5A #define B2056_TX_PGAG_MASTER 0x5B #define B2056_TX_PGAG_IDAC 0x5C #define B2056_TX_PGAG_GAIN 0x5D #define B2056_TX_PGAG_BOOST_TUNE 0x5E #define B2056_TX_PGAG_SLOPE 0x5F #define B2056_TX_PGAG_MISC 0x60 #define B2056_TX_MIXA_MASTER 0x61 #define B2056_TX_MIXA_BOOST_TUNE 0x62 #define B2056_TX_MIXG 0x63 #define B2056_TX_MIXG_BOOST_TUNE 0x64 #define B2056_TX_BB_GM_MASTER 0x65 #define B2056_TX_GMBB_GM 0x66 #define B2056_TX_GMBB_IDAC 0x67 #define B2056_TX_TXLPF_MASTER 0x68 #define B2056_TX_TXLPF_RCCAL 0x69 #define B2056_TX_TXLPF_RCCAL_OFF0 0x6A #define B2056_TX_TXLPF_RCCAL_OFF1 0x6B #define B2056_TX_TXLPF_RCCAL_OFF2 0x6C #define B2056_TX_TXLPF_RCCAL_OFF3 0x6D #define B2056_TX_TXLPF_RCCAL_OFF4 0x6E #define B2056_TX_TXLPF_RCCAL_OFF5 0x6F #define B2056_TX_TXLPF_RCCAL_OFF6 0x70 #define B2056_TX_TXLPF_BW 0x71 #define B2056_TX_TXLPF_GAIN 0x72 #define B2056_TX_TXLPF_IDAC 0x73 #define B2056_TX_TXLPF_IDAC_0 0x74 #define B2056_TX_TXLPF_IDAC_1 0x75 #define B2056_TX_TXLPF_IDAC_2 0x76 #define B2056_TX_TXLPF_IDAC_3 0x77 #define B2056_TX_TXLPF_IDAC_4 0x78 #define B2056_TX_TXLPF_IDAC_5 0x79 #define B2056_TX_TXLPF_IDAC_6 0x7A #define B2056_TX_TXLPF_OPAMP_IDAC 0x7B #define B2056_TX_TXLPF_MISC 0x7C #define B2056_TX_TXSPARE1 0x7D #define B2056_TX_TXSPARE2 0x7E #define B2056_TX_TXSPARE3 0x7F #define B2056_TX_TXSPARE4 0x80 #define B2056_TX_TXSPARE5 0x81 #define B2056_TX_TXSPARE6 0x82 #define B2056_TX_TXSPARE7 0x83 #define B2056_TX_TXSPARE8 0x84 #define B2056_TX_TXSPARE9 0x85 #define B2056_TX_TXSPARE10 0x86 #define B2056_TX_TXSPARE11 0x87 #define B2056_TX_TXSPARE12 0x88 #define B2056_TX_TXSPARE13 0x89 #define B2056_TX_TXSPARE14 0x8A #define B2056_TX_TXSPARE15 0x8B #define B2056_TX_TXSPARE16 0x8C #define B2056_TX_STATUS_INTPA_GAIN 0x8D #define B2056_TX_STATUS_PAD_GAIN 0x8E #define B2056_TX_STATUS_PGA_GAIN 0x8F #define B2056_TX_STATUS_GM_TXLPF_GAIN 0x90 #define B2056_TX_STATUS_TXLPF_BW 0x91 #define B2056_TX_STATUS_TXLPF_RC 0x92 #define B2056_TX_GMBB_IDAC0 0x93 #define B2056_TX_GMBB_IDAC1 0x94 #define B2056_TX_GMBB_IDAC2 0x95 #define B2056_TX_GMBB_IDAC3 0x96 #define B2056_TX_GMBB_IDAC4 0x97 #define B2056_TX_GMBB_IDAC5 0x98 #define B2056_TX_GMBB_IDAC6 0x99 #define B2056_TX_GMBB_IDAC7 0x9A #define B2056_RX_RESERVED_ADDR0 0x00 #define B2056_RX_IDCODE 0x01 #define B2056_RX_RESERVED_ADDR2 0x02 #define B2056_RX_RESERVED_ADDR3 0x03 #define B2056_RX_RESERVED_ADDR4 0x04 #define B2056_RX_RESERVED_ADDR5 0x05 #define B2056_RX_RESERVED_ADDR6 0x06 #define B2056_RX_RESERVED_ADDR7 0x07 #define B2056_RX_COM_CTRL 0x08 #define B2056_RX_COM_PU 0x09 #define B2056_RX_COM_OVR 0x0A #define B2056_RX_COM_RESET 0x0B #define B2056_RX_COM_RCAL 0x0C #define B2056_RX_COM_RC_RXLPF 0x0D #define B2056_RX_COM_RC_TXLPF 0x0E #define B2056_RX_COM_RC_RXHPF 0x0F #define B2056_RX_RESERVED_ADDR16 0x10 #define B2056_RX_RESERVED_ADDR17 0x11 #define B2056_RX_RESERVED_ADDR18 0x12 #define B2056_RX_RESERVED_ADDR19 0x13 #define B2056_RX_RESERVED_ADDR20 0x14 #define B2056_RX_RESERVED_ADDR21 0x15 #define B2056_RX_RESERVED_ADDR22 0x16 #define B2056_RX_RESERVED_ADDR23 0x17 #define B2056_RX_RESERVED_ADDR24 0x18 #define B2056_RX_RESERVED_ADDR25 0x19 #define B2056_RX_RESERVED_ADDR26 0x1A #define B2056_RX_RESERVED_ADDR27 0x1B #define B2056_RX_RESERVED_ADDR28 0x1C #define B2056_RX_RESERVED_ADDR29 0x1D #define B2056_RX_RESERVED_ADDR30 0x1E #define B2056_RX_RESERVED_ADDR31 0x1F #define B2056_RX_RXIQCAL_RXMUX 0x20 #define B2056_RX_RSSI_PU 0x21 #define B2056_RX_RSSI_SEL 0x22 #define B2056_RX_RSSI_GAIN 0x23 #define B2056_RX_RSSI_NB_IDAC 0x24 #define B2056_RX_RSSI_WB2I_IDAC_1 0x25 #define B2056_RX_RSSI_WB2I_IDAC_2 0x26 #define B2056_RX_RSSI_WB2Q_IDAC_1 0x27 #define B2056_RX_RSSI_WB2Q_IDAC_2 0x28 #define B2056_RX_RSSI_POLE 0x29 #define B2056_RX_RSSI_WB1_IDAC 0x2A #define B2056_RX_RSSI_MISC 0x2B #define B2056_RX_LNAA_MASTER 0x2C #define B2056_RX_LNAA_TUNE 0x2D #define B2056_RX_LNAA_GAIN 0x2E #define B2056_RX_LNA_A_SLOPE 0x2F #define B2056_RX_BIASPOLE_LNAA1_IDAC 0x30 #define B2056_RX_LNAA2_IDAC 0x31 #define B2056_RX_LNA1A_MISC 0x32 #define B2056_RX_LNAG_MASTER 0x33 #define B2056_RX_LNAG_TUNE 0x34 #define B2056_RX_LNAG_GAIN 0x35 #define B2056_RX_LNA_G_SLOPE 0x36 #define B2056_RX_BIASPOLE_LNAG1_IDAC 0x37 #define B2056_RX_LNAG2_IDAC 0x38 #define B2056_RX_LNA1G_MISC 0x39 #define B2056_RX_MIXA_MASTER 0x3A #define B2056_RX_MIXA_VCM 0x3B #define B2056_RX_MIXA_CTRLPTAT 0x3C #define B2056_RX_MIXA_LOB_BIAS 0x3D #define B2056_RX_MIXA_CORE_IDAC 0x3E #define B2056_RX_MIXA_CMFB_IDAC 0x3F #define B2056_RX_MIXA_BIAS_AUX 0x40 #define B2056_RX_MIXA_BIAS_MAIN 0x41 #define B2056_RX_MIXA_BIAS_MISC 0x42 #define B2056_RX_MIXA_MAST_BIAS 0x43 #define B2056_RX_MIXG_MASTER 0x44 #define B2056_RX_MIXG_VCM 0x45 #define B2056_RX_MIXG_CTRLPTAT 0x46 #define B2056_RX_MIXG_LOB_BIAS 0x47 #define B2056_RX_MIXG_CORE_IDAC 0x48 #define B2056_RX_MIXG_CMFB_IDAC 0x49 #define B2056_RX_MIXG_BIAS_AUX 0x4A #define B2056_RX_MIXG_BIAS_MAIN 0x4B #define B2056_RX_MIXG_BIAS_MISC 0x4C #define B2056_RX_MIXG_MAST_BIAS 0x4D #define B2056_RX_TIA_MASTER 0x4E #define B2056_RX_TIA_IOPAMP 0x4F #define B2056_RX_TIA_QOPAMP 0x50 #define B2056_RX_TIA_IMISC 0x51 #define B2056_RX_TIA_QMISC 0x52 #define B2056_RX_TIA_GAIN 0x53 #define B2056_RX_TIA_SPARE1 0x54 #define B2056_RX_TIA_SPARE2 0x55 #define B2056_RX_BB_LPF_MASTER 0x56 #define B2056_RX_AACI_MASTER 0x57 #define B2056_RX_RXLPF_IDAC 0x58 #define B2056_RX_RXLPF_OPAMPBIAS_LOWQ 0x59 #define B2056_RX_RXLPF_OPAMPBIAS_HIGHQ 0x5A #define B2056_RX_RXLPF_BIAS_DCCANCEL 0x5B #define B2056_RX_RXLPF_OUTVCM 0x5C #define B2056_RX_RXLPF_INVCM_BODY 0x5D #define B2056_RX_RXLPF_CC_OP 0x5E #define B2056_RX_RXLPF_GAIN 0x5F #define B2056_RX_RXLPF_Q_BW 0x60 #define B2056_RX_RXLPF_HP_CORNER_BW 0x61 #define B2056_RX_RXLPF_RCCAL_HPC 0x62 #define B2056_RX_RXHPF_OFF0 0x63 #define B2056_RX_RXHPF_OFF1 0x64 #define B2056_RX_RXHPF_OFF2 0x65 #define B2056_RX_RXHPF_OFF3 0x66 #define B2056_RX_RXHPF_OFF4 0x67 #define B2056_RX_RXHPF_OFF5 0x68 #define B2056_RX_RXHPF_OFF6 0x69 #define B2056_RX_RXHPF_OFF7 0x6A #define B2056_RX_RXLPF_RCCAL_LPC 0x6B #define B2056_RX_RXLPF_OFF_0 0x6C #define B2056_RX_RXLPF_OFF_1 0x6D #define B2056_RX_RXLPF_OFF_2 0x6E #define B2056_RX_RXLPF_OFF_3 0x6F #define B2056_RX_RXLPF_OFF_4 0x70 #define B2056_RX_UNUSED 0x71 #define B2056_RX_VGA_MASTER 0x72 #define B2056_RX_VGA_BIAS 0x73 #define B2056_RX_VGA_BIAS_DCCANCEL 0x74 #define B2056_RX_VGA_GAIN 0x75 #define B2056_RX_VGA_HP_CORNER_BW 0x76 #define B2056_RX_VGABUF_BIAS 0x77 #define B2056_RX_VGABUF_GAIN_BW 0x78 #define B2056_RX_TXFBMIX_A 0x79 #define B2056_RX_TXFBMIX_G 0x7A #define B2056_RX_RXSPARE1 0x7B #define B2056_RX_RXSPARE2 0x7C #define B2056_RX_RXSPARE3 0x7D #define B2056_RX_RXSPARE4 0x7E #define B2056_RX_RXSPARE5 0x7F #define B2056_RX_RXSPARE6 0x80 #define B2056_RX_RXSPARE7 0x81 #define B2056_RX_RXSPARE8 0x82 #define B2056_RX_RXSPARE9 0x83 #define B2056_RX_RXSPARE10 0x84 #define B2056_RX_RXSPARE11 0x85 #define B2056_RX_RXSPARE12 0x86 #define B2056_RX_RXSPARE13 0x87 #define B2056_RX_RXSPARE14 0x88 #define B2056_RX_RXSPARE15 0x89 #define B2056_RX_RXSPARE16 0x8A #define B2056_RX_STATUS_LNAA_GAIN 0x8B #define B2056_RX_STATUS_LNAG_GAIN 0x8C #define B2056_RX_STATUS_MIXTIA_GAIN 0x8D #define B2056_RX_STATUS_RXLPF_GAIN 0x8E #define B2056_RX_STATUS_VGA_BUF_GAIN 0x8F #define B2056_RX_STATUS_RXLPF_Q 0x90 #define B2056_RX_STATUS_RXLPF_BUF_BW 0x91 #define B2056_RX_STATUS_RXLPF_VGA_HPC 0x92 #define B2056_RX_STATUS_RXLPF_RC 0x93 #define B2056_RX_STATUS_HPC_RC 0x94 #define B2056_LNA1_A_PU 0x01 #define B2056_LNA2_A_PU 0x02 #define B2056_LNA1_G_PU 0x01 #define B2056_LNA2_G_PU 0x02 #define B2056_MIXA_PU_I 0x01 #define B2056_MIXA_PU_Q 0x02 #define B2056_MIXA_PU_GM 0x10 #define B2056_MIXG_PU_I 0x01 #define B2056_MIXG_PU_Q 0x02 #define B2056_MIXG_PU_GM 0x10 #define B2056_TIA_PU 0x01 #define B2056_BB_LPF_PU 0x20 #define B2056_W1_PU 0x02 #define B2056_W2_PU 0x04 #define B2056_NB_PU 0x08 #define B2056_RSSI_W1_SEL 0x02 #define B2056_RSSI_W2_SEL 0x04 #define B2056_RSSI_NB_SEL 0x08 #define B2056_VCM_MASK 0x1C #define B2056_RSSI_VCM_SHIFT 0x02 struct b43_nphy_channeltab_entry_rev3 { /* The channel frequency in MHz */ u16 freq; /* Radio register values on channelswitch */ u8 radio_syn_pll_vcocal1; u8 radio_syn_pll_vcocal2; u8 radio_syn_pll_refdiv; u8 radio_syn_pll_mmd2; u8 radio_syn_pll_mmd1; u8 radio_syn_pll_loopfilter1; u8 radio_syn_pll_loopfilter2; u8 radio_syn_pll_loopfilter3; u8 radio_syn_pll_loopfilter4; u8 radio_syn_pll_loopfilter5; u8 radio_syn_reserved_addr27; u8 radio_syn_reserved_addr28; u8 radio_syn_reserved_addr29; u8 radio_syn_logen_vcobuf1; u8 radio_syn_logen_mixer2; u8 radio_syn_logen_buf3; u8 radio_syn_logen_buf4; u8 radio_rx0_lnaa_tune; u8 radio_rx0_lnag_tune; u8 radio_tx0_intpaa_boost_tune; u8 radio_tx0_intpag_boost_tune; u8 radio_tx0_pada_boost_tune; u8 radio_tx0_padg_boost_tune; u8 radio_tx0_pgaa_boost_tune; u8 radio_tx0_pgag_boost_tune; u8 radio_tx0_mixa_boost_tune; u8 radio_tx0_mixg_boost_tune; u8 radio_rx1_lnaa_tune; u8 radio_rx1_lnag_tune; u8 radio_tx1_intpaa_boost_tune; u8 radio_tx1_intpag_boost_tune; u8 radio_tx1_pada_boost_tune; u8 radio_tx1_padg_boost_tune; u8 radio_tx1_pgaa_boost_tune; u8 radio_tx1_pgag_boost_tune; u8 radio_tx1_mixa_boost_tune; u8 radio_tx1_mixg_boost_tune; /* PHY register values on channelswitch */ struct b43_phy_n_sfo_cfg phy_regs; }; void b2056_upload_inittabs(struct b43_wldev *dev, bool ghz5, bool ignore_uploadflag); #endif /* B43_RADIO_2056_H_ */
{ "language": "C" }
#ifndef LIBQOS_USB_H #define LIBQOS_USB_H #include "libqos/pci-pc.h" struct qhc { QPCIDevice *dev; QPCIBar bar; }; void qusb_pci_init_one(QPCIBus *pcibus, struct qhc *hc, uint32_t devfn, int bar); void uhci_port_test(struct qhc *hc, int port, uint16_t expect); void uhci_deinit(struct qhc *hc); void usb_test_hotplug(const char *bus_name, const char *port, void (*port_check)(void)); #endif
{ "language": "C" }
/* Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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. */ /* * See the paper "On Randomness" by Ben Laurie for an explanation of this PRNG. * http://www.apache-ssl.org/randomness.pdf * XXX: Is there a formal proof of this PRNG? Couldn't we use the more popular * Mersenne Twister PRNG (and BSD licensed)? */ #include "apr.h" #include "apr_pools.h" #include "apr_random.h" #include "apr_thread_proc.h" #include <assert.h> #ifdef min #undef min #endif #define min(a,b) ((a) < (b) ? (a) : (b)) #define APR_RANDOM_DEFAULT_POOLS 32 #define APR_RANDOM_DEFAULT_REHASH_SIZE 1024 #define APR_RANDOM_DEFAULT_RESEED_SIZE 32 #define APR_RANDOM_DEFAULT_HASH_SECRET_SIZE 32 #define APR_RANDOM_DEFAULT_G_FOR_INSECURE 32 #define APR_RANDOM_DEFAULT_G_FOR_SECURE 320 typedef struct apr_random_pool_t { unsigned char *pool; unsigned int bytes; unsigned int pool_size; } apr_random_pool_t; #define hash_init(h) (h)->init(h) #define hash_add(h,b,n) (h)->add(h,b,n) #define hash_finish(h,r) (h)->finish(h,r) #define hash(h,r,b,n) hash_init(h),hash_add(h,b,n),hash_finish(h,r) #define crypt_setkey(c,k) (c)->set_key((c)->data,k) #define crypt_crypt(c,out,in) (c)->crypt((c)->date,out,in) struct apr_random_t { apr_pool_t *apr_pool; apr_crypto_hash_t *pool_hash; unsigned int npools; apr_random_pool_t *pools; unsigned int next_pool; unsigned int generation; apr_size_t rehash_size; apr_size_t reseed_size; apr_crypto_hash_t *key_hash; #define K_size(g) ((g)->key_hash->size) apr_crypto_hash_t *prng_hash; #define B_size(g) ((g)->prng_hash->size) unsigned char *H; unsigned char *H_waiting; #define H_size(g) (B_size(g)+K_size(g)) #define H_current(g) (((g)->insecure_started && !(g)->secure_started) \ ? (g)->H_waiting : (g)->H) unsigned char *randomness; apr_size_t random_bytes; unsigned int g_for_insecure; unsigned int g_for_secure; unsigned int secure_base; unsigned int insecure_started:1; unsigned int secure_started:1; apr_random_t *next; }; static apr_random_t *all_random; static apr_status_t random_cleanup(void *data) { apr_random_t *remove_this = data, *cur = all_random, **prev_ptr = &all_random; while (cur) { if (cur == remove_this) { *prev_ptr = cur->next; break; } prev_ptr = &cur->next; cur = cur->next; } return APR_SUCCESS; } APR_DECLARE(void) apr_random_init(apr_random_t *g,apr_pool_t *p, apr_crypto_hash_t *pool_hash, apr_crypto_hash_t *key_hash, apr_crypto_hash_t *prng_hash) { unsigned int n; g->apr_pool = p; g->pool_hash = pool_hash; g->key_hash = key_hash; g->prng_hash = prng_hash; g->npools = APR_RANDOM_DEFAULT_POOLS; g->pools = apr_palloc(p,g->npools*sizeof *g->pools); for (n = 0; n < g->npools; ++n) { g->pools[n].bytes = g->pools[n].pool_size = 0; g->pools[n].pool = NULL; } g->next_pool = 0; g->generation = 0; g->rehash_size = APR_RANDOM_DEFAULT_REHASH_SIZE; /* Ensure that the rehash size is twice the size of the pool hasher */ g->rehash_size = ((g->rehash_size+2*g->pool_hash->size-1)/g->pool_hash->size /2)*g->pool_hash->size*2; g->reseed_size = APR_RANDOM_DEFAULT_RESEED_SIZE; g->H = apr_pcalloc(p,H_size(g)); g->H_waiting = apr_pcalloc(p,H_size(g)); g->randomness = apr_palloc(p,B_size(g)); g->random_bytes = 0; g->g_for_insecure = APR_RANDOM_DEFAULT_G_FOR_INSECURE; g->secure_base = 0; g->g_for_secure = APR_RANDOM_DEFAULT_G_FOR_SECURE; g->secure_started = g->insecure_started = 0; g->next = all_random; all_random = g; apr_pool_cleanup_register(p, g, random_cleanup, apr_pool_cleanup_null); } static void mix_pid(apr_random_t *g,unsigned char *H,pid_t pid) { hash_init(g->key_hash); hash_add(g->key_hash,H,H_size(g)); hash_add(g->key_hash,&pid,sizeof pid); hash_finish(g->key_hash,H); } static void mixer(apr_random_t *g,pid_t pid) { unsigned char *H = H_current(g); /* mix the PID into the current H */ mix_pid(g,H,pid); /* if we are in waiting, then also mix into main H */ if (H != g->H) mix_pid(g,g->H,pid); /* change order of pool mixing for good measure - note that going backwards is much better than going forwards */ --g->generation; /* blow away any lingering randomness */ g->random_bytes = 0; } APR_DECLARE(void) apr_random_after_fork(apr_proc_t *proc) { apr_random_t *r; for (r = all_random; r; r = r->next) /* * XXX Note: the pid does not provide sufficient entropy to * actually call this secure. See Ben's paper referenced at * the top of this file. */ mixer(r,proc->pid); } APR_DECLARE(apr_random_t *) apr_random_standard_new(apr_pool_t *p) { apr_random_t *r = apr_palloc(p,sizeof *r); apr_random_init(r,p,apr_crypto_sha256_new(p),apr_crypto_sha256_new(p), apr_crypto_sha256_new(p)); return r; } static void rekey(apr_random_t *g) { unsigned int n; unsigned char *H = H_current(g); hash_init(g->key_hash); hash_add(g->key_hash,H,H_size(g)); for (n = 0 ; n < g->npools && (n == 0 || g->generation&(1 << (n-1))) ; ++n) { hash_add(g->key_hash,g->pools[n].pool,g->pools[n].bytes); g->pools[n].bytes = 0; } hash_finish(g->key_hash,H+B_size(g)); ++g->generation; if (!g->insecure_started && g->generation > g->g_for_insecure) { g->insecure_started = 1; if (!g->secure_started) { memcpy(g->H_waiting,g->H,H_size(g)); g->secure_base = g->generation; } } if (!g->secure_started && g->generation > g->secure_base+g->g_for_secure) { g->secure_started = 1; memcpy(g->H,g->H_waiting,H_size(g)); } } APR_DECLARE(void) apr_random_add_entropy(apr_random_t *g,const void *entropy_, apr_size_t bytes) { unsigned int n; const unsigned char *entropy = entropy_; for (n = 0; n < bytes; ++n) { apr_random_pool_t *p = &g->pools[g->next_pool]; if (++g->next_pool == g->npools) g->next_pool = 0; if (p->pool_size < p->bytes+1) { unsigned char *np = apr_palloc(g->apr_pool,(p->bytes+1)*2); memcpy(np,p->pool,p->bytes); p->pool = np; p->pool_size = (p->bytes+1)*2; } p->pool[p->bytes++] = entropy[n]; if (p->bytes == g->rehash_size) { apr_size_t r; for (r = 0; r < p->bytes/2; r+=g->pool_hash->size) hash(g->pool_hash,p->pool+r,p->pool+r*2,g->pool_hash->size*2); p->bytes/=2; } assert(p->bytes < g->rehash_size); } if (g->pools[0].bytes >= g->reseed_size) rekey(g); } /* This will give g->B_size bytes of randomness */ static void apr_random_block(apr_random_t *g,unsigned char *random) { /* FIXME: in principle, these are different hashes */ hash(g->prng_hash,g->H,g->H,H_size(g)); hash(g->prng_hash,random,g->H,B_size(g)); } static void apr_random_bytes(apr_random_t *g,unsigned char *random, apr_size_t bytes) { apr_size_t n; for (n = 0; n < bytes; ) { apr_size_t l; if (g->random_bytes == 0) { apr_random_block(g,g->randomness); g->random_bytes = B_size(g); } l = min(bytes-n,g->random_bytes); memcpy(&random[n],g->randomness+B_size(g)-g->random_bytes,l); g->random_bytes-=l; n+=l; } } APR_DECLARE(apr_status_t) apr_random_secure_bytes(apr_random_t *g, void *random, apr_size_t bytes) { if (!g->secure_started) return APR_ENOTENOUGHENTROPY; apr_random_bytes(g,random,bytes); return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_random_insecure_bytes(apr_random_t *g, void *random, apr_size_t bytes) { if (!g->insecure_started) return APR_ENOTENOUGHENTROPY; apr_random_bytes(g,random,bytes); return APR_SUCCESS; } APR_DECLARE(void) apr_random_barrier(apr_random_t *g) { g->secure_started = 0; g->secure_base = g->generation; } APR_DECLARE(apr_status_t) apr_random_secure_ready(apr_random_t *r) { if (!r->secure_started) return APR_ENOTENOUGHENTROPY; return APR_SUCCESS; } APR_DECLARE(apr_status_t) apr_random_insecure_ready(apr_random_t *r) { if (!r->insecure_started) return APR_ENOTENOUGHENTROPY; return APR_SUCCESS; }
{ "language": "C" }
/* * LED Kernel Default ON Trigger * * Copyright 2008 Nick Forbes <nick.forbes@incepta.com> * * Based on Richard Purdie's ledtrig-timer.c. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2 as * published by the Free Software Foundation. * */ #include <linux/module.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/leds.h> #include "leds.h" static void defon_trig_activate(struct led_classdev *led_cdev) { led_set_brightness(led_cdev, led_cdev->max_brightness); } static struct led_trigger defon_led_trigger = { .name = "default-on", .activate = defon_trig_activate, }; static int __init defon_trig_init(void) { return led_trigger_register(&defon_led_trigger); } static void __exit defon_trig_exit(void) { led_trigger_unregister(&defon_led_trigger); } module_init(defon_trig_init); module_exit(defon_trig_exit); MODULE_AUTHOR("Nick Forbes <nick.forbes@incepta.com>"); MODULE_DESCRIPTION("Default-ON LED trigger"); MODULE_LICENSE("GPL");
{ "language": "C" }
/* * Copyright 2015 Advanced Micro Devices, Inc. * * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) 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. * */ #ifndef _ICELAND_SMC_H #define _ICELAND_SMC_H #include "smumgr.h" int iceland_populate_all_graphic_levels(struct pp_hwmgr *hwmgr); int iceland_populate_all_memory_levels(struct pp_hwmgr *hwmgr); int iceland_init_smc_table(struct pp_hwmgr *hwmgr); int iceland_thermal_setup_fan_table(struct pp_hwmgr *hwmgr); int iceland_update_sclk_threshold(struct pp_hwmgr *hwmgr); uint32_t iceland_get_offsetof(uint32_t type, uint32_t member); uint32_t iceland_get_mac_definition(uint32_t value); int iceland_process_firmware_header(struct pp_hwmgr *hwmgr); int iceland_initialize_mc_reg_table(struct pp_hwmgr *hwmgr); bool iceland_is_dpm_running(struct pp_hwmgr *hwmgr); #endif
{ "language": "C" }
/*------------------------------------------------------------------------- * * tlist.c * Target list manipulation routines * * Portions Copyright (c) 2007-2008, Greenplum inc * Portions Copyright (c) 2012-Present Pivotal Software, Inc. * Portions Copyright (c) 1996-2019, PostgreSQL Global Development Group * Portions Copyright (c) 1994, Regents of the University of California * * * IDENTIFICATION * src/backend/optimizer/util/tlist.c * *------------------------------------------------------------------------- */ #include "postgres.h" #include "nodes/makefuncs.h" #include "nodes/nodeFuncs.h" #include "optimizer/cost.h" #include "optimizer/optimizer.h" #include "optimizer/tlist.h" #include "utils/lsyscache.h" /* get_typavgwidth() */ typedef struct maxSortGroupRef_context { Index maxsgr; bool include_orderedagg; } maxSortGroupRef_context; static bool maxSortGroupRef_walker(Node *node, maxSortGroupRef_context *cxt); /* Test if an expression node represents a SRF call. Beware multiple eval! */ #define IS_SRF_CALL(node) \ ((IsA(node, FuncExpr) && ((FuncExpr *) (node))->funcretset) || \ (IsA(node, OpExpr) && ((OpExpr *) (node))->opretset)) /* * Data structures for split_pathtarget_at_srfs(). To preserve the identity * of sortgroupref items even if they are textually equal(), what we track is * not just bare expressions but expressions plus their sortgroupref indexes. */ typedef struct { Node *expr; /* some subexpression of a PathTarget */ Index sortgroupref; /* its sortgroupref, or 0 if none */ } split_pathtarget_item; typedef struct { /* This is a List of bare expressions: */ List *input_target_exprs; /* exprs available from input */ /* These are Lists of Lists of split_pathtarget_items: */ List *level_srfs; /* SRF exprs to evaluate at each level */ List *level_input_vars; /* input vars needed at each level */ List *level_input_srfs; /* input SRFs needed at each level */ /* These are Lists of split_pathtarget_items: */ List *current_input_vars; /* vars needed in current subexpr */ List *current_input_srfs; /* SRFs needed in current subexpr */ /* Auxiliary data for current split_pathtarget_walker traversal: */ int current_depth; /* max SRF depth in current subexpr */ Index current_sgref; /* current subexpr's sortgroupref, or 0 */ } split_pathtarget_context; static bool split_pathtarget_walker(Node *node, split_pathtarget_context *context); static void add_sp_item_to_pathtarget(PathTarget *target, split_pathtarget_item *item); static void add_sp_items_to_pathtarget(PathTarget *target, List *items); /***************************************************************************** * Target list creation and searching utilities *****************************************************************************/ /* * tlist_member * Finds the (first) member of the given tlist whose expression is * equal() to the given expression. Result is NULL if no such member. */ TargetEntry * tlist_member(Expr *node, List *targetlist) { ListCell *temp; foreach(temp, targetlist) { TargetEntry *tlentry = (TargetEntry *) lfirst(temp); Assert(IsA(tlentry, TargetEntry)); if (equal(node, tlentry->expr)) return tlentry; } return NULL; } /* * tlist_members * Finds all members of the given tlist whose expression is * equal() to the given expression. Result is NIL if no such member. * Note: We do not make a copy of the tlist entries that match. * The caller is responsible for cleaning up the memory allocated * to the List returned. */ List * tlist_members(Node *node, List *targetlist) { List *tlist = NIL; ListCell *temp = NULL; foreach(temp, targetlist) { TargetEntry *tlentry = (TargetEntry *) lfirst(temp); Assert(IsA(tlentry, TargetEntry)); if (equal(node, tlentry->expr)) { tlist = lappend(tlist, tlentry); } } return tlist; } /* * tlist_member_ignore_relabel * Same as above, except that we ignore top-level RelabelType nodes * while checking for a match. This is needed for some scenarios * involving binary-compatible sort operations. */ TargetEntry * tlist_member_ignore_relabel(Expr *node, List *targetlist) { ListCell *temp; while (node && IsA(node, RelabelType)) node = ((RelabelType *) node)->arg; foreach(temp, targetlist) { TargetEntry *tlentry = (TargetEntry *) lfirst(temp); Expr *tlexpr = tlentry->expr; while (tlexpr && IsA(tlexpr, RelabelType)) tlexpr = ((RelabelType *) tlexpr)->arg; if (equal(node, tlexpr)) return tlentry; } return NULL; } /* * tlist_member_match_var * Same as above, except that we match the provided Var on the basis * of varno/varattno/varlevelsup/vartype only, rather than full equal(). * * This is needed in some cases where we can't be sure of an exact typmod * match. For safety, though, we insist on vartype match. */ static TargetEntry * tlist_member_match_var(Var *var, List *targetlist) { ListCell *temp; foreach(temp, targetlist) { TargetEntry *tlentry = (TargetEntry *) lfirst(temp); Var *tlvar = (Var *) tlentry->expr; if (!tlvar || !IsA(tlvar, Var)) continue; if (var->varno == tlvar->varno && var->varattno == tlvar->varattno && var->varlevelsup == tlvar->varlevelsup && var->vartype == tlvar->vartype) return tlentry; } return NULL; } /* * add_to_flat_tlist * Add more items to a flattened tlist (if they're not already in it) * * 'tlist' is the flattened tlist * 'exprs' is a list of expressions (usually, but not necessarily, Vars) * * Returns the extended tlist. */ List * add_to_flat_tlist(List *tlist, List *exprs) { return add_to_flat_tlist_junk(tlist, exprs, false); } List * add_to_flat_tlist_junk(List *tlist, List *exprs, bool resjunk) { int next_resno = list_length(tlist) + 1; ListCell *lc; foreach(lc, exprs) { Expr *expr = (Expr *) lfirst(lc); if (!tlist_member_ignore_relabel(expr, tlist)) { TargetEntry *tle; tle = makeTargetEntry(copyObject(expr), /* copy needed?? */ next_resno++, NULL, resjunk); tlist = lappend(tlist, tle); } } return tlist; } /* * get_tlist_exprs * Get just the expression subtrees of a tlist * * Resjunk columns are ignored unless includeJunk is true */ List * get_tlist_exprs(List *tlist, bool includeJunk) { List *result = NIL; ListCell *l; foreach(l, tlist) { TargetEntry *tle = (TargetEntry *) lfirst(l); if (tle->resjunk && !includeJunk) continue; result = lappend(result, tle->expr); } return result; } /* * count_nonjunk_tlist_entries * What it says ... */ int count_nonjunk_tlist_entries(List *tlist) { int len = 0; ListCell *l; foreach(l, tlist) { TargetEntry *tle = (TargetEntry *) lfirst(l); if (!tle->resjunk) len++; } return len; } /* * tlist_same_exprs * Check whether two target lists contain the same expressions * * Note: this function is used to decide whether it's safe to jam a new tlist * into a non-projection-capable plan node. Obviously we can't do that unless * the node's tlist shows it already returns the column values we want. * However, we can ignore the TargetEntry attributes resname, ressortgroupref, * resorigtbl, resorigcol, and resjunk, because those are only labelings that * don't affect the row values computed by the node. (Moreover, if we didn't * ignore them, we'd frequently fail to make the desired optimization, since * the planner tends to not bother to make resname etc. valid in intermediate * plan nodes.) Note that on success, the caller must still jam the desired * tlist into the plan node, else it won't have the desired labeling fields. */ bool tlist_same_exprs(List *tlist1, List *tlist2) { ListCell *lc1, *lc2; if (list_length(tlist1) != list_length(tlist2)) return false; /* not same length, so can't match */ forboth(lc1, tlist1, lc2, tlist2) { TargetEntry *tle1 = (TargetEntry *) lfirst(lc1); TargetEntry *tle2 = (TargetEntry *) lfirst(lc2); if (!equal(tle1->expr, tle2->expr)) return false; } return true; } /* * Does tlist have same output datatypes as listed in colTypes? * * Resjunk columns are ignored if junkOK is true; otherwise presence of * a resjunk column will always cause a 'false' result. * * Note: currently no callers care about comparing typmods. */ bool tlist_same_datatypes(List *tlist, List *colTypes, bool junkOK) { ListCell *l; ListCell *curColType = list_head(colTypes); foreach(l, tlist) { TargetEntry *tle = (TargetEntry *) lfirst(l); if (tle->resjunk) { if (!junkOK) return false; } else { if (curColType == NULL) return false; /* tlist longer than colTypes */ if (exprType((Node *) tle->expr) != lfirst_oid(curColType)) return false; curColType = lnext(curColType); } } if (curColType != NULL) return false; /* tlist shorter than colTypes */ return true; } /* * Does tlist have same exposed collations as listed in colCollations? * * Identical logic to the above, but for collations. */ bool tlist_same_collations(List *tlist, List *colCollations, bool junkOK) { ListCell *l; ListCell *curColColl = list_head(colCollations); foreach(l, tlist) { TargetEntry *tle = (TargetEntry *) lfirst(l); if (tle->resjunk) { if (!junkOK) return false; } else { if (curColColl == NULL) return false; /* tlist longer than colCollations */ if (exprCollation((Node *) tle->expr) != lfirst_oid(curColColl)) return false; curColColl = lnext(curColColl); } } if (curColColl != NULL) return false; /* tlist shorter than colCollations */ return true; } /* * apply_tlist_labeling * Apply the TargetEntry labeling attributes of src_tlist to dest_tlist * * This is useful for reattaching column names etc to a plan's final output * targetlist. */ void apply_tlist_labeling(List *dest_tlist, List *src_tlist) { ListCell *ld, *ls; Assert(list_length(dest_tlist) == list_length(src_tlist)); forboth(ld, dest_tlist, ls, src_tlist) { TargetEntry *dest_tle = (TargetEntry *) lfirst(ld); TargetEntry *src_tle = (TargetEntry *) lfirst(ls); Assert(dest_tle->resno == src_tle->resno); dest_tle->resname = src_tle->resname; dest_tle->ressortgroupref = src_tle->ressortgroupref; dest_tle->resorigtbl = src_tle->resorigtbl; dest_tle->resorigcol = src_tle->resorigcol; dest_tle->resjunk = src_tle->resjunk; } } /* * get_sortgroupref_tle * Find the targetlist entry matching the given SortGroupRef index, * and return it. */ TargetEntry * get_sortgroupref_tle(Index sortref, List *targetList) { ListCell *l; foreach(l, targetList) { TargetEntry *tle = (TargetEntry *) lfirst(l); if (tle->ressortgroupref == sortref) return tle; } elog(ERROR, "ORDER/GROUP BY expression not found in targetlist"); return NULL; /* keep compiler quiet */ } /* * get_sortgroupclause_tle * Find the targetlist entry matching the given SortGroupClause * by ressortgroupref, and return it. */ TargetEntry * get_sortgroupclause_tle(SortGroupClause *sgClause, List *targetList) { return get_sortgroupref_tle(sgClause->tleSortGroupRef, targetList); } /* * get_sortgroupclauses_tles * Find a list of unique targetlist entries matching the given list of * SortGroupClauses, or GroupingClauses. * * In each grouping set, targets that do not appear in a GroupingClause * will be put in the front of those that appear in a GroupingClauses. * The targets within the same clause will be appended in the order * of their appearance. * * The unique targetlist entries are returned in *tles, and the sort * and equality operators associated with each tle are returned in * *sortops and *eqops. */ static void get_sortgroupclauses_tles_recurse(List *clauses, List *targetList, List **tles, List **sortops, List **eqops) { ListCell *lc; ListCell *lc_sortop; ListCell *lc_eqop; List *sub_grouping_tles = NIL; List *sub_grouping_sortops = NIL; List *sub_grouping_eqops = NIL; foreach(lc, clauses) { Node *node = lfirst(lc); if (node == NULL) continue; if (IsA(node, SortGroupClause)) { SortGroupClause *sgc = (SortGroupClause *) node; TargetEntry *tle = get_sortgroupclause_tle(sgc, targetList); if (!list_member(*tles, tle)) { *tles = lappend(*tles, tle); *sortops = lappend_oid(*sortops, sgc->sortop); *eqops = lappend_oid(*eqops, sgc->eqop); } } else if (IsA(node, List)) { get_sortgroupclauses_tles_recurse((List *) node, targetList, tles, sortops, eqops); } else elog(ERROR, "unrecognized node type in list of sort/group clauses: %d", (int) nodeTag(node)); } /* * Put SortGroupClauses before GroupingClauses. */ forthree(lc, sub_grouping_tles, lc_sortop, sub_grouping_sortops, lc_eqop, sub_grouping_eqops) { if (!list_member(*tles, lfirst(lc))) { *tles = lappend(*tles, lfirst(lc)); *sortops = lappend_oid(*sortops, lfirst_oid(lc_sortop)); *eqops = lappend_oid(*eqops, lfirst_oid(lc_eqop)); } } } void get_sortgroupclauses_tles(List *clauses, List *targetList, List **tles, List **sortops, List **eqops) { *tles = NIL; *sortops = NIL; *eqops = NIL; get_sortgroupclauses_tles_recurse(clauses, targetList, tles, sortops, eqops); } /* * get_sortgroupclause_expr * Find the targetlist entry matching the given SortGroupClause * by ressortgroupref, and return its expression. */ Node * get_sortgroupclause_expr(SortGroupClause *sgClause, List *targetList) { TargetEntry *tle = get_sortgroupclause_tle(sgClause, targetList); return (Node *) tle->expr; } /* * get_sortgrouplist_exprs * Given a list of SortGroupClauses, build a list * of the referenced targetlist expressions. */ List * get_sortgrouplist_exprs(List *sgClauses, List *targetList) { List *result = NIL; ListCell *l; foreach(l, sgClauses) { SortGroupClause *sortcl = (SortGroupClause *) lfirst(l); Node *sortexpr; sortexpr = get_sortgroupclause_expr(sortcl, targetList); result = lappend(result, sortexpr); } return result; } /* * get_sortgroupref_clause * Find the SortGroupClause matching the given SortGroupRef index, * and return it. */ SortGroupClause * get_sortgroupref_clause(Index sortref, List *clauses) { ListCell *l; foreach(l, clauses) { SortGroupClause *cl = (SortGroupClause *) lfirst(l); if (cl->tleSortGroupRef == sortref) return cl; } elog(ERROR, "ORDER/GROUP BY expression not found in list"); return NULL; /* keep compiler quiet */ } /* * get_sortgroupref_clause_noerr * As above, but return NULL rather than throwing an error if not found. */ SortGroupClause * get_sortgroupref_clause_noerr(Index sortref, List *clauses) { ListCell *l; foreach(l, clauses) { SortGroupClause *cl = (SortGroupClause *) lfirst(l); if (cl->tleSortGroupRef == sortref) return cl; } return NULL; } /* * extract_grouping_ops - make an array of the equality operator OIDs * for a SortGroupClause list */ Oid * extract_grouping_ops(List *groupClause) { int numCols = list_length(groupClause); int colno = 0; Oid *groupOperators; ListCell *glitem; groupOperators = (Oid *) palloc(sizeof(Oid) * numCols); foreach(glitem, groupClause) { SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem); groupOperators[colno] = groupcl->eqop; Assert(OidIsValid(groupOperators[colno])); colno++; } return groupOperators; } /* * extract_grouping_collations - make an array of the grouping column collations * for a SortGroupClause list */ Oid * extract_grouping_collations(List *groupClause, List *tlist) { int numCols = list_length(groupClause); int colno = 0; Oid *grpCollations; ListCell *glitem; grpCollations = (Oid *) palloc(sizeof(Oid) * numCols); foreach(glitem, groupClause) { SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem); TargetEntry *tle = get_sortgroupclause_tle(groupcl, tlist); grpCollations[colno++] = exprCollation((Node *) tle->expr); } return grpCollations; } /* * extract_grouping_cols - make an array of the grouping column resnos * for a SortGroupClause list */ AttrNumber * extract_grouping_cols(List *groupClause, List *tlist) { AttrNumber *grpColIdx; int numCols = list_length(groupClause); int colno = 0; ListCell *glitem; grpColIdx = (AttrNumber *) palloc(sizeof(AttrNumber) * numCols); foreach(glitem, groupClause) { SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem); TargetEntry *tle = get_sortgroupclause_tle(groupcl, tlist); grpColIdx[colno++] = tle->resno; } return grpColIdx; } /* * grouping_is_sortable - is it possible to implement grouping list by sorting? * * This is easy since the parser will have included a sortop if one exists. */ bool grouping_is_sortable(List *groupClause) { ListCell *glitem; foreach(glitem, groupClause) { SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem); if (!OidIsValid(groupcl->sortop)) return false; } return true; } /* * grouping_is_hashable - is it possible to implement grouping list by hashing? * * We rely on the parser to have set the hashable flag correctly. */ bool grouping_is_hashable(List *groupClause) { ListCell *glitem; foreach(glitem, groupClause) { SortGroupClause *groupcl = (SortGroupClause *) lfirst(glitem); if (!groupcl->hashable) return false; } return true; } /* * Return the largest sortgroupref value in use in the given * target list. * * If include_orderedagg is false, consider only the top-level * entries in the target list, i.e., those that might be occur * in a groupClause, distinctClause, or sortClause of the Query * node that immediately contains the target list. * * If include_orderedagg is true, also consider AggOrder entries * embedded in Aggref nodes within the target list. Though * such entries will only occur in the aggregation sub_tlist * (input) they affect sortgroupref numbering for both sub_tlist * and tlist (aggregate). */ Index maxSortGroupRef(List *targetlist, bool include_orderedagg) { maxSortGroupRef_context context; context.maxsgr = 0; context.include_orderedagg = include_orderedagg; if (targetlist != NIL) { if ( !IsA(targetlist, List) || !IsA(linitial(targetlist), TargetEntry ) ) elog(ERROR, "non-targetlist argument supplied"); maxSortGroupRef_walker((Node*)targetlist, &context); } return context.maxsgr; } bool maxSortGroupRef_walker(Node *node, maxSortGroupRef_context *cxt) { if ( node == NULL ) return false; if ( IsA(node, TargetEntry) ) { TargetEntry *tle = (TargetEntry*)node; if ( tle->ressortgroupref > cxt->maxsgr ) cxt->maxsgr = tle->ressortgroupref; return maxSortGroupRef_walker((Node*)tle->expr, cxt); } /* Aggref nodes don't nest, so we can treat them here without recurring * further. */ if ( IsA(node, Aggref) ) { Aggref *ref = (Aggref*)node; if ( cxt->include_orderedagg ) { ListCell *lc; foreach (lc, ref->aggorder) { SortGroupClause *sort = (SortGroupClause *)lfirst(lc); Assert(IsA(sort, SortGroupClause)); Assert( sort->tleSortGroupRef != 0 ); if (sort->tleSortGroupRef > cxt->maxsgr ) cxt->maxsgr = sort->tleSortGroupRef; } } return false; } return expression_tree_walker(node, maxSortGroupRef_walker, cxt); } /** * Returns the width of the row by traversing through the * target list and adding up the width of each target entry. */ int get_row_width(List *tlist) { int width = 0; ListCell *plc = NULL; foreach(plc, tlist) { TargetEntry *pte = (TargetEntry*) lfirst(plc); Expr *pexpr = pte->expr; Assert(NULL != pexpr); Oid oidType = exprType( (Node *) pexpr); int32 iTypmod = exprTypmod( (Node *) pexpr); width += get_typavgwidth(oidType, iTypmod); } return width; } /***************************************************************************** * PathTarget manipulation functions * * PathTarget is a somewhat stripped-down version of a full targetlist; it * omits all the TargetEntry decoration except (optionally) sortgroupref data, * and it adds evaluation cost and output data width info. *****************************************************************************/ /* * make_pathtarget_from_tlist * Construct a PathTarget equivalent to the given targetlist. * * This leaves the cost and width fields as zeroes. Most callers will want * to use create_pathtarget(), so as to get those set. */ PathTarget * make_pathtarget_from_tlist(List *tlist) { PathTarget *target = makeNode(PathTarget); int i; ListCell *lc; target->sortgrouprefs = (Index *) palloc(list_length(tlist) * sizeof(Index)); i = 0; foreach(lc, tlist) { TargetEntry *tle = (TargetEntry *) lfirst(lc); target->exprs = lappend(target->exprs, tle->expr); target->sortgrouprefs[i] = tle->ressortgroupref; i++; } return target; } /* * make_tlist_from_pathtarget * Construct a targetlist from a PathTarget. */ List * make_tlist_from_pathtarget(PathTarget *target) { List *tlist = NIL; int i; ListCell *lc; i = 0; foreach(lc, target->exprs) { Expr *expr = (Expr *) lfirst(lc); TargetEntry *tle; tle = makeTargetEntry(expr, i + 1, NULL, false); if (target->sortgrouprefs) tle->ressortgroupref = target->sortgrouprefs[i]; tlist = lappend(tlist, tle); i++; } return tlist; } /* * copy_pathtarget * Copy a PathTarget. * * The new PathTarget has its own List cells, but shares the underlying * target expression trees with the old one. We duplicate the List cells * so that items can be added to one target without damaging the other. */ PathTarget * copy_pathtarget(PathTarget *src) { PathTarget *dst = makeNode(PathTarget); /* Copy scalar fields */ memcpy(dst, src, sizeof(PathTarget)); /* Shallow-copy the expression list */ dst->exprs = list_copy(src->exprs); /* Duplicate sortgrouprefs if any (if not, the memcpy handled this) */ if (src->sortgrouprefs) { Size nbytes = list_length(src->exprs) * sizeof(Index); dst->sortgrouprefs = (Index *) palloc(nbytes); memcpy(dst->sortgrouprefs, src->sortgrouprefs, nbytes); } return dst; } /* * create_empty_pathtarget * Create an empty (zero columns, zero cost) PathTarget. */ PathTarget * create_empty_pathtarget(void) { /* This is easy, but we don't want callers to hard-wire this ... */ return makeNode(PathTarget); } /* * add_column_to_pathtarget * Append a target column to the PathTarget. * * As with make_pathtarget_from_tlist, we leave it to the caller to update * the cost and width fields. */ void add_column_to_pathtarget(PathTarget *target, Expr *expr, Index sortgroupref) { /* Updating the exprs list is easy ... */ target->exprs = lappend(target->exprs, expr); /* ... the sortgroupref data, a bit less so */ if (target->sortgrouprefs) { int nexprs = list_length(target->exprs); /* This might look inefficient, but actually it's usually cheap */ target->sortgrouprefs = (Index *) repalloc(target->sortgrouprefs, nexprs * sizeof(Index)); target->sortgrouprefs[nexprs - 1] = sortgroupref; } else if (sortgroupref) { /* Adding sortgroupref labeling to a previously unlabeled target */ int nexprs = list_length(target->exprs); target->sortgrouprefs = (Index *) palloc0(nexprs * sizeof(Index)); target->sortgrouprefs[nexprs - 1] = sortgroupref; } } /* * add_new_column_to_pathtarget * Append a target column to the PathTarget, but only if it's not * equal() to any pre-existing target expression. * * The caller cannot specify a sortgroupref, since it would be unclear how * to merge that with a pre-existing column. * * As with make_pathtarget_from_tlist, we leave it to the caller to update * the cost and width fields. */ void add_new_column_to_pathtarget(PathTarget *target, Expr *expr) { if (!list_member(target->exprs, expr)) add_column_to_pathtarget(target, expr, 0); } /* * add_new_columns_to_pathtarget * Apply add_new_column_to_pathtarget() for each element of the list. */ void add_new_columns_to_pathtarget(PathTarget *target, List *exprs) { ListCell *lc; foreach(lc, exprs) { Expr *expr = (Expr *) lfirst(lc); add_new_column_to_pathtarget(target, expr); } } /* * apply_pathtarget_labeling_to_tlist * Apply any sortgrouprefs in the PathTarget to matching tlist entries * * Here, we do not assume that the tlist entries are one-for-one with the * PathTarget. The intended use of this function is to deal with cases * where createplan.c has decided to use some other tlist and we have * to identify what matches exist. */ void apply_pathtarget_labeling_to_tlist(List *tlist, PathTarget *target) { int i; ListCell *lc; /* Nothing to do if PathTarget has no sortgrouprefs data */ if (target->sortgrouprefs == NULL) return; i = 0; foreach(lc, target->exprs) { Expr *expr = (Expr *) lfirst(lc); TargetEntry *tle; if (target->sortgrouprefs[i]) { /* * For Vars, use tlist_member_match_var's weakened matching rule; * this allows us to deal with some cases where a set-returning * function has been inlined, so that we now have more knowledge * about what it returns than we did when the original Var was * created. Otherwise, use regular equal() to find the matching * TLE. (In current usage, only the Var case is actually needed; * but it seems best to have sane behavior here for non-Vars too.) */ if (expr && IsA(expr, Var)) tle = tlist_member_match_var((Var *) expr, tlist); else tle = tlist_member(expr, tlist); /* * Complain if noplace for the sortgrouprefs label, or if we'd * have to label a column twice. (The case where it already has * the desired label probably can't happen, but we may as well * allow for it.) */ if (!tle) elog(ERROR, "ORDER/GROUP BY expression not found in targetlist"); if (tle->ressortgroupref != 0 && tle->ressortgroupref != target->sortgrouprefs[i]) elog(ERROR, "targetlist item has multiple sortgroupref labels"); tle->ressortgroupref = target->sortgrouprefs[i]; } i++; } } /* * split_pathtarget_at_srfs * Split given PathTarget into multiple levels to position SRFs safely * * The executor can only handle set-returning functions that appear at the * top level of the targetlist of a ProjectSet plan node. If we have any SRFs * that are not at top level, we need to split up the evaluation into multiple * plan levels in which each level satisfies this constraint. This function * creates appropriate PathTarget(s) for each level. * * As an example, consider the tlist expression * x + srf1(srf2(y + z)) * This expression should appear as-is in the top PathTarget, but below that * we must have a PathTarget containing * x, srf1(srf2(y + z)) * and below that, another PathTarget containing * x, srf2(y + z) * and below that, another PathTarget containing * x, y, z * When these tlists are processed by setrefs.c, subexpressions that match * output expressions of the next lower tlist will be replaced by Vars, * so that what the executor gets are tlists looking like * Var1 + Var2 * Var1, srf1(Var2) * Var1, srf2(Var2 + Var3) * x, y, z * which satisfy the desired property. * * Another example is * srf1(x), srf2(srf3(y)) * That must appear as-is in the top PathTarget, but below that we need * srf1(x), srf3(y) * That is, each SRF must be computed at a level corresponding to the nesting * depth of SRFs within its arguments. * * In some cases, a SRF has already been evaluated in some previous plan level * and we shouldn't expand it again (that is, what we see in the target is * already meant as a reference to a lower subexpression). So, don't expand * any tlist expressions that appear in input_target, if that's not NULL. * * It's also important that we preserve any sortgroupref annotation appearing * in the given target, especially on expressions matching input_target items. * * The outputs of this function are two parallel lists, one a list of * PathTargets and the other an integer list of bool flags indicating * whether the corresponding PathTarget contains any evaluatable SRFs. * The lists are given in the order they'd need to be evaluated in, with * the "lowest" PathTarget first. So the last list entry is always the * originally given PathTarget, and any entries before it indicate evaluation * levels that must be inserted below it. The first list entry must not * contain any SRFs (other than ones duplicating input_target entries), since * it will typically be attached to a plan node that cannot evaluate SRFs. * * Note: using a list for the flags may seem like overkill, since there * are only a few possible patterns for which levels contain SRFs. * But this representation decouples callers from that knowledge. */ void split_pathtarget_at_srfs(PlannerInfo *root, PathTarget *target, PathTarget *input_target, List **targets, List **targets_contain_srfs) { split_pathtarget_context context; int max_depth; bool need_extra_projection; List *prev_level_tlist; int lci; ListCell *lc, *lc1, *lc2, *lc3; /* * It's not unusual for planner.c to pass us two physically identical * targets, in which case we can conclude without further ado that all * expressions are available from the input. (The logic below would * arrive at the same conclusion, but much more tediously.) */ if (target == input_target) { *targets = list_make1(target); *targets_contain_srfs = list_make1_int(false); return; } /* Pass any input_target exprs down to split_pathtarget_walker() */ context.input_target_exprs = input_target ? input_target->exprs : NIL; /* * Initialize with empty level-zero lists, and no levels after that. * (Note: we could dispense with representing level zero explicitly, since * it will never receive any SRFs, but then we'd have to special-case that * level when we get to building result PathTargets. Level zero describes * the SRF-free PathTarget that will be given to the input plan node.) */ context.level_srfs = list_make1(NIL); context.level_input_vars = list_make1(NIL); context.level_input_srfs = list_make1(NIL); /* Initialize data we'll accumulate across all the target expressions */ context.current_input_vars = NIL; context.current_input_srfs = NIL; max_depth = 0; need_extra_projection = false; /* Scan each expression in the PathTarget looking for SRFs */ lci = 0; foreach(lc, target->exprs) { Node *node = (Node *) lfirst(lc); /* Tell split_pathtarget_walker about this expr's sortgroupref */ context.current_sgref = get_pathtarget_sortgroupref(target, lci); lci++; /* * Find all SRFs and Vars (and Var-like nodes) in this expression, and * enter them into appropriate lists within the context struct. */ context.current_depth = 0; split_pathtarget_walker(node, &context); /* An expression containing no SRFs is of no further interest */ if (context.current_depth == 0) continue; /* * Track max SRF nesting depth over the whole PathTarget. Also, if * this expression establishes a new max depth, we no longer care * whether previous expressions contained nested SRFs; we can handle * any required projection for them in the final ProjectSet node. */ if (max_depth < context.current_depth) { max_depth = context.current_depth; need_extra_projection = false; } /* * If any maximum-depth SRF is not at the top level of its expression, * we'll need an extra Result node to compute the top-level scalar * expression. */ if (max_depth == context.current_depth && !IS_SRF_CALL(node)) need_extra_projection = true; } /* * If we found no SRFs needing evaluation (maybe they were all present in * input_target, or maybe they were all removed by const-simplification), * then no ProjectSet is needed; fall out. */ if (max_depth == 0) { *targets = list_make1(target); *targets_contain_srfs = list_make1_int(false); return; } /* * The Vars and SRF outputs needed at top level can be added to the last * level_input lists if we don't need an extra projection step. If we do * need one, add a SRF-free level to the lists. */ if (need_extra_projection) { context.level_srfs = lappend(context.level_srfs, NIL); context.level_input_vars = lappend(context.level_input_vars, context.current_input_vars); context.level_input_srfs = lappend(context.level_input_srfs, context.current_input_srfs); } else { lc = list_nth_cell(context.level_input_vars, max_depth); lfirst(lc) = list_concat(lfirst(lc), context.current_input_vars); lc = list_nth_cell(context.level_input_srfs, max_depth); lfirst(lc) = list_concat(lfirst(lc), context.current_input_srfs); } /* * Now construct the output PathTargets. The original target can be used * as-is for the last one, but we need to construct a new SRF-free target * representing what the preceding plan node has to emit, as well as a * target for each intermediate ProjectSet node. */ *targets = *targets_contain_srfs = NIL; prev_level_tlist = NIL; forthree(lc1, context.level_srfs, lc2, context.level_input_vars, lc3, context.level_input_srfs) { List *level_srfs = (List *) lfirst(lc1); PathTarget *ntarget; if (lnext(lc1) == NULL) { ntarget = target; } else { ntarget = create_empty_pathtarget(); /* * This target should actually evaluate any SRFs of the current * level, and it needs to propagate forward any Vars needed by * later levels, as well as SRFs computed earlier and needed by * later levels. */ add_sp_items_to_pathtarget(ntarget, level_srfs); for_each_cell(lc, lnext(lc2)) { List *input_vars = (List *) lfirst(lc); add_sp_items_to_pathtarget(ntarget, input_vars); } for_each_cell(lc, lnext(lc3)) { List *input_srfs = (List *) lfirst(lc); ListCell *lcx; foreach(lcx, input_srfs) { split_pathtarget_item *item = lfirst(lcx); if (list_member(prev_level_tlist, item->expr)) add_sp_item_to_pathtarget(ntarget, item); } } set_pathtarget_cost_width(root, ntarget); } /* * Add current target and does-it-compute-SRFs flag to output lists. */ *targets = lappend(*targets, ntarget); *targets_contain_srfs = lappend_int(*targets_contain_srfs, (level_srfs != NIL)); /* Remember this level's output for next pass */ prev_level_tlist = ntarget->exprs; } } /* * Recursively examine expressions for split_pathtarget_at_srfs. * * Note we make no effort here to prevent duplicate entries in the output * lists. Duplicates will be gotten rid of later. */ static bool split_pathtarget_walker(Node *node, split_pathtarget_context *context) { if (node == NULL) return false; /* * A subexpression that matches an expression already computed in * input_target can be treated like a Var (which indeed it will be after * setrefs.c gets done with it), even if it's actually a SRF. Record it * as being needed for the current expression, and ignore any * substructure. (Note in particular that this preserves the identity of * any expressions that appear as sortgrouprefs in input_target.) */ if (list_member(context->input_target_exprs, node)) { split_pathtarget_item *item = palloc(sizeof(split_pathtarget_item)); item->expr = node; item->sortgroupref = context->current_sgref; context->current_input_vars = lappend(context->current_input_vars, item); return false; } /* * Vars and Var-like constructs are expected to be gotten from the input, * too. We assume that these constructs cannot contain any SRFs (if one * does, there will be an executor failure from a misplaced SRF). */ if (IsA(node, Var) || IsA(node, PlaceHolderVar) || IsA(node, Aggref) || IsA(node, GroupingFunc) || IsA(node, WindowFunc)) { split_pathtarget_item *item = palloc(sizeof(split_pathtarget_item)); item->expr = node; item->sortgroupref = context->current_sgref; context->current_input_vars = lappend(context->current_input_vars, item); return false; } /* * If it's a SRF, recursively examine its inputs, determine its level, and * make appropriate entries in the output lists. */ if (IS_SRF_CALL(node)) { split_pathtarget_item *item = palloc(sizeof(split_pathtarget_item)); List *save_input_vars = context->current_input_vars; List *save_input_srfs = context->current_input_srfs; int save_current_depth = context->current_depth; int srf_depth; ListCell *lc; item->expr = node; item->sortgroupref = context->current_sgref; context->current_input_vars = NIL; context->current_input_srfs = NIL; context->current_depth = 0; context->current_sgref = 0; /* subexpressions are not sortgroup items */ (void) expression_tree_walker(node, split_pathtarget_walker, (void *) context); /* Depth is one more than any SRF below it */ srf_depth = context->current_depth + 1; /* If new record depth, initialize another level of output lists */ if (srf_depth >= list_length(context->level_srfs)) { context->level_srfs = lappend(context->level_srfs, NIL); context->level_input_vars = lappend(context->level_input_vars, NIL); context->level_input_srfs = lappend(context->level_input_srfs, NIL); } /* Record this SRF as needing to be evaluated at appropriate level */ lc = list_nth_cell(context->level_srfs, srf_depth); lfirst(lc) = lappend(lfirst(lc), item); /* Record its inputs as being needed at the same level */ lc = list_nth_cell(context->level_input_vars, srf_depth); lfirst(lc) = list_concat(lfirst(lc), context->current_input_vars); lc = list_nth_cell(context->level_input_srfs, srf_depth); lfirst(lc) = list_concat(lfirst(lc), context->current_input_srfs); /* * Restore caller-level state and update it for presence of this SRF. * Notice we report the SRF itself as being needed for evaluation of * surrounding expression. */ context->current_input_vars = save_input_vars; context->current_input_srfs = lappend(save_input_srfs, item); context->current_depth = Max(save_current_depth, srf_depth); /* We're done here */ return false; } /* * Otherwise, the node is a scalar (non-set) expression, so recurse to * examine its inputs. */ context->current_sgref = 0; /* subexpressions are not sortgroup items */ return expression_tree_walker(node, split_pathtarget_walker, (void *) context); } /* * Add a split_pathtarget_item to the PathTarget, unless a matching item is * already present. This is like add_new_column_to_pathtarget, but allows * for sortgrouprefs to be handled. An item having zero sortgroupref can * be merged with one that has a sortgroupref, acquiring the latter's * sortgroupref. * * Note that we don't worry about possibly adding duplicate sortgrouprefs * to the PathTarget. That would be bad, but it should be impossible unless * the target passed to split_pathtarget_at_srfs already had duplicates. * As long as it didn't, we can have at most one split_pathtarget_item with * any particular nonzero sortgroupref. */ static void add_sp_item_to_pathtarget(PathTarget *target, split_pathtarget_item *item) { int lci; ListCell *lc; /* * Look for a pre-existing entry that is equal() and does not have a * conflicting sortgroupref already. */ lci = 0; foreach(lc, target->exprs) { Node *node = (Node *) lfirst(lc); Index sgref = get_pathtarget_sortgroupref(target, lci); if ((item->sortgroupref == sgref || item->sortgroupref == 0 || sgref == 0) && equal(item->expr, node)) { /* Found a match. Assign item's sortgroupref if it has one. */ if (item->sortgroupref) { if (target->sortgrouprefs == NULL) { target->sortgrouprefs = (Index *) palloc0(list_length(target->exprs) * sizeof(Index)); } target->sortgrouprefs[lci] = item->sortgroupref; } return; } lci++; } /* * No match, so add item to PathTarget. Copy the expr for safety. */ add_column_to_pathtarget(target, (Expr *) copyObject(item->expr), item->sortgroupref); } /* * Apply add_sp_item_to_pathtarget to each element of list. */ static void add_sp_items_to_pathtarget(PathTarget *target, List *items) { ListCell *lc; foreach(lc, items) { split_pathtarget_item *item = lfirst(lc); add_sp_item_to_pathtarget(target, item); } }
{ "language": "C" }
/** * @file <argos3/plugins/simulator/visualizations/qt-opengl/qtopengl_lua_statetree_item.h> * * @author Carlo Pinciroli <ilpincy@gmail.com> */ #ifndef QTOPENGL_LUA_STATETREE_ITEM_H #define QTOPENGL_LUA_STATETREE_ITEM_H namespace argos { class CQTOpenGLLuaStateTreeItem; } #include <QList> #include <QVariant> namespace argos { class CQTOpenGLLuaStateTreeItem { public: CQTOpenGLLuaStateTreeItem(CQTOpenGLLuaStateTreeItem* pc_parent = 0); CQTOpenGLLuaStateTreeItem(QList<QVariant>& list_data, CQTOpenGLLuaStateTreeItem* pc_parent = 0); ~CQTOpenGLLuaStateTreeItem(); CQTOpenGLLuaStateTreeItem* GetParent(); CQTOpenGLLuaStateTreeItem* GetChild(size_t un_idx); void AddChild(CQTOpenGLLuaStateTreeItem* pc_child); void RemoveChild(CQTOpenGLLuaStateTreeItem* pc_child); size_t GetNumChildren() const; void SortChildren(); QVariant GetData(int n_col) const; int GetRow(); private: QList<QVariant> m_listData; CQTOpenGLLuaStateTreeItem* m_pcParent; QList<CQTOpenGLLuaStateTreeItem*> m_listChildren; }; } #endif
{ "language": "C" }
/***********************license start*********************************** * Copyright (c) 2003-2017 Cavium Inc. (support@cavium.com). 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 Cavium 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, including technical data, may be subject to U.S. export * control laws, including the U.S. Export Administration Act and its * associated regulations, and may be subject to export or import * regulations in other countries. * * TO THE MAXIMUM EXTENT PERMITTED BY LAW, THE SOFTWARE IS PROVIDED "AS IS" * AND WITH ALL FAULTS AND CAVIUM INC. MAKES NO PROMISES, REPRESENTATIONS OR * WARRANTIES, EITHER EXPRESS, IMPLIED, STATUTORY, OR OTHERWISE, WITH RESPECT * TO THE SOFTWARE, INCLUDING ITS CONDITION, ITS CONFORMITY TO ANY * REPRESENTATION OR DESCRIPTION, OR THE EXISTENCE OF ANY LATENT OR PATENT * DEFECTS, AND CAVIUM SPECIFICALLY DISCLAIMS ALL IMPLIED (IF ANY) WARRANTIES * OF TITLE, MERCHANTABILITY, NONINFRINGEMENT, FITNESS FOR A PARTICULAR * PURPOSE, LACK OF VIRUSES, ACCURACY OR COMPLETENESS, QUIET ENJOYMENT, * QUIET POSSESSION OR CORRESPONDENCE TO DESCRIPTION. THE ENTIRE RISK * ARISING OUT OF USE OR PERFORMANCE OF THE SOFTWARE LIES WITH YOU. ***********************license end**************************************/ #ifndef __LIBDRAM_CONFIG_H__ #define __LIBDRAM_CONFIG_H__ #include <libbdk-arch/bdk-csrs-lmc.h> #define DDR_CFG_T_MAX_DIMMS 2 /* ThunderX supports a max of two DIMMs per LMC */ /* Structure that provides DIMM information, either in the form of an SPD TWSI address, or a pointer to an array that contains SPD data. One of the two fields must be valid. Note that these fields historically were dimension 2, left over from CN38XX/CN58XX. These chips supported a 128 bit wide LMC, requiring two DIMMs. All other chips use a 64bit wide LMC with multiple LMCs. All Thunder chips use one DIMM for 64bits, so we no longer use an index */ typedef struct { uint16_t spd_addr; /* TWSI address of SPD, 0 if not used */ const uint8_t *spd_ptr; /* pointer to SPD data array, NULL if not used */ } dimm_config_t; typedef struct { uint8_t odt_ena; /* FIX: dqx_ctl for Octeon 3 DDR4 */ uint64_t odt_mask; /* FIX: wodt_mask for Octeon 3 */ bdk_lmcx_modereg_params1_t odt_mask1; bdk_lmcx_modereg_params2_t odt_mask2; /* FIX: needed for DDR4 */ uint8_t qs_dic; /* FIX: rodt_ctl for Octeon 3 */ uint64_t rodt_ctl; /* FIX: rodt_mask for Octeon 3 */ } dimm_odt_config_t; /* The parameters below make up the custom_lmc_config data structure. This structure is used to customize the way that the LMC DRAM Controller is configured for a particular board design. The HRM describes LMC Read Leveling which supports automatic selection of per byte-lane delays. When measuring the read delays the LMC configuration software sweeps through a range of settings for LMC0_COMP_CTL2[RODT_CTL], the Octeon II on-die-termination resistance and LMC0_MODEREG_PARAMS1[RTT_NOM_XX], the DRAM on-die-termination resistance. The minimum and maximum parameters for rtt_nom_idx and rodt_ctl listed below determine the ranges of ODT settings used for the measurements. Note that for rtt_nom an index is used into a sorted table rather than the direct csr setting in order to optimize the sweep. .min_rtt_nom_idx: 1=120ohms, 2=60ohms, 3=40ohms, 4=30ohms, 5=20ohms .max_rtt_nom_idx: 1=120ohms, 2=60ohms, 3=40ohms, 4=30ohms, 5=20ohms .min_rodt_ctl: 1=20ohms, 2=30ohms, 3=40ohms, 4=60ohms, 5=120ohms .max_rodt_ctl: 1=20ohms, 2=30ohms, 3=40ohms, 4=60ohms, 5=120ohms The settings below control the Octeon II drive strength for the CK, ADD/CMD, and DQ/DQS signals. 1=24ohms, 2=26.67ohms, 3=30ohms, 4=34.3ohms, 5=40ohms, 6=48ohms, 6=60ohms. .dqx_ctl: Drive strength control for DDR_DQX/DDR_DQS_X_P/N drivers. .ck_ctl: Drive strength control for DDR_CK_X_P/DDR_DIMMX_CSX_L/DDR_DIMMX_ODT_X drivers. .cmd_ctl: Drive strength control for CMD/A/RESET_L/CKEX drivers. The LMC controller software selects the most optimal CAS Latency that complies with the appropriate SPD values and the frequency that the DRAMS are being operated. When operating the DRAMs at frequencies substantially lower than their rated frequencies it might be necessary to limit the minimum CAS Latency the LMC controller software is allowed to select in order to make the DRAM work reliably. .min_cas_latency: Minimum allowed CAS Latency The value used for LMC0_RLEVEL_CTL[OFFSET_EN] determine how the read-leveling information that the Octeon II gathers is interpreted to determine the per-byte read delays. .offset_en: Value used for LMC0_RLEVEL_CTL[OFFSET_EN]. .offset_udimm: Value used for LMC0_RLEVEL_CTL[OFFSET] for UDIMMS. .offset_rdimm: Value used for LMC0_RLEVEL_CTL[OFFSET] for RDIMMS. The LMC configuration software sweeps through a range of ODT settings while measuring the per-byte read delays. During those measurements the software makes an assessment of the quality of the measurements in order to determine which measurements provide the most accurate delays. The automatic settings provide the option to allow that same assessment to determine the most optimal RODT_CTL and/or RTT_NOM settings. The automatic approach might provide the best means to determine the settings used for initial poweron of a new design. However, the final settings should be determined by board analysis, testing, and experience. .ddr_rtt_nom_auto: 1 means automatically set RTT_NOM value. .ddr_rodt_ctl_auto: 1 means automatically set RODT_CTL value. .rlevel_compute: Enables software interpretation of per-byte read delays using the measurements collected by the Octeon II rather than completely relying on the Octeon II to determine the delays. 1=software computation is recommended since a more complete analysis is implemented in software. .rlevel_comp_offset: Set to 2 unless instructed differently by Cavium. .rlevel_average_loops: Determines the number of times the read-leveling sequence is run for each rank. The results is then averaged across the number of loops. The default setting is 1. .ddr2t_udimm: .ddr2t_rdimm: Turn on the DDR 2T mode. 2-cycle window for CMD and address. This mode helps relieve setup time pressure on the address and command bus. Please refer to Micron's tech note tn_47_01 titled DDR2-533 Memory Design Guide for Two Dimm Unbuffered Systems for physical details. .disable_sequential_delay_check: As result of the flyby topology prescribed in the JEDEC specifications the byte delays should maintain a consistent increasing or decreasing trend across the bytes on standard dimms. This setting can be used disable that check for unusual circumstances where the check is not useful. .maximum_adjacent_rlevel_delay_increment: An additional sequential delay check for the delays that result from the flyby topology. This value specifies the maximum difference between the delays of adjacent bytes. A value of 0 disables this check. .fprch2 Front Porch Enable: When set, the turn-off time for the default DDR_DQ/DQS drivers is FPRCH2 CKs earlier. 00 = 0 CKs 01 = 1 CKs 10 = 2 CKs .parity: The parity input signal PAR_IN on each dimm must be strapped high or low on the board. This bit is programmed into LMC0_DIMM_CTL[PARITY] and it must be set to match the board strapping. This signal is typically strapped low. .mode32b: Enable 32-bit datapath mode. Set to 1 if only 32 DQ pins are used. (cn61xx, cn71xx) .dll_write_offset: FIXME: Add description .dll_read_offset: FIXME: Add description */ typedef struct { const char *part; int speed; uint64_t rlevel_rank[4][4]; } rlevel_table_t; typedef struct { uint8_t min_rtt_nom_idx; uint8_t max_rtt_nom_idx; uint8_t min_rodt_ctl; uint8_t max_rodt_ctl; //uint8_t dqx_ctl; uint8_t ck_ctl; uint8_t cmd_ctl; uint8_t ctl_ctl; uint8_t min_cas_latency; uint8_t offset_en; uint8_t offset_udimm; uint8_t offset_rdimm; uint8_t rlevel_compute; uint8_t ddr_rtt_nom_auto; uint8_t ddr_rodt_ctl_auto; uint8_t rlevel_comp_offset_udimm; uint8_t rlevel_comp_offset_rdimm; uint8_t rlevel_average_loops; uint8_t ddr2t_udimm; uint8_t ddr2t_rdimm; uint8_t disable_sequential_delay_check; uint8_t maximum_adjacent_rlevel_delay_increment; uint8_t parity; uint8_t fprch2; uint8_t mode32b; uint8_t measured_vref; const int8_t *dll_write_offset; /* Indexed by byte number (0-8, includes ecc byte) */ const int8_t *dll_read_offset; /* Indexed by byte number (0-8, includes ecc byte) */ const rlevel_table_t *rlevel_table; /* Only used if ENABLE_CUSTOM_RLEVEL_TABLE. List of DIMMs to check */ } ddr3_custom_config_t; typedef struct { dimm_config_t dimm_config_table[DDR_CFG_T_MAX_DIMMS]; /* Indexed by DIMM */ dimm_odt_config_t odt_1rank_config[DDR_CFG_T_MAX_DIMMS]; /* Indexed by number of DIMMs minus 1 */ dimm_odt_config_t odt_2rank_config[DDR_CFG_T_MAX_DIMMS]; /* Indexed by number of DIMMs minus 1 */ dimm_odt_config_t odt_4rank_config[DDR_CFG_T_MAX_DIMMS]; /* Indexed by number of DIMMs minus 1 */ ddr3_custom_config_t custom_lmc_config; } ddr_configuration_t; typedef struct { const char *name; ddr_configuration_t config[4]; /* Indexed by LMC */ int ddr_clock_hertz; } dram_config_t; extern int libdram_config(int node, const dram_config_t *dram_config, int ddr_clock_override); extern int libdram_tune(int node); //extern int libdram_margin_write_voltage(int node); //extern int libdram_margin_read_voltage(int node); //extern int libdram_margin_read_timing(int node); //extern int libdram_margin_write_timing(int node); extern int libdram_margin(int node); extern uint32_t libdram_get_freq(int node); extern uint32_t libdram_get_freq_from_pll(int node, int lmc); /** * Load a DRAM configuration based on the current bdk-config settings * * @param node Node the DRAM config is for * * @return Pointer to __libdram_global_cfg, a global structure. Returns NULL if bdk-config * lacks information about DRAM. */ extern const dram_config_t* libdram_config_load(bdk_node_t node); /* The various DRAM configs in the libdram/configs directory need space to store the DRAM config. Since only one config is ever in active use at a time, store the configs in __libdram_global_cfg. In a multi-node setup, independent calls to get the DRAM config will load first node 0's config, then node 1's */ extern dram_config_t __libdram_global_cfg; #endif /* __LIBDRAM_CONFIG_H__ */
{ "language": "C" }
/* Copyright 2013-present Barefoot Networks, 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. */ /* * Antonin Bas (antonin@barefootnetworks.com) * */ //! @file //! Functions to query counter information in a p4info object. #ifndef PI_INC_PI_P4INFO_COUNTERS_H_ #define PI_INC_PI_P4INFO_COUNTERS_H_ #include <PI/pi_base.h> #ifdef __cplusplus extern "C" { #endif // TODO(antonin): remnant of P4_14, remove? typedef enum { PI_P4INFO_COUNTER_UNIT_BYTES = 0, PI_P4INFO_COUNTER_UNIT_PACKETS, PI_P4INFO_COUNTER_UNIT_BOTH } pi_p4info_counter_unit_t; pi_p4_id_t pi_p4info_counter_id_from_name(const pi_p4info_t *p4info, const char *name); const char *pi_p4info_counter_name_from_id(const pi_p4info_t *p4info, pi_p4_id_t counter_id); pi_p4_id_t pi_p4info_counter_get_direct(const pi_p4info_t *p4info, pi_p4_id_t counter_id); pi_p4info_counter_unit_t pi_p4info_counter_get_unit(const pi_p4info_t *p4info, pi_p4_id_t counter_id); size_t pi_p4info_counter_get_size(const pi_p4info_t *p4info, pi_p4_id_t counter_id); pi_p4_id_t pi_p4info_counter_begin(const pi_p4info_t *p4info); pi_p4_id_t pi_p4info_counter_next(const pi_p4info_t *p4info, pi_p4_id_t id); pi_p4_id_t pi_p4info_counter_end(const pi_p4info_t *p4info); pi_p4_id_t pi_p4info_direct_counter_begin(const pi_p4info_t *p4info); pi_p4_id_t pi_p4info_direct_counter_next(const pi_p4info_t *p4info, pi_p4_id_t id); pi_p4_id_t pi_p4info_direct_counter_end(const pi_p4info_t *p4info); #ifdef __cplusplus } #endif #endif // PI_INC_PI_P4INFO_COUNTERS_H_
{ "language": "C" }
/** ****************************************************************************** * @file TIM/TIM_PWMOutput/Src/stm32f4xx_it.c * @author MCD Application Team * @brief Main Interrupt Service Routines. * This file provides template for all exceptions handler and * peripherals interrupt service routine. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2> * * 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 STMicroelectronics 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. * ****************************************************************************** */ /* Includes ------------------------------------------------------------------*/ #include "main.h" #include "stm32f4xx_it.h" /** @addtogroup STM32F4xx_HAL_Examples * @{ */ /** @addtogroup TIM_PWMOutput * @{ */ /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ /* Private function prototypes -----------------------------------------------*/ /* Private functions ---------------------------------------------------------*/ /******************************************************************************/ /* Cortex-M4 Processor Exceptions Handlers */ /******************************************************************************/ /** * @brief This function handles NMI exception. * @param None * @retval None */ void NMI_Handler(void) { } /** * @brief This function handles Hard Fault exception. * @param None * @retval None */ void HardFault_Handler(void) { /* Go to infinite loop when Hard Fault exception occurs */ while (1) { } } /** * @brief This function handles Memory Manage exception. * @param None * @retval None */ void MemManage_Handler(void) { /* Go to infinite loop when Memory Manage exception occurs */ while (1) { } } /** * @brief This function handles Bus Fault exception. * @param None * @retval None */ void BusFault_Handler(void) { /* Go to infinite loop when Bus Fault exception occurs */ while (1) { } } /** * @brief This function handles Usage Fault exception. * @param None * @retval None */ void UsageFault_Handler(void) { /* Go to infinite loop when Usage Fault exception occurs */ while (1) { } } /** * @brief This function handles SVCall exception. * @param None * @retval None */ void SVC_Handler(void) { } /** * @brief This function handles Debug Monitor exception. * @param None * @retval None */ void DebugMon_Handler(void) { } /** * @brief This function handles PendSVC exception. * @param None * @retval None */ void PendSV_Handler(void) { } /** * @brief This function handles SysTick Handler. * @param None * @retval None */ void SysTick_Handler(void) { HAL_IncTick(); } /******************************************************************************/ /* STM32F4xx Peripherals Interrupt Handlers */ /* Add here the Interrupt Handler for the used peripheral(s) (PPP), for the */ /* available peripheral interrupt handler's name please refer to the startup */ /* file (startup_stm32f4xx.s). */ /******************************************************************************/ /** * @brief This function handles PPP interrupt request. * @param None * @retval None */ /*void PPP_IRQHandler(void) { }*/ /** * @} */ /** * @} */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
{ "language": "C" }
/* === This file is part of Tomahawk Player - <http://tomahawk-player.org> === * * Copyright 2010-2011, Christian Muehlhaeuser <muesli@tomahawk-player.org> * Copyright 2010-2011, Jeff Mitchell <jeff@tomahawk-player.org> * Copyright 2013, Uwe L. Korn <uwelk@xhochy.com> * * Tomahawk is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * Tomahawk 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 Tomahawk. If not, see <http://www.gnu.org/licenses/>. */ #ifndef DATABASECOMMAND_P_H #define DATABASECOMMAND_P_H #include "DatabaseCommand.h" namespace Tomahawk { class DatabaseCommandPrivate { public: explicit DatabaseCommandPrivate( DatabaseCommand* q ) : q_ptr( q ) , state( DatabaseCommand::PENDING ) { } explicit DatabaseCommandPrivate( DatabaseCommand* q, const Tomahawk::source_ptr& src ) : q_ptr( q ) , source( src ) , state( DatabaseCommand::PENDING ) { } Q_DECLARE_PUBLIC( DatabaseCommand ) DatabaseCommand* q_ptr; private: Tomahawk::source_ptr source; DatabaseCommand::State state; mutable QString guid; QVariant data; QWeakPointer< Tomahawk::DatabaseCommand > ownRef; }; } // Tomahawk #endif // DATABASECOMMAND_P_H
{ "language": "C" }
// This file is part of Eigen, a lightweight C++ template library // for linear algebra. // // Copyright (C) 2016 Benoit Steiner <benoit.steiner.goog@gmail.com> // // This Source Code Form is subject to the terms of the Mozilla // Public License v. 2.0. If a copy of the MPL was not distributed // with this file, You can obtain one at http://mozilla.org/MPL/2.0/. #ifndef EIGEN_CXX11_THREADPOOL_THREAD_YIELD_H #define EIGEN_CXX11_THREADPOOL_THREAD_YIELD_H // Try to come up with a portable way to yield #if EIGEN_COMP_GNUC && EIGEN_GNUC_AT_MOST(4, 7) #define EIGEN_THREAD_YIELD() sched_yield() #else #define EIGEN_THREAD_YIELD() std::this_thread::yield() #endif #endif // EIGEN_CXX11_THREADPOOL_THREAD_YIELD_H
{ "language": "C" }
/** @file Basic TPM command functions. Copyright (c) 2005 - 2018, Intel Corporation. All rights reserved.<BR> SPDX-License-Identifier: BSD-2-Clause-Patent **/ #include "CommonHeader.h" /** Single function calculates SHA1 digest value for all raw data. It combines Sha1Init(), Sha1Update() and Sha1Final(). @param[in] Data Raw data to be digested. @param[in] DataLen Size of the raw data. @param[out] Digest Pointer to a buffer that stores the final digest. @retval EFI_SUCCESS Always successfully calculate the final digest. **/ EFI_STATUS EFIAPI TpmCommHashAll ( IN CONST UINT8 *Data, IN UINTN DataLen, OUT TPM_DIGEST *Digest ) { VOID *Sha1Ctx; UINTN CtxSize; CtxSize = Sha1GetContextSize (); Sha1Ctx = AllocatePool (CtxSize); ASSERT (Sha1Ctx != NULL); Sha1Init (Sha1Ctx); Sha1Update (Sha1Ctx, Data, DataLen); Sha1Final (Sha1Ctx, (UINT8 *)Digest); FreePool (Sha1Ctx); return EFI_SUCCESS; }
{ "language": "C" }
/* * testRegexp.c: simple module for testing regular expressions * * See Copyright for the status of this software. * * Daniel Veillard <veillard@redhat.com> */ #include "libxml.h" #ifdef LIBXML_AUTOMATA_ENABLED #include <string.h> #include <libxml/tree.h> #include <libxml/xmlautomata.h> static int scanNumber(char **ptr) { int ret = 0; char *cur; cur = *ptr; while ((*cur >= '0') && (*cur <= '9')) { ret = ret * 10 + (*cur - '0'); cur++; } *ptr = cur; return(ret); } static void testRegexpFile(const char *filename) { FILE *input; char expr[5000]; int len; int ret; int i; xmlAutomataPtr am; xmlAutomataStatePtr states[1000]; xmlRegexpPtr regexp = NULL; xmlRegExecCtxtPtr exec = NULL; for (i = 0;i<1000;i++) states[i] = NULL; input = fopen(filename, "r"); if (input == NULL) { xmlGenericError(xmlGenericErrorContext, "Cannot open %s for reading\n", filename); return; } am = xmlNewAutomata(); if (am == NULL) { xmlGenericError(xmlGenericErrorContext, "Cannot create automata\n"); fclose(input); return; } states[0] = xmlAutomataGetInitState(am); if (states[0] == NULL) { xmlGenericError(xmlGenericErrorContext, "Cannot get start state\n"); xmlFreeAutomata(am); fclose(input); return; } ret = 0; while (fgets(expr, 4500, input) != NULL) { if (expr[0] == '#') continue; len = strlen(expr); len--; while ((len >= 0) && ((expr[len] == '\n') || (expr[len] == '\t') || (expr[len] == '\r') || (expr[len] == ' '))) len--; expr[len + 1] = 0; if (len >= 0) { if ((am != NULL) && (expr[0] == 't') && (expr[1] == ' ')) { char *ptr = &expr[2]; int from, to; from = scanNumber(&ptr); if (*ptr != ' ') { xmlGenericError(xmlGenericErrorContext, "Bad line %s\n", expr); break; } if (states[from] == NULL) states[from] = xmlAutomataNewState(am); ptr++; to = scanNumber(&ptr); if (*ptr != ' ') { xmlGenericError(xmlGenericErrorContext, "Bad line %s\n", expr); break; } if (states[to] == NULL) states[to] = xmlAutomataNewState(am); ptr++; xmlAutomataNewTransition(am, states[from], states[to], BAD_CAST ptr, NULL); } else if ((am != NULL) && (expr[0] == 'e') && (expr[1] == ' ')) { char *ptr = &expr[2]; int from, to; from = scanNumber(&ptr); if (*ptr != ' ') { xmlGenericError(xmlGenericErrorContext, "Bad line %s\n", expr); break; } if (states[from] == NULL) states[from] = xmlAutomataNewState(am); ptr++; to = scanNumber(&ptr); if (states[to] == NULL) states[to] = xmlAutomataNewState(am); xmlAutomataNewEpsilon(am, states[from], states[to]); } else if ((am != NULL) && (expr[0] == 'f') && (expr[1] == ' ')) { char *ptr = &expr[2]; int state; state = scanNumber(&ptr); if (states[state] == NULL) { xmlGenericError(xmlGenericErrorContext, "Bad state %d : %s\n", state, expr); break; } xmlAutomataSetFinalState(am, states[state]); } else if ((am != NULL) && (expr[0] == 'c') && (expr[1] == ' ')) { char *ptr = &expr[2]; int from, to; int min, max; from = scanNumber(&ptr); if (*ptr != ' ') { xmlGenericError(xmlGenericErrorContext, "Bad line %s\n", expr); break; } if (states[from] == NULL) states[from] = xmlAutomataNewState(am); ptr++; to = scanNumber(&ptr); if (*ptr != ' ') { xmlGenericError(xmlGenericErrorContext, "Bad line %s\n", expr); break; } if (states[to] == NULL) states[to] = xmlAutomataNewState(am); ptr++; min = scanNumber(&ptr); if (*ptr != ' ') { xmlGenericError(xmlGenericErrorContext, "Bad line %s\n", expr); break; } ptr++; max = scanNumber(&ptr); if (*ptr != ' ') { xmlGenericError(xmlGenericErrorContext, "Bad line %s\n", expr); break; } ptr++; xmlAutomataNewCountTrans(am, states[from], states[to], BAD_CAST ptr, min, max, NULL); } else if ((am != NULL) && (expr[0] == '-') && (expr[1] == '-')) { /* end of the automata */ regexp = xmlAutomataCompile(am); xmlFreeAutomata(am); am = NULL; if (regexp == NULL) { xmlGenericError(xmlGenericErrorContext, "Failed to compile the automata"); break; } } else if ((expr[0] == '=') && (expr[1] == '>')) { if (regexp == NULL) { printf("=> failed not compiled\n"); } else { if (exec == NULL) exec = xmlRegNewExecCtxt(regexp, NULL, NULL); if (ret == 0) { ret = xmlRegExecPushString(exec, NULL, NULL); } if (ret == 1) printf("=> Passed\n"); else if ((ret == 0) || (ret == -1)) printf("=> Failed\n"); else if (ret < 0) printf("=> Error\n"); xmlRegFreeExecCtxt(exec); exec = NULL; } ret = 0; } else if (regexp != NULL) { if (exec == NULL) exec = xmlRegNewExecCtxt(regexp, NULL, NULL); ret = xmlRegExecPushString(exec, BAD_CAST expr, NULL); } else { xmlGenericError(xmlGenericErrorContext, "Unexpected line %s\n", expr); } } } fclose(input); if (regexp != NULL) xmlRegFreeRegexp(regexp); if (exec != NULL) xmlRegFreeExecCtxt(exec); if (am != NULL) xmlFreeAutomata(am); } int main(int argc, char **argv) { xmlInitMemory(); if (argc == 1) { int ret; xmlAutomataPtr am; xmlAutomataStatePtr start, cur; xmlRegexpPtr regexp; xmlRegExecCtxtPtr exec; am = xmlNewAutomata(); start = xmlAutomataGetInitState(am); /* generate a[ba]*a */ cur = xmlAutomataNewTransition(am, start, NULL, BAD_CAST"a", NULL); xmlAutomataNewTransition(am, cur, cur, BAD_CAST"b", NULL); xmlAutomataNewTransition(am, cur, cur, BAD_CAST"a", NULL); cur = xmlAutomataNewCountTrans(am, cur, NULL, BAD_CAST"a", 2, 3, NULL); xmlAutomataSetFinalState(am, cur); /* compile it in a regexp and free the automata */ regexp = xmlAutomataCompile(am); xmlFreeAutomata(am); /* test the regexp */ xmlRegexpPrint(stdout, regexp); exec = xmlRegNewExecCtxt(regexp, NULL, NULL); ret = xmlRegExecPushString(exec, BAD_CAST"a", NULL); if (ret == 1) printf("final\n"); else if (ret < 0) printf("error\n"); ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL); if (ret == 1) printf("final\n"); else if (ret < 0) printf("error\n"); ret =xmlRegExecPushString(exec, BAD_CAST"b", NULL); if (ret == 1) printf("final\n"); else if (ret < 0) printf("error\n"); ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL); if (ret == 1) printf("final\n"); else if (ret < 0) printf("error\n"); ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL); if (ret == 1) printf("final\n"); else if (ret < 0) printf("error\n"); ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL); if (ret == 1) printf("final\n"); else if (ret < 0) printf("error\n"); ret =xmlRegExecPushString(exec, BAD_CAST"a", NULL); if (ret == 1) printf("final\n"); else if (ret < 0) printf("error\n"); if (ret == 0) { ret = xmlRegExecPushString(exec, NULL, NULL); if (ret == 1) printf("final\n"); else if (ret < 0) printf("error\n"); } xmlRegFreeExecCtxt(exec); /* free the regexp */ xmlRegFreeRegexp(regexp); } else { int i; for (i = 1;i < argc;i++) testRegexpFile(argv[i]); } xmlCleanupParser(); xmlMemoryDump(); return(0); } #else #include <stdio.h> int main(int argc ATTRIBUTE_UNUSED, char **argv ATTRIBUTE_UNUSED) { printf("%s : Automata support not compiled in\n", argv[0]); return(0); } #endif /* LIBXML_AUTOMATA_ENABLED */
{ "language": "C" }
//== llvm/CodeGen/GlobalISel/CombinerHelper.h -------------- -*- C++ -*-==// // // The LLVM Compiler Infrastructure // // This file is distributed under the University of Illinois Open Source // License. See LICENSE.TXT for details. // //===--------------------------------------------------------------------===// // /// This contains common combine transformations that may be used in a combine /// pass,or by the target elsewhere. /// Targets can pick individual opcode transformations from the helper or use /// tryCombine which invokes all transformations. All of the transformations /// return true if the MachineInstruction changed and false otherwise. // //===--------------------------------------------------------------------===// #ifndef LLVM_CODEGEN_GLOBALISEL_COMBINER_HELPER_H #define LLVM_CODEGEN_GLOBALISEL_COMBINER_HELPER_H namespace llvm { class MachineIRBuilder; class MachineRegisterInfo; class MachineInstr; class CombinerHelper { MachineIRBuilder &Builder; MachineRegisterInfo &MRI; public: CombinerHelper(MachineIRBuilder &B); /// If \p MI is COPY, try to combine it. /// Returns true if MI changed. bool tryCombineCopy(MachineInstr &MI); /// Try to transform \p MI by using all of the above /// combine functions. Returns true if changed. bool tryCombine(MachineInstr &MI); }; } // namespace llvm #endif
{ "language": "C" }
unsigned char lib_arsc[] = { 0x02, 0x00, 0x0c, 0x00, 0xb8, 0x02, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1c, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x20, 0x01, 0x90, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x63, 0x00, 0x6f, 0x00, 0x6d, 0x00, 0x2e, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x64, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x69, 0x00, 0x64, 0x00, 0x2e, 0x00, 0x74, 0x00, 0x65, 0x00, 0x73, 0x00, 0x74, 0x00, 0x2e, 0x00, 0x62, 0x00, 0x61, 0x00, 0x73, 0x00, 0x69, 0x00, 0x63, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x60, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1c, 0x00, 0x40, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0c, 0x00, 0x00, 0x00, 0x04, 0x00, 0x61, 0x00, 0x74, 0x00, 0x74, 0x00, 0x72, 0x00, 0x00, 0x00, 0x05, 0x00, 0x73, 0x00, 0x74, 0x00, 0x79, 0x00, 0x6c, 0x00, 0x65, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x1c, 0x00, 0x40, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x24, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0e, 0x00, 0x00, 0x00, 0x05, 0x00, 0x61, 0x00, 0x74, 0x00, 0x74, 0x00, 0x72, 0x00, 0x31, 0x00, 0x00, 0x00, 0x05, 0x00, 0x54, 0x00, 0x68, 0x00, 0x65, 0x00, 0x6d, 0x00, 0x65, 0x00, 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x44, 0x00, 0x64, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x08, 0x00, 0x00, 0x10, 0x04, 0x00, 0x00, 0x00, 0x02, 0x02, 0x10, 0x00, 0x14, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x02, 0x44, 0x00, 0x64, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x48, 0x00, 0x00, 0x00, 0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x08, 0x00, 0x00, 0x10, 0xbc, 0x02, 0x00, 0x00 }; unsigned int lib_arsc_len = 696;
{ "language": "C" }
/* * Copyright (c) 1983 Regents of the University of California. * All rights reserved. The Berkeley software License Agreement * specifies the terms and conditions for redistribution. */ #if defined(LIBC_SCCS) && !defined(lint) static char sccsid[] = "@(#)gethostent.c 5.3 (Berkeley) 3/9/86"; #endif LIBC_SCCS and not lint #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <arpa/inet.h> #include <netdb.h> #include <ctype.h> #include <ndbm.h> /* * Internet version. */ #define MAXALIASES 20 #define MAXADDRSIZE (sizeof (u_long)) static FILE *hostf = NULL; static char line[160+1]; static char hostaddr[MAXADDRSIZE]; static struct hostent host; static char *host_aliases[MAXALIASES]; static char *host_addrs[] = { hostaddr, NULL }; /* * The following is shared with gethostnamadr.c */ char *_host_file = "/etc/hosts"; int _host_stayopen; DBM *_host_db; /* set by gethostbyname(), gethostbyaddr() */ static char *any(); sethostent(f) int f; { if (hostf != NULL) rewind(hostf); _host_stayopen |= f; } endhostent() { if (hostf) { fclose(hostf); hostf = NULL; } if (_host_db) { dbm_close(_host_db); _host_db = (DBM *)NULL; } _host_stayopen = 0; } struct hostent * gethostent() { char *p; register char *cp, **q; if (hostf == NULL && (hostf = fopen(_host_file, "r" )) == NULL) return (NULL); again: if ((p = fgets(line, sizeof(line)-1, hostf)) == NULL) return (NULL); if (*p == '#') goto again; cp = any(p, "#\n"); if (cp == NULL) goto again; *cp = '\0'; cp = any(p, " \t"); if (cp == NULL) goto again; *cp++ = '\0'; /* THIS STUFF IS INTERNET SPECIFIC */ host.h_addr_list = host_addrs; *((u_long *)host.h_addr) = inet_addr(p); host.h_length = sizeof (u_long); host.h_addrtype = AF_INET; while (*cp == ' ' || *cp == '\t') cp++; host.h_name = cp; q = host.h_aliases = host_aliases; cp = any(cp, " \t"); if (cp != NULL) *cp++ = '\0'; while (cp && *cp) { if (*cp == ' ' || *cp == '\t') { cp++; continue; } if (q < &host_aliases[MAXALIASES - 1]) *q++ = cp; cp = any(cp, " \t"); if (cp != NULL) *cp++ = '\0'; } *q = NULL; return (&host); } sethostfile(file) char *file; { _host_file = file; } static char * any(cp, match) register char *cp; char *match; { register char *mp, c; while (c = *cp) { for (mp = match; *mp; mp++) if (*mp == c) return (cp); cp++; } return ((char *)0); }
{ "language": "C" }
/* * Copyright (c) 2017 Google Inc. * * 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 "libavutil/internal.h" #include "libavutil/arm/cpu.h" #include "vp9dsp_init.h" #define declare_fpel(type, sz, suffix) \ void ff_vp9_##type##sz##suffix##_neon(uint8_t *dst, ptrdiff_t dst_stride, \ const uint8_t *src, ptrdiff_t src_stride, \ int h, int mx, int my) #define decl_mc_func(op, filter, dir, sz, bpp) \ void ff_vp9_##op##_##filter##sz##_##dir##_##bpp##_neon(uint8_t *dst, ptrdiff_t dst_stride, \ const uint8_t *src, ptrdiff_t src_stride, \ int h, int mx, int my) #define define_8tap_2d_fn(op, filter, sz, bpp) \ static void op##_##filter##sz##_hv_##bpp##_neon(uint8_t *dst, ptrdiff_t dst_stride, \ const uint8_t *src, \ ptrdiff_t src_stride, \ int h, int mx, int my) \ { \ LOCAL_ALIGNED_16(uint8_t, temp, [((1 + (sz < 64)) * sz + 8) * sz * 2]); \ /* We only need h + 7 lines, but the horizontal filter assumes an \ * even number of rows, so filter h + 8 lines here. */ \ ff_vp9_put_##filter##sz##_h_##bpp##_neon(temp, 2 * sz, \ src - 3 * src_stride, src_stride, \ h + 8, mx, 0); \ ff_vp9_##op##_##filter##sz##_v_##bpp##_neon(dst, dst_stride, \ temp + 3 * 2 * sz, 2 * sz, \ h, 0, my); \ } #define decl_filter_funcs(op, dir, sz, bpp) \ decl_mc_func(op, regular, dir, sz, bpp); \ decl_mc_func(op, sharp, dir, sz, bpp); \ decl_mc_func(op, smooth, dir, sz, bpp) #define decl_mc_funcs(sz, bpp) \ decl_filter_funcs(put, h, sz, bpp); \ decl_filter_funcs(avg, h, sz, bpp); \ decl_filter_funcs(put, v, sz, bpp); \ decl_filter_funcs(avg, v, sz, bpp); \ decl_filter_funcs(put, hv, sz, bpp); \ decl_filter_funcs(avg, hv, sz, bpp) declare_fpel(copy, 128, ); declare_fpel(copy, 64, ); declare_fpel(copy, 32, ); declare_fpel(copy, 16, ); declare_fpel(copy, 8, ); declare_fpel(avg, 64, _16); declare_fpel(avg, 32, _16); declare_fpel(avg, 16, _16); declare_fpel(avg, 8, _16); declare_fpel(avg, 4, _16); decl_mc_funcs(64, BPP); decl_mc_funcs(32, BPP); decl_mc_funcs(16, BPP); decl_mc_funcs(8, BPP); decl_mc_funcs(4, BPP); #define define_8tap_2d_funcs(sz, bpp) \ define_8tap_2d_fn(put, regular, sz, bpp) \ define_8tap_2d_fn(put, sharp, sz, bpp) \ define_8tap_2d_fn(put, smooth, sz, bpp) \ define_8tap_2d_fn(avg, regular, sz, bpp) \ define_8tap_2d_fn(avg, sharp, sz, bpp) \ define_8tap_2d_fn(avg, smooth, sz, bpp) define_8tap_2d_funcs(64, BPP) define_8tap_2d_funcs(32, BPP) define_8tap_2d_funcs(16, BPP) define_8tap_2d_funcs(8, BPP) define_8tap_2d_funcs(4, BPP) static av_cold void vp9dsp_mc_init_arm(VP9DSPContext *dsp) { int cpu_flags = av_get_cpu_flags(); if (have_neon(cpu_flags)) { #define init_fpel(idx1, idx2, sz, type, suffix) \ dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = \ dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = \ dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = \ dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = ff_vp9_##type##sz##suffix##_neon #define init_copy_avg(idx, sz1, sz2) \ init_fpel(idx, 0, sz2, copy, ); \ init_fpel(idx, 1, sz1, avg, _16) #define init_mc_func(idx1, idx2, op, filter, fname, dir, mx, my, sz, pfx, bpp) \ dsp->mc[idx1][filter][idx2][mx][my] = pfx##op##_##fname##sz##_##dir##_##bpp##_neon #define init_mc_funcs(idx, dir, mx, my, sz, pfx, bpp) \ init_mc_func(idx, 0, put, FILTER_8TAP_REGULAR, regular, dir, mx, my, sz, pfx, bpp); \ init_mc_func(idx, 0, put, FILTER_8TAP_SHARP, sharp, dir, mx, my, sz, pfx, bpp); \ init_mc_func(idx, 0, put, FILTER_8TAP_SMOOTH, smooth, dir, mx, my, sz, pfx, bpp); \ init_mc_func(idx, 1, avg, FILTER_8TAP_REGULAR, regular, dir, mx, my, sz, pfx, bpp); \ init_mc_func(idx, 1, avg, FILTER_8TAP_SHARP, sharp, dir, mx, my, sz, pfx, bpp); \ init_mc_func(idx, 1, avg, FILTER_8TAP_SMOOTH, smooth, dir, mx, my, sz, pfx, bpp) #define init_mc_funcs_dirs(idx, sz, bpp) \ init_mc_funcs(idx, h, 1, 0, sz, ff_vp9_, bpp); \ init_mc_funcs(idx, v, 0, 1, sz, ff_vp9_, bpp); \ init_mc_funcs(idx, hv, 1, 1, sz, , bpp) init_copy_avg(0, 64, 128); init_copy_avg(1, 32, 64); init_copy_avg(2, 16, 32); init_copy_avg(3, 8, 16); init_copy_avg(4, 4, 8); init_mc_funcs_dirs(0, 64, BPP); init_mc_funcs_dirs(1, 32, BPP); init_mc_funcs_dirs(2, 16, BPP); init_mc_funcs_dirs(3, 8, BPP); init_mc_funcs_dirs(4, 4, BPP); } } #define define_itxfm2(type_a, type_b, sz, bpp) \ void ff_vp9_##type_a##_##type_b##_##sz##x##sz##_add_##bpp##_neon(uint8_t *_dst, \ ptrdiff_t stride, \ int16_t *_block, int eob) #define define_itxfm(type_a, type_b, sz, bpp) define_itxfm2(type_a, type_b, sz, bpp) #define define_itxfm_funcs(sz, bpp) \ define_itxfm(idct, idct, sz, bpp); \ define_itxfm(iadst, idct, sz, bpp); \ define_itxfm(idct, iadst, sz, bpp); \ define_itxfm(iadst, iadst, sz, bpp) define_itxfm_funcs(4, BPP); define_itxfm_funcs(8, BPP); define_itxfm_funcs(16, BPP); define_itxfm(idct, idct, 32, BPP); define_itxfm(iwht, iwht, 4, BPP); static av_cold void vp9dsp_itxfm_init_arm(VP9DSPContext *dsp) { int cpu_flags = av_get_cpu_flags(); if (have_neon(cpu_flags)) { #define init_itxfm2(tx, sz, bpp) \ dsp->itxfm_add[tx][DCT_DCT] = ff_vp9_idct_idct_##sz##_add_##bpp##_neon; \ dsp->itxfm_add[tx][DCT_ADST] = ff_vp9_iadst_idct_##sz##_add_##bpp##_neon; \ dsp->itxfm_add[tx][ADST_DCT] = ff_vp9_idct_iadst_##sz##_add_##bpp##_neon; \ dsp->itxfm_add[tx][ADST_ADST] = ff_vp9_iadst_iadst_##sz##_add_##bpp##_neon #define init_itxfm(tx, sz, bpp) init_itxfm2(tx, sz, bpp) #define init_idct2(tx, nm, bpp) \ dsp->itxfm_add[tx][DCT_DCT] = \ dsp->itxfm_add[tx][ADST_DCT] = \ dsp->itxfm_add[tx][DCT_ADST] = \ dsp->itxfm_add[tx][ADST_ADST] = ff_vp9_##nm##_add_##bpp##_neon #define init_idct(tx, nm, bpp) init_idct2(tx, nm, bpp) init_itxfm(TX_4X4, 4x4, BPP); init_itxfm(TX_8X8, 8x8, BPP); init_itxfm(TX_16X16, 16x16, BPP); init_idct(TX_32X32, idct_idct_32x32, BPP); init_idct(4, iwht_iwht_4x4, BPP); } } #define define_loop_filter(dir, wd, size, bpp) \ void ff_vp9_loop_filter_##dir##_##wd##_##size##_##bpp##_neon(uint8_t *dst, ptrdiff_t stride, int E, int I, int H) #define define_loop_filters(wd, size, bpp) \ define_loop_filter(h, wd, size, bpp); \ define_loop_filter(v, wd, size, bpp) define_loop_filters(4, 8, BPP); define_loop_filters(8, 8, BPP); define_loop_filters(16, 8, BPP); define_loop_filters(16, 16, BPP); define_loop_filters(44, 16, BPP); define_loop_filters(48, 16, BPP); define_loop_filters(84, 16, BPP); define_loop_filters(88, 16, BPP); static av_cold void vp9dsp_loopfilter_init_arm(VP9DSPContext *dsp) { int cpu_flags = av_get_cpu_flags(); if (have_neon(cpu_flags)) { #define init_lpf_func_8(idx1, idx2, dir, wd, bpp) \ dsp->loop_filter_8[idx1][idx2] = ff_vp9_loop_filter_##dir##_##wd##_8_##bpp##_neon #define init_lpf_func_16(idx, dir, bpp) \ dsp->loop_filter_16[idx] = ff_vp9_loop_filter_##dir##_16_16_##bpp##_neon #define init_lpf_func_mix2(idx1, idx2, idx3, dir, wd, bpp) \ dsp->loop_filter_mix2[idx1][idx2][idx3] = ff_vp9_loop_filter_##dir##_##wd##_16_##bpp##_neon #define init_lpf_funcs_8_wd(idx, wd, bpp) \ init_lpf_func_8(idx, 0, h, wd, bpp); \ init_lpf_func_8(idx, 1, v, wd, bpp) #define init_lpf_funcs_16(bpp) \ init_lpf_func_16(0, h, bpp); \ init_lpf_func_16(1, v, bpp) #define init_lpf_funcs_mix2_wd(idx1, idx2, wd, bpp) \ init_lpf_func_mix2(idx1, idx2, 0, h, wd, bpp); \ init_lpf_func_mix2(idx1, idx2, 1, v, wd, bpp) #define init_lpf_funcs_8(bpp) \ init_lpf_funcs_8_wd(0, 4, bpp); \ init_lpf_funcs_8_wd(1, 8, bpp); \ init_lpf_funcs_8_wd(2, 16, bpp) #define init_lpf_funcs_mix2(bpp) \ init_lpf_funcs_mix2_wd(0, 0, 44, bpp); \ init_lpf_funcs_mix2_wd(0, 1, 48, bpp); \ init_lpf_funcs_mix2_wd(1, 0, 84, bpp); \ init_lpf_funcs_mix2_wd(1, 1, 88, bpp) init_lpf_funcs_8(BPP); init_lpf_funcs_16(BPP); init_lpf_funcs_mix2(BPP); } } av_cold void INIT_FUNC(VP9DSPContext *dsp) { vp9dsp_mc_init_arm(dsp); vp9dsp_loopfilter_init_arm(dsp); vp9dsp_itxfm_init_arm(dsp); }
{ "language": "C" }
// Copyright 2013 the V8 project authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef V8_CRANKSHAFT_HYDROGEN_ESCAPE_ANALYSIS_H_ #define V8_CRANKSHAFT_HYDROGEN_ESCAPE_ANALYSIS_H_ #include "src/allocation.h" #include "src/crankshaft/hydrogen.h" namespace v8 { namespace internal { class HEscapeAnalysisPhase : public HPhase { public: explicit HEscapeAnalysisPhase(HGraph* graph) : HPhase("H_Escape analysis", graph), captured_(0, zone()), number_of_objects_(0), number_of_values_(0), cumulative_values_(0), block_states_(graph->blocks()->length(), zone()) { } void Run(); private: void CollectCapturedValues(); bool HasNoEscapingUses(HValue* value, int size); void PerformScalarReplacement(); void AnalyzeDataFlow(HInstruction* instr); HCapturedObject* NewState(HInstruction* prev); HCapturedObject* NewStateForAllocation(HInstruction* prev); HCapturedObject* NewStateForLoopHeader(HInstruction* prev, HCapturedObject*); HCapturedObject* NewStateCopy(HInstruction* prev, HCapturedObject* state); HPhi* NewPhiAndInsert(HBasicBlock* block, HValue* incoming_value, int index); HValue* NewMapCheckAndInsert(HCapturedObject* state, HCheckMaps* mapcheck); HValue* NewLoadReplacement(HLoadNamedField* load, HValue* load_value); HCapturedObject* StateAt(HBasicBlock* block) { return block_states_.at(block->block_id()); } void SetStateAt(HBasicBlock* block, HCapturedObject* state) { block_states_.Set(block->block_id(), state); } // List of allocations captured during collection phase. ZoneList<HInstruction*> captured_; // Number of captured objects on which scalar replacement was done. int number_of_objects_; // Number of scalar values tracked during scalar replacement phase. int number_of_values_; int cumulative_values_; // Map of block IDs to the data-flow state at block entry during the // scalar replacement phase. ZoneList<HCapturedObject*> block_states_; }; } // namespace internal } // namespace v8 #endif // V8_CRANKSHAFT_HYDROGEN_ESCAPE_ANALYSIS_H_
{ "language": "C" }
#ifndef BABYLON_MESHES_TRAIL_MESH_H #define BABYLON_MESHES_TRAIL_MESH_H #include <babylon/babylon_api.h> #include <babylon/meshes/mesh.h> namespace BABYLON { class TrailMesh; using TrailMeshPtr = std::shared_ptr<TrailMesh>; /** * @brief Class used to create a trail following a mesh. */ class BABYLON_SHARED_EXPORT TrailMesh : public Mesh { public: template <typename... Ts> static TrailMeshPtr New(Ts&&... args) { auto mesh = std::shared_ptr<TrailMesh>(new TrailMesh(std::forward<Ts>(args)...)); mesh->addToScene(mesh); return mesh; } ~TrailMesh() override; // = default /** * @brief "TrailMesh" * @returns "TrailMesh" */ std::string getClassName() const override; /** * @brief Start trailing mesh. */ void start(); /** * @brief Stop trailing mesh. */ void stop(); /** * @brief Update trailing mesh geometry. */ void update(); /** * @brief Returns a new TrailMesh object. * @param name is a string, the name given to the new mesh * @param newGenerator use new generator object for cloned trail mesh * @returns a new mesh */ TrailMeshPtr clone(const std::string& name = "", const TransformNodePtr& newGenerator = nullptr); /** * @brief Serializes this trail mesh. * @param serializationObject object to write serialization to */ void serialize(json& serializationObject) const override; /** * @brief Parses a serialized trail mesh. * @param parsedMesh the serialized mesh * @param scene the scene to create the trail mesh in * @returns the created trail mesh */ static TrailMeshPtr Parse(const json& parsedMesh, Scene* scene); protected: /** * @brief Constructor * @param name The value used by scene.getMeshByName() to do a lookup. * @param generator The mesh or transform node to generate a trail. * @param scene The scene to add this mesh to. * @param diameter Diameter of trailing mesh. Default is 1. * @param length Length of trailing mesh. Default is 60. * @param autoStart Automatically start trailing mesh. Default true. */ TrailMesh(const std::string& name, const TransformNodePtr& generator, Scene* scene, float diameter = 1.f, float length = 60.f, bool autoStart = true); private: void _createMesh(); private: TransformNodePtr _generator; bool _autoStart; bool _running; float _diameter; float _length; uint32_t _sectionPolygonPointsCount; std::vector<Vector3> _sectionVectors; std::vector<Vector3> _sectionNormalVectors; Observer<Scene>::Ptr _beforeRenderObserver; }; // end of class TrailMesh } // end of namespace BABYLON #endif // end of BABYLON_MESHES_TRAIL_MESH_H
{ "language": "C" }
/* 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_PERIPHERALNAMES_H #define MBED_PERIPHERALNAMES_H #include <compiler.h> #include "cmsis.h" #include "PinNames.h" #ifdef __cplusplus extern "C" { #endif #define _SERCOM_SPI_NAME(n, unused) \ SPI##n, #define _SERCOM_PAD_NAME(n, pad) \ SERCOM##n##_PAD##pad = ((n & 0xF) | ((pad & 0xF) << 4)), #define _SERCOM_I2C_NAME(n, unused) \ I2C##n, typedef enum { UART_0 = (int)0x42000800UL, // Base address of SERCOM0 UART_1 = (int)0x42000C00UL, // Base address of SERCOM1 UART_2 = (int)0x42001000UL, // Base address of SERCOM2 UART_3 = (int)0x42001400UL, // Base address of SERCOM3 UART_4 = (int)0x42001800UL, // Base address of SERCOM4 UART_5 = (int)0x42001C00UL // Base address of SERCOM5 } UARTName; typedef enum { ADC_0 = 0x0ul, ADC_1 = 0x1ul, ADC_2 = 0x2ul, ADC_3 = 0x3ul, ADC_4 = 0x4ul, ADC_5 = 0x5ul, ADC_6 = 0x6ul, ADC_7 = 0x7ul, ADC_8 = 0x8ul, ADC_9 = 0x8ul, ADC_10 = 0xAul, ADC_11 = 0xBul, ADC_12 = 0xCul, ADC_13 = 0xDul, ADC_14 = 0xEul, ADC_15 = 0xFul, ADC_16 = 0x10ul, ADC_17 = 0x11ul, ADC_18 = 0x12ul, ADC_19 = 0x13ul } ADCName; typedef enum { DAC_0 = 0x42004800UL } DACName; typedef enum { // for each channel EXTINT_0 = 0, EXTINT_1, EXTINT_2, EXTINT_3, EXTINT_4, EXTINT_5, EXTINT_6, EXTINT_7, EXTINT_8, EXTINT_9, EXTINT_10, EXTINT_11, EXTINT_12, EXTINT_13, EXTINT_14, EXTINT_15 } EXTINTName; typedef enum { MREPEAT(SERCOM_INST_NUM, _SERCOM_SPI_NAME, ~) } SPIName; typedef enum { MREPEAT(SERCOM_INST_NUM, _SERCOM_I2C_NAME, ~) } I2CName; typedef enum { /* Pad 0 definitions */ MREPEAT(SERCOM_INST_NUM, _SERCOM_PAD_NAME, 0) /* Pad 1 definitions */ MREPEAT(SERCOM_INST_NUM, _SERCOM_PAD_NAME, 1) /* Pad 2 definitions */ MREPEAT(SERCOM_INST_NUM, _SERCOM_PAD_NAME, 2) /* Pad 3 definitions */ MREPEAT(SERCOM_INST_NUM, _SERCOM_PAD_NAME, 3) } SercomPadName; typedef enum { PWM_0 = (0x42002000UL), /**< \brief (TCC0) APB Base Address */ PWM_1 = (0x42002400UL), /**< \brief (TCC1) APB Base Address */ PWM_2 = (0x42002800UL), /**< \brief (TCC2) APB Base Address */ } PWMName; struct pwm_pin_channel { PinName pin; PWMName pwm; uint8_t channel_index; }; #define STDIO_UART_TX USBTX #define STDIO_UART_RX USBRX #define STDIO_UART UART_3 // Default peripherals #define MBED_SPI0 PA18, PA16, PA19, PA17 #define MBED_UART0 PA04, PA05 #define MBED_UARTUSB USBTX, USBRX #define MBED_I2C0 PA08, PA09 #define MBED_ANALOGOUT0 PA02 #define MBED_ANALOGIN0 PA03 #define MBED_ANALOGIN1 PA08 #define MBED_ANALOGIN2 PB09 #define MBED_ANALOGIN3 PA04 #define MBED_ANALOGIN4 PA05 #define MBED_ANALOGIN5 PA06 #define MBED_ANALOGIN7 PA07 #define MBED_ANALOGIN8 PB00 #define MBED_ANALOGIN9 PB01 #define MBED_PWMOUT0 PA18 #define MBED_PWMOUT1 PA19 #ifdef __cplusplus } #endif #endif
{ "language": "C" }
/* inftrees.h -- header to use inftrees.c * Copyright (C) 1995-2002 Mark Adler * For conditions of distribution and use, see copyright notice in zlib.h */ /* WARNING: this file should *not* be used by applications. It is part of the implementation of the compression library and is subject to change. Applications should only use zlib.h. */ /* Huffman code lookup table entry--this entry is four bytes for machines that have 16-bit pointers (e.g. PC's in the small or medium model). */ #ifndef _INFTREES_H #define _INFTREES_H typedef struct inflate_huft_s FAR inflate_huft; struct inflate_huft_s { union { struct { Byte Exop; /* number of extra bits or operation */ Byte Bits; /* number of bits in this code or subcode */ } what; uInt pad; /* pad structure to a power of 2 (4 bytes for */ } word; /* 16-bit, 8 bytes for 32-bit int's) */ uInt base; /* literal, length base, distance base, or table offset */ }; /* Maximum size of dynamic tree. The maximum found in a long but non- exhaustive search was 1004 huft structures (850 for length/literals and 154 for distances, the latter actually the result of an exhaustive search). The actual maximum is not known, but the value below is more than safe. */ #define MANY 1440 local int inflate_trees_bits OF(( uIntf *, /* 19 code lengths */ uIntf *, /* bits tree desired/actual depth */ inflate_huft * FAR *, /* bits tree result */ inflate_huft *, /* space for trees */ z_streamp)); /* for messages */ local int inflate_trees_dynamic OF(( uInt, /* number of literal/length codes */ uInt, /* number of distance codes */ uIntf *, /* that many (total) code lengths */ uIntf *, /* literal desired/actual bit depth */ uIntf *, /* distance desired/actual bit depth */ inflate_huft * FAR *, /* literal/length tree result */ inflate_huft * FAR *, /* distance tree result */ inflate_huft *, /* space for trees */ z_streamp)); /* for messages */ local int inflate_trees_fixed OF(( uIntf *, /* literal desired/actual bit depth */ uIntf *, /* distance desired/actual bit depth */ const inflate_huft * FAR *, /* literal/length tree result */ const inflate_huft * FAR *, /* distance tree result */ z_streamp)); /* for memory allocation */ #endif /* _INFTREES_H */
{ "language": "C" }
/* * Copyright 2020 The WebRTC Project Authors. All rights reserved. * * Use of this source code is governed by a BSD-style license * that can be found in the LICENSE file in the root of the source * tree. An additional intellectual property rights grant can be found * in the file PATENTS. All contributing project authors may * be found in the AUTHORS file in the root of the source tree. */ #ifndef RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_ #define RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_ #include "absl/synchronization/mutex.h" #include "rtc_base/thread_annotations.h" namespace webrtc { class RTC_LOCKABLE MutexImpl final { public: MutexImpl() = default; MutexImpl(const MutexImpl&) = delete; MutexImpl& operator=(const MutexImpl&) = delete; void Lock() RTC_EXCLUSIVE_LOCK_FUNCTION() { mutex_.Lock(); } RTC_WARN_UNUSED_RESULT bool TryLock() RTC_EXCLUSIVE_TRYLOCK_FUNCTION(true) { return mutex_.TryLock(); } void Unlock() RTC_UNLOCK_FUNCTION() { mutex_.Unlock(); } private: absl::Mutex mutex_; }; } // namespace webrtc #endif // RTC_BASE_SYNCHRONIZATION_MUTEX_ABSEIL_H_
{ "language": "C" }
// // Copyright (C) 2005 Andras Varga // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License // as published by the Free Software Foundation; either version 2 // of the License, or (at your option) any later version. // // This program is distributed in the hope that it will be useful, // but WITHOUT ANY WARRANTY; without even the implied warranty of // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. // // You should have received a copy of the GNU General Public License // along with this program; if not, see <http://www.gnu.org/licenses/>. // #ifndef __INET_BONNMOTIONFILECACHE_H #define __INET_BONNMOTIONFILECACHE_H #include <list> #include <vector> #include "inet/common/INETDefs.h" namespace inet { class BonnMotionFileCache; /** * Represents a BonnMotion file's contents. * @see BonnMotionFileCache, BonnMotionMobility */ class INET_API BonnMotionFile { public: typedef std::vector<double> Line; protected: friend class BonnMotionFileCache; typedef std::list<Line> LineList; LineList lines; public: const Line *getLine(int nodeId) const; }; /** * Singleton object to read and store BonnMotion files. Used within * BonnMotionMobility. Needed because otherwise every node would * have to open and read the file independently. * * @ingroup mobility * @author Andras Varga */ class INET_API BonnMotionFileCache { protected: typedef std::map<std::string, BonnMotionFile> BmFileMap; BmFileMap cache; static BonnMotionFileCache *inst; void parseFile(const char *filename, BonnMotionFile& bmFile); BonnMotionFileCache() {} virtual ~BonnMotionFileCache() {} public: /** * Returns the singleton instance. */ static BonnMotionFileCache *getInstance(); /** * Deletes the singleton instance. */ static void deleteInstance(); /** * Returns the given document. */ virtual const BonnMotionFile *getFile(const char *filename); }; } // namespace inet #endif // ifndef __INET_BONNMOTIONFILECACHE_H
{ "language": "C" }
/* (c) Copyright 2012-2013 DirectFB integrated media GmbH (c) Copyright 2001-2013 The world wide DirectFB Open Source Community (directfb.org) (c) Copyright 2000-2004 Convergence (integrated media) GmbH All rights reserved. Written by Denis Oliver Kropp <dok@directfb.org>, Andreas Shimokawa <andi@directfb.org>, Marek Pikarski <mass@directfb.org>, Sven Neumann <neo@directfb.org>, Ville Syrjälä <syrjala@sci.fi> and Claudio Ciccani <klan@users.sf.net>. This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. You should have received a copy of the GNU Lesser General Public License along with this library; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #ifndef __VT_H__ #define __VT_H__ #include <signal.h> #include <termios.h> #include <unistd.h> #include <linux/vt.h> #include <directfb.h> typedef struct { int fd0; /* file descriptor of /dev/tty0 */ int fd; /* file descriptor of /dev/ttyN where N is the number of the allocated VT, may be equal to 'fd0' if VT allocation is disabled by "--no-vt-switch" */ int num; /* number of vt where DirectFB runs */ int prev; /* number of vt DirectFB was started from */ int old_fb; /* original fb mapped to vt */ struct sigaction sig_usr1; /* previous signal handler for USR1 */ struct sigaction sig_usr2; /* previous signal handler for USR2 */ struct vt_mode vt_mode; /* previous VT mode */ DirectThread *thread; pthread_mutex_t lock; pthread_cond_t wait; int vt_sig; struct termios old_ts; bool flush; DirectThread *flush_thread; } VirtualTerminal; /* * allocates and switches to a new virtual terminal */ DFBResult dfb_vt_initialize( void ); DFBResult dfb_vt_join( void ); /* * deallocates virtual terminal */ DFBResult dfb_vt_shutdown( bool emergency ); DFBResult dfb_vt_leave( bool emergency ); DFBResult dfb_vt_detach( bool force ); bool dfb_vt_switch( int num ); #endif
{ "language": "C" }
#pragma once #include "ofMain.h" #include "ofxNetwork.h" #include "RobotManager.h" #define dimensionX 0.8128f // table width #define dimensionY 0.508f // table height #define robotSize 0.027f // approximate robot radius class Behavior { private: int minrobots; public: void init(vector<RobotState>* robots); void update(vector<RobotState>* robots); protected: void discard(vector<RobotState>* robots, int from, int to); void setminrobots(int minrobots); void move(vector<RobotState>* robots, int robot, float x, float y); };
{ "language": "C" }
/* */ #ifndef Foundation_H #define Foundation_H /* */ class ostream; const long DEFAULT_LIST_CAPACITY = 200; #ifndef defs_h #define defs_h /* */ //typedef int bool; //const int true = 1; //const int false = 0; /* */ #endif /* */ template <class Item> class List { public: List(long size = DEFAULT_LIST_CAPACITY); List(List&); ~List(); List& operator=(const List&); /* */ long Count() const; Item& Get(long index) const; Item& First() const; Item& Last() const; bool Includes(const Item&) const; /* */ void Append(const Item&); void Prepend(const Item&); /* */ void Remove(const Item&); void RemoveLast(); void RemoveFirst(); void RemoveAll(); /* */ Item& Top() const; void Push(const Item&); Item& Pop(); }; /* */ template <class Item> class Iterator { public: virtual void First() = 0; virtual void Next() = 0; virtual bool IsDone() const = 0; virtual Item CurrentItem() const = 0; protected: Iterator(); }; /* */ template <class Item> class ListIterator : public Iterator<Item> { public: ListIterator(const List<Item>* aList); /* */ virtual void First(); virtual void Next(); virtual bool IsDone() const; virtual Item CurrentItem() const; }; /* */ typedef float Coord; /* */ class ostream; class istream; /* */ class Point { public: static const Point& Zero; /* */ Point(Coord x = 0.0, Coord y = 0.0); /* */ Coord X() const; void X(Coord x); Coord Y() const; void Y(Coord y); /* */ friend Point& operator+(const Point&, const Point&); friend Point& operator-(const Point&, const Point&); friend Point& operator*(const Point&, const Point&); friend Point& operator/(const Point&, const Point&); /* */ Point& operator+=(const Point&); Point& operator-=(const Point&); Point& operator*=(const Point&); Point& operator/=(const Point&); /* */ Point operator-(); /* */ friend bool operator==(const Point&, const Point&); friend bool operator!=(const Point&, const Point&); /* */ friend ostream& operator<<(ostream&, const Point&); friend istream& operator>>(istream&, Point&); }; /* */ class Rect { public: static const Rect& Zero; /* */ Rect(Coord x, Coord y, Coord w, Coord h); Rect(const Point& origin, const Point& extent); /* */ Coord Width() const; void Width(Coord); Coord Height() const; void Height(Coord); Coord Left() const; void Left(Coord); Coord Bottom() const; void Bottom(Coord); /* */ Point& Origin() const; void Origin(const Point&); Point& Extent() const; void Extent(const Point&); /* */ void MoveTo(const Point&); void MoveBy(const Point&); /* */ bool IsEmpty() const; bool Contains(const Point&) const; }; /* */ void dummy_found () { Rect* tmp = new /* */ Rect(Point(0, 0), Point(0, 0)); /* */ } #endif /* */
{ "language": "C" }
/** \file * * This file contains special DoxyGen information for the generation of the main page and other special * documentation pages. It is not a project source file. */ /** \mainpage MIDI Tone Generator Project * * \section Sec_Compat Project Compatibility: * * The following list indicates what microcontrollers are compatible with this project. * * \li Series 7 USB AVRs (AT90USBxxx7) * \li Series 6 USB AVRs (AT90USBxxx6) * \li Series 4 USB AVRs (ATMEGAxxU4) * * \section Sec_Info USB Information: * * The following table gives a rundown of the USB utilization of this project. * * <table> * <tr> * <td><b>USB Mode:</b></td> * <td>Device</td> * </tr> * <tr> * <td><b>USB Class:</b></td> * <td>Audio Class</td> * </tr> * <tr> * <td><b>USB Subclass:</b></td> * <td>Standard Audio Device</td> * </tr> * <tr> * <td><b>Relevant Standards:</b></td> * <td>USBIF Audio Class Specification \n * USB-MIDI Audio Class Extension Specification \n * General MIDI Specification</td> * </tr> * <tr> * <td><b>Supported USB Speeds:</b></td> * <td>Full Speed Mode</td> * </tr> * </table> * * \section Sec_Description Project Description: * * MIDI note synthesiser project. This project implements a basic DDS frequency synthesiser, capable of producing 8-bit PWM sine * waves of variable frequency. When attached to a USB host, this project will allow for multiple MIDI notes to be synthesised into * audiable sound via PWM, using the notes sent to MIDI channel 1. * * Outgoing audio will output in 8-bit PWM onto the timer 3 output compare channel A. Decouple the audio output with a capacitor * and attach to a speaker to hear the audio. * * \section Sec_Options Project Options * * The following defines can be found in this project, which can control the project behaviour when defined, or changed in value. * * <table> * <tr> * <th><b>Define Name:</b></th> * <th><b>Location:</b></th> * <th><b>Description:</b></th> * </tr> * <tr> * <td>MAX_SIMULTANEOUS_NOTES</td> * <td>AppConfig.h</td> * <td>Sets the maximum number of MIDI notes that can be generated simultaneously. More notes require more processing time, * and thus a value that is too high will cause audiable sound distortion due to insufficient CPU time.</td> * </tr> * </table> */
{ "language": "C" }
.Dd February 15, 2008 .Dt ffi_call 3 .Sh NAME .Nm ffi_call .Nd Invoke a foreign function. .Sh SYNOPSIS .In ffi.h .Ft void .Fo ffi_call .Fa "ffi_cif *cif" .Fa "void (*fn)(void)" .Fa "void *rvalue" .Fa "void **avalue" .Fc .Sh DESCRIPTION The .Nm ffi_call function provides a simple mechanism for invoking a function without requiring knowledge of the function's interface at compile time. .Fa fn is called with the values retrieved from the pointers in the .Fa avalue array. The return value from .Fa fn is placed in storage pointed to by .Fa rvalue . .Fa cif contains information describing the data types, sizes and alignments of the arguments to and return value from .Fa fn , and must be initialized with .Nm ffi_prep_cif before it is used with .Nm ffi_call . .Pp .Fa rvalue must point to storage that is sizeof(ffi_arg) or larger for non-floating point types. For smaller-sized return value types, the .Nm ffi_arg or .Nm ffi_sarg integral type must be used to hold the return value. .Sh EXAMPLES .Bd -literal #include <ffi.h> #include <stdio.h> unsigned char foo(unsigned int, float); int main(int argc, const char **argv) { ffi_cif cif; ffi_type *arg_types[2]; void *arg_values[2]; ffi_status status; // Because the return value from foo() is smaller than sizeof(long), it // must be passed as ffi_arg or ffi_sarg. ffi_arg result; // Specify the data type of each argument. Available types are defined // in <ffi/ffi.h>. arg_types[0] = &ffi_type_uint; arg_types[1] = &ffi_type_float; // Prepare the ffi_cif structure. if ((status = ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ffi_type_uint8, arg_types)) != FFI_OK) { // Handle the ffi_status error. } // Specify the values of each argument. unsigned int arg1 = 42; float arg2 = 5.1; arg_values[0] = &arg1; arg_values[1] = &arg2; // Invoke the function. ffi_call(&cif, FFI_FN(foo), &result, arg_values); // The ffi_arg 'result' now contains the unsigned char returned from foo(), // which can be accessed by a typecast. printf("result is %hhu", (unsigned char)result); return 0; } // The target function. unsigned char foo(unsigned int x, float y) { unsigned char result = x - y; return result; } .Ed .Sh SEE ALSO .Xr ffi 3 , .Xr ffi_prep_cif 3
{ "language": "C" }
/** * Copyright (c) 2014, Analog Devices, Inc. All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted (subject to the limitations in the * disclaimer below) 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 Analog Devices, Inc. nor the names of its * contributors may be used to endorse or promote products derived * from this software without specific prior written permission. * * NO EXPRESS OR IMPLIED LICENSES TO ANY PARTY'S PATENT RIGHTS ARE * GRANTED BY THIS LICENSE. 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. */ /** * \author Jim Paris <jim.paris@rigado.com> * * \file * This file exists only because some examples rely on it. */ #ifndef UART0_H #define UART0_H #include "dev/uart.h" #undef BAUD2UBR #define BAUD2UBR(x) (x) #define uart0_set_input(f) uart_set_input(f) #endif /* UART0_H */
{ "language": "C" }
/** ****************************************************************************** * @file stm32f4xx_hal_pcd_ex.h * @author MCD Application Team * @version V1.7.1 * @date 14-April-2017 * @brief Header file of PCD HAL module. ****************************************************************************** * @attention * * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2> * * 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 STMicroelectronics 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. * ****************************************************************************** */ /* Define to prevent recursive inclusion -------------------------------------*/ #ifndef __STM32F4xx_HAL_PCD_EX_H #define __STM32F4xx_HAL_PCD_EX_H #ifdef __cplusplus extern "C" { #endif #if defined(STM32F405xx) || defined(STM32F415xx) || defined(STM32F407xx) || defined(STM32F417xx) || \ defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \ defined(STM32F401xC) || defined(STM32F401xE) || defined(STM32F411xE) || defined(STM32F446xx) || \ defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) /* Includes ------------------------------------------------------------------*/ #include "stm32f4xx_hal_def.h" /** @addtogroup STM32F4xx_HAL_Driver * @{ */ /** @addtogroup PCDEx * @{ */ /* Exported types ------------------------------------------------------------*/ #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) typedef enum { PCD_LPM_L0_ACTIVE = 0x00U, /* on */ PCD_LPM_L1_ACTIVE = 0x01U /* LPM L1 sleep */ }PCD_LPM_MsgTypeDef; #endif /* STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx*/ #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) typedef enum { PCD_BCD_ERROR = 0xFFU, PCD_BCD_CONTACT_DETECTION = 0xFEU, PCD_BCD_STD_DOWNSTREAM_PORT = 0xFDU, PCD_BCD_CHARGING_DOWNSTREAM_PORT = 0xFCU, PCD_BCD_DEDICATED_CHARGING_PORT = 0xFBU, PCD_BCD_DISCOVERY_COMPLETED = 0x00U }PCD_BCD_MsgTypeDef; #endif /* STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx*/ /* Exported constants --------------------------------------------------------*/ /* Exported macros -----------------------------------------------------------*/ /* Exported functions --------------------------------------------------------*/ /** @addtogroup PCDEx_Exported_Functions PCD Extended Exported Functions * @{ */ /** @addtogroup PCDEx_Exported_Functions_Group1 Peripheral Control functions * @{ */ HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size); HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size); #if defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) || defined(STM32F412Zx) || defined(STM32F412Vx) || \ defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) HAL_StatusTypeDef HAL_PCDEx_ActivateLPM(PCD_HandleTypeDef *hpcd); HAL_StatusTypeDef HAL_PCDEx_DeActivateLPM(PCD_HandleTypeDef *hpcd); void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg); #endif /* STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx */ #if defined(STM32F412Zx) || defined(STM32F412Vx) || defined(STM32F412Rx) || defined(STM32F412Cx) || defined(STM32F413xx) || defined(STM32F423xx) HAL_StatusTypeDef HAL_PCDEx_ActivateBCD(PCD_HandleTypeDef *hpcd); HAL_StatusTypeDef HAL_PCDEx_DeActivateBCD(PCD_HandleTypeDef *hpcd); void HAL_PCDEx_BCD_VBUSDetect(PCD_HandleTypeDef *hpcd); void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg); void HAL_PCDEx_ADP_Sensing_Start(PCD_HandleTypeDef *hpcd); void HAL_PCDEx_ADP_Sensing_Callback(PCD_HandleTypeDef *hpcd); #endif /* STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx*/ /** * @} */ /** * @} */ /** * @} */ /** * @} */ #endif /* STM32F405xx || STM32F415xx || STM32F407xx || STM32F417xx || STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F401xC || STM32F401xE || STM32F411xE || STM32F446xx || STM32F469xx || STM32F479xx || STM32F412Zx || STM32F412Rx || STM32F412Vx || STM32F412Cx || STM32F413xx || STM32F423xx */ #ifdef __cplusplus } #endif #endif /* __STM32F4xx_HAL_PCD_EX_H */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
{ "language": "C" }
/* Copyright (c) 2016, 2018, Oracle and/or its affiliates. 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.0, as published by the Free Software Foundation. This program is also distributed with certain software (including but not limited to OpenSSL) that is licensed under separate terms, as designated in a particular file or component or in included license documentation. The authors of MySQL hereby grant you an additional permission to link the program and your derivative works with the separately licensed software that they have included with MySQL. 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.0, for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #ifndef HAVE_SECURITY_CONTEXT_WRAPPER_H #define HAVE_SECURITY_CONTEXT_WRAPPER_H #include <mysql/plugin.h> namespace connection_control { class Security_context_wrapper { public: Security_context_wrapper(MYSQL_THD thd); ~Security_context_wrapper() {} const char *get_proxy_user(); const char *get_priv_user(); const char *get_priv_host(); const char *get_user(); const char *get_host(); const char *get_ip(); bool security_context_exists(); bool is_super_user(); bool is_connection_admin(); private: bool get_property(const char *property, LEX_CSTRING *value); MYSQL_SECURITY_CONTEXT m_sctx; bool m_valid; }; } // namespace connection_control #endif // !HAVE_SECURITY_CONTEXT_WRAPPER_H
{ "language": "C" }
#include "pebble.h" static const GPathInfo MINUTE_SEGMENT_PATH_POINTS = { 3, (GPoint[]) { {0, 0}, {-8, -80}, // 80 = radius + fudge; 8 = 80*tan(6 degrees); 6 degrees per minute; {8, -80}, } }; static const GPathInfo HOUR_SEGMENT_PATH_POINTS = { 3, (GPoint[]) { {0, 0}, {-13, -50}, // 50 = radius + fudge; _ = 50*tan(15 degrees); 30 degrees per hour; {13, -50}, } }; static Window *s_main_window; static Layer *s_minute_display_layer, *s_hour_display_layer; static GPath *s_minute_segment_path, *s_hour_segment_path; static void minute_display_update_proc(Layer *layer, GContext* ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); unsigned int angle = t->tm_min * 6; gpath_rotate_to(s_minute_segment_path, (TRIG_MAX_ANGLE / 360) * angle); GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, center, 77); graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, s_minute_segment_path); graphics_fill_circle(ctx, center, 52); } static void hour_display_update_proc(Layer *layer, GContext* ctx) { time_t now = time(NULL); struct tm *t = localtime(&now); unsigned int angle = (t->tm_hour % 12) * 30; GRect bounds = layer_get_bounds(layer); GPoint center = grect_center_point(&bounds); graphics_context_set_fill_color(ctx, GColorWhite); graphics_fill_circle(ctx, center, 48); for (unsigned int i = 0; i < 360; i += 15) { if ((i != angle) && (i != (angle + 15)) && (i != ((angle - 15 + 360) % 360)) ) { gpath_rotate_to(s_hour_segment_path, (TRIG_MAX_ANGLE / 360) * i); graphics_context_set_fill_color(ctx, GColorBlack); gpath_draw_filled(ctx, s_hour_segment_path); } } // Stray pixels graphics_context_set_fill_color(ctx, GColorBlack); graphics_fill_circle(ctx, center, 5); graphics_context_set_stroke_color(ctx, GColorBlack); if ((angle != 0) && (angle != 330)) { graphics_draw_pixel(ctx, GPoint(71, 77)); graphics_draw_pixel(ctx, GPoint(71, 78)); } } static void handle_minute_tick(struct tm *tick_time, TimeUnits units_changed) { layer_mark_dirty(s_minute_display_layer); layer_mark_dirty(s_hour_display_layer); } static void main_window_load(Window *window) { Layer *window_layer = window_get_root_layer(window); GRect bounds = layer_get_bounds(window_layer); s_minute_display_layer = layer_create(bounds); layer_set_update_proc(s_minute_display_layer, minute_display_update_proc); layer_add_child(window_layer, s_minute_display_layer); s_minute_segment_path = gpath_create(&MINUTE_SEGMENT_PATH_POINTS); gpath_move_to(s_minute_segment_path, grect_center_point(&bounds)); s_hour_display_layer = layer_create(bounds); layer_set_update_proc(s_hour_display_layer, hour_display_update_proc); layer_add_child(window_layer, s_hour_display_layer); s_hour_segment_path = gpath_create(&HOUR_SEGMENT_PATH_POINTS); gpath_move_to(s_hour_segment_path, grect_center_point(&bounds)); } static void main_window_unload(Window *window) { gpath_destroy(s_minute_segment_path); gpath_destroy(s_hour_segment_path); layer_destroy(s_minute_display_layer); layer_destroy(s_hour_display_layer); } static void init() { s_main_window = window_create(); window_set_background_color(s_main_window, GColorBlack); window_set_window_handlers(s_main_window, (WindowHandlers) { .load = main_window_load, .unload = main_window_unload, }); window_stack_push(s_main_window, true); tick_timer_service_subscribe(MINUTE_UNIT, handle_minute_tick); } static void deinit() { window_destroy(s_main_window); tick_timer_service_unsubscribe(); } int main() { init(); app_event_loop(); deinit(); }
{ "language": "C" }
/* * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at> * * 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 */ /** * @file * common internal and external API header */ #ifndef AVUTIL_COMMON_H #define AVUTIL_COMMON_H #if defined(__cplusplus) && !defined(__STDC_CONSTANT_MACROS) && !defined(UINT64_C) #error missing -D__STDC_CONSTANT_MACROS / #define __STDC_CONSTANT_MACROS #endif #include <errno.h> #include <inttypes.h> #include <limits.h> #include <math.h> #include <stdint.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include "attributes.h" #include "version.h" #include "libavutil/avconfig.h" #if AV_HAVE_BIGENDIAN # define AV_NE(be, le) (be) #else # define AV_NE(be, le) (le) #endif //rounded division & shift #define RSHIFT(a,b) ((a) > 0 ? ((a) + ((1<<(b))>>1))>>(b) : ((a) + ((1<<(b))>>1)-1)>>(b)) /* assume b>0 */ #define ROUNDED_DIV(a,b) (((a)>0 ? (a) + ((b)>>1) : (a) - ((b)>>1))/(b)) /* assume a>0 and b>0 */ #define FF_CEIL_RSHIFT(a,b) (!av_builtin_constant_p(b) ? -((-(a)) >> (b)) \ : ((a) + (1<<(b)) - 1) >> (b)) #define FFUDIV(a,b) (((a)>0 ?(a):(a)-(b)+1) / (b)) #define FFUMOD(a,b) ((a)-(b)*FFUDIV(a,b)) #define FFABS(a) ((a) >= 0 ? (a) : (-(a))) #define FFSIGN(a) ((a) > 0 ? 1 : -1) #define FFMAX(a,b) ((a) > (b) ? (a) : (b)) #define FFMAX3(a,b,c) FFMAX(FFMAX(a,b),c) #define FFMIN(a,b) ((a) > (b) ? (b) : (a)) #define FFMIN3(a,b,c) FFMIN(FFMIN(a,b),c) #define FFSWAP(type,a,b) do{type SWAP_tmp= b; b= a; a= SWAP_tmp;}while(0) #define FF_ARRAY_ELEMS(a) (sizeof(a) / sizeof((a)[0])) #define FFALIGN(x, a) (((x)+(a)-1)&~((a)-1)) /* misc math functions */ /** * Reverse the order of the bits of an 8-bits unsigned integer. */ #if FF_API_AV_REVERSE extern attribute_deprecated const uint8_t av_reverse[256]; #endif #ifdef HAVE_AV_CONFIG_H # include "config.h" # include "intmath.h" #endif /* Pull in unguarded fallback defines at the end of this file. */ #include "common.h" #ifndef av_log2 av_const int av_log2(unsigned v); #endif #ifndef av_log2_16bit av_const int av_log2_16bit(unsigned v); #endif /** * Clip a signed integer value into the amin-amax range. * @param a value to clip * @param amin minimum value of the clip range * @param amax maximum value of the clip range * @return clipped value */ static av_always_inline av_const int av_clip_c(int a, int amin, int amax) { #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 if (amin > amax) abort(); #endif if (a < amin) return amin; else if (a > amax) return amax; else return a; } /** * Clip a signed 64bit integer value into the amin-amax range. * @param a value to clip * @param amin minimum value of the clip range * @param amax maximum value of the clip range * @return clipped value */ static av_always_inline av_const int64_t av_clip64_c(int64_t a, int64_t amin, int64_t amax) { #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 if (amin > amax) abort(); #endif if (a < amin) return amin; else if (a > amax) return amax; else return a; } /** * Clip a signed integer value into the 0-255 range. * @param a value to clip * @return clipped value */ static av_always_inline av_const uint8_t av_clip_uint8_c(int a) { if (a&(~0xFF)) return (-a)>>31; else return a; } /** * Clip a signed integer value into the -128,127 range. * @param a value to clip * @return clipped value */ static av_always_inline av_const int8_t av_clip_int8_c(int a) { if ((a+0x80U) & ~0xFF) return (a>>31) ^ 0x7F; else return a; } /** * Clip a signed integer value into the 0-65535 range. * @param a value to clip * @return clipped value */ static av_always_inline av_const uint16_t av_clip_uint16_c(int a) { if (a&(~0xFFFF)) return (-a)>>31; else return a; } /** * Clip a signed integer value into the -32768,32767 range. * @param a value to clip * @return clipped value */ static av_always_inline av_const int16_t av_clip_int16_c(int a) { if ((a+0x8000U) & ~0xFFFF) return (a>>31) ^ 0x7FFF; else return a; } /** * Clip a signed 64-bit integer value into the -2147483648,2147483647 range. * @param a value to clip * @return clipped value */ static av_always_inline av_const int32_t av_clipl_int32_c(int64_t a) { if ((a+0x80000000u) & ~UINT64_C(0xFFFFFFFF)) return (int32_t)((a>>63) ^ 0x7FFFFFFF); else return (int32_t)a; } /** * Clip a signed integer into the -(2^p),(2^p-1) range. * @param a value to clip * @param p bit position to clip at * @return clipped value */ static av_always_inline av_const int av_clip_intp2_c(int a, int p) { if ((a + (1 << p)) & ~((2 << p) - 1)) return (a >> 31) ^ ((1 << p) - 1); else return a; } /** * Clip a signed integer to an unsigned power of two range. * @param a value to clip * @param p bit position to clip at * @return clipped value */ static av_always_inline av_const unsigned av_clip_uintp2_c(int a, int p) { if (a & ~((1<<p) - 1)) return -a >> 31 & ((1<<p) - 1); else return a; } /** * Clear high bits from an unsigned integer starting with specific bit position * @param a value to clip * @param p bit position to clip at * @return clipped value */ static av_always_inline av_const unsigned av_mod_uintp2_c(unsigned a, unsigned p) { return a & ((1 << p) - 1); } /** * Add two signed 32-bit values with saturation. * * @param a one value * @param b another value * @return sum with signed saturation */ static av_always_inline int av_sat_add32_c(int a, int b) { return av_clipl_int32((int64_t)a + b); } /** * Add a doubled value to another value with saturation at both stages. * * @param a first value * @param b value doubled and added to a * @return sum with signed saturation */ static av_always_inline int av_sat_dadd32_c(int a, int b) { return av_sat_add32(a, av_sat_add32(b, b)); } /** * Clip a float value into the amin-amax range. * @param a value to clip * @param amin minimum value of the clip range * @param amax maximum value of the clip range * @return clipped value */ static av_always_inline av_const float av_clipf_c(float a, float amin, float amax) { #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 if (amin > amax) abort(); #endif if (a < amin) return amin; else if (a > amax) return amax; else return a; } /** * Clip a double value into the amin-amax range. * @param a value to clip * @param amin minimum value of the clip range * @param amax maximum value of the clip range * @return clipped value */ static av_always_inline av_const double av_clipd_c(double a, double amin, double amax) { #if defined(HAVE_AV_CONFIG_H) && defined(ASSERT_LEVEL) && ASSERT_LEVEL >= 2 if (amin > amax) abort(); #endif if (a < amin) return amin; else if (a > amax) return amax; else return a; } /** Compute ceil(log2(x)). * @param x value used to compute ceil(log2(x)) * @return computed ceiling of log2(x) */ static av_always_inline av_const int av_ceil_log2_c(int x) { return av_log2((x - 1) << 1); } /** * Count number of bits set to one in x * @param x value to count bits of * @return the number of bits set to one in x */ static av_always_inline av_const int av_popcount_c(uint32_t x) { x -= (x >> 1) & 0x55555555; x = (x & 0x33333333) + ((x >> 2) & 0x33333333); x = (x + (x >> 4)) & 0x0F0F0F0F; x += x >> 8; return (x + (x >> 16)) & 0x3F; } /** * Count number of bits set to one in x * @param x value to count bits of * @return the number of bits set to one in x */ static av_always_inline av_const int av_popcount64_c(uint64_t x) { return av_popcount((uint32_t)x) + av_popcount((uint32_t)(x >> 32)); } #define MKTAG(a,b,c,d) ((a) | ((b) << 8) | ((c) << 16) | ((unsigned)(d) << 24)) #define MKBETAG(a,b,c,d) ((d) | ((c) << 8) | ((b) << 16) | ((unsigned)(a) << 24)) /** * Convert a UTF-8 character (up to 4 bytes) to its 32-bit UCS-4 encoded form. * * @param val Output value, must be an lvalue of type uint32_t. * @param GET_BYTE Expression reading one byte from the input. * Evaluated up to 7 times (4 for the currently * assigned Unicode range). With a memory buffer * input, this could be *ptr++. * @param ERROR Expression to be evaluated on invalid input, * typically a goto statement. * * @warning ERROR should not contain a loop control statement which * could interact with the internal while loop, and should force an * exit from the macro code (e.g. through a goto or a return) in order * to prevent undefined results. */ #define GET_UTF8(val, GET_BYTE, ERROR)\ val= GET_BYTE;\ {\ uint32_t top = (val & 128) >> 1;\ if ((val & 0xc0) == 0x80 || val >= 0xFE)\ ERROR\ while (val & top) {\ int tmp= GET_BYTE - 128;\ if(tmp>>6)\ ERROR\ val= (val<<6) + tmp;\ top <<= 5;\ }\ val &= (top << 1) - 1;\ } /** * Convert a UTF-16 character (2 or 4 bytes) to its 32-bit UCS-4 encoded form. * * @param val Output value, must be an lvalue of type uint32_t. * @param GET_16BIT Expression returning two bytes of UTF-16 data converted * to native byte order. Evaluated one or two times. * @param ERROR Expression to be evaluated on invalid input, * typically a goto statement. */ #define GET_UTF16(val, GET_16BIT, ERROR)\ val = GET_16BIT;\ {\ unsigned int hi = val - 0xD800;\ if (hi < 0x800) {\ val = GET_16BIT - 0xDC00;\ if (val > 0x3FFU || hi > 0x3FFU)\ ERROR\ val += (hi<<10) + 0x10000;\ }\ }\ /** * @def PUT_UTF8(val, tmp, PUT_BYTE) * Convert a 32-bit Unicode character to its UTF-8 encoded form (up to 4 bytes long). * @param val is an input-only argument and should be of type uint32_t. It holds * a UCS-4 encoded Unicode character that is to be converted to UTF-8. If * val is given as a function it is executed only once. * @param tmp is a temporary variable and should be of type uint8_t. It * represents an intermediate value during conversion that is to be * output by PUT_BYTE. * @param PUT_BYTE writes the converted UTF-8 bytes to any proper destination. * It could be a function or a statement, and uses tmp as the input byte. * For example, PUT_BYTE could be "*output++ = tmp;" PUT_BYTE will be * executed up to 4 times for values in the valid UTF-8 range and up to * 7 times in the general case, depending on the length of the converted * Unicode character. */ #define PUT_UTF8(val, tmp, PUT_BYTE)\ {\ int bytes, shift;\ uint32_t in = val;\ if (in < 0x80) {\ tmp = in;\ PUT_BYTE\ } else {\ bytes = (av_log2(in) + 4) / 5;\ shift = (bytes - 1) * 6;\ tmp = (256 - (256 >> bytes)) | (in >> shift);\ PUT_BYTE\ while (shift >= 6) {\ shift -= 6;\ tmp = 0x80 | ((in >> shift) & 0x3f);\ PUT_BYTE\ }\ }\ } /** * @def PUT_UTF16(val, tmp, PUT_16BIT) * Convert a 32-bit Unicode character to its UTF-16 encoded form (2 or 4 bytes). * @param val is an input-only argument and should be of type uint32_t. It holds * a UCS-4 encoded Unicode character that is to be converted to UTF-16. If * val is given as a function it is executed only once. * @param tmp is a temporary variable and should be of type uint16_t. It * represents an intermediate value during conversion that is to be * output by PUT_16BIT. * @param PUT_16BIT writes the converted UTF-16 data to any proper destination * in desired endianness. It could be a function or a statement, and uses tmp * as the input byte. For example, PUT_BYTE could be "*output++ = tmp;" * PUT_BYTE will be executed 1 or 2 times depending on input character. */ #define PUT_UTF16(val, tmp, PUT_16BIT)\ {\ uint32_t in = val;\ if (in < 0x10000) {\ tmp = in;\ PUT_16BIT\ } else {\ tmp = 0xD800 | ((in - 0x10000) >> 10);\ PUT_16BIT\ tmp = 0xDC00 | ((in - 0x10000) & 0x3FF);\ PUT_16BIT\ }\ }\ #include "mem.h" #ifdef HAVE_AV_CONFIG_H # include "internal.h" #endif /* HAVE_AV_CONFIG_H */ #endif /* AVUTIL_COMMON_H */ /* * The following definitions are outside the multiple inclusion guard * to ensure they are immediately available in intmath.h. */ #ifndef av_ceil_log2 # define av_ceil_log2 av_ceil_log2_c #endif #ifndef av_clip # define av_clip av_clip_c #endif #ifndef av_clip64 # define av_clip64 av_clip64_c #endif #ifndef av_clip_uint8 # define av_clip_uint8 av_clip_uint8_c #endif #ifndef av_clip_int8 # define av_clip_int8 av_clip_int8_c #endif #ifndef av_clip_uint16 # define av_clip_uint16 av_clip_uint16_c #endif #ifndef av_clip_int16 # define av_clip_int16 av_clip_int16_c #endif #ifndef av_clipl_int32 # define av_clipl_int32 av_clipl_int32_c #endif #ifndef av_clip_intp2 # define av_clip_intp2 av_clip_intp2_c #endif #ifndef av_clip_uintp2 # define av_clip_uintp2 av_clip_uintp2_c #endif #ifndef av_mod_uintp2 # define av_mod_uintp2 av_mod_uintp2_c #endif #ifndef av_sat_add32 # define av_sat_add32 av_sat_add32_c #endif #ifndef av_sat_dadd32 # define av_sat_dadd32 av_sat_dadd32_c #endif #ifndef av_clipf # define av_clipf av_clipf_c #endif #ifndef av_clipd # define av_clipd av_clipd_c #endif #ifndef av_popcount # define av_popcount av_popcount_c #endif #ifndef av_popcount64 # define av_popcount64 av_popcount64_c #endif
{ "language": "C" }
/* Area: closure_call Purpose: Check return value sshort. Limitations: none. PR: none. Originator: <andreast@gcc.gnu.org> 20031108 */ /* { dg-do run } */ #include "ffitest.h" static void cls_ret_sshort_fn(ffi_cif* cif __UNUSED__, void* resp, void** args, void* userdata __UNUSED__) { *(ffi_arg*)resp = *(signed short *)args[0]; printf("%d: %d\n",*(signed short *)args[0], (int)*(ffi_arg *)(resp)); } typedef signed short (*cls_ret_sshort)(signed short); int main (void) { ffi_cif cif; void *code; ffi_closure *pcl = ffi_closure_alloc(sizeof(ffi_closure), &code); ffi_type * cl_arg_types[2]; signed short res; cl_arg_types[0] = &ffi_type_sshort; cl_arg_types[1] = NULL; /* Initialize the cif */ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ffi_type_sshort, cl_arg_types) == FFI_OK); CHECK(ffi_prep_closure_loc(pcl, &cif, cls_ret_sshort_fn, NULL, code) == FFI_OK); res = (*((cls_ret_sshort)code))(255); /* { dg-output "255: 255" } */ printf("res: %d\n",res); /* { dg-output "\nres: 255" } */ exit(0); }
{ "language": "C" }
/* * mainstone-wm97xx.c -- Mainstone Continuous Touch screen driver for * Wolfson WM97xx AC97 Codecs. * * Copyright 2004, 2007 Wolfson Microelectronics PLC. * Author: Liam Girdwood <lrg@slimlogic.co.uk> * Parts Copyright : Ian Molton <spyro@f2s.com> * Andrew Zabolotny <zap@homelink.ru> * * 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. * * Notes: * This is a wm97xx extended touch driver to capture touch * data in a continuous manner on the Intel XScale architecture * * Features: * - codecs supported:- WM9705, WM9712, WM9713 * - processors supported:- Intel XScale PXA25x, PXA26x, PXA27x * */ #include <linux/module.h> #include <linux/moduleparam.h> #include <linux/kernel.h> #include <linux/init.h> #include <linux/delay.h> #include <linux/irq.h> #include <linux/interrupt.h> #include <linux/wm97xx.h> #include <linux/io.h> #include <linux/gpio.h> #include <mach/regs-ac97.h> #include <asm/mach-types.h> struct continuous { u16 id; /* codec id */ u8 code; /* continuous code */ u8 reads; /* number of coord reads per read cycle */ u32 speed; /* number of coords per second */ }; #define WM_READS(sp) ((sp / HZ) + 1) static const struct continuous cinfo[] = { {WM9705_ID2, 0, WM_READS(94), 94}, {WM9705_ID2, 1, WM_READS(188), 188}, {WM9705_ID2, 2, WM_READS(375), 375}, {WM9705_ID2, 3, WM_READS(750), 750}, {WM9712_ID2, 0, WM_READS(94), 94}, {WM9712_ID2, 1, WM_READS(188), 188}, {WM9712_ID2, 2, WM_READS(375), 375}, {WM9712_ID2, 3, WM_READS(750), 750}, {WM9713_ID2, 0, WM_READS(94), 94}, {WM9713_ID2, 1, WM_READS(120), 120}, {WM9713_ID2, 2, WM_READS(154), 154}, {WM9713_ID2, 3, WM_READS(188), 188}, }; /* continuous speed index */ static int sp_idx; static u16 last, tries; static int irq; /* * Pen sampling frequency (Hz) in continuous mode. */ static int cont_rate = 200; module_param(cont_rate, int, 0); MODULE_PARM_DESC(cont_rate, "Sampling rate in continuous mode (Hz)"); /* * Pen down detection. * * This driver can either poll or use an interrupt to indicate a pen down * event. If the irq request fails then it will fall back to polling mode. */ static int pen_int; module_param(pen_int, int, 0); MODULE_PARM_DESC(pen_int, "Pen down detection (1 = interrupt, 0 = polling)"); /* * Pressure readback. * * Set to 1 to read back pen down pressure */ static int pressure; module_param(pressure, int, 0); MODULE_PARM_DESC(pressure, "Pressure readback (1 = pressure, 0 = no pressure)"); /* * AC97 touch data slot. * * Touch screen readback data ac97 slot */ static int ac97_touch_slot = 5; module_param(ac97_touch_slot, int, 0); MODULE_PARM_DESC(ac97_touch_slot, "Touch screen data slot AC97 number"); /* flush AC97 slot 5 FIFO on pxa machines */ #ifdef CONFIG_PXA27x static void wm97xx_acc_pen_up(struct wm97xx *wm) { schedule_timeout_uninterruptible(1); while (MISR & (1 << 2)) MODR; } #else static void wm97xx_acc_pen_up(struct wm97xx *wm) { unsigned int count; schedule_timeout_uninterruptible(1); for (count = 0; count < 16; count++) MODR; } #endif static int wm97xx_acc_pen_down(struct wm97xx *wm) { u16 x, y, p = 0x100 | WM97XX_ADCSEL_PRES; int reads = 0; /* When the AC97 queue has been drained we need to allow time * to buffer up samples otherwise we end up spinning polling * for samples. The controller can't have a suitably low * threshold set to use the notifications it gives. */ schedule_timeout_uninterruptible(1); if (tries > 5) { tries = 0; return RC_PENUP; } x = MODR; if (x == last) { tries++; return RC_AGAIN; } last = x; do { if (reads) x = MODR; y = MODR; if (pressure) p = MODR; dev_dbg(wm->dev, "Raw coordinates: x=%x, y=%x, p=%x\n", x, y, p); /* are samples valid */ if ((x & WM97XX_ADCSEL_MASK) != WM97XX_ADCSEL_X || (y & WM97XX_ADCSEL_MASK) != WM97XX_ADCSEL_Y || (p & WM97XX_ADCSEL_MASK) != WM97XX_ADCSEL_PRES) goto up; /* coordinate is good */ tries = 0; input_report_abs(wm->input_dev, ABS_X, x & 0xfff); input_report_abs(wm->input_dev, ABS_Y, y & 0xfff); input_report_abs(wm->input_dev, ABS_PRESSURE, p & 0xfff); input_report_key(wm->input_dev, BTN_TOUCH, (p != 0)); input_sync(wm->input_dev); reads++; } while (reads < cinfo[sp_idx].reads); up: return RC_PENDOWN | RC_AGAIN; } static int wm97xx_acc_startup(struct wm97xx *wm) { int idx = 0, ret = 0; /* check we have a codec */ if (wm->ac97 == NULL) return -ENODEV; /* Go you big red fire engine */ for (idx = 0; idx < ARRAY_SIZE(cinfo); idx++) { if (wm->id != cinfo[idx].id) continue; sp_idx = idx; if (cont_rate <= cinfo[idx].speed) break; } wm->acc_rate = cinfo[sp_idx].code; wm->acc_slot = ac97_touch_slot; dev_info(wm->dev, "mainstone accelerated touchscreen driver, %d samples/sec\n", cinfo[sp_idx].speed); /* IRQ driven touchscreen is used on Palm hardware */ if (machine_is_palmt5() || machine_is_palmtx() || machine_is_palmld()) { pen_int = 1; irq = 27; /* There is some obscure mutant of WM9712 interbred with WM9713 * used on Palm HW */ wm->variant = WM97xx_WM1613; } else if (machine_is_mainstone() && pen_int) irq = 4; if (irq) { ret = gpio_request(irq, "Touchscreen IRQ"); if (ret) goto out; ret = gpio_direction_input(irq); if (ret) { gpio_free(irq); goto out; } wm->pen_irq = gpio_to_irq(irq); irq_set_irq_type(wm->pen_irq, IRQ_TYPE_EDGE_BOTH); } else /* pen irq not supported */ pen_int = 0; /* codec specific irq config */ if (pen_int) { switch (wm->id) { case WM9705_ID2: break; case WM9712_ID2: case WM9713_ID2: /* use PEN_DOWN GPIO 13 to assert IRQ on GPIO line 2 */ wm97xx_config_gpio(wm, WM97XX_GPIO_13, WM97XX_GPIO_IN, WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_STICKY, WM97XX_GPIO_WAKE); wm97xx_config_gpio(wm, WM97XX_GPIO_2, WM97XX_GPIO_OUT, WM97XX_GPIO_POL_HIGH, WM97XX_GPIO_NOTSTICKY, WM97XX_GPIO_NOWAKE); break; default: dev_err(wm->dev, "pen down irq not supported on this device\n"); pen_int = 0; break; } } out: return ret; } static void wm97xx_acc_shutdown(struct wm97xx *wm) { /* codec specific deconfig */ if (pen_int) { if (irq) gpio_free(irq); wm->pen_irq = 0; } } static void wm97xx_irq_enable(struct wm97xx *wm, int enable) { if (enable) enable_irq(wm->pen_irq); else disable_irq_nosync(wm->pen_irq); } static struct wm97xx_mach_ops mainstone_mach_ops = { .acc_enabled = 1, .acc_pen_up = wm97xx_acc_pen_up, .acc_pen_down = wm97xx_acc_pen_down, .acc_startup = wm97xx_acc_startup, .acc_shutdown = wm97xx_acc_shutdown, .irq_enable = wm97xx_irq_enable, .irq_gpio = WM97XX_GPIO_2, }; static int mainstone_wm97xx_probe(struct platform_device *pdev) { struct wm97xx *wm = platform_get_drvdata(pdev); return wm97xx_register_mach_ops(wm, &mainstone_mach_ops); } static int mainstone_wm97xx_remove(struct platform_device *pdev) { struct wm97xx *wm = platform_get_drvdata(pdev); wm97xx_unregister_mach_ops(wm); return 0; } static struct platform_driver mainstone_wm97xx_driver = { .probe = mainstone_wm97xx_probe, .remove = mainstone_wm97xx_remove, .driver = { .name = "wm97xx-touch", }, }; module_platform_driver(mainstone_wm97xx_driver); /* Module information */ MODULE_AUTHOR("Liam Girdwood <lrg@slimlogic.co.uk>"); MODULE_DESCRIPTION("wm97xx continuous touch driver for mainstone"); MODULE_LICENSE("GPL");
{ "language": "C" }
/* * Copyright 2012 The Nouveau community * * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Authors: Martin Peres */ #include "priv.h" #include <subdev/gpio.h> #include <subdev/timer.h> struct nvkm_fantog { struct nvkm_fan base; struct nvkm_alarm alarm; spinlock_t lock; u32 period_us; u32 percent; struct dcb_gpio_func func; }; static void nvkm_fantog_update(struct nvkm_fantog *fan, int percent) { struct nvkm_therm *therm = fan->base.parent; struct nvkm_device *device = therm->subdev.device; struct nvkm_timer *tmr = device->timer; struct nvkm_gpio *gpio = device->gpio; unsigned long flags; int duty; spin_lock_irqsave(&fan->lock, flags); if (percent < 0) percent = fan->percent; fan->percent = percent; duty = !nvkm_gpio_get(gpio, 0, DCB_GPIO_FAN, 0xff); nvkm_gpio_set(gpio, 0, DCB_GPIO_FAN, 0xff, duty); if (percent != (duty * 100)) { u64 next_change = (percent * fan->period_us) / 100; if (!duty) next_change = fan->period_us - next_change; nvkm_timer_alarm(tmr, next_change * 1000, &fan->alarm); } spin_unlock_irqrestore(&fan->lock, flags); } static void nvkm_fantog_alarm(struct nvkm_alarm *alarm) { struct nvkm_fantog *fan = container_of(alarm, struct nvkm_fantog, alarm); nvkm_fantog_update(fan, -1); } static int nvkm_fantog_get(struct nvkm_therm *therm) { struct nvkm_fantog *fan = (void *)therm->fan; return fan->percent; } static int nvkm_fantog_set(struct nvkm_therm *therm, int percent) { struct nvkm_fantog *fan = (void *)therm->fan; if (therm->func->pwm_ctrl) therm->func->pwm_ctrl(therm, fan->func.line, false); nvkm_fantog_update(fan, percent); return 0; } int nvkm_fantog_create(struct nvkm_therm *therm, struct dcb_gpio_func *func) { struct nvkm_fantog *fan; int ret; if (therm->func->pwm_ctrl) { ret = therm->func->pwm_ctrl(therm, func->line, false); if (ret) return ret; } fan = kzalloc(sizeof(*fan), GFP_KERNEL); therm->fan = &fan->base; if (!fan) return -ENOMEM; fan->base.type = "toggle"; fan->base.get = nvkm_fantog_get; fan->base.set = nvkm_fantog_set; nvkm_alarm_init(&fan->alarm, nvkm_fantog_alarm); fan->period_us = 100000; /* 10Hz */ fan->percent = 100; fan->func = *func; spin_lock_init(&fan->lock); return 0; }
{ "language": "C" }
/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License (the "License"). * You may not use this file except in compliance with the License. * * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE * or http://www.opensolaris.org/os/licensing. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at usr/src/OPENSOLARIS.LICENSE. * If applicable, add the following below this CDDL HEADER, with the * fields enclosed by brackets "[]" replaced with your own identifying * information: Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END */ /* * Copyright 2008 Sun Microsystems, Inc. All rights reserved. * Use is subject to license terms. */ /* * Copyright 2012 Garrett D'Amore <garrett@damore.org>. All rights reserved. */ /* * Floppy Disk Controller Driver * * for the standard PC architecture using the Intel 8272A fdc. * Note that motor control and drive select use a latch external * to the fdc. * * This driver is EISA capable, and uses DMA buffer chaining if available. * If this driver is attached to the ISA bus nexus (or if the EISA bus driver * does not support DMA buffer chaining), then the bus driver must ensure * that dma mapping (breakup) and dma engine requests are properly degraded. */ /* * hack for bugid 1160621: * workaround compiler optimization bug by turning on DEBUG */ #ifndef DEBUG #define DEBUG 1 #endif #include <sys/param.h> #include <sys/buf.h> #include <sys/ioctl.h> #include <sys/uio.h> #include <sys/open.h> #include <sys/conf.h> #include <sys/file.h> #include <sys/cmn_err.h> #include <sys/note.h> #include <sys/debug.h> #include <sys/kmem.h> #include <sys/stat.h> #include <sys/autoconf.h> #include <sys/dkio.h> #include <sys/vtoc.h> #include <sys/kstat.h> #include <sys/fdio.h> #include <sys/fdc.h> #include <sys/i8272A.h> #include <sys/fd_debug.h> #include <sys/promif.h> #include <sys/ddi.h> #include <sys/sunddi.h> /* * bss (uninitialized data) */ static void *fdc_state_head; /* opaque handle top of state structs */ static ddi_dma_attr_t fdc_dma_attr; static ddi_device_acc_attr_t fdc_accattr = {DDI_DEVICE_ATTR_V0, DDI_STRUCTURE_LE_ACC, DDI_STRICTORDER_ACC}; /* * Local static data */ #define OURUN_TRIES 12 static uchar_t rwretry = 4; static uchar_t skretry = 3; static uchar_t configurecmd[4] = {FO_CNFG, 0, 0x0F, 0}; static uchar_t recalcmd[2] = {FO_RECAL, 0}; static uchar_t senseintcmd = FO_SINT; /* * error handling * * for debugging, set rwretry and skretry = 1 * set fcerrlevel to 1 * set fcerrmask to 224 or 644 * * after debug, set rwretry to 4, skretry to 3, and fcerrlevel to 5 * set fcerrmask to FDEM_ALL * or remove the define DEBUG */ static uint_t fcerrmask = FDEM_ALL; static int fcerrlevel = 6; #define KIOIP KSTAT_INTR_PTR(fcp->c_intrstat) static xlate_tbl_t drate_mfm[] = { { 250, 2}, { 300, 1}, { 417, 0}, { 500, 0}, { 1000, 3}, { 0, 0} }; static xlate_tbl_t sector_size[] = { { 256, 1}, { 512, 2}, { 1024, 3}, { 0, 2} }; static xlate_tbl_t motor_onbits[] = { { 0, 0x10}, { 1, 0x20}, { 2, 0x40}, { 3, 0x80}, { 0, 0x80} }; static xlate_tbl_t step_rate[] = { { 10, 0xF0}, /* for 500K data rate */ { 20, 0xE0}, { 30, 0xD0}, { 40, 0xC0}, { 50, 0xB0}, { 60, 0xA0}, { 70, 0x90}, { 80, 0x80}, { 90, 0x70}, { 100, 0x60}, { 110, 0x50}, { 120, 0x40}, { 130, 0x30}, { 140, 0x20}, { 150, 0x10}, { 160, 0x00}, { 0, 0x00} }; #ifdef notdef static xlate_tbl_t head_unld[] = { { 16, 0x1}, /* for 500K data rate */ { 32, 0x2}, { 48, 0x3}, { 64, 0x4}, { 80, 0x5}, { 96, 0x6}, { 112, 0x7}, { 128, 0x8}, { 144, 0x9}, { 160, 0xA}, { 176, 0xB}, { 192, 0xC}, { 208, 0xD}, { 224, 0xE}, { 240, 0xF}, { 256, 0x0}, { 0, 0x0} }; #endif static struct fdcmdinfo { char *cmdname; /* command name */ uchar_t ncmdbytes; /* number of bytes of command */ uchar_t nrsltbytes; /* number of bytes in result */ uchar_t cmdtype; /* characteristics */ } fdcmds[] = { "", 0, 0, 0, /* - */ "", 0, 0, 0, /* - */ "read_track", 9, 7, 1, /* 2 */ "specify", 3, 0, 3, /* 3 */ "sense_drv_status", 2, 1, 3, /* 4 */ "write", 9, 7, 1, /* 5 */ "read", 9, 7, 1, /* 6 */ "recalibrate", 2, 0, 2, /* 7 */ "sense_int_status", 1, 2, 3, /* 8 */ "write_del", 9, 7, 1, /* 9 */ "read_id", 2, 7, 2, /* A */ "", 0, 0, 0, /* - */ "read_del", 9, 7, 1, /* C */ "format_track", 10, 7, 1, /* D */ "dump_reg", 1, 10, 4, /* E */ "seek", 3, 0, 2, /* F */ "version", 1, 1, 3, /* 10 */ "", 0, 0, 0, /* - */ "perp_mode", 2, 0, 3, /* 12 */ "configure", 4, 0, 4, /* 13 */ /* relative seek */ }; static int fdc_bus_ctl(dev_info_t *, dev_info_t *, ddi_ctl_enum_t, void *, void *); static int get_ioaddr(dev_info_t *dip, int *ioaddr); static int get_unit(dev_info_t *dip, int *cntrl_num); struct bus_ops fdc_bus_ops = { BUSO_REV, nullbusmap, 0, /* ddi_intrspec_t (*bus_get_intrspec)(); */ 0, /* int (*bus_add_intrspec)(); */ 0, /* void (*bus_remove_intrspec)(); */ i_ddi_map_fault, 0, ddi_dma_allochdl, ddi_dma_freehdl, ddi_dma_bindhdl, ddi_dma_unbindhdl, ddi_dma_flush, ddi_dma_win, ddi_dma_mctl, fdc_bus_ctl, ddi_bus_prop_op, }; static int fdc_getinfo(dev_info_t *, ddi_info_cmd_t, void *, void **); static int fdc_probe(dev_info_t *); static int fdc_attach(dev_info_t *, ddi_attach_cmd_t); static int fdc_detach(dev_info_t *, ddi_detach_cmd_t); static int fdc_quiesce(dev_info_t *); static int fdc_enhance_probe(struct fdcntlr *fcp); struct dev_ops fdc_ops = { DEVO_REV, /* devo_rev, */ 0, /* refcnt */ fdc_getinfo, /* getinfo */ nulldev, /* identify */ fdc_probe, /* probe */ fdc_attach, /* attach */ fdc_detach, /* detach */ nodev, /* reset */ (struct cb_ops *)0, /* driver operations */ &fdc_bus_ops, /* bus operations */ NULL, /* power */ fdc_quiesce, /* quiesce */ }; /* * This is the loadable module wrapper. */ #include <sys/modctl.h> extern struct mod_ops mod_driverops; static struct modldrv modldrv = { &mod_driverops, /* Type of module. This one is a driver */ "Floppy Controller", /* Name of the module. */ &fdc_ops, /* Driver ops vector */ }; static struct modlinkage modlinkage = { MODREV_1, (void *)&modldrv, NULL }; int _init(void) { int retval; if ((retval = ddi_soft_state_init(&fdc_state_head, sizeof (struct fdcntlr) + NFDUN * sizeof (struct fcu_obj), 0)) != 0) return (retval); if ((retval = mod_install(&modlinkage)) != 0) ddi_soft_state_fini(&fdc_state_head); return (retval); } int _fini(void) { int retval; if ((retval = mod_remove(&modlinkage)) != 0) return (retval); ddi_soft_state_fini(&fdc_state_head); return (retval); } int _info(struct modinfo *modinfop) { return (mod_info(&modlinkage, modinfop)); } int fdc_abort(struct fcu_obj *); int fdc_dkinfo(struct fcu_obj *, struct dk_cinfo *); int fdc_select(struct fcu_obj *, int, int); int fdgetchng(struct fcu_obj *, int); int fdresetchng(struct fcu_obj *, int); int fdrecalseek(struct fcu_obj *, int, int, int); int fdrw(struct fcu_obj *, int, int, int, int, int, caddr_t, uint_t); int fdtrkformat(struct fcu_obj *, int, int, int, int); int fdrawioctl(struct fcu_obj *, int, caddr_t); static struct fcobjops fdc_iops = { fdc_abort, /* controller abort */ fdc_dkinfo, /* get disk controller info */ fdc_select, /* select / deselect unit */ fdgetchng, /* get media change */ fdresetchng, /* reset media change */ fdrecalseek, /* recal / seek */ NULL, /* read /write request (UNUSED) */ fdrw, /* read /write sector */ fdtrkformat, /* format track */ fdrawioctl /* raw ioctl */ }; /* * Function prototypes */ void encode(xlate_tbl_t *tablep, int val, uchar_t *rcode); int decode(xlate_tbl_t *, int, int *); static int fdc_propinit1(struct fdcntlr *, int); static void fdc_propinit2(struct fdcntlr *); void fdcquiesce(struct fdcntlr *); int fdcsense_chng(struct fdcntlr *, int); int fdcsense_drv(struct fdcntlr *, int); int fdcsense_int(struct fdcntlr *, int *, int *); int fdcspecify(struct fdcntlr *, int, int, int); int fdcspdchange(struct fdcntlr *, struct fcu_obj *, int); static int fdc_exec(struct fdcntlr *, int, int); int fdcheckdisk(struct fdcntlr *, int); static uint_t fdc_intr(caddr_t arg); static void fdwatch(void *arg); static void fdmotort(void *arg); static int fdrecover(struct fdcntlr *); static int fdc_motorsm(struct fcu_obj *, int, int); static int fdc_statemach(struct fdcntlr *); int fdc_docmd(struct fdcntlr *, uchar_t *, uchar_t); int fdc_result(struct fdcntlr *, uchar_t *, uchar_t); static int fdc_bus_ctl(dev_info_t *dip, dev_info_t *rdip, ddi_ctl_enum_t ctlop, void *arg, void *result) { struct fdcntlr *fcp; struct fcu_obj *fjp; _NOTE(ARGUNUSED(result)); FCERRPRINT(FDEP_L0, FDEM_ATTA, (CE_CONT, "fdc_bus_ctl: cmd= %x\n", ctlop)); if ((fcp = ddi_get_driver_private(dip)) == NULL) return (DDI_FAILURE); switch (ctlop) { case DDI_CTLOPS_REPORTDEV: cmn_err(CE_CONT, "?%s%d at %s%d\n", ddi_get_name(rdip), ddi_get_instance(rdip), ddi_get_name(dip), ddi_get_instance(dip)); FCERRPRINT(FDEP_L3, FDEM_ATTA, (CE_WARN, "fdc_bus_ctl: report %s%d at %s%d", ddi_get_name(rdip), ddi_get_instance(rdip), ddi_get_name(dip), ddi_get_instance(dip))); return (DDI_SUCCESS); case DDI_CTLOPS_INITCHILD: { dev_info_t *udip = (dev_info_t *)arg; int cntlr; int len; int unit; char name[MAXNAMELEN]; FCERRPRINT(FDEP_L3, FDEM_ATTA, (CE_WARN, "fdc_bus_ctl: init child 0x%p", (void*)udip)); cntlr = fcp->c_number; len = sizeof (unit); if (ddi_prop_op(DDI_DEV_T_ANY, udip, PROP_LEN_AND_VAL_BUF, DDI_PROP_DONTPASS, "unit", (caddr_t)&unit, &len) != DDI_PROP_SUCCESS || cntlr != FDCTLR(unit) || (fcp->c_unit[FDUNIT(unit)])->fj_dip) return (DDI_NOT_WELL_FORMED); (void) sprintf(name, "%d,%d", cntlr, FDUNIT(unit)); ddi_set_name_addr(udip, name); fjp = fcp->c_unit[FDUNIT(unit)]; fjp->fj_unit = unit; fjp->fj_dip = udip; fjp->fj_ops = &fdc_iops; fjp->fj_fdc = fcp; fjp->fj_iblock = &fcp->c_iblock; ddi_set_driver_private(udip, fjp); return (DDI_SUCCESS); } case DDI_CTLOPS_UNINITCHILD: { dev_info_t *udip = (dev_info_t *)arg; FCERRPRINT(FDEP_L3, FDEM_ATTA, (CE_WARN, "fdc_bus_ctl: uninit child 0x%p", (void *)udip)); fjp = ddi_get_driver_private(udip); ddi_set_driver_private(udip, NULL); fjp->fj_dip = NULL; ddi_set_name_addr(udip, NULL); return (DDI_SUCCESS); } default: return (DDI_FAILURE); } } static int fdc_getinfo(dev_info_t *dip, ddi_info_cmd_t cmd, void *arg, void **result) { struct fdcntlr *fcp; int rval; _NOTE(ARGUNUSED(dip)); switch (cmd) { case DDI_INFO_DEVT2DEVINFO: if (fcp = ddi_get_soft_state(fdc_state_head, (dev_t)arg)) { *result = fcp->c_dip; rval = DDI_SUCCESS; break; } else { rval = DDI_FAILURE; break; } case DDI_INFO_DEVT2INSTANCE: *result = (void *)(uintptr_t)getminor((dev_t)arg); rval = DDI_SUCCESS; break; default: rval = DDI_FAILURE; } return (rval); } static int fdc_probe(dev_info_t *dip) { int debug[2]; int ioaddr; int len; uchar_t stat; len = sizeof (debug); if (ddi_prop_op(DDI_DEV_T_ANY, dip, PROP_LEN_AND_VAL_BUF, DDI_PROP_DONTPASS, "debug", (caddr_t)debug, &len) == DDI_PROP_SUCCESS) { fcerrlevel = debug[0]; fcerrmask = (uint_t)debug[1]; } FCERRPRINT(FDEP_L3, FDEM_ATTA, (CE_WARN, "fdc_probe: dip %p", (void*)dip)); if (get_ioaddr(dip, &ioaddr) != DDI_SUCCESS) return (DDI_PROBE_FAILURE); stat = inb(ioaddr + FCR_MSR); if ((stat & (MS_RQM | MS_DIO | MS_CB)) != MS_RQM && (stat & ~MS_DIO) != MS_CB) return (DDI_PROBE_FAILURE); return (DDI_PROBE_SUCCESS); } static int fdc_attach(dev_info_t *dip, ddi_attach_cmd_t cmd) { struct fdcntlr *fcp; struct fcu_obj *fjp; int cntlr_num, ctlr, unit; int intr_set = 0; int len; char name[MAXNAMELEN]; FCERRPRINT(FDEP_L3, FDEM_ATTA, (CE_WARN, "fdc_attach: dip %p", (void*)dip)); switch (cmd) { case DDI_ATTACH: if (ddi_getprop (DDI_DEV_T_ANY, dip, 0, "ignore-hardware-nodes", 0)) { len = sizeof (cntlr_num); if (ddi_prop_op(DDI_DEV_T_ANY, dip, PROP_LEN_AND_VAL_BUF, DDI_PROP_DONTPASS, "unit", (caddr_t)&cntlr_num, &len) != DDI_PROP_SUCCESS) { FCERRPRINT(FDEP_L3, FDEM_ATTA, (CE_WARN, "fdc_attach failed: dip %p", (void*)dip)); return (DDI_FAILURE); } } else { if (get_unit(dip, &cntlr_num) != DDI_SUCCESS) return (DDI_FAILURE); } ctlr = ddi_get_instance(dip); if (ddi_soft_state_zalloc(fdc_state_head, ctlr) != 0) return (DDI_FAILURE); fcp = ddi_get_soft_state(fdc_state_head, ctlr); for (unit = 0, fjp = (struct fcu_obj *)(fcp+1); unit < NFDUN; unit++) { fcp->c_unit[unit] = fjp++; } fcp->c_dip = dip; if (fdc_propinit1(fcp, cntlr_num) != DDI_SUCCESS) goto no_attach; /* get iblock cookie to initialize mutex used in the ISR */ if (ddi_get_iblock_cookie(dip, (uint_t)0, &fcp->c_iblock) != DDI_SUCCESS) { cmn_err(CE_WARN, "fdc_attach: cannot get iblock cookie"); goto no_attach; } mutex_init(&fcp->c_lock, NULL, MUTEX_DRIVER, fcp->c_iblock); intr_set = 1; /* setup interrupt handler */ if (ddi_add_intr(dip, (uint_t)0, NULL, (ddi_idevice_cookie_t *)0, fdc_intr, (caddr_t)fcp) != DDI_SUCCESS) { cmn_err(CE_WARN, "fdc: cannot add intr"); goto no_attach; } intr_set++; /* * acquire the DMA channel * this assumes that the chnl is not shared; else allocate * and free the chnl with each fdc request */ if (ddi_dmae_alloc(dip, fcp->c_dmachan, DDI_DMA_DONTWAIT, NULL) != DDI_SUCCESS) { cmn_err(CE_WARN, "fdc: cannot acquire dma%d", fcp->c_dmachan); goto no_attach; } (void) ddi_dmae_getattr(dip, &fdc_dma_attr); fdc_dma_attr.dma_attr_align = MMU_PAGESIZE; mutex_init(&fcp->c_dorlock, NULL, MUTEX_DRIVER, fcp->c_iblock); cv_init(&fcp->c_iocv, NULL, CV_DRIVER, fcp->c_iblock); sema_init(&fcp->c_selsem, 1, NULL, SEMA_DRIVER, NULL); (void) sprintf(name, "fdc%d", ctlr); fcp->c_intrstat = kstat_create("fdc", ctlr, name, "controller", KSTAT_TYPE_INTR, 1, KSTAT_FLAG_PERSISTENT); if (fcp->c_intrstat) { kstat_install(fcp->c_intrstat); } ddi_set_driver_private(dip, fcp); /* * reset the controller */ sema_p(&fcp->c_selsem); mutex_enter(&fcp->c_lock); fcp->c_csb.csb_xstate = FXS_RESET; fcp->c_flags |= FCFLG_WAITING; fdcquiesce(fcp); /* first test for mode == Model 30 */ fcp->c_mode = (inb(fcp->c_regbase + FCR_SRB) & 0x1c) ? FDCMODE_AT : FDCMODE_30; while (fcp->c_flags & FCFLG_WAITING) { cv_wait(&fcp->c_iocv, &fcp->c_lock); } mutex_exit(&fcp->c_lock); sema_v(&fcp->c_selsem); fdc_propinit2(fcp); ddi_report_dev(dip); return (DDI_SUCCESS); case DDI_RESUME: fcp = ddi_get_driver_private(dip); mutex_enter(&fcp->c_lock); fcp->c_suspended = B_FALSE; fcp->c_csb.csb_xstate = FXS_RESET; fcp->c_flags |= FCFLG_WAITING; fdcquiesce(fcp); while (fcp->c_flags & FCFLG_WAITING) { cv_wait(&fcp->c_iocv, &fcp->c_lock); } mutex_exit(&fcp->c_lock); /* should be good to go now */ sema_v(&fcp->c_selsem); return (DDI_SUCCESS); /* break; */ default: return (DDI_FAILURE); } no_attach: if (intr_set) { if (intr_set > 1) ddi_remove_intr(dip, 0, fcp->c_iblock); mutex_destroy(&fcp->c_lock); } ddi_soft_state_free(fdc_state_head, cntlr_num); return (DDI_FAILURE); } static int fdc_propinit1(struct fdcntlr *fcp, int cntlr) { dev_info_t *dip; int len; int value; dip = fcp->c_dip; len = sizeof (value); if (get_ioaddr(dip, &value) != DDI_SUCCESS) return (DDI_FAILURE); fcp->c_regbase = (ushort_t)value; if (ddi_prop_op(DDI_DEV_T_ANY, dip, PROP_LEN_AND_VAL_BUF, DDI_PROP_DONTPASS, "dma-channels", (caddr_t)&value, &len) != DDI_PROP_SUCCESS) { cmn_err(CE_WARN, "fdc_attach: Error, could not find a dma channel"); return (DDI_FAILURE); } fcp->c_dmachan = (ushort_t)value; fcp->c_number = cntlr; return (DDI_SUCCESS); } static void fdc_propinit2(struct fdcntlr *fcp) { dev_info_t *dip; int ccr; int len; int value; dip = fcp->c_dip; len = sizeof (value); if (ddi_prop_op(DDI_DEV_T_ANY, dip, PROP_LEN_AND_VAL_BUF, DDI_PROP_DONTPASS, "chip", (caddr_t)&value, &len) == DDI_PROP_SUCCESS) fcp->c_chip = value; else { static uchar_t perpindcmd[2] = {FO_PERP, 0}; static uchar_t versioncmd = FO_VRSN; uchar_t result; fcp->c_chip = i8272A; (void) fdc_docmd(fcp, &versioncmd, 1); /* * Ignored return. If failed, warning was issued by fdc_docmd. * fdc_results retrieves the controller/drive status */ if (!fdc_result(fcp, &result, 1) && result == 0x90) { /* * try a perpendicular_mode cmd to ensure * that we really have an enhanced controller */ if (fdc_docmd(fcp, perpindcmd, 2) || fdc_docmd(fcp, configurecmd, 4)) /* * perpindicular_mode will be rejected by * older controllers; make sure we don't hang. */ (void) fdc_result(fcp, &result, 1); /* * Ignored return. If failed, warning was * issued by fdc_result. */ else /* enhanced type controller */ if ((fcp->c_chip = fdc_enhance_probe(fcp)) == 0) /* default enhanced cntlr */ fcp->c_chip = i82077; } (void) ddi_prop_update_int(DDI_DEV_T_NONE, dip, "chip", fcp->c_chip); /* * Ignoring return value because, for passed arguments, only * DDI_SUCCESS is returned. */ } if (fcp->c_chip >= i82077 && fcp->c_mode == FDCMODE_30 && (inb(fcp->c_regbase + FCR_DIR) & 0x70) == 0) for (ccr = 0; ccr <= (FCC_NOPREC | FCC_DRATE); ccr++) { /* * run through all the combinations of NOPREC and * datarate selection, and see if they show up in the * Model 30 DIR */ outb(fcp->c_regbase + FCR_CCR, ccr); drv_usecwait(5); if ((inb(fcp->c_regbase + FCR_DIR) & (FCC_NOPREC | FCC_DRATE)) != ccr) { fcp->c_mode = FDCMODE_AT; break; } } else fcp->c_mode = FDCMODE_AT; outb(fcp->c_regbase + FCR_CCR, 0); } static int fdc_enhance_probe(struct fdcntlr *fcp) { static uchar_t nsccmd = FO_NSC; uint_t ddic; int retcode = 0; uchar_t result; uchar_t save; /* * Try to identify the enhanced floppy controller. * This is required so that we can program the DENSEL output to * control 3D mode (1.0 MB, 1.6 MB and 2.0 MB unformatted capacity, * 720 KB, 1.2 MB, and 1.44 MB formatted capacity) 3.5" dual-speed * floppy drives. Refer to bugid 1195155. */ (void) fdc_docmd(fcp, &nsccmd, 1); /* * Ignored return. If failed, warning was issued by fdc_docmd. * fdc_results retrieves the controller/drive status */ if (!fdc_result(fcp, &result, 1) && result != S0_IVCMD) { /* * only enhanced National Semi PC8477 core * should respond to this command */ if ((result & 0xf0) == 0x70) { /* low 4 bits may change */ fcp->c_flags |= FCFLG_3DMODE; retcode = PC87322; } else cmn_err(CE_CONT, "?fdc: unidentified, enhanced, National Semiconductor cntlr %x\n", result); } else { save = inb(fcp->c_regbase + FCR_SRA); do { /* probe for motherboard version of SMC cntlr */ /* try to enable configuration mode */ ddic = ddi_enter_critical(); outb(fcp->c_regbase + FCR_SRA, FSA_ENA5); outb(fcp->c_regbase + FCR_SRA, FSA_ENA5); ddi_exit_critical(ddic); outb(fcp->c_regbase + FCR_SRA, 0x0F); if (inb(fcp->c_regbase + FCR_SRB) != 0x00) /* always expect 0 from config reg F */ break; outb(fcp->c_regbase + FCR_SRA, 0x0D); if (inb(fcp->c_regbase + FCR_SRB) != 0x65) /* expect 0x65 from config reg D */ break; outb(fcp->c_regbase + FCR_SRA, 0x0E); result = inb(fcp->c_regbase + FCR_SRB); if (result != 0x02) { /* expect revision level 2 from config reg E */ cmn_err(CE_CONT, "?fdc: unidentified, enhanced, SMC cntlr revision %x\n", result); /* break; */ } fcp->c_flags |= FCFLG_3DMODE; retcode = FDC37C665; } while (retcode == 0); outb(fcp->c_regbase + FCR_SRA, FSA_DISB); while (retcode == 0) { /* probe for adapter version of SMC cntlr */ ddic = ddi_enter_critical(); outb(fcp->c_regbase + FCR_SRA, FSA_ENA6); outb(fcp->c_regbase + FCR_SRA, FSA_ENA6); ddi_exit_critical(ddic); outb(fcp->c_regbase + FCR_SRA, 0x0F); if (inb(fcp->c_regbase + FCR_SRB) != 0x00) /* always expect 0 from config reg F */ break; outb(fcp->c_regbase + FCR_SRA, 0x0D); if (inb(fcp->c_regbase + FCR_SRB) != 0x66) /* expect 0x66 from config reg D */ break; outb(fcp->c_regbase + FCR_SRA, 0x0E); result = inb(fcp->c_regbase + FCR_SRB); if (result != 0x02) { /* expect revision level 2 from config reg E */ cmn_err(CE_CONT, "?fdc: unidentified, enhanced, SMC cntlr revision %x\n", result); /* break; */ } fcp->c_flags |= FCFLG_3DMODE; retcode = FDC37C666; } outb(fcp->c_regbase + FCR_SRA, FSA_DISB); drv_usecwait(10); outb(fcp->c_regbase + FCR_SRA, save); } return (retcode); } static int fdc_detach(dev_info_t *dip, ddi_detach_cmd_t cmd) { struct fdcntlr *fcp; int unit; int rval = 0; FCERRPRINT(FDEP_L3, FDEM_ATTA, (CE_WARN, "fdc_detach: dip %p", (void*)dip)); fcp = ddi_get_driver_private(dip); switch (cmd) { case DDI_DETACH: for (unit = 0; unit < NFDUN; unit++) if ((fcp->c_unit[unit])->fj_dip) { rval = EBUSY; break; } kstat_delete(fcp->c_intrstat); fcp->c_intrstat = NULL; ddi_remove_intr(fcp->c_dip, 0, fcp->c_iblock); if (ddi_dmae_release(fcp->c_dip, fcp->c_dmachan) != DDI_SUCCESS) cmn_err(CE_WARN, "fdc_detach: dma release failed, " "dip %p, dmachan %x", (void*)fcp->c_dip, fcp->c_dmachan); ddi_prop_remove_all(fcp->c_dip); ddi_set_driver_private(fcp->c_dip, NULL); mutex_destroy(&fcp->c_lock); mutex_destroy(&fcp->c_dorlock); cv_destroy(&fcp->c_iocv); sema_destroy(&fcp->c_selsem); ddi_soft_state_free(fdc_state_head, ddi_get_instance(dip)); break; case DDI_SUSPEND: /* * For suspend, we just use the semaphore to * keep any child devices from accessing any of our * hardware routines, and then shutdown the hardware. * * On resume, we'll reinit the hardware and release the * semaphore. */ sema_p(&fcp->c_selsem); if (ddi_dmae_disable(fcp->c_dip, fcp->c_dmachan) != DDI_SUCCESS) { cmn_err(CE_WARN, "fdc_suspend: dma disable failed, " "dip %p, dmachan %x", (void *)fcp->c_dip, fcp->c_dmachan); /* give it back on failure */ sema_v(&fcp->c_selsem); return (DDI_FAILURE); } mutex_enter(&fcp->c_lock); fcp->c_suspended = B_TRUE; mutex_exit(&fcp->c_lock); rval = DDI_SUCCESS; break; default: rval = EINVAL; break; } return (rval); } int fdc_abort(struct fcu_obj *fjp) { struct fdcntlr *fcp = fjp->fj_fdc; int unit = fjp->fj_unit & 3; FCERRPRINT(FDEP_L3, FDEM_RESE, (CE_WARN, "fdc_abort")); if (fcp->c_curunit == unit) { mutex_enter(&fcp->c_lock); if (fcp->c_flags & FCFLG_WAITING) { /* * this can cause data corruption ! */ fdcquiesce(fcp); fcp->c_csb.csb_xstate = FXS_RESET; fcp->c_flags |= FCFLG_TIMEOUT; if (ddi_dmae_stop(fcp->c_dip, fcp->c_dmachan) != DDI_SUCCESS) cmn_err(CE_WARN, "fdc_detach: dma release failed, " "dip %p, dmachan %x", (void*)fcp->c_dip, fcp->c_dmachan); } mutex_exit(&fcp->c_lock); drv_usecwait(500); return (DDI_SUCCESS); } return (DDI_FAILURE); } int fdc_dkinfo(struct fcu_obj *fjp, struct dk_cinfo *dcp) { struct fdcntlr *fcp = fjp->fj_fdc; (void) strncpy((char *)&dcp->dki_cname, ddi_get_name(fcp->c_dip), DK_DEVLEN); dcp->dki_ctype = DKC_UNKNOWN; /* no code for generic PC/AT fdc */ dcp->dki_flags = DKI_FMTTRK; dcp->dki_addr = fcp->c_regbase; dcp->dki_space = 0; dcp->dki_prio = fcp->c_intprio; dcp->dki_vec = fcp->c_intvec; (void) strncpy((char *)&dcp->dki_dname, ddi_driver_name(fjp->fj_dip), DK_DEVLEN); dcp->dki_slave = fjp->fj_unit & 3; dcp->dki_maxtransfer = maxphys / DEV_BSIZE; return (DDI_SUCCESS); } /* * on=> non-zero = select, 0 = de-select */ int fdc_select(struct fcu_obj *fjp, int funit, int on) { struct fdcntlr *fcp = fjp->fj_fdc; int unit = funit & 3; if (on) { /* possess controller */ sema_p(&fcp->c_selsem); FCERRPRINT(FDEP_L2, FDEM_DSEL, (CE_NOTE, "fdc_select unit %d: on", funit)); if (fcp->c_curunit != unit || !(fjp->fj_flags & FUNIT_CHAROK)) { fcp->c_curunit = unit; fjp->fj_flags |= FUNIT_CHAROK; if (fdcspecify(fcp, fjp->fj_chars->fdc_transfer_rate, fjp->fj_drive->fdd_steprate, 40)) cmn_err(CE_WARN, "fdc_select: controller setup rejected " "fdcntrl %p transfer rate %x step rate %x" " head load time 40", (void*)fcp, fjp->fj_chars->fdc_transfer_rate, fjp->fj_drive->fdd_steprate); } mutex_enter(&fcp->c_dorlock); /* make sure drive is not selected in case we change speed */ fcp->c_digout = (fcp->c_digout & ~FD_DRSEL) | (~unit & FD_DRSEL); outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); (void) fdc_motorsm(fjp, FMI_STARTCMD, fjp->fj_drive->fdd_motoron); /* * Return value ignored - fdcmotort deals with failure. */ if (fdcspdchange(fcp, fjp, fjp->fj_attr->fda_rotatespd)) { /* 3D drive requires 500 ms for speed change */ (void) fdc_motorsm(fjp, FMI_RSTARTCMD, 5); /* * Return value ignored - fdcmotort deals with failure. */ } fcp->c_digout = (fcp->c_digout & ~FD_DRSEL) | (unit & FD_DRSEL); outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); mutex_exit(&fcp->c_dorlock); fcp->c_csb.csb_drive = (uchar_t)unit; } else { FCERRPRINT(FDEP_L2, FDEM_DSEL, (CE_NOTE, "fdc_select unit %d: off", funit)); mutex_enter(&fcp->c_dorlock); fcp->c_digout |= FD_DRSEL; outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); (void) fdc_motorsm(fjp, FMI_IDLECMD, fjp->fj_drive->fdd_motoroff); /* * Return value ignored - fdcmotort deals with failure. */ mutex_exit(&fcp->c_dorlock); /* give up controller */ sema_v(&fcp->c_selsem); } return (0); } int fdgetchng(struct fcu_obj *fjp, int funit) { if (fdcsense_drv(fjp->fj_fdc, funit & 3)) cmn_err(CE_WARN, "fdgetchng: write protect check failed"); return (fdcsense_chng(fjp->fj_fdc, funit & 3)); } int fdresetchng(struct fcu_obj *fjp, int funit) { struct fdcntlr *fcp = fjp->fj_fdc; int unit = funit & 3; int newcyl; /* where to seek for reset of DSKCHG */ FCERRPRINT(FDEP_L2, FDEM_CHEK, (CE_NOTE, "fdmediachng unit %d", funit)); if (fcp->c_curpcyl[unit]) newcyl = fcp->c_curpcyl[unit] - 1; else newcyl = 1; return (fdrecalseek(fjp, funit, newcyl, 0)); } /* * fdrecalseek */ int fdrecalseek(struct fcu_obj *fjp, int funit, int arg, int execflg) { struct fdcntlr *fcp = fjp->fj_fdc; struct fdcsb *csb; int unit = funit & 3; int rval; FCERRPRINT(FDEP_L2, FDEM_RECA, (CE_NOTE, "fdrecalseek unit %d to %d", funit, arg)); csb = &fcp->c_csb; csb->csb_cmd[1] = (uchar_t)unit; if (arg < 0) { /* is recal... */ *csb->csb_cmd = FO_RECAL; csb->csb_ncmds = 2; csb->csb_timer = 28; } else { *csb->csb_cmd = FO_SEEK; csb->csb_cmd[2] = (uchar_t)arg; csb->csb_ncmds = 3; csb->csb_timer = 10; } csb->csb_nrslts = 2; /* 2 for SENSE INTERRUPTS */ csb->csb_opflags = CSB_OFINRPT; csb->csb_maxretry = skretry; csb->csb_dmahandle = NULL; csb->csb_handle_bound = 0; csb->csb_dmacookiecnt = 0; csb->csb_dmacurrcookie = 0; csb->csb_dmawincnt = 0; csb->csb_dmacurrwin = 0; /* send cmd off to fdc_exec */ if (rval = fdc_exec(fcp, 1, execflg)) goto out; if (!(*csb->csb_rslt & S0_SEKEND) || (*csb->csb_rslt & S0_ICMASK) || ((*csb->csb_rslt & S0_ECHK) && arg < 0) || csb->csb_cmdstat) rval = ENODEV; if (fdcsense_drv(fcp, unit)) cmn_err(CE_WARN, "fdgetchng: write protect check failed"); out: return (rval); } /* * fdrw- used only for read/writing sectors into/from kernel buffers. */ int fdrw(struct fcu_obj *fjp, int funit, int rw, int cyl, int head, int sector, caddr_t bufp, uint_t len) { struct fdcntlr *fcp = fjp->fj_fdc; struct fdcsb *csb; uint_t dmar_flags = 0; int unit = funit & 3; int rval; ddi_acc_handle_t mem_handle = NULL; caddr_t aligned_buf; size_t real_size; FCERRPRINT(FDEP_L1, FDEM_RW, (CE_CONT, "fdrw unit %d\n", funit)); csb = &fcp->c_csb; if (rw) { dmar_flags = DDI_DMA_READ; csb->csb_opflags = CSB_OFDMARD | CSB_OFINRPT; *csb->csb_cmd = FO_MT | FO_MFM | FO_SK | FO_RDDAT; } else { /* write */ dmar_flags = DDI_DMA_WRITE; csb->csb_opflags = CSB_OFDMAWT | CSB_OFINRPT; *csb->csb_cmd = FO_MT | FO_MFM | FO_WRDAT; } csb->csb_cmd[1] = (uchar_t)(unit | ((head & 0x1) << 2)); csb->csb_cmd[2] = (uchar_t)cyl; csb->csb_cmd[3] = (uchar_t)head; csb->csb_cmd[4] = (uchar_t)sector; encode(sector_size, fjp->fj_chars->fdc_sec_size, &csb->csb_cmd[5]); csb->csb_cmd[6] = (uchar_t)max(fjp->fj_chars->fdc_secptrack, sector); csb->csb_cmd[7] = fjp->fj_attr->fda_gapl; csb->csb_cmd[8] = 0xFF; csb->csb_ncmds = 9; csb->csb_nrslts = 7; csb->csb_timer = 36; if (rw == FDRDONE) csb->csb_maxretry = 1; else csb->csb_maxretry = rwretry; csb->csb_dmahandle = NULL; csb->csb_handle_bound = 0; csb->csb_dmacookiecnt = 0; csb->csb_dmacurrcookie = 0; csb->csb_dmawincnt = 0; csb->csb_dmacurrwin = 0; dmar_flags |= (DDI_DMA_STREAMING | DDI_DMA_PARTIAL); if (ddi_dma_alloc_handle(fcp->c_dip, &fdc_dma_attr, DDI_DMA_SLEEP, 0, &csb->csb_dmahandle) != DDI_SUCCESS) { rval = EINVAL; goto out; } /* * allocate a page aligned buffer to dma to/from. This way we can * ensure the cookie is a whole multiple of granularity and avoids * any alignment issues. */ rval = ddi_dma_mem_alloc(csb->csb_dmahandle, len, &fdc_accattr, DDI_DMA_CONSISTENT, DDI_DMA_SLEEP, NULL, &aligned_buf, &real_size, &mem_handle); if (rval != DDI_SUCCESS) { rval = EINVAL; goto out; } if (dmar_flags & DDI_DMA_WRITE) { bcopy(bufp, aligned_buf, len); } rval = ddi_dma_addr_bind_handle(csb->csb_dmahandle, NULL, aligned_buf, len, dmar_flags, DDI_DMA_SLEEP, 0, &csb->csb_dmacookie, &csb->csb_dmacookiecnt); if (rval == DDI_DMA_MAPPED) { csb->csb_dmawincnt = 1; csb->csb_handle_bound = 1; } else if (rval == DDI_DMA_PARTIAL_MAP) { csb->csb_handle_bound = 1; if (ddi_dma_numwin(csb->csb_dmahandle, &csb->csb_dmawincnt) != DDI_SUCCESS) { cmn_err(CE_WARN, "fdrw: dma numwin failed"); rval = EINVAL; goto out; } } else { cmn_err(CE_WARN, "fdrw: dma addr bind handle failed, rval = %d", rval); rval = EINVAL; goto out; } rval = fdc_exec(fcp, 1, 1); if (dmar_flags & DDI_DMA_READ) { bcopy(aligned_buf, bufp, len); } out: if (csb->csb_dmahandle) { if (csb->csb_handle_bound) { if (ddi_dma_unbind_handle(csb->csb_dmahandle) != DDI_SUCCESS) cmn_err(CE_WARN, "fdrw: " "dma unbind handle failed"); csb->csb_handle_bound = 0; } if (mem_handle != NULL) { ddi_dma_mem_free(&mem_handle); } ddi_dma_free_handle(&csb->csb_dmahandle); csb->csb_dmahandle = NULL; } return (rval); } int fdtrkformat(struct fcu_obj *fjp, int funit, int cyl, int head, int filldata) { struct fdcntlr *fcp = fjp->fj_fdc; struct fdcsb *csb; int unit = funit & 3; int fmdatlen, lsector, lstart; int interleave, numsctr, offset, psector; uchar_t *dp; int rval; ddi_acc_handle_t mem_handle = NULL; caddr_t aligned_buf; size_t real_size; FCERRPRINT(FDEP_L2, FDEM_FORM, (CE_NOTE, "fdformattrk unit %d cyl=%d, hd=%d", funit, cyl, head)); csb = &fcp->c_csb; csb->csb_opflags = CSB_OFDMAWT | CSB_OFINRPT; *csb->csb_cmd = FO_FRMT | FO_MFM; csb->csb_cmd[1] = (head << 2) | unit; encode(sector_size, fjp->fj_chars->fdc_sec_size, &csb->csb_cmd[2]); csb->csb_cmd[3] = numsctr = fjp->fj_chars->fdc_secptrack; csb->csb_cmd[4] = fjp->fj_attr->fda_gapf; csb->csb_cmd[5] = (uchar_t)filldata; csb->csb_npcyl = (uchar_t)(cyl * fjp->fj_chars->fdc_steps); csb->csb_dmahandle = NULL; csb->csb_handle_bound = 0; csb->csb_dmacookiecnt = 0; csb->csb_dmacurrcookie = 0; csb->csb_dmawincnt = 0; csb->csb_dmacurrwin = 0; csb->csb_ncmds = 6; csb->csb_nrslts = 7; csb->csb_timer = 32; csb->csb_maxretry = rwretry; /* * alloc space for format track cmd */ /* * NOTE: have to add size of fifo also - for dummy format action */ fmdatlen = 4 * numsctr; if (ddi_dma_alloc_handle(fcp->c_dip, &fdc_dma_attr, DDI_DMA_SLEEP, 0, &csb->csb_dmahandle) != DDI_SUCCESS) { rval = EINVAL; goto out; } /* * allocate a page aligned buffer to dma to/from. This way we can * ensure the cookie is a whole multiple of granularity and avoids * any alignment issues. */ rval = ddi_dma_mem_alloc(csb->csb_dmahandle, fmdatlen, &fdc_accattr, DDI_DMA_CONSISTENT, DDI_DMA_SLEEP, NULL, &aligned_buf, &real_size, &mem_handle); if (rval != DDI_SUCCESS) { rval = EINVAL; goto out; } dp = (uchar_t *)aligned_buf; interleave = fjp->fj_attr->fda_intrlv; offset = (numsctr + interleave - 1) / interleave; for (psector = lstart = 1; psector <= numsctr; psector += interleave, lstart++) { for (lsector = lstart; lsector <= numsctr; lsector += offset) { *dp++ = (uchar_t)cyl; *dp++ = (uchar_t)head; *dp++ = (uchar_t)lsector; *dp++ = csb->csb_cmd[2]; } } rval = ddi_dma_addr_bind_handle(csb->csb_dmahandle, NULL, aligned_buf, fmdatlen, DDI_DMA_WRITE | DDI_DMA_STREAMING | DDI_DMA_PARTIAL, DDI_DMA_SLEEP, 0, &csb->csb_dmacookie, &csb->csb_dmacookiecnt); if (rval == DDI_DMA_MAPPED) { csb->csb_dmawincnt = 1; csb->csb_handle_bound = 1; } else if (rval == DDI_DMA_PARTIAL_MAP) { csb->csb_handle_bound = 1; if (ddi_dma_numwin(csb->csb_dmahandle, &csb->csb_dmawincnt) != DDI_SUCCESS) { cmn_err(CE_WARN, "fdtrkformat: dma numwin failed"); rval = EINVAL; goto out; } } else { cmn_err(CE_WARN, "fdtrkformat: dma buf bind handle failed, rval = %d", rval); rval = EINVAL; goto out; } rval = fdc_exec(fcp, 1, 1); out: if (csb->csb_dmahandle) { if (csb->csb_handle_bound) { if (ddi_dma_unbind_handle(csb->csb_dmahandle) != DDI_SUCCESS) cmn_err(CE_WARN, "fdtrkformat: " "dma unbind handle failed"); csb->csb_handle_bound = 0; } if (mem_handle != NULL) { ddi_dma_mem_free(&mem_handle); } ddi_dma_free_handle(&csb->csb_dmahandle); csb->csb_dmahandle = NULL; } return (rval); } int fdrawioctl(struct fcu_obj *fjp, int funit, caddr_t arg) { struct fdcntlr *fcp = fjp->fj_fdc; struct fd_raw *fdrp = (struct fd_raw *)arg; struct fdcsb *csb; uint_t dmar_flags = 0; int i; int change = 1; int sleep = 1; int rval = 0; int rval_exec = 0; ddi_acc_handle_t mem_handle = NULL; caddr_t aligned_buf; size_t real_size; _NOTE(ARGUNUSED(funit)); FCERRPRINT(FDEP_L2, FDEM_RAWI, (CE_NOTE, "fdrawioctl: cmd[0]=0x%x", fdrp->fdr_cmd[0])); csb = &fcp->c_csb; /* copy cmd bytes into csb */ for (i = 0; i <= fdrp->fdr_cnum; i++) csb->csb_cmd[i] = fdrp->fdr_cmd[i]; csb->csb_ncmds = (uchar_t)fdrp->fdr_cnum; csb->csb_maxretry = 0; /* let the application deal with errors */ csb->csb_opflags = CSB_OFRAWIOCTL; csb->csb_nrslts = 0; csb->csb_timer = 50; switch (fdrp->fdr_cmd[0] & 0x0f) { case FO_SEEK: change = 0; /* FALLTHROUGH */ case FO_RECAL: csb->csb_opflags |= CSB_OFINRPT; break; case FO_FRMT: csb->csb_npcyl = *(uchar_t *)(fdrp->fdr_addr) * fjp->fj_chars->fdc_steps; /* FALLTHROUGH */ case FO_WRDAT: case FO_WRDEL: csb->csb_opflags |= CSB_OFDMAWT | CSB_OFRESLT | CSB_OFINRPT; csb->csb_nrslts = 7; if (fdrp->fdr_nbytes == 0) return (EINVAL); dmar_flags = DDI_DMA_WRITE; break; case FO_RDDAT: case FO_RDDEL: case FO_RDTRK: csb->csb_opflags |= CSB_OFDMARD | CSB_OFRESLT | CSB_OFINRPT; csb->csb_nrslts = 7; dmar_flags = DDI_DMA_READ; break; case FO_RDID: csb->csb_opflags |= CSB_OFRESLT | CSB_OFINRPT; csb->csb_nrslts = 7; break; case FO_SDRV: sleep = 0; csb->csb_nrslts = 1; break; case FO_SINT: sleep = 0; change = 0; csb->csb_nrslts = 2; break; case FO_SPEC: sleep = 0; change = 0; break; default: return (EINVAL); } csb->csb_dmahandle = NULL; csb->csb_handle_bound = 0; csb->csb_dmacookiecnt = 0; csb->csb_dmacurrcookie = 0; csb->csb_dmawincnt = 0; csb->csb_dmacurrwin = 0; if (csb->csb_opflags & (CSB_OFDMARD | CSB_OFDMAWT)) { if (ddi_dma_alloc_handle(fcp->c_dip, &fdc_dma_attr, DDI_DMA_SLEEP, 0, &csb->csb_dmahandle) != DDI_SUCCESS) { rval = EINVAL; goto out; } /* * allocate a page aligned buffer to dma to/from. This way we * can ensure the cookie is a whole multiple of granularity and * avoids any alignment issues. */ rval = ddi_dma_mem_alloc(csb->csb_dmahandle, (uint_t)fdrp->fdr_nbytes, &fdc_accattr, DDI_DMA_CONSISTENT, DDI_DMA_SLEEP, NULL, &aligned_buf, &real_size, &mem_handle); if (rval != DDI_SUCCESS) { rval = EINVAL; goto out; } if (dmar_flags & DDI_DMA_WRITE) { bcopy(fdrp->fdr_addr, aligned_buf, (uint_t)fdrp->fdr_nbytes); } dmar_flags |= (DDI_DMA_STREAMING | DDI_DMA_PARTIAL); rval = ddi_dma_addr_bind_handle(csb->csb_dmahandle, NULL, aligned_buf, (uint_t)fdrp->fdr_nbytes, dmar_flags, DDI_DMA_SLEEP, 0, &csb->csb_dmacookie, &csb->csb_dmacookiecnt); if (rval == DDI_DMA_MAPPED) { csb->csb_dmawincnt = 1; csb->csb_handle_bound = 1; } else if (rval == DDI_DMA_PARTIAL_MAP) { csb->csb_handle_bound = 1; if (ddi_dma_numwin(csb->csb_dmahandle, &csb->csb_dmawincnt) != DDI_SUCCESS) { cmn_err(CE_WARN, "fdrawioctl: dma numwin failed"); rval = EINVAL; goto out; } } else { cmn_err(CE_WARN, "fdrawioctl: " "dma buf bind handle failed, rval = %d", rval); rval = EINVAL; goto out; } } FCERRPRINT(FDEP_L1, FDEM_RAWI, (CE_CONT, "cmd: %x %x %x %x %x %x %x %x %x %x\n", csb->csb_cmd[0], csb->csb_cmd[1], csb->csb_cmd[2], csb->csb_cmd[3], csb->csb_cmd[4], csb->csb_cmd[5], csb->csb_cmd[6], csb->csb_cmd[7], csb->csb_cmd[8], csb->csb_cmd[9])); FCERRPRINT(FDEP_L1, FDEM_RAWI, (CE_CONT, "nbytes: %x, opflags: %x, addr: %p, len: %x\n", csb->csb_ncmds, csb->csb_opflags, (void *)fdrp->fdr_addr, fdrp->fdr_nbytes)); /* * Note that we ignore any error returns from fdexec. * This is the way the driver has been, and it may be * that the raw ioctl senders simply don't want to * see any errors returned in this fashion. */ /* * VP/ix sense drive ioctl call checks for the error return. */ rval_exec = fdc_exec(fcp, sleep, change); if (dmar_flags & DDI_DMA_READ) { bcopy(aligned_buf, fdrp->fdr_addr, (uint_t)fdrp->fdr_nbytes); } FCERRPRINT(FDEP_L1, FDEM_RAWI, (CE_CONT, "rslt: %x %x %x %x %x %x %x %x %x %x\n", csb->csb_rslt[0], csb->csb_rslt[1], csb->csb_rslt[2], csb->csb_rslt[3], csb->csb_rslt[4], csb->csb_rslt[5], csb->csb_rslt[6], csb->csb_rslt[7], csb->csb_rslt[8], csb->csb_rslt[9])); /* copy results into fdr */ for (i = 0; i <= (int)csb->csb_nrslts; i++) fdrp->fdr_result[i] = csb->csb_rslt[i]; /* fdrp->fdr_nbytes = fdc->c_csb.csb_rlen; return resid */ out: if (csb->csb_dmahandle) { if (csb->csb_handle_bound) { if (ddi_dma_unbind_handle(csb->csb_dmahandle) != DDI_SUCCESS) cmn_err(CE_WARN, "fdrawioctl: " "dma unbind handle failed"); csb->csb_handle_bound = 0; } if (mem_handle != NULL) { ddi_dma_mem_free(&mem_handle); } ddi_dma_free_handle(&csb->csb_dmahandle); csb->csb_dmahandle = NULL; } if ((fdrp->fdr_cmd[0] & 0x0f) == FO_SDRV) { return (rval_exec); } return (rval); } void encode(xlate_tbl_t *tablep, int val, uchar_t *rcode) { do { if (tablep->value >= val) { *rcode = tablep->code; return; } } while ((++tablep)->value); *rcode = tablep->code; cmn_err(CE_WARN, "fdc encode failed, table %p val %x code %x", (void *)tablep, val, (uint_t)*rcode); } int decode(xlate_tbl_t *tablep, int kode, int *rvalue) { do { if (tablep->code == kode) { *rvalue = tablep->value; return (0); } } while ((++tablep)->value); return (-1); } /* * quiesce(9E) entry point. * * This function is called when the system is single-threaded at high * PIL with preemption disabled. Therefore, this function must not be * blocked. * * This function returns DDI_SUCCESS on success, or DDI_FAILURE on failure. * DDI_FAILURE indicates an error condition and should almost never happen. */ int fdc_quiesce(dev_info_t *dip) { struct fdcntlr *fcp; int ctlr = ddi_get_instance(dip); int unit; fcp = ddi_get_soft_state(fdc_state_head, ctlr); if (fcp == NULL) return (DDI_FAILURE); /* * If no FD units are attached, there is no need to quiesce. */ for (unit = 0; unit < NFDUN; unit++) { struct fcu_obj *fjp = fcp->c_unit[unit]; if (fjp->fj_flags & FUNIT_DRVATCH) { break; } } if (unit == NFDUN) return (DDI_SUCCESS); (void) ddi_dmae_disable(fcp->c_dip, fcp->c_dmachan); fcp->c_digout = (fcp->c_digout & (FD_DMTREN | FD_DRSEL)) | FD_ENABLE; outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); drv_usecwait(20); fcp->c_digout |= FD_RSETZ; outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); if (fcp->c_chip >= i82077) { int count = 4; uchar_t *oplistp = configurecmd; do { int ntries = FDC_RQM_RETRY; do { if ((inb(fcp->c_regbase + FCR_MSR) & (MS_RQM|MS_DIO)) == MS_RQM) break; else drv_usecwait(1); } while (--ntries); if (ntries == 0) { break; } outb(fcp->c_regbase + FCR_DATA, *oplistp++); drv_usecwait(16); /* See comment in fdc_result() */ } while (--count); } return (DDI_SUCCESS); } void fdcquiesce(struct fdcntlr *fcp) { int unit; FCERRPRINT(FDEP_L2, FDEM_RESE, (CE_NOTE, "fdcquiesce fcp %p", (void*)fcp)); ASSERT(MUTEX_HELD(&fcp->c_lock)); mutex_enter(&fcp->c_dorlock); if (ddi_dmae_stop(fcp->c_dip, fcp->c_dmachan) != DDI_SUCCESS) cmn_err(CE_WARN, "fdcquiesce: dmae stop failed, " "dip %p, dmachan %x", (void*)fcp->c_dip, fcp->c_dmachan); fcp->c_digout = (fcp->c_digout & (FD_DMTREN | FD_DRSEL)) | FD_ENABLE; outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); drv_usecwait(20); fcp->c_digout |= FD_RSETZ; outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); mutex_exit(&fcp->c_dorlock); /* count resets */ fcp->fdstats.reset++; fcp->c_curunit = -1; for (unit = 0; unit < NFDUN; unit++) fcp->c_curpcyl[unit] = -1; if (fcp->c_chip >= i82077) { (void) fdc_docmd(fcp, configurecmd, 4); /* * Ignored return. If failed, warning was issued by fdc_docmd. */ } } void fdcreadid(struct fdcntlr *fcp, struct fdcsb *csb) { static uchar_t readidcmd[2] = {FO_RDID | FO_MFM, 0}; readidcmd[1] = csb->csb_cmd[1]; (void) fdc_docmd(fcp, readidcmd, 2); } int fdcseek(struct fdcntlr *fcp, int unit, int cyl) { static uchar_t seekabscmd[3] = {FO_SEEK, 0, 0}; FCERRPRINT(FDEP_L0, FDEM_RECA, (CE_CONT, "fdcseek unit %d to cyl %d\n", unit, cyl)); seekabscmd[1] = (uchar_t)unit; seekabscmd[2] = (uchar_t)cyl; return (fdc_docmd(fcp, seekabscmd, 3)); } /* * Returns status of disk change line of selected drive. * = 0 means diskette is present * != 0 means diskette was removed and current state is unknown */ int fdcsense_chng(struct fdcntlr *fcp, int unit) { int digital_input; FCERRPRINT(FDEP_L0, FDEM_SCHG, (CE_CONT, "fdcsense_chng unit %d\n", unit)); digital_input = inb(fcp->c_regbase + FCR_DIR); if (fcp->c_mode == FDCMODE_30) digital_input ^= FDI_DKCHG; return (digital_input & FDI_DKCHG); } int fdcsense_drv(struct fdcntlr *fcp, int unit) { static uchar_t sensedrvcmd[2] = {FO_SDRV, 0}; uchar_t senser; int rval; sensedrvcmd[1] = (uchar_t)unit; (void) fdc_docmd(fcp, sensedrvcmd, 2); /* * Ignored return. If failed, warning was issued by fdc_docmd. * fdc_results retrieves the controller/drive status */ if (rval = fdc_result(fcp, &senser, 1)) goto done; if (senser & S3_WPROT) fcp->c_unit[unit]->fj_flags |= FUNIT_WPROT; else fcp->c_unit[unit]->fj_flags &= ~FUNIT_WPROT; done: return (rval); } int fdcsense_int(struct fdcntlr *fcp, int *unitp, int *cylp) { uchar_t senser[2]; int rval; (void) fdc_docmd(fcp, &senseintcmd, 1); /* * Ignored return. If failed, warning was issued by fdc_docmd. * fdc_results retrieves the controller/drive status */ if (!(rval = fdc_result(fcp, senser, 2))) { if ((*senser & (S0_IVCMD | S0_SEKEND | S0_ECHK)) != S0_SEKEND) rval = 1; if (unitp) *unitp = *senser & 3; if (cylp) *cylp = senser[1]; } return (rval); } int fdcspecify(struct fdcntlr *fcp, int xferrate, int steprate, int hlt) { static uchar_t perpindcmd[2] = {FO_PERP, 0}; static uchar_t specifycmd[3] = {FO_SPEC, 0, 0}; encode(drate_mfm, xferrate, &fcp->c_config); outb(fcp->c_regbase + FCR_CCR, fcp->c_config); if (fcp->c_chip >= i82077) { /* * Use old style perpendicular mode command of 82077. */ if (xferrate == 1000) { /* Set GAP and WGATE */ perpindcmd[1] = 3; /* double step rate because xlate table is for 500Kb */ steprate <<= 1; hlt <<= 1; } else perpindcmd[1] = 0; (void) fdc_docmd(fcp, perpindcmd, 2); /* * Ignored return. If failed, warning was issued by fdc_docmd. */ } encode(step_rate, steprate, &fcp->c_hutsrt); specifycmd[1] = fcp->c_hutsrt |= 0x0F; /* use max head unload time */ hlt = (hlt >= 256) ? 0 : (hlt >> 1); /* encode head load time */ specifycmd[2] = fcp->c_hlt = hlt << 1; /* make room for DMA bit */ return (fdc_docmd(fcp, specifycmd, 3)); } int fdcspdchange(struct fdcntlr *fcp, struct fcu_obj *fjp, int rpm) { int retcode = 0; uint_t ddic; uchar_t deselect = 0; uchar_t ds_code; uchar_t enable_code; uchar_t save; if (((fcp->c_flags & FCFLG_DSOUT) == 0 && rpm <= fjp->fj_rotspd) || ((fcp->c_flags & FCFLG_DSOUT) && (fjp->fj_flags & FUNIT_3DMODE) && rpm > fjp->fj_rotspd)) { return (0); } FCERRPRINT(FDEP_L1, FDEM_SCHG, (CE_CONT, "fdcspdchange: %d rpm\n", rpm)); ASSERT(MUTEX_HELD(&fcp->c_dorlock)); switch (fcp->c_chip) { default: break; case i82077: break; case PC87322: { uchar_t nscmodecmd[5] = {FO_MODE, 0x02, 0x00, 0xC8, 0x00}; if (rpm > fjp->fj_rotspd) { nscmodecmd[3] ^= 0xC0; retcode = (fcp->c_flags ^ FCFLG_DSOUT) || (fjp->fj_flags ^ FUNIT_3DMODE); fcp->c_flags |= FCFLG_DSOUT; fjp->fj_flags |= FUNIT_3DMODE; } else { /* program DENSEL to default output */ fcp->c_flags &= ~FCFLG_DSOUT; retcode = fjp->fj_flags & FUNIT_3DMODE; fjp->fj_flags &= ~FUNIT_3DMODE; } if (retcode && (fcp->c_digout & FD_DRSEL) == fcp->c_curunit) { /* de-select drive while changing speed */ deselect = fcp->c_digout ^ FD_DRSEL; outb(fcp->c_regbase + FCR_DOR, deselect); } (void) fdc_docmd(fcp, nscmodecmd, 5); /* * Ignored return. If failed, warning was issued by fdc_docmd. */ break; } case FDC37C665: enable_code = FSA_ENA5; goto SMC_config; case FDC37C666: enable_code = FSA_ENA6; SMC_config: if (rpm > fjp->fj_rotspd) { /* force DENSEL output to active LOW */ ds_code = FSB_DSHI; retcode = (fcp->c_flags ^ FCFLG_DSOUT) || (fjp->fj_flags ^ FUNIT_3DMODE); fcp->c_flags |= FCFLG_DSOUT; fjp->fj_flags |= FUNIT_3DMODE; } else { /* program DENSEL to default output */ ds_code = 0; fcp->c_flags &= ~FCFLG_DSOUT; retcode = fjp->fj_flags & FUNIT_3DMODE; fjp->fj_flags &= ~FUNIT_3DMODE; } if (retcode && (fcp->c_digout & FD_DRSEL) == fcp->c_curunit) { /* de-select drive while changing speed */ deselect = fcp->c_digout ^ FD_DRSEL; outb(fcp->c_regbase + FCR_DOR, deselect); } save = inb(fcp->c_regbase + FCR_SRA); /* enter configuration mode */ ddic = ddi_enter_critical(); outb(fcp->c_regbase + FCR_SRA, enable_code); outb(fcp->c_regbase + FCR_SRA, enable_code); ddi_exit_critical(ddic); outb(fcp->c_regbase + FCR_SRA, FSA_CR5); enable_code = inb(fcp->c_regbase + FCR_SRB) & FSB_DSDEF; /* update DENSEL mode bits */ outb(fcp->c_regbase + FCR_SRB, enable_code | ds_code); /* exit configuration mode */ outb(fcp->c_regbase + FCR_SRA, FSA_DISB); drv_usecwait(10); outb(fcp->c_regbase + FCR_SRA, save); break; } if (deselect) /* reselect drive */ outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); return (retcode); } static int fdc_motorsm(struct fcu_obj *fjp, int input, int timeval) { struct fdcntlr *fcp = fjp->fj_fdc; int unit = fjp->fj_unit & 3; int old_mstate; int rval = 0; uchar_t motorbit; ASSERT(MUTEX_HELD(&fcp->c_dorlock)); old_mstate = fcp->c_mtrstate[unit]; encode(motor_onbits, unit, &motorbit); switch (input) { case FMI_TIMER: /* timer expired */ fcp->c_motort[unit] = 0; switch (old_mstate) { case FMS_START: case FMS_DELAY: fcp->c_mtrstate[unit] = FMS_ON; break; case FMS_KILLST: fcp->c_motort[unit] = timeout(fdmotort, (void *)fjp, drv_usectohz(1000000)); fcp->c_mtrstate[unit] = FMS_IDLE; break; case FMS_IDLE: fcp->c_digout &= ~motorbit; outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); fcp->c_mtrstate[unit] = FMS_OFF; fjp->fj_flags &= ~FUNIT_3DMODE; break; case 86: rval = -1; break; case FMS_OFF: case FMS_ON: default: rval = -2; } break; case FMI_STARTCMD: /* start command */ switch (old_mstate) { case FMS_IDLE: fcp->c_mtrstate[unit] = 86; mutex_exit(&fcp->c_dorlock); (void) untimeout(fcp->c_motort[unit]); mutex_enter(&fcp->c_dorlock); fcp->c_motort[unit] = 0; fcp->c_mtrstate[unit] = FMS_ON; break; case FMS_OFF: fcp->c_digout |= motorbit; outb(fcp->c_regbase + FCR_DOR, fcp->c_digout); /* start motor_spinup_timer */ ASSERT(timeval > 0); fcp->c_motort[unit] = timeout(fdmotort, (void *)fjp, drv_usectohz(100000 * timeval)); /* FALLTHROUGH */ case FMS_KILLST: fcp->c_mtrstate[unit] = FMS_START; break; default: rval = -2; } break; case FMI_RSTARTCMD: /* restart command */ if (fcp->c_motort[unit] != 0) { fcp->c_mtrstate[unit] = 86; mutex_exit(&fcp->c_dorlock); (void) untimeout(fcp->c_motort[unit]); mutex_enter(&fcp->c_dorlock); } ASSERT(timeval > 0); fcp->c_motort[unit] = timeout(fdmotort, (void *)fjp, drv_usectohz(100000 * timeval)); fcp->c_mtrstate[unit] = FMS_START; break; case FMI_DELAYCMD: /* delay command */ if (fcp->c_motort[unit] == 0) fcp->c_motort[unit] = timeout(fdmotort, (void *)fjp, drv_usectohz(15000)); fcp->c_mtrstate[unit] = FMS_DELAY; break; case FMI_IDLECMD: /* idle command */ switch (old_mstate) { case FMS_DELAY: fcp->c_mtrstate[unit] = 86; mutex_exit(&fcp->c_dorlock); (void) untimeout(fcp->c_motort[unit]); mutex_enter(&fcp->c_dorlock); /* FALLTHROUGH */ case FMS_ON: ASSERT(timeval > 0); fcp->c_motort[unit] = timeout(fdmotort, (void *)fjp, drv_usectohz(100000 * timeval)); fcp->c_mtrstate[unit] = FMS_IDLE; break; case FMS_START: fcp->c_mtrstate[unit] = FMS_KILLST; break; default: rval = -2; } break; default: rval = -3; } if (rval) { FCERRPRINT(FDEP_L4, FDEM_EXEC, (CE_WARN, "fdc_motorsm: unit %d bad input %d or bad state %d", (int)fjp->fj_unit, input, old_mstate)); #if 0 cmn_err(CE_WARN, "fdc_motorsm: unit %d bad input %d or bad state %d", (int)fjp->fj_unit, input, old_mstate); fcp->c_mtrstate[unit] = FMS_OFF; if (fcp->c_motort[unit] != 0) { mutex_exit(&fcp->c_dorlock); (void) untimeout(fcp->c_motort[unit]); mutex_enter(&fcp->c_dorlock); fcp->c_motort[unit] = 0; } #endif } else FCERRPRINT(FDEP_L0, FDEM_EXEC, (CE_CONT, "fdc_motorsm unit %d: input %d, %d -> %d\n", (int)fjp->fj_unit, input, old_mstate, fcp->c_mtrstate[unit])); return (rval); } /* * fdmotort * is called from timeout() when a motor timer has expired. */ static void fdmotort(void *arg) { struct fcu_obj *fjp = (struct fcu_obj *)arg; struct fdcntlr *fcp = fjp->fj_fdc; struct fdcsb *csb = &fcp->c_csb; int unit = fjp->fj_unit & 3; int mval; int newxstate = 0; mutex_enter(&fcp->c_dorlock); mval = fdc_motorsm(fjp, FMI_TIMER, 0); mutex_exit(&fcp->c_dorlock); if (mval < 0) return; mutex_enter(&fcp->c_lock); if ((fcp->c_flags & FCFLG_WAITING) && fcp->c_mtrstate[unit] == FMS_ON && (csb->csb_xstate == FXS_MTRON || csb->csb_xstate == FXS_HDST || csb->csb_xstate == FXS_DKCHGX)) { newxstate = fdc_statemach(fcp); if (newxstate == -1) { FCERRPRINT(FDEP_L3, FDEM_EXEC, (CE_WARN, "fdc_motort unit %d: motor ready but bad xstate", (int)fjp->fj_unit)); fcp->c_csb.csb_cmdstat = EIO; } if (newxstate == -1 || newxstate == FXS_END) { fcp->c_flags ^= FCFLG_WAITING; cv_signal(&fcp->c_iocv); } } mutex_exit(&fcp->c_lock); } /* * DMA interrupt service routine * * Called by EISA dma interrupt service routine when buffer chaining * is required. */ ddi_dma_cookie_t * fdc_dmae_isr(struct fdcntlr *fcp) { struct fdcsb *csb = &fcp->c_csb; off_t off; size_t len; if (csb->csb_dmahandle && !csb->csb_cmdstat) { if (++csb->csb_dmacurrcookie < csb->csb_dmacookiecnt) { ddi_dma_nextcookie(csb->csb_dmahandle, &csb->csb_dmacookie); return (&csb->csb_dmacookie); } else if (++csb->csb_dmacurrwin < csb->csb_dmawincnt) { if (ddi_dma_getwin(csb->csb_dmahandle, csb->csb_dmacurrwin, &off, &len, &csb->csb_dmacookie, &csb->csb_dmacookiecnt) != DDI_SUCCESS) { return (NULL); } csb->csb_dmacurrcookie = 0; return (&csb->csb_dmacookie); } } else cmn_err(CE_WARN, "fdc: unsolicited DMA interrupt"); return (NULL); } /* * returns: * 0 if all ok, * ENXIO - diskette not in drive * ETIMEDOUT - for immediate operations that timed out * EBUSY - if stupid chip is locked busy??? * ENOEXEC - for timeout during sending cmds to chip * * to sleep: set sleep * to check for disk changed: set change */ static int fdc_exec(struct fdcntlr *fcp, int sleep, int change) { struct ddi_dmae_req dmaereq; struct fcu_obj *fjp; struct fdcsb *csb; off_t off; size_t len; int unit; mutex_enter(&fcp->c_lock); FCERRPRINT(FDEP_L0, FDEM_EXEC, (CE_CONT, "fdc_exec: sleep %x change %x\n", sleep, change)); csb = &fcp->c_csb; unit = csb->csb_drive; fjp = fcp->c_unit[unit]; if (csb->csb_opflags & CSB_OFINRPT) { if (*csb->csb_cmd == FO_RECAL) csb->csb_npcyl = 0; else if ((*csb->csb_cmd & ~FO_MFM) != FO_FRMT) csb->csb_npcyl = csb->csb_cmd[2] * fjp->fj_chars->fdc_steps; csb->csb_xstate = FXS_START; } else csb->csb_xstate = FXS_DOIT; csb->csb_retrys = 0; csb->csb_ourtrys = 0; if (csb->csb_dmahandle) { /* ensure that entire format xfer is in one cookie */ /* * The change from ddi_dma_buf/addr_setup() to * ddi_dma_buf/addr_bind_handle() has already loaded * the first DMA window and cookie. */ if ((*csb->csb_cmd & ~FO_MFM) == FO_FRMT && (4 * csb->csb_cmd[3]) != csb->csb_dmacookie.dmac_size) { mutex_exit(&fcp->c_lock); return (EINVAL); } } retry: if (fcp->c_curunit != unit || !(fjp->fj_flags & FUNIT_CHAROK)) { fcp->c_curunit = unit; fjp->fj_flags |= FUNIT_CHAROK; if (fjp->fj_chars->fdc_transfer_rate == 417) { /* XXX hack for fdformat */ /* fjp->fj_chars->fdc_transfer_rate == 500; */ fjp->fj_attr->fda_rotatespd = 360; } if (fdcspecify(fcp, fjp->fj_chars->fdc_transfer_rate, fjp->fj_drive->fdd_steprate, 40)) cmn_err(CE_WARN, "fdc_select: controller setup rejected " "fdcntrl %p transfer rate %x step rate %x " "head load time 40", (void*)fcp, fjp->fj_chars->fdc_transfer_rate, fjp->fj_drive->fdd_steprate); mutex_enter(&fcp->c_dorlock); if (fdcspdchange(fcp, fjp, fjp->fj_attr->fda_rotatespd)) { /* 3D drive requires 500 ms for speed change */ (void) fdc_motorsm(fjp, FMI_RSTARTCMD, 5); /* * Return value ignored - fdcmotort deals with failure. */ } mutex_exit(&fcp->c_dorlock); } /* * If checking for disk_change is enabled * (i.e. not seeking in fdresetchng), * we sample the DSKCHG line to see if the diskette has wandered away. */ if (change && fdcsense_chng(fcp, unit)) { FCERRPRINT(FDEP_L3, FDEM_EXEC, (CE_WARN, "diskette %d changed!!!", csb->csb_drive)); fcp->c_unit[unit]->fj_flags |= FUNIT_CHANGED; /* * If the diskette is still gone... so are we, adios! */ if (fdcheckdisk(fcp, unit)) { mutex_exit(&fcp->c_lock); /* VP/ix expects an EBUSY return here */ if (*csb->csb_cmd == FO_SDRV) { return (EBUSY); } return (ENXIO); } /* * delay to ensure that new diskette is up to speed */ mutex_enter(&fcp->c_dorlock); (void) fdc_motorsm(fjp, FMI_RSTARTCMD, fjp->fj_drive->fdd_motoron); /* * Return value ignored - fdcmotort deals with failure. */ mutex_exit(&fcp->c_dorlock); } /* * gather some statistics */ switch (csb->csb_cmd[0] & 0x1f) { case FO_RDDAT: fcp->fdstats.rd++; break; case FO_WRDAT: fcp->fdstats.wr++; break; case FO_RECAL: fcp->fdstats.recal++; break; case FO_FRMT: fcp->fdstats.form++; break; default: fcp->fdstats.other++; break; } bzero(csb->csb_rslt, 10); csb->csb_cmdstat = 0; if (csb->csb_dmahandle) { bzero(&dmaereq, sizeof (struct ddi_dmae_req)); dmaereq.der_command = (csb->csb_opflags & CSB_OFDMAWT) ? DMAE_CMD_WRITE : DMAE_CMD_READ; /* * setup for dma buffer chaining regardless of bus capability */ dmaereq.der_bufprocess = DMAE_BUF_CHAIN; dmaereq.proc = fdc_dmae_isr; dmaereq.procparms = (void *)fcp; if (ddi_dmae_prog(fcp->c_dip, &dmaereq, &csb->csb_dmacookie, fcp->c_dmachan) != DDI_SUCCESS) cmn_err(CE_WARN, "fdc_exec: dmae prog failed, " "dip %p, dmachan %x", (void*)fcp->c_dip, fcp->c_dmachan); } if ((fdc_statemach(fcp) == FXS_DOWT) && !sleep) { /* * If the operation has no results - then just return */ if (!csb->csb_nrslts) { mutex_exit(&fcp->c_lock); return (0); } /* * this operation has no interrupt and an immediate result * so wait for the results and stuff them into the csb */ if (fdc_statemach(fcp) == -1) { mutex_exit(&fcp->c_lock); return (EIO); } } else { fcp->c_flags |= FCFLG_WAITING; /* * wait for completion interrupt */ while (fcp->c_flags & FCFLG_WAITING) { cv_wait(&fcp->c_iocv, &fcp->c_lock); } } /* * See if there was an error detected, if so, fdrecover() * will check it out and say what to do. * * Don't do this, though, if this was the Sense Drive Status * or the Dump Registers command. */ if (csb->csb_cmdstat && *csb->csb_cmd != FO_SDRV) { /* if it can restarted OK, then do so, else return error */ if (fdrecover(fcp)) { mutex_exit(&fcp->c_lock); return (EIO); } /* ASSUMES that cmd is still intact in csb */ if (csb->csb_xstate == FXS_END) csb->csb_xstate = FXS_START; if (fdc_dma_attr.dma_attr_sgllen > 1 && csb->csb_dmahandle) { /* * restarted read/write operation requires * first DMA cookie of current window */ if (ddi_dma_getwin(csb->csb_dmahandle, csb->csb_dmacurrwin, &off, &len, &csb->csb_dmacookie, &csb->csb_dmacookiecnt) != DDI_SUCCESS) { mutex_exit(&fcp->c_lock); return (EIO); } csb->csb_dmacurrcookie = 0; } goto retry; } /* things went ok */ mutex_exit(&fcp->c_lock); return (0); } /* * fdcheckdisk * called by fdc_exec to check if the disk is still there - do a seek * then see if DSKCHG line went away; if so, diskette is in; else * it's (still) out. */ int fdcheckdisk(struct fdcntlr *fcp, int unit) { struct fdcsb *csb = &fcp->c_csb; int newcyl; /* where to seek for reset of DSKCHG */ int rval; enum fxstate save_xstate; uchar_t save_cmd, save_cd1, save_npcyl; ASSERT(MUTEX_HELD(&fcp->c_lock)); FCERRPRINT(FDEP_L1, FDEM_CHEK, (CE_CONT, "fdcheckdisk unit %d\n", unit)); if (fcp->c_curpcyl[unit]) newcyl = fcp->c_curpcyl[unit] - 1; else newcyl = 1; save_cmd = *csb->csb_cmd; save_cd1 = csb->csb_cmd[1]; save_npcyl = csb->csb_npcyl; save_xstate = csb->csb_xstate; *csb->csb_cmd = FO_SEEK; csb->csb_cmd[1] = (uchar_t)unit; csb->csb_npcyl = (uchar_t)newcyl; fcp->c_flags |= FCFLG_WAITING; if (fcp->c_mtrstate[unit] != FMS_ON && fcp->c_motort[unit] != 0) /* * wait for motor to get up to speed, * and let motor_timer issue seek cmd */ csb->csb_xstate = FXS_DKCHGX; else { /* * motor is up to speed; issue seek cmd now */ csb->csb_xstate = FXS_SEEK; if (rval = fdcseek(fcp, unit, newcyl)) { /* * any recal/seek errors are too serious to attend to */ FCERRPRINT(FDEP_L3, FDEM_CHEK, (CE_WARN, "fdcheckdisk err %d", rval)); fcp->c_flags ^= FCFLG_WAITING; } } /* * wait for completion interrupt * XXX This should be backed up with a watchdog timer! */ while (fcp->c_flags & FCFLG_WAITING) { cv_wait(&fcp->c_iocv, &fcp->c_lock); } /* * if disk change still asserted, no diskette in drive! */ if (rval = fdcsense_chng(fcp, unit)) { FCERRPRINT(FDEP_L3, FDEM_CHEK, (CE_WARN, "fdcheckdisk no disk %d", unit)); } *csb->csb_cmd = save_cmd; csb->csb_cmd[1] = save_cd1; csb->csb_npcyl = save_npcyl; csb->csb_xstate = save_xstate; return (rval); } static int fdrecover(struct fdcntlr *fcp) { struct fcu_obj *fjp; struct fdcsb *csb = &fcp->c_csb; int residual; int unit; char *failure; FCERRPRINT(FDEP_L2, FDEM_RECO, (CE_NOTE, "fdrecover unit %d", csb->csb_drive)); unit = csb->csb_drive; fjp = fcp->c_unit[unit]; if (fcp->c_flags & FCFLG_TIMEOUT) { fcp->c_flags ^= FCFLG_TIMEOUT; csb->csb_rslt[1] |= 0x08; FCERRPRINT(FDEP_L3, FDEM_RECO, (CE_WARN, "fd unit %d: %s timed out", csb->csb_drive, fdcmds[*csb->csb_cmd & 0x1f].cmdname)); } if (csb->csb_status & S0_SEKEND) fcp->c_curpcyl[unit] = -1; switch (csb->csb_oldxs) { case FXS_RCAL: /* recalibrate */ case FXS_SEEK: /* seek */ case FXS_RESET: /* cntlr reset */ FCERRPRINT(FDEP_L4, FDEM_RECO, (CE_WARN, "fd unit %d: %s error: st0=0x%x pcn=%d", csb->csb_drive, fdcmds[*csb->csb_cmd & 0x1f].cmdname, *csb->csb_rslt, csb->csb_rslt[1])); if (csb->csb_retrys++ < skretry && !(csb->csb_opflags & CSB_OFRAWIOCTL)) return (0); break; case FXS_RDID: /* read ID */ if (!(csb->csb_status & S0_SEKEND)) csb->csb_xstate = FXS_HDST; /* FALLTHROUGH */ case FXS_DOIT: /* original operation */ case FXS_DOWT: /* waiting on operation */ if (csb->csb_opflags & (CSB_OFDMARD | CSB_OFDMAWT)) { if (ddi_dmae_getcnt(fcp->c_dip, fcp->c_dmachan, &residual) != DDI_SUCCESS) cmn_err(CE_WARN, "fdc_recover: dmae getcnt failed, " "dip %p dmachan %x residual %x", (void*)fcp->c_dip, fcp->c_dmachan, residual); FCERRPRINT(FDEP_L2, FDEM_RECO, (CE_NOTE, "fd unit %d: %s error: " "dma count=0x%lx residual=0x%x", csb->csb_drive, fdcmds[*csb->csb_cmd & 0x1f].cmdname, csb->csb_dmacookie.dmac_size, residual)); } if (csb->csb_rslt[1] == S1_OVRUN) /* * handle retries of over/underrun * with a secondary retry counter */ if (++csb->csb_ourtrys <= OURUN_TRIES) { FCERRPRINT(FDEP_L2, FDEM_RECO, (CE_NOTE, "fd unit %d: %s error: over/under-run", csb->csb_drive, fdcmds[*csb->csb_cmd & 0x1f].cmdname)); return (0); } else /* * count 1 set of over/underruns * as 1 primary retry effort */ csb->csb_ourtrys = 0; if ((fjp->fj_flags & (FUNIT_UNLABELED | FUNIT_LABELOK)) && !(csb->csb_opflags & CSB_OFRAWIOCTL)) { /* * device is open so keep trying and * gather statistics on errors */ if (csb->csb_rslt[1] & S1_CRCER) fcp->fdstats.de++; if (csb->csb_rslt[1] & S1_OVRUN) fcp->fdstats.run++; if (csb->csb_rslt[1] & (S1_NODATA | S1_MADMK)) fcp->fdstats.bfmt++; if (csb->csb_rslt[1] & 0x08) fcp->fdstats.to++; /* * if we have not run out of retries, return 0 */ if (csb->csb_retrys++ < csb->csb_maxretry && (*csb->csb_cmd & ~FO_MFM) != FO_FRMT) { if (csb->csb_opflags & (CSB_OFDMARD | CSB_OFDMAWT)) { FCERRPRINT(FDEP_L4, FDEM_RECO, (CE_WARN, "fd unit %d: %s error: " "st0=0x%x st1=0x%x st2=0x%x", csb->csb_drive, fdcmds[*csb->csb_cmd & 0x1f].cmdname, *csb->csb_rslt, csb->csb_rslt[1], csb->csb_rslt[2])); } if ((csb->csb_retrys & 1) && csb->csb_xstate == FXS_END) csb->csb_xstate = FXS_DOIT; else if (csb->csb_retrys == 3) csb->csb_xstate = FXS_RESTART; return (0); } if (csb->csb_rslt[1] & S1_CRCER) failure = "crc error"; else if (csb->csb_rslt[1] & S1_OVRUN) failure = "over/under-run"; else if (csb->csb_rslt[1] & (S1_NODATA | S1_MADMK)) failure = "bad format"; else if (csb->csb_rslt[1] & 0x08) failure = "timeout"; else failure = "failed"; cmn_err(CE_NOTE, "!fd unit %d: %s %s (%x %x %x)", csb->csb_drive, fdcmds[*csb->csb_cmd & 0x1f].cmdname, failure, *csb->csb_rslt, csb->csb_rslt[1], csb->csb_rslt[2]); } else { FCERRPRINT(FDEP_L2, FDEM_RECO, (CE_NOTE, "fd unit %d: %s failed (%x %x %x)", csb->csb_drive, fdcmds[*csb->csb_cmd & 0x1f].cmdname, *csb->csb_rslt, csb->csb_rslt[1], csb->csb_rslt[2])); } break; default: FCERRPRINT(FDEP_L4, FDEM_RECO, (CE_WARN, "fd unit %d: %s failed: st0=0x%x st1=0x%x st2=0x%x", csb->csb_drive, fdcmds[*csb->csb_cmd & 0x1f].cmdname, *csb->csb_rslt, csb->csb_rslt[1], csb->csb_rslt[2])); break; } return (1); } /* Autovector Interrupt Entry Point */ static uint_t fdc_intr(caddr_t arg) { struct fdcntlr *fcp = (struct fdcntlr *)arg; struct fdcsb *csb; off_t off; size_t blklen; int drive; int newstate; int pendstate; int rval = DDI_DMA_DONE; int state; int maxspin = 10; csb = &fcp->c_csb; mutex_enter(&fcp->c_lock); if (fcp->c_suspended) { mutex_exit(&fcp->c_lock); return (DDI_INTR_UNCLAIMED); } /* * Wait for the RQM bit to be set, or until we've tested it * a bunch of times (which may imply this isn't our interrupt). */ state = inb(fcp->c_regbase + FCR_MSR); pendstate = state & (MS_RQM | MS_DIO | MS_CB); while (((pendstate & MS_RQM) == 0) && (maxspin-- > 0)) { /* Small pause in between reading the status port */ drv_usecwait(10); /* Reread the status port */ state = inb(fcp->c_regbase + FCR_MSR); pendstate = state & (MS_RQM | MS_DIO | MS_CB); } FCERRPRINT(FDEP_L0, FDEM_INTR, (CE_CONT, "fdc_intr unit %d: xstate=%d MSR=0x%x\n", csb->csb_drive, csb->csb_xstate, state)); /* * If there is an operation outstanding AND the controller is ready * to receive a command or send us the result of a command (OR if the * controller is ready to accept a new command), AND if * someone has been waiting for a command to finish AND (if no unit * is BUSY OR if the unit that we're waiting for is BUSY (i.e. it's in * the middle of a seek/recalibrate)) then this interrupt is for us. */ if ((pendstate == (MS_RQM | MS_DIO | MS_CB) || pendstate == MS_RQM) && (fcp->c_flags & FCFLG_WAITING) && (!(state & 0x0f) || ((1 << csb->csb_drive) & state))) { /* * Remove one of the conditions for entering this code. * The state_machine will release the c_lock if it * calls untimeout() */ fcp->c_flags ^= FCFLG_WAITING; if ((newstate = fdc_statemach(fcp)) == -1) { /* restore waiting flag */ fcp->c_flags |= FCFLG_WAITING; mutex_exit(&fcp->c_lock); return (DDI_INTR_CLAIMED); } if (fcp->c_intrstat) KIOIP->intrs[KSTAT_INTR_HARD]++; if (newstate == FXS_END) { if (csb->csb_dmahandle && !csb->csb_cmdstat && /* * read/write operation may have multiple DMA * cookies: process next one */ ((csb->csb_dmacurrcookie < (csb->csb_dmacookiecnt - 1)) || (csb->csb_dmacurrwin) < (csb->csb_dmawincnt - 1))) { /* * read/write operation requires another * DMA cookie: process next one */ if (++csb->csb_dmacurrcookie < csb->csb_dmacookiecnt) { ddi_dma_nextcookie(csb->csb_dmahandle, &csb->csb_dmacookie); } else if (++csb->csb_dmacurrwin < csb->csb_dmawincnt) { if (ddi_dma_getwin(csb->csb_dmahandle, csb->csb_dmacurrwin, &off, &blklen, &csb->csb_dmacookie, &csb->csb_dmacookiecnt) != DDI_SUCCESS) { cmn_err(CE_WARN, "fdc_intr: " "dma getwin failed"); } csb->csb_dmacurrcookie = 0; } if (ddi_dmae_prog(fcp->c_dip, NULL, &csb->csb_dmacookie, fcp->c_dmachan) != DDI_SUCCESS) cmn_err(CE_WARN, "fdc_intr: dmae prog failed, " "dip %p dmachannel %x", (void*)fcp->c_dip, fcp->c_dmachan); /* * status of last operation has disk * address for continuation */ csb->csb_cmd[2] = csb->csb_rslt[3]; csb->csb_cmd[3] = csb->csb_rslt[4]; csb->csb_cmd[4] = csb->csb_rslt[5]; csb->csb_cmd[1] = (csb->csb_cmd[1] & ~0x04) | (csb->csb_cmd[3] << 2); csb->csb_xstate = FXS_START; (void) fdc_statemach(fcp); /* * Ignored return. If failed, warning already * posted. Returned state irrelevant. */ /* restore waiting flag */ fcp->c_flags |= FCFLG_WAITING; goto fi_exit; } if (rval != DDI_DMA_DONE) csb->csb_cmdstat = EIO; /* * somebody's waiting for completion of fdcntlr/csb, * wake them */ cv_signal(&fcp->c_iocv); } else /* restore waiting flag */ fcp->c_flags |= FCFLG_WAITING; fi_exit: mutex_exit(&fcp->c_lock); return (DDI_INTR_CLAIMED); } if (state & MS_RQM) { (void) fdcsense_int(fcp, &drive, NULL); /* * Ignored return - senser state already saved */ FCERRPRINT(FDEP_L4, FDEM_INTR, (CE_WARN, "fdc_intr unit %d: nobody sleeping 0x%x", drive, state)); } else { FCERRPRINT(FDEP_L4, FDEM_INTR, (CE_WARN, "fdc_intr: nobody sleeping on %d 0x%x", csb->csb_drive, state)); } /* * This should probably be protected, but, what the * heck...the cost isn't worth the accuracy for this * statistic. */ if (fcp->c_intrstat) KIOIP->intrs[KSTAT_INTR_SPURIOUS]++; mutex_exit(&fcp->c_lock); return (DDI_INTR_UNCLAIMED); } /* * fdwatch * is called from timeout() when a floppy operation timer has expired. */ static void fdwatch(void *arg) { struct fdcntlr *fcp = (struct fdcntlr *)arg; struct fdcsb *csb; mutex_enter(&fcp->c_lock); if (fcp->c_timeid == 0) { /* * fdc_intr got here first, ergo, no timeout condition.. */ mutex_exit(&fcp->c_lock); return; } if (fcp->c_flags & FCFLG_WAITING) { if (ddi_dmae_stop(fcp->c_dip, fcp->c_dmachan) != DDI_SUCCESS) cmn_err(CE_WARN, "fdwatch: dmae stop failed, " "dip %p, dmachan %x", (void*)fcp->c_dip, fcp->c_dmachan); csb = &fcp->c_csb; FCERRPRINT(FDEP_L3, FDEM_WATC, (CE_WARN, "fdcwatch unit %d: xstate = %d", csb->csb_drive, csb->csb_xstate)); drv_usecwait(50); if (inb(fcp->c_regbase + FCR_MSR) != MS_RQM) { /* * cntlr is still busy, so reset it */ csb->csb_xstate = FXS_KILL; (void) fdc_statemach(fcp); /* * Ignored return. If failed, warning already * posted. Returned state irrelevant. */ } else { csb->csb_xstate = FXS_END; fcp->c_timeid = 0; fcp->c_flags ^= FCFLG_WAITING; cv_signal(&fcp->c_iocv); } csb->csb_cmdstat = EIO; fcp->c_flags |= FCFLG_TIMEOUT; } else { FCERRPRINT(FDEP_L4, FDEM_INTR, (CE_WARN, "fdcwatch: not sleeping for unit %d", fcp->c_csb.csb_drive)); } if (fcp->c_intrstat) KIOIP->intrs[KSTAT_INTR_WATCHDOG]++; mutex_exit(&fcp->c_lock); } static int fdc_statemach(struct fdcntlr *fcp) { struct fcu_obj *fjp; struct fdcsb *csb = &fcp->c_csb; int backoff; clock_t time; int unit; ASSERT(MUTEX_HELD(&fcp->c_lock)); unit = csb->csb_drive; fjp = fcp->c_unit[unit]; csb->csb_oldxs = csb->csb_xstate; switch (csb->csb_xstate) { case FXS_START: /* start of operation */ ASSERT(fcp->c_timeid == 0); time = drv_usectohz(100000 * (unsigned int)csb->csb_timer); if (time == 0) time = drv_usectohz(2000000); fcp->c_timeid = timeout(fdwatch, (void *)fcp, time); if (fcp->c_mtrstate[unit] == FMS_START) { /* * wait for motor to get up to speed */ csb->csb_xstate = FXS_MTRON; break; } /* FALLTHROUGH */ case FXS_MTRON: /* motor is at speed */ if (fcp->c_mtrstate[unit] != FMS_ON) { /* how did we get here ?? */ cmn_err(CE_WARN, "fdc: selected but motor off"); return (-1); } if (fcp->c_curpcyl[unit] != -1 && *csb->csb_cmd != FO_RECAL) goto nxs_seek; recalcmd[1] = (uchar_t)unit; if (fdc_docmd(fcp, recalcmd, 2) == -1) { /* cntlr did not accept command bytes */ fdcquiesce(fcp); csb->csb_cmdstat = EIO; csb->csb_xstate = FXS_RESET; break; } fcp->c_sekdir[unit] = 0; csb->csb_xstate = FXS_RCAL; break; case FXS_RCAL: /* forced recalibrate is complete */ #if 0 /* #ifdef _VPIX */ /* WARNING: this code breaks SPARC compatibility */ if (csb->csb_opflags & CSB_OFRAWIOCTL && *csb->csb_cmd == FO_RECAL) { fcp->c_curpcyl[unit] = 0; csb->csb_status = 0; goto nxs_cmpl; } #endif (void) fdc_docmd(fcp, &senseintcmd, 1); /* * Ignored return. If failed, warning was issued by fdc_docmd. * fdc_results retrieves the controller/drive status */ (void) fdc_result(fcp, csb->csb_rslt, 2); /* * Ignored return. If failed, warning was issued by fdc_result. * Actual results checked below */ if ((csb->csb_status = ((*csb->csb_rslt ^ S0_SEKEND) & (S0_ICMASK | S0_SEKEND | S0_ECHK | S0_NOTRDY))) != 0) { FCERRPRINT(FDEP_L3, FDEM_EXEC, (CE_WARN, "fdc_statemach unit %d: recal result %x", csb->csb_drive, *csb->csb_rslt)); fdcquiesce(fcp); csb->csb_cmdstat = EIO; csb->csb_xstate = FXS_RESET; break; } if (unit != (*csb->csb_rslt & 3) || csb->csb_rslt[1]) { csb->csb_status = S0_SEKEND; goto nxs_cmpl; } fcp->c_curpcyl[unit] = csb->csb_rslt[1]; if (*csb->csb_cmd == FO_RECAL) goto nxs_cmpl; nxs_seek: if (*csb->csb_cmd != FO_SEEK && csb->csb_npcyl == fcp->c_curpcyl[unit]) goto nxs_doit; fcp->c_sekdir[unit] = csb->csb_npcyl - fcp->c_curpcyl[unit]; /* FALLTHROUGH */ case FXS_DKCHGX: /* reset Disk-Change latch */ (void) fdcseek(fcp, csb->csb_cmd[1], csb->csb_npcyl); /* * Ignored return. If command rejected, warnig already posted * by fdc_docmd(). */ csb->csb_xstate = FXS_SEEK; break; case FXS_RESTART: /* special restart of read/write operation */ ASSERT(fcp->c_timeid == 0); time = drv_usectohz(100000 * csb->csb_timer); if (time == 0) time = drv_usectohz(2000000); fcp->c_timeid = timeout(fdwatch, (void *)fcp, time); if (fcp->c_mtrstate[unit] != FMS_ON) { cmn_err(CE_WARN, "fdc: selected but motor off"); return (-1); } if ((csb->csb_npcyl == 0 || fcp->c_sekdir[unit] >= 0) && (int)csb->csb_cmd[2] < (fjp->fj_chars->fdc_ncyl - 1)) backoff = csb->csb_npcyl + 1; else backoff = csb->csb_npcyl - 1; (void) fdcseek(fcp, csb->csb_cmd[1], backoff); /* * Ignored return. If command rejected, warnig already posted * by fdc_docmd(). */ csb->csb_xstate = FXS_RESEEK; break; case FXS_RESEEK: /* seek to backoff-cyl complete */ (void) fdc_docmd(fcp, &senseintcmd, 1); /* * Ignored return. If failed, warning was issued by fdc_docmd. * fdc_results retrieves the controller/drive status */ (void) fdc_result(fcp, csb->csb_rslt, 2); /* * Ignored return. If failed, warning was issued by fdc_result. * Actual results checked below */ if ((csb->csb_status = ((*csb->csb_rslt ^ S0_SEKEND) & (S0_ICMASK | S0_SEKEND | S0_ECHK | S0_NOTRDY))) != 0) goto nxs_cmpl; (void) fdcseek(fcp, csb->csb_cmd[1], csb->csb_npcyl); /* * Ignored return. If command rejected, warnig already posted * by fdc_docmd(). */ csb->csb_xstate = FXS_SEEK; break; case FXS_SEEK: /* seek complete */ #if 0 /* #ifdef _VPIX */ /* WARNING: this code breaks SPARC compatibility and */ /* rawioctls in fdformat */ if (csb->csb_opflags & CSB_OFRAWIOCTL) { fcp->c_curpcyl[unit] = csb->csb_npcyl; csb->csb_status = 0; goto nxs_cmpl; } #endif (void) fdc_docmd(fcp, &senseintcmd, 1); /* * Ignored return. If failed, warning was issued by fdc_docmd. * fdc_results retrieves the controller/drive status */ (void) fdc_result(fcp, csb->csb_rslt, 2); /* * Ignored return. If failed, warning was issued by fdc_result. * Actual results checked below */ if ((csb->csb_status = ((*csb->csb_rslt ^ S0_SEKEND) & (S0_ICMASK | S0_SEKEND | S0_ECHK | S0_NOTRDY))) != 0) goto nxs_cmpl; if (unit != (*csb->csb_rslt & 3) || csb->csb_rslt[1] != csb->csb_npcyl) { csb->csb_status = S0_SEKEND; goto nxs_cmpl; }; fcp->c_curpcyl[unit] = csb->csb_rslt[1]; /* use motor_timer to delay for head settle */ mutex_enter(&fcp->c_dorlock); (void) fdc_motorsm(fjp, FMI_DELAYCMD, fjp->fj_drive->fdd_headsettle / 1000); /* * Return value ignored - fdcmotort deals with failure. */ mutex_exit(&fcp->c_dorlock); csb->csb_xstate = FXS_HDST; break; case FXS_HDST: /* head settle */ if (*csb->csb_cmd == FO_SEEK) goto nxs_cmpl; if ((*csb->csb_cmd & ~FO_MFM) == FO_FRMT) goto nxs_doit; fdcreadid(fcp, csb); csb->csb_xstate = FXS_RDID; break; case FXS_RDID: /* read ID complete */ (void) fdc_result(fcp, csb->csb_rslt, 7); /* * Ignored return. If failed, warning was issued by fdc_result. * Actual results checked below */ if ((csb->csb_status = (*csb->csb_rslt & (S0_ICMASK | S0_ECHK | S0_NOTRDY))) != 0) goto nxs_cmpl; if (csb->csb_cmd[2] != csb->csb_rslt[3]) { /* at wrong logical cylinder */ csb->csb_status = S0_SEKEND; goto nxs_cmpl; }; goto nxs_doit; case FXS_DOIT: /* do original operation */ ASSERT(fcp->c_timeid == 0); time = drv_usectohz(100000 * csb->csb_timer); if (time == 0) time = drv_usectohz(2000000); fcp->c_timeid = timeout(fdwatch, (void *)fcp, time); nxs_doit: if (fdc_docmd(fcp, csb->csb_cmd, csb->csb_ncmds) == -1) { /* cntlr did not accept command bytes */ fdcquiesce(fcp); csb->csb_xstate = FXS_RESET; csb->csb_cmdstat = EIO; break; } csb->csb_xstate = FXS_DOWT; break; case FXS_DOWT: /* operation complete */ (void) fdc_result(fcp, csb->csb_rslt, csb->csb_nrslts); /* * Ignored return. If failed, warning was issued by fdc_result. * Actual results checked below. */ if (*csb->csb_cmd == FO_SDRV) { csb->csb_status = (*csb->csb_rslt ^ (S3_DRRDY | S3_2SIDE)) & ~(S3_HEAD | S3_UNIT); } else { csb->csb_status = *csb->csb_rslt & (S0_ICMASK | S0_ECHK | S0_NOTRDY); } nxs_cmpl: if (csb->csb_status) csb->csb_cmdstat = EIO; csb->csb_xstate = FXS_END; /* remove watchdog timer if armed and not already triggered */ if (fcp->c_timeid != 0) { timeout_id_t timeid; timeid = fcp->c_timeid; fcp->c_timeid = 0; mutex_exit(&fcp->c_lock); (void) untimeout(timeid); mutex_enter(&fcp->c_lock); } break; case FXS_KILL: /* quiesce cntlr by reset */ fdcquiesce(fcp); fcp->c_timeid = timeout(fdwatch, (void *)fcp, drv_usectohz(2000000)); csb->csb_xstate = FXS_RESET; break; case FXS_RESET: /* int from reset */ for (unit = 0; unit < NFDUN; unit++) { (void) fdcsense_int(fcp, NULL, NULL); fcp->c_curpcyl[unit] = -1; } if (fcp->c_timeid != 0) { timeout_id_t timeid; timeid = fcp->c_timeid; fcp->c_timeid = 0; mutex_exit(&fcp->c_lock); (void) untimeout(timeid); mutex_enter(&fcp->c_lock); } csb->csb_xstate = FXS_END; break; default: cmn_err(CE_WARN, "fdc: statemach, unknown state"); return (-1); } FCERRPRINT(FDEP_L1, FDEM_EXEC, (CE_CONT, "fdc_statemach unit %d: %d -> %d\n", csb->csb_drive, csb->csb_oldxs, csb->csb_xstate)); return (csb->csb_xstate); } /* * routine to program a command into the floppy disk controller. */ int fdc_docmd(struct fdcntlr *fcp, uchar_t *oplistp, uchar_t count) { int ntries; ASSERT(count >= 1); FCERRPRINT(FDEP_L0, FDEM_EXEC, (CE_CONT, "fdc_docmd: %x %x %x %x %x %x %x %x %x\n", oplistp[0], oplistp[1], oplistp[2], oplistp[3], oplistp[4], oplistp[5], oplistp[6], oplistp[7], oplistp[8])); do { ntries = FDC_RQM_RETRY; do { if ((inb(fcp->c_regbase + FCR_MSR) & (MS_RQM|MS_DIO)) == MS_RQM) break; else drv_usecwait(1); } while (--ntries); if (ntries == 0) { FCERRPRINT(FDEP_L3, FDEM_EXEC, (CE_WARN, "fdc_docmd: ctlr not ready")); return (-1); } outb(fcp->c_regbase + FCR_DATA, *oplistp++); drv_usecwait(16); /* See comment in fdc_result() */ } while (--count); return (0); } /* * Routine to return controller/drive status information. * The diskette-controller data-register is read the * requested number of times and the results are placed in * consecutive memory locations starting at the passed * address. */ int fdc_result(struct fdcntlr *fcp, uchar_t *rsltp, uchar_t rcount) { int ntries; uchar_t *abresultp = rsltp; uchar_t stat; int laxative = 7; ntries = 10 * FDC_RQM_RETRY; do { do { if ((inb(fcp->c_regbase + FCR_MSR) & (MS_RQM | MS_DIO)) == (MS_RQM | MS_DIO)) break; else drv_usecwait(10); } while (--ntries); if (!ntries) { FCERRPRINT(FDEP_L3, FDEM_EXEC, (CE_WARN, "fdc_result: ctlr not ready")); return (-2); } *rsltp++ = inb(fcp->c_regbase + FCR_DATA); /* * The PRM suggests waiting for 14.5 us. * Adding a bit more to cover the case of bad calibration * of drv_usecwait(). */ drv_usecwait(16); ntries = FDC_RQM_RETRY; } while (--rcount); while ((inb(fcp->c_regbase + FCR_MSR) & MS_CB) && laxative--) { FCERRPRINT(FDEP_L3, FDEM_EXEC, (CE_WARN, "fdc_result: ctlr still busy")); /* * try to complete Result phase by purging * result bytes queued for reading */ *abresultp = S0_IVCMD; do { stat = inb(fcp->c_regbase + FCR_MSR) & (MS_RQM | MS_DIO); if (stat == MS_RQM) { /* * Result phase is complete * but did we get the results corresponding to * the command we think we executed? */ return (-1); } if (stat == (MS_RQM | MS_DIO)) break; else drv_usecwait(10); } while (--ntries); if (!ntries || !laxative) { FCERRPRINT(FDEP_L3, FDEM_EXEC, (CE_WARN, "fdc_result: ctlr still busy and not ready")); return (-3); } (void) inb(fcp->c_regbase + FCR_DATA); drv_usecwait(16); /* See comment above */ ntries = FDC_RQM_RETRY; } return (0); } /* * Function: get_unit() * * Assumptions: ioaddr is either 0x3f0 or 0x370 */ static int get_unit(dev_info_t *dip, int *cntrl_num) { int ioaddr; if (get_ioaddr(dip, &ioaddr) != DDI_SUCCESS) return (DDI_FAILURE); switch (ioaddr) { case 0x3f0: *cntrl_num = 0; break; case 0x370: *cntrl_num = 1; break; default: return (DDI_FAILURE); } return (DDI_SUCCESS); } static int get_ioaddr(dev_info_t *dip, int *ioaddr) { int reglen, nregs, i; int status = DDI_FAILURE; struct { int bustype; int base; int size; } *reglist; if (ddi_getlongprop(DDI_DEV_T_ANY, dip, DDI_PROP_DONTPASS, "reg", (caddr_t)&reglist, &reglen) != DDI_PROP_SUCCESS) { cmn_err(CE_WARN, "fdc: reg property not found"); return (DDI_FAILURE); } nregs = reglen / sizeof (*reglist); for (i = 0; i < nregs; i++) { if (reglist[i].bustype == 1) { *ioaddr = reglist[i].base; status = DDI_SUCCESS; break; } } kmem_free(reglist, reglen); if (status == DDI_SUCCESS) { if (*ioaddr == 0x3f2 || *ioaddr == 0x372) { /* * Some BIOS's (ASUS is one) don't include first * two IO ports in the floppy controller resources. */ *ioaddr -= 2; /* step back to 0x3f0 or 0x370 */ /* * It would be nice to update the regs property as well * so device pathname contains 3f0 instead of 3f2, but * updating the regs now won't have this effect as that * component of the device pathname has already been * constructed by the ISA nexus driver. * * reglist[i].base -= 2; * reglist[i].size += 2; * dev = makedevice(ddi_driver_major(dip), 0); * ddi_prop_update_int_array(dev, dip, "reg", * (int *)reglist, reglen / sizeof (int)); */ } } return (status); }
{ "language": "C" }
/* * Copyright 2012 Red Hat Inc. * * 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 COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Authors: Ben Skeggs */ #include "nv50.h" #include "ram.h" static const struct nv50_fb_func g84_fb = { .ram_new = nv50_ram_new, .trap = 0x001d07ff, }; int g84_fb_new(struct nvkm_device *device, int index, struct nvkm_fb **pfb) { return nv50_fb_new_(&g84_fb, device, index, pfb); }
{ "language": "C" }
/* * (C) 2010,2011 Thomas Renninger <trenn@suse.de>, Novell Inc. * * Licensed under the terms of the GNU GPL License version 2. * * ToDo: Needs to be done more properly for AMD/Intel specifics */ /* Helper struct for qsort, must be in sync with cpupower_topology.cpu_info */ /* Be careful: Need to pass unsigned to the sort, so that offlined cores are in the end, but double check for -1 for offlined cpus at other places */ #include <stdlib.h> #include <stdio.h> #include <unistd.h> #include <errno.h> #include <fcntl.h> #include <cpuidle.h> /* CPU topology/hierarchy parsing ******************/
{ "language": "C" }
/* * Copyright (c) 2002 Mark Hills <mark@pogo.org.uk> * * 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 <vorbis/vorbisenc.h> #include "libavutil/avassert.h" #include "libavutil/fifo.h" #include "libavutil/opt.h" #include "avcodec.h" #include "audio_frame_queue.h" #include "internal.h" #include "vorbis.h" #include "vorbis_parser.h" /* Number of samples the user should send in each call. * This value is used because it is the LCD of all possible frame sizes, so * an output packet will always start at the same point as one of the input * packets. */ #define LIBVORBIS_FRAME_SIZE 64 #define BUFFER_SIZE (1024 * 64) typedef struct LibvorbisEncContext { AVClass *av_class; /**< class for AVOptions */ vorbis_info vi; /**< vorbis_info used during init */ vorbis_dsp_state vd; /**< DSP state used for analysis */ vorbis_block vb; /**< vorbis_block used for analysis */ AVFifoBuffer *pkt_fifo; /**< output packet buffer */ int eof; /**< end-of-file flag */ int dsp_initialized; /**< vd has been initialized */ vorbis_comment vc; /**< VorbisComment info */ double iblock; /**< impulse block bias option */ AVVorbisParseContext *vp; /**< parse context to get durations */ AudioFrameQueue afq; /**< frame queue for timestamps */ } LibvorbisEncContext; static const AVOption options[] = { { "iblock", "Sets the impulse block bias", offsetof(LibvorbisEncContext, iblock), AV_OPT_TYPE_DOUBLE, { .dbl = 0 }, -15, 0, AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM }, { NULL } }; static const AVCodecDefault defaults[] = { { "b", "0" }, { NULL }, }; static const AVClass vorbis_class = { .class_name = "libvorbis", .item_name = av_default_item_name, .option = options, .version = LIBAVUTIL_VERSION_INT, }; static int vorbis_error_to_averror(int ov_err) { switch (ov_err) { case OV_EFAULT: return AVERROR_BUG; case OV_EINVAL: return AVERROR(EINVAL); case OV_EIMPL: return AVERROR(EINVAL); default: return AVERROR_UNKNOWN; } } static av_cold int libvorbis_setup(vorbis_info *vi, AVCodecContext *avctx) { LibvorbisEncContext *s = avctx->priv_data; double cfreq; int ret; if (avctx->flags & AV_CODEC_FLAG_QSCALE || !avctx->bit_rate) { /* variable bitrate * NOTE: we use the oggenc range of -1 to 10 for global_quality for * user convenience, but libvorbis uses -0.1 to 1.0. */ float q = avctx->global_quality / (float)FF_QP2LAMBDA; /* default to 3 if the user did not set quality or bitrate */ if (!(avctx->flags & AV_CODEC_FLAG_QSCALE)) q = 3.0; if ((ret = vorbis_encode_setup_vbr(vi, avctx->channels, avctx->sample_rate, q / 10.0))) goto error; } else { int minrate = avctx->rc_min_rate > 0 ? avctx->rc_min_rate : -1; int maxrate = avctx->rc_max_rate > 0 ? avctx->rc_max_rate : -1; /* average bitrate */ if ((ret = vorbis_encode_setup_managed(vi, avctx->channels, avctx->sample_rate, maxrate, avctx->bit_rate, minrate))) goto error; /* variable bitrate by estimate, disable slow rate management */ if (minrate == -1 && maxrate == -1) if ((ret = vorbis_encode_ctl(vi, OV_ECTL_RATEMANAGE2_SET, NULL))) goto error; /* should not happen */ } /* cutoff frequency */ if (avctx->cutoff > 0) { cfreq = avctx->cutoff / 1000.0; if ((ret = vorbis_encode_ctl(vi, OV_ECTL_LOWPASS_SET, &cfreq))) goto error; /* should not happen */ } /* impulse block bias */ if (s->iblock) { if ((ret = vorbis_encode_ctl(vi, OV_ECTL_IBLOCK_SET, &s->iblock))) goto error; } if (avctx->channels == 3 && avctx->channel_layout != (AV_CH_LAYOUT_STEREO|AV_CH_FRONT_CENTER) || avctx->channels == 4 && avctx->channel_layout != AV_CH_LAYOUT_2_2 && avctx->channel_layout != AV_CH_LAYOUT_QUAD || avctx->channels == 5 && avctx->channel_layout != AV_CH_LAYOUT_5POINT0 && avctx->channel_layout != AV_CH_LAYOUT_5POINT0_BACK || avctx->channels == 6 && avctx->channel_layout != AV_CH_LAYOUT_5POINT1 && avctx->channel_layout != AV_CH_LAYOUT_5POINT1_BACK || avctx->channels == 7 && avctx->channel_layout != (AV_CH_LAYOUT_5POINT1|AV_CH_BACK_CENTER) || avctx->channels == 8 && avctx->channel_layout != AV_CH_LAYOUT_7POINT1) { if (avctx->channel_layout) { char name[32]; av_get_channel_layout_string(name, sizeof(name), avctx->channels, avctx->channel_layout); av_log(avctx, AV_LOG_ERROR, "%s not supported by Vorbis: " "output stream will have incorrect " "channel layout.\n", name); } else { av_log(avctx, AV_LOG_WARNING, "No channel layout specified. The encoder " "will use Vorbis channel layout for " "%d channels.\n", avctx->channels); } } if ((ret = vorbis_encode_setup_init(vi))) goto error; return 0; error: return vorbis_error_to_averror(ret); } /* How many bytes are needed for a buffer of length 'l' */ static int xiph_len(int l) { return 1 + l / 255 + l; } static av_cold int libvorbis_encode_close(AVCodecContext *avctx) { LibvorbisEncContext *s = avctx->priv_data; /* notify vorbisenc this is EOF */ if (s->dsp_initialized) vorbis_analysis_wrote(&s->vd, 0); vorbis_block_clear(&s->vb); vorbis_dsp_clear(&s->vd); vorbis_info_clear(&s->vi); av_fifo_freep(&s->pkt_fifo); ff_af_queue_close(&s->afq); av_freep(&avctx->extradata); av_vorbis_parse_free(&s->vp); return 0; } static av_cold int libvorbis_encode_init(AVCodecContext *avctx) { LibvorbisEncContext *s = avctx->priv_data; ogg_packet header, header_comm, header_code; uint8_t *p; unsigned int offset; int ret; vorbis_info_init(&s->vi); if ((ret = libvorbis_setup(&s->vi, avctx))) { av_log(avctx, AV_LOG_ERROR, "encoder setup failed\n"); goto error; } if ((ret = vorbis_analysis_init(&s->vd, &s->vi))) { av_log(avctx, AV_LOG_ERROR, "analysis init failed\n"); ret = vorbis_error_to_averror(ret); goto error; } s->dsp_initialized = 1; if ((ret = vorbis_block_init(&s->vd, &s->vb))) { av_log(avctx, AV_LOG_ERROR, "dsp init failed\n"); ret = vorbis_error_to_averror(ret); goto error; } vorbis_comment_init(&s->vc); if (!(avctx->flags & AV_CODEC_FLAG_BITEXACT)) vorbis_comment_add_tag(&s->vc, "encoder", LIBAVCODEC_IDENT); if ((ret = vorbis_analysis_headerout(&s->vd, &s->vc, &header, &header_comm, &header_code))) { ret = vorbis_error_to_averror(ret); goto error; } avctx->extradata_size = 1 + xiph_len(header.bytes) + xiph_len(header_comm.bytes) + header_code.bytes; p = avctx->extradata = av_malloc(avctx->extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); if (!p) { ret = AVERROR(ENOMEM); goto error; } p[0] = 2; offset = 1; offset += av_xiphlacing(&p[offset], header.bytes); offset += av_xiphlacing(&p[offset], header_comm.bytes); memcpy(&p[offset], header.packet, header.bytes); offset += header.bytes; memcpy(&p[offset], header_comm.packet, header_comm.bytes); offset += header_comm.bytes; memcpy(&p[offset], header_code.packet, header_code.bytes); offset += header_code.bytes; av_assert0(offset == avctx->extradata_size); s->vp = av_vorbis_parse_init(avctx->extradata, avctx->extradata_size); if (!s->vp) { av_log(avctx, AV_LOG_ERROR, "invalid extradata\n"); return ret; } vorbis_comment_clear(&s->vc); avctx->frame_size = LIBVORBIS_FRAME_SIZE; ff_af_queue_init(avctx, &s->afq); s->pkt_fifo = av_fifo_alloc(BUFFER_SIZE); if (!s->pkt_fifo) { ret = AVERROR(ENOMEM); goto error; } return 0; error: libvorbis_encode_close(avctx); return ret; } static int libvorbis_encode_frame(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr) { LibvorbisEncContext *s = avctx->priv_data; ogg_packet op; int ret, duration; /* send samples to libvorbis */ if (frame) { const int samples = frame->nb_samples; float **buffer; int c, channels = s->vi.channels; buffer = vorbis_analysis_buffer(&s->vd, samples); for (c = 0; c < channels; c++) { int co = (channels > 8) ? c : ff_vorbis_encoding_channel_layout_offsets[channels - 1][c]; memcpy(buffer[c], frame->extended_data[co], samples * sizeof(*buffer[c])); } if ((ret = vorbis_analysis_wrote(&s->vd, samples)) < 0) { av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n"); return vorbis_error_to_averror(ret); } if ((ret = ff_af_queue_add(&s->afq, frame)) < 0) return ret; } else { if (!s->eof && s->afq.frame_alloc) if ((ret = vorbis_analysis_wrote(&s->vd, 0)) < 0) { av_log(avctx, AV_LOG_ERROR, "error in vorbis_analysis_wrote()\n"); return vorbis_error_to_averror(ret); } s->eof = 1; } /* retrieve available packets from libvorbis */ while ((ret = vorbis_analysis_blockout(&s->vd, &s->vb)) == 1) { if ((ret = vorbis_analysis(&s->vb, NULL)) < 0) break; if ((ret = vorbis_bitrate_addblock(&s->vb)) < 0) break; /* add any available packets to the output packet buffer */ while ((ret = vorbis_bitrate_flushpacket(&s->vd, &op)) == 1) { if (av_fifo_space(s->pkt_fifo) < sizeof(ogg_packet) + op.bytes) { av_log(avctx, AV_LOG_ERROR, "packet buffer is too small\n"); return AVERROR_BUG; } av_fifo_generic_write(s->pkt_fifo, &op, sizeof(ogg_packet), NULL); av_fifo_generic_write(s->pkt_fifo, op.packet, op.bytes, NULL); } if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "error getting available packets\n"); break; } } if (ret < 0) { av_log(avctx, AV_LOG_ERROR, "error getting available packets\n"); return vorbis_error_to_averror(ret); } /* check for available packets */ if (av_fifo_size(s->pkt_fifo) < sizeof(ogg_packet)) return 0; av_fifo_generic_read(s->pkt_fifo, &op, sizeof(ogg_packet), NULL); if ((ret = ff_alloc_packet2(avctx, avpkt, op.bytes, 0)) < 0) return ret; av_fifo_generic_read(s->pkt_fifo, avpkt->data, op.bytes, NULL); avpkt->pts = ff_samples_to_time_base(avctx, op.granulepos); duration = av_vorbis_parse_frame(s->vp, avpkt->data, avpkt->size); if (duration > 0) { /* we do not know encoder delay until we get the first packet from * libvorbis, so we have to update the AudioFrameQueue counts */ if (!avctx->initial_padding && s->afq.frames) { avctx->initial_padding = duration; av_assert0(!s->afq.remaining_delay); s->afq.frames->duration += duration; if (s->afq.frames->pts != AV_NOPTS_VALUE) s->afq.frames->pts -= duration; s->afq.remaining_samples += duration; } ff_af_queue_remove(&s->afq, duration, &avpkt->pts, &avpkt->duration); } *got_packet_ptr = 1; return 0; } AVCodec ff_libvorbis_encoder = { .name = "libvorbis", .long_name = NULL_IF_CONFIG_SMALL("libvorbis"), .type = AVMEDIA_TYPE_AUDIO, .id = AV_CODEC_ID_VORBIS, .priv_data_size = sizeof(LibvorbisEncContext), .init = libvorbis_encode_init, .encode2 = libvorbis_encode_frame, .close = libvorbis_encode_close, .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_SMALL_LAST_FRAME, .sample_fmts = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_NONE }, .priv_class = &vorbis_class, .defaults = defaults, };
{ "language": "C" }
/* * EHCI HCD (Host Controller Driver) for USB. * * (C) Copyright 2006-2007 Stefan Roese <sr@denx.de>, DENX Software Engineering * * Bus Glue for PPC On-Chip EHCI driver * Tested on AMCC 440EPx * * Based on "ehci-au1xxx.c" by K.Boge <karsten.boge@amd.com> * * This file is licenced under the GPL. */ #include <linux/platform_device.h> extern int usb_disabled(void); /* called during probe() after chip reset completes */ static int ehci_ppc_soc_setup(struct usb_hcd *hcd) { struct ehci_hcd *ehci = hcd_to_ehci(hcd); int retval; retval = ehci_halt(ehci); if (retval) return retval; retval = ehci_init(hcd); if (retval) return retval; ehci->sbrn = 0x20; return ehci_reset(ehci); } /** * usb_ehci_ppc_soc_probe - initialize PPC-SoC-based HCDs * Context: !in_interrupt() * * Allocates basic resources for this USB host controller, and * then invokes the start() method for the HCD associated with it * through the hotplug entry's driver_data. * */ int usb_ehci_ppc_soc_probe(const struct hc_driver *driver, struct usb_hcd **hcd_out, struct platform_device *dev) { int retval; struct usb_hcd *hcd; struct ehci_hcd *ehci; if (dev->resource[1].flags != IORESOURCE_IRQ) { pr_debug("resource[1] is not IORESOURCE_IRQ"); retval = -ENOMEM; } hcd = usb_create_hcd(driver, &dev->dev, "PPC-SOC EHCI"); if (!hcd) return -ENOMEM; hcd->rsrc_start = dev->resource[0].start; hcd->rsrc_len = dev->resource[0].end - dev->resource[0].start + 1; if (!request_mem_region(hcd->rsrc_start, hcd->rsrc_len, hcd_name)) { pr_debug("request_mem_region failed"); retval = -EBUSY; goto err1; } hcd->regs = ioremap(hcd->rsrc_start, hcd->rsrc_len); if (!hcd->regs) { pr_debug("ioremap failed"); retval = -ENOMEM; goto err2; } ehci = hcd_to_ehci(hcd); ehci->big_endian_mmio = 1; ehci->big_endian_desc = 1; ehci->caps = hcd->regs; ehci->regs = hcd->regs + HC_LENGTH(ehci_readl(ehci, &ehci->caps->hc_capbase)); /* cache this readonly data; minimize chip reads */ ehci->hcs_params = ehci_readl(ehci, &ehci->caps->hcs_params); #if defined(CONFIG_440EPX) /* * 440EPx Errata USBH_3 * Fix: Enable Break Memory Transfer (BMT) in INSNREG3 */ out_be32((void *)((ulong)(&ehci->regs->command) + 0x8c), (1 << 0)); ehci_dbg(ehci, "Break Memory Transfer (BMT) has beed enabled!\n"); #endif retval = usb_add_hcd(hcd, dev->resource[1].start, IRQF_DISABLED); if (retval == 0) return retval; iounmap(hcd->regs); err2: release_mem_region(hcd->rsrc_start, hcd->rsrc_len); err1: usb_put_hcd(hcd); return retval; } /* may be called without controller electrically present */ /* may be called with controller, bus, and devices active */ /** * usb_ehci_hcd_ppc_soc_remove - shutdown processing for PPC-SoC-based HCDs * @dev: USB Host Controller being removed * Context: !in_interrupt() * * Reverses the effect of usb_ehci_hcd_ppc_soc_probe(), first invoking * the HCD's stop() method. It is always called from a thread * context, normally "rmmod", "apmd", or something similar. * */ void usb_ehci_ppc_soc_remove(struct usb_hcd *hcd, struct platform_device *dev) { usb_remove_hcd(hcd); iounmap(hcd->regs); release_mem_region(hcd->rsrc_start, hcd->rsrc_len); usb_put_hcd(hcd); } static const struct hc_driver ehci_ppc_soc_hc_driver = { .description = hcd_name, .product_desc = "PPC-SOC EHCI", .hcd_priv_size = sizeof(struct ehci_hcd), /* * generic hardware linkage */ .irq = ehci_irq, .flags = HCD_MEMORY | HCD_USB2, /* * basic lifecycle operations */ .reset = ehci_ppc_soc_setup, .start = ehci_run, .stop = ehci_stop, .shutdown = ehci_shutdown, /* * managing i/o requests and associated device resources */ .urb_enqueue = ehci_urb_enqueue, .urb_dequeue = ehci_urb_dequeue, .endpoint_disable = ehci_endpoint_disable, /* * scheduling support */ .get_frame_number = ehci_get_frame, /* * root hub support */ .hub_status_data = ehci_hub_status_data, .hub_control = ehci_hub_control, #ifdef CONFIG_PM .hub_suspend = ehci_hub_suspend, .hub_resume = ehci_hub_resume, #endif .relinquish_port = ehci_relinquish_port, .port_handed_over = ehci_port_handed_over, }; static int ehci_hcd_ppc_soc_drv_probe(struct platform_device *pdev) { struct usb_hcd *hcd = NULL; int ret; pr_debug("In ehci_hcd_ppc_soc_drv_probe\n"); if (usb_disabled()) return -ENODEV; ret = usb_ehci_ppc_soc_probe(&ehci_ppc_soc_hc_driver, &hcd, pdev); return ret; } static int ehci_hcd_ppc_soc_drv_remove(struct platform_device *pdev) { struct usb_hcd *hcd = platform_get_drvdata(pdev); usb_ehci_ppc_soc_remove(hcd, pdev); return 0; } MODULE_ALIAS("ppc-soc-ehci"); static struct platform_driver ehci_ppc_soc_driver = { .probe = ehci_hcd_ppc_soc_drv_probe, .remove = ehci_hcd_ppc_soc_drv_remove, .shutdown = usb_hcd_platform_shutdown, .driver = { .name = "ppc-soc-ehci", .bus = &platform_bus_type } };
{ "language": "C" }
<!doctype html> <html> <head> <script type="text/javascript" src="../../js/case.js"></script> <?php include __DIR__ . '/../../include.php'; ?> </head> <body class="simple"> <div class="test-1"> <h1>Remove Column 1</h1> <div class="test-input"> <div class="editable"> <table> <tr> <td>Column 1</td> <td>{}Column 2</td> <td>Column 3</td> </tr> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> </tr> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> </tr> </table> </div> </div> <div class="test-expected"> <div class="editable"> <table> <tr> <td>Column 1</td> <td>Column 3</td> </tr> <tr> <td>Column 1</td> <td>Column 3</td> </tr> <tr> <td>Column 1</td> <td>Column 3</td> </tr> </table> </div> </div> </div> <script type="text/javascript"> testEditor('.test-1', function(input) { var ranges = tokensToRanges(input); clickButton(input, '.raptor-ui-table-delete-column'); }); </script> <div class="test-2"> <h1>Remove Column 2</h1> <div class="test-input"> <div class="editable"> <table> <thead> <tr> <th>Header</th> <th>Header</th> <th>Header</th> <th>Header</th> <th>Header</th> <th>Header</th> </tr> </thead> <tbody> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> <td rowspan="2">Column 4</td> <td>{}Column 5</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td colspan="2">Column 2</td> <td rowspan="2">Column 5</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td>Column 2</td> <td colspan="2">Column 3</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> <td>Column 4</td> <td>Column 5</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td colspan="2">Column 2</td> <td>Column 4</td> <td>Column 5</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> <td>Column 4</td> <td>Column 5</td> <td>Column 6</td> </tr> </tbody> <tfoot> <tr> <th>Footer</th> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> </tr> </tfoot> </table> </div> </div> <div class="test-expected"> <div class="editable"> <table> <thead> <tr> <th>Header</th> <th>Header</th> <th>Header</th> <th>Header</th> <th>Header</th> </tr> </thead> <tbody> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> <td rowspan="2">Column 4</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td colspan="2">Column 2</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td>Column 2</td> <td colspan="2">Column 3</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> <td>Column 4</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td colspan="2">Column 2</td> <td>Column 4</td> <td>Column 6</td> </tr> <tr> <td>Column 1</td> <td>Column 2</td> <td>Column 3</td> <td>Column 4</td> <td>Column 6</td> </tr> </tbody> <tfoot> <tr> <th>Footer</th> <td>Cell</td> <td>Cell</td> <td>Cell</td> <td>Cell</td> </tr> </tfoot> </table> </div> </div> </div> <script type="text/javascript"> testEditor('.test-2', function(input) { var ranges = tokensToRanges(input); clickButton(input, '.raptor-ui-table-delete-column'); }); </script> </body> </html>
{ "language": "C" }
#if !defined ( ROM_MAPPER033_H ) #define ROM_MAPPER033_H #include "cnesrom.h" class CROMMapper033 : public CROM { private: CROMMapper033(); public: static inline CROMMapper033* CARTFACTORY() { return new CROMMapper033(); } virtual ~CROMMapper033(); void RESET ( bool soft ); void HMAPPER ( uint32_t addr, uint8_t data ); uint32_t DEBUGINFO ( uint32_t addr ); protected: uint8_t m_reg[8]; }; #endif
{ "language": "C" }
/* atomic/gcc_ppc.h * Copyright (C) 2006-2010, Parrot Foundation. * Overview: * This header provides an implementation of atomic * operations on PowerPC platforms with GCC-style * inline assembly suppport. * Data Structure and Algorithms: * History: * Notes: * References: */ /* =pod =head1 NAME include/parrot/atomic/gcc_ppc.h =head1 DESCRIPTION This header provides an implementation of atomic operations on PowerPC platforms with GCC-style inline assembly support =cut */ #ifndef PARROT_ATOMIC_GCC_PCC_H_GUARD #define PARROT_ATOMIC_GCC_PCC_H_GUARD typedef struct Parrot_atomic_pointer { void * volatile val; } Parrot_atomic_pointer; # define PARROT_ATOMIC_PTR_GET(result, a) (result) = (void *) (a).val # define PARROT_ATOMIC_PTR_SET(a, b) (a).val = (void *) (b) /* =over 4 =item C<inline static void *parrot_ppc_cmpset(void * volatile *ptr, void *expect, void *update)> Generate ppc cmpset =cut */ inline static void *parrot_ppc_cmpset(void * volatile *ptr, void *expect, void *update) { void *tmp; /* see http://www-128.ibm.com/developerworks/linux/library/pa-atom/ */ __asm__ __volatile__(/*%0 = tmp, %1 = ptr, %2 = old, %3 = new */ "1: lwarx %0, 0, %1\n" /* tmp = *ptr, with reservation */ " cmpw %2, %0\n" /* tmp == old ? */ " bne 2f\n" /* no, goto flush reservation, end */ /* " sync\n" -- XXX needed on PPC 405, see * http://www.kegel.com/xgcc3/ppc405erratum77.html */ " stwcx. %3, 0, %1\n" /* store new using reservation */ " bne- 1b\n" /* spin on failure of reservation; - is branch prediction hint */ " b 3f\n" "2: stwcx. %0, 0, %1\n" /* flush reservation */ "3: \n" /* end label */ : /* output */ "=&r"(tmp) : /* input */ "r"(ptr), "r"(expect), "r"(update) : /* clobber */ "memory"); return tmp; } /* =item C<inline static long parrot_ppc_add(volatile long *val, long what)> Generate ppc add =back =cut */ inline static long parrot_ppc_add(volatile long *val, long what) { long tmp; __asm__ __volatile__(/*%0 = tmp, %1 = val, %2 = what */ "1: lwarx %0, 0, %1\n" /* tmp = *val, with reservation */ " add %0, %0, %2\n" /* tmp += what */ /* " sync\n" -- XXX needed on PPC 405, see * http://www.kegel.com/xgcc3/ppc405erratum77.html */ " stwcx. %0, 0, %1\n" /* *val <- tmp using reservation */ " bne- 1b\n" /* spin on failure of reservation; - is branch prediction hint */ "2: \n" /* end label */ : /* output */ "=&r"(tmp) : /* input */ "r"(val), "r"(what) : /* clobber */ "memory"); return tmp; } # define PARROT_ATOMIC_PTR_CAS(result, a, expect, update) \ do { \ if (parrot_ppc_cmpset(&(a).val, (expect), (update)) == (expect)) { \ (result) = 1; \ } \ else { \ (result) = 0; \ } \ } while (0) # define PARROT_ATOMIC_PTR_INIT(a) # define PARROT_ATOMIC_PTR_DESTROY(a) typedef struct Parrot_atomic_integer { volatile long val; } Parrot_atomic_integer; # define PARROT_ATOMIC_INT_INIT(a) # define PARROT_ATOMIC_INT_DESTROY(a) # define PARROT_ATOMIC_INT_GET(result, a) ((result) = (a).val) # define PARROT_ATOMIC_INT_SET(a, b) ((a).val = (b)) # define PARROT_ATOMIC_INT_CAS(result, a, expect, update) \ do { \ if (parrot_ppc_cmpset(\ (void * volatile *) &(a).val, (void *) (expect), \ (void *) (update)) == (void *) (expect)) { \ (result) = 1; \ } \ else { \ (result) = 0; \ } \ } while (0) # define PARROT_ATOMIC_INT_INC(result, a) \ do { \ (result) = parrot_ppc_add(&(a).val, 1); \ } while (0) # define PARROT_ATOMIC_INT_DEC(result, a) \ do { \ (result) = parrot_ppc_add(&(a).val, -1); \ } while (0) #endif /* PARROT_ATOMIC_GCC_PCC_H_GUARD */ /* * Local variables: * c-file-style: "parrot" * End: * vim: expandtab shiftwidth=4 cinoptions='\:2=2' : */
{ "language": "C" }
/* Copyright (C) 2010-2020 The RetroArch team * * --------------------------------------------------------------------------------------- * The following license statement only applies to this file (retro_common.h). * --------------------------------------------------------------------------------------- * * 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. */ #ifndef _LIBRETRO_COMMON_RETRO_COMMON_H #define _LIBRETRO_COMMON_RETRO_COMMON_H /* This file is designed to normalize the libretro-common compiling environment. It is not to be used in public API headers, as they should be designed as leanly as possible. Nonetheless.. in the meantime, if you do something like use ssize_t, which is not fully portable, in a public API, you may need this. */ /* conditional compilation is handled inside here */ #include <compat/msvc.h> #endif
{ "language": "C" }
/* * System Control and Power Interface (SCPI) Protocol based clock driver * * Copyright (C) 2015 ARM Ltd. * * This program is free software; you can redistribute it and/or modify it * under the terms and conditions of the GNU General Public License, * version 2, as published by the Free Software Foundation. * * This program is distributed in the hope it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for * more details. * * You should have received a copy of the GNU General Public License along with * this program. If not, see <http://www.gnu.org/licenses/>. */ #include <linux/clk-provider.h> #include <linux/device.h> #include <linux/err.h> #include <linux/of.h> #include <linux/module.h> #include <linux/of_platform.h> #include <linux/platform_device.h> #include <linux/scpi_protocol.h> struct scpi_clk { u32 id; struct clk_hw hw; struct scpi_dvfs_info *info; struct scpi_ops *scpi_ops; }; #define to_scpi_clk(clk) container_of(clk, struct scpi_clk, hw) static struct platform_device *cpufreq_dev; static unsigned long scpi_clk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct scpi_clk *clk = to_scpi_clk(hw); return clk->scpi_ops->clk_get_val(clk->id); } static long scpi_clk_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) { /* * We can't figure out what rate it will be, so just return the * rate back to the caller. scpi_clk_recalc_rate() will be called * after the rate is set and we'll know what rate the clock is * running at then. */ return rate; } static int scpi_clk_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct scpi_clk *clk = to_scpi_clk(hw); return clk->scpi_ops->clk_set_val(clk->id, rate); } static const struct clk_ops scpi_clk_ops = { .recalc_rate = scpi_clk_recalc_rate, .round_rate = scpi_clk_round_rate, .set_rate = scpi_clk_set_rate, }; /* find closest match to given frequency in OPP table */ static long __scpi_dvfs_round_rate(struct scpi_clk *clk, unsigned long rate) { int idx; unsigned long fmin = 0, fmax = ~0, ftmp; const struct scpi_opp *opp = clk->info->opps; for (idx = 0; idx < clk->info->count; idx++, opp++) { ftmp = opp->freq; if (ftmp >= rate) { if (ftmp <= fmax) fmax = ftmp; break; } else if (ftmp >= fmin) { fmin = ftmp; } } return fmax != ~0 ? fmax : fmin; } static unsigned long scpi_dvfs_recalc_rate(struct clk_hw *hw, unsigned long parent_rate) { struct scpi_clk *clk = to_scpi_clk(hw); int idx = clk->scpi_ops->dvfs_get_idx(clk->id); const struct scpi_opp *opp; if (idx < 0) return 0; opp = clk->info->opps + idx; return opp->freq; } static long scpi_dvfs_round_rate(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate) { struct scpi_clk *clk = to_scpi_clk(hw); return __scpi_dvfs_round_rate(clk, rate); } static int __scpi_find_dvfs_index(struct scpi_clk *clk, unsigned long rate) { int idx, max_opp = clk->info->count; const struct scpi_opp *opp = clk->info->opps; for (idx = 0; idx < max_opp; idx++, opp++) if (opp->freq == rate) return idx; return -EINVAL; } static int scpi_dvfs_set_rate(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate) { struct scpi_clk *clk = to_scpi_clk(hw); int ret = __scpi_find_dvfs_index(clk, rate); if (ret < 0) return ret; return clk->scpi_ops->dvfs_set_idx(clk->id, (u8)ret); } static const struct clk_ops scpi_dvfs_ops = { .recalc_rate = scpi_dvfs_recalc_rate, .round_rate = scpi_dvfs_round_rate, .set_rate = scpi_dvfs_set_rate, }; static const struct of_device_id scpi_clk_match[] = { { .compatible = "arm,scpi-dvfs-clocks", .data = &scpi_dvfs_ops, }, { .compatible = "arm,scpi-variable-clocks", .data = &scpi_clk_ops, }, {} }; static int scpi_clk_ops_init(struct device *dev, const struct of_device_id *match, struct scpi_clk *sclk, const char *name) { struct clk_init_data init; unsigned long min = 0, max = 0; int ret; init.name = name; init.flags = 0; init.num_parents = 0; init.ops = match->data; sclk->hw.init = &init; sclk->scpi_ops = get_scpi_ops(); if (init.ops == &scpi_dvfs_ops) { sclk->info = sclk->scpi_ops->dvfs_get_info(sclk->id); if (IS_ERR(sclk->info)) return PTR_ERR(sclk->info); } else if (init.ops == &scpi_clk_ops) { if (sclk->scpi_ops->clk_get_range(sclk->id, &min, &max) || !max) return -EINVAL; } else { return -EINVAL; } ret = devm_clk_hw_register(dev, &sclk->hw); if (!ret && max) clk_hw_set_rate_range(&sclk->hw, min, max); return ret; } struct scpi_clk_data { struct scpi_clk **clk; unsigned int clk_num; }; static struct clk_hw * scpi_of_clk_src_get(struct of_phandle_args *clkspec, void *data) { struct scpi_clk *sclk; struct scpi_clk_data *clk_data = data; unsigned int idx = clkspec->args[0], count; for (count = 0; count < clk_data->clk_num; count++) { sclk = clk_data->clk[count]; if (idx == sclk->id) return &sclk->hw; } return ERR_PTR(-EINVAL); } static int scpi_clk_add(struct device *dev, struct device_node *np, const struct of_device_id *match) { int idx, count, err; struct scpi_clk_data *clk_data; count = of_property_count_strings(np, "clock-output-names"); if (count < 0) { dev_err(dev, "%s: invalid clock output count\n", np->name); return -EINVAL; } clk_data = devm_kmalloc(dev, sizeof(*clk_data), GFP_KERNEL); if (!clk_data) return -ENOMEM; clk_data->clk_num = count; clk_data->clk = devm_kcalloc(dev, count, sizeof(*clk_data->clk), GFP_KERNEL); if (!clk_data->clk) return -ENOMEM; for (idx = 0; idx < count; idx++) { struct scpi_clk *sclk; const char *name; u32 val; sclk = devm_kzalloc(dev, sizeof(*sclk), GFP_KERNEL); if (!sclk) return -ENOMEM; if (of_property_read_string_index(np, "clock-output-names", idx, &name)) { dev_err(dev, "invalid clock name @ %s\n", np->name); return -EINVAL; } if (of_property_read_u32_index(np, "clock-indices", idx, &val)) { dev_err(dev, "invalid clock index @ %s\n", np->name); return -EINVAL; } sclk->id = val; err = scpi_clk_ops_init(dev, match, sclk, name); if (err) { dev_err(dev, "failed to register clock '%s'\n", name); return err; } dev_dbg(dev, "Registered clock '%s'\n", name); clk_data->clk[idx] = sclk; } return of_clk_add_hw_provider(np, scpi_of_clk_src_get, clk_data); } static int scpi_clocks_remove(struct platform_device *pdev) { struct device *dev = &pdev->dev; struct device_node *child, *np = dev->of_node; if (cpufreq_dev) { platform_device_unregister(cpufreq_dev); cpufreq_dev = NULL; } for_each_available_child_of_node(np, child) of_clk_del_provider(np); return 0; } static int scpi_clocks_probe(struct platform_device *pdev) { int ret; struct device *dev = &pdev->dev; struct device_node *child, *np = dev->of_node; const struct of_device_id *match; if (!get_scpi_ops()) return -ENXIO; for_each_available_child_of_node(np, child) { match = of_match_node(scpi_clk_match, child); if (!match) continue; ret = scpi_clk_add(dev, child, match); if (ret) { scpi_clocks_remove(pdev); of_node_put(child); return ret; } if (match->data != &scpi_dvfs_ops) continue; /* Add the virtual cpufreq device if it's DVFS clock provider */ cpufreq_dev = platform_device_register_simple("scpi-cpufreq", -1, NULL, 0); if (IS_ERR(cpufreq_dev)) pr_warn("unable to register cpufreq device"); } return 0; } static const struct of_device_id scpi_clocks_ids[] = { { .compatible = "arm,scpi-clocks", }, {} }; MODULE_DEVICE_TABLE(of, scpi_clocks_ids); static struct platform_driver scpi_clocks_driver = { .driver = { .name = "scpi_clocks", .of_match_table = scpi_clocks_ids, }, .probe = scpi_clocks_probe, .remove = scpi_clocks_remove, }; module_platform_driver(scpi_clocks_driver); MODULE_AUTHOR("Sudeep Holla <sudeep.holla@arm.com>"); MODULE_DESCRIPTION("ARM SCPI clock driver"); MODULE_LICENSE("GPL v2");
{ "language": "C" }
/* * Remote processor framework * * Copyright (C) 2011 Texas Instruments, Inc. * Copyright (C) 2011 Google, Inc. * * Ohad Ben-Cohen <ohad@wizery.com> * Brian Swetland <swetland@google.com> * * This software is licensed under the terms of the GNU General Public * License version 2, as published by the Free Software Foundation, and * may be copied, distributed, and modified under those terms. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. */ #ifndef REMOTEPROC_INTERNAL_H #define REMOTEPROC_INTERNAL_H #include <linux/irqreturn.h> #include <linux/firmware.h> struct rproc; /** * struct rproc_fw_ops - firmware format specific operations. * @find_rsc_table: find the resource table inside the firmware image * @find_loaded_rsc_table: find the loaded resouce table * @load: load firmeware to memory, where the remote processor * expects to find it * @sanity_check: sanity check the fw image * @get_boot_addr: get boot address to entry point specified in firmware */ struct rproc_fw_ops { struct resource_table *(*find_rsc_table)(struct rproc *rproc, const struct firmware *fw, int *tablesz); struct resource_table *(*find_loaded_rsc_table)(struct rproc *rproc, const struct firmware *fw); int (*load)(struct rproc *rproc, const struct firmware *fw); int (*sanity_check)(struct rproc *rproc, const struct firmware *fw); u32 (*get_boot_addr)(struct rproc *rproc, const struct firmware *fw); }; /* from remoteproc_core.c */ void rproc_release(struct kref *kref); irqreturn_t rproc_vq_interrupt(struct rproc *rproc, int vq_id); /* from remoteproc_virtio.c */ int rproc_add_virtio_dev(struct rproc_vdev *rvdev, int id); void rproc_remove_virtio_dev(struct rproc_vdev *rvdev); /* from remoteproc_debugfs.c */ void rproc_remove_trace_file(struct dentry *tfile); struct dentry *rproc_create_trace_file(const char *name, struct rproc *rproc, struct rproc_mem_entry *trace); void rproc_delete_debug_dir(struct rproc *rproc); void rproc_create_debug_dir(struct rproc *rproc); void rproc_init_debugfs(void); void rproc_exit_debugfs(void); void rproc_free_vring(struct rproc_vring *rvring); int rproc_alloc_vring(struct rproc_vdev *rvdev, int i); void *rproc_da_to_va(struct rproc *rproc, u64 da, int len); int rproc_trigger_recovery(struct rproc *rproc); static inline int rproc_fw_sanity_check(struct rproc *rproc, const struct firmware *fw) { if (rproc->fw_ops->sanity_check) return rproc->fw_ops->sanity_check(rproc, fw); return 0; } static inline u32 rproc_get_boot_addr(struct rproc *rproc, const struct firmware *fw) { if (rproc->fw_ops->get_boot_addr) return rproc->fw_ops->get_boot_addr(rproc, fw); return 0; } static inline int rproc_load_segments(struct rproc *rproc, const struct firmware *fw) { if (rproc->fw_ops->load) return rproc->fw_ops->load(rproc, fw); return -EINVAL; } static inline struct resource_table *rproc_find_rsc_table(struct rproc *rproc, const struct firmware *fw, int *tablesz) { if (rproc->fw_ops->find_rsc_table) return rproc->fw_ops->find_rsc_table(rproc, fw, tablesz); return NULL; } static inline struct resource_table *rproc_find_loaded_rsc_table(struct rproc *rproc, const struct firmware *fw) { if (rproc->fw_ops->find_loaded_rsc_table) return rproc->fw_ops->find_loaded_rsc_table(rproc, fw); return NULL; } extern const struct rproc_fw_ops rproc_elf_fw_ops; #endif /* REMOTEPROC_INTERNAL_H */
{ "language": "C" }
/**************************************************************************************** Copyright (C) 2015 Autodesk, Inc. All rights reserved. Use of this software is subject to the terms of the Autodesk license agreement provided at the time of installation or download, or which otherwise accompanies this software in either electronic or hard copy form. ****************************************************************************************/ //! \file fbxwritercollada14.h #ifndef _FBXSDK_FILEIO_COLLADA_WRITER_H_ #define _FBXSDK_FILEIO_COLLADA_WRITER_H_ #include <fbxsdk.h> #include <fbxsdk/fileio/collada/fbxcolladautils.h> #include <fbxsdk/fbxsdk_nsbegin.h> /** \brief Class to export FBX scene into a Collada file. * \nosubgrouping */ class FbxWriterCollada : public FbxWriter { public: /** * \name Constructors and Destructor */ //@{ /** Constructor. * \param pManager FBX SDK object Manager. * \param pID Internal ID. * \param pStatus The FbxStatus object to hold error codes. */ FbxWriterCollada(FbxManager& pManager, int pID, FbxStatus& pStatus); //! Destructor. virtual ~FbxWriterCollada(); //@} /** * \name File Management */ //@{ /** Create and open file with the given name. * \param pFileName the name of file. * \return Return true if the specified file is created and opened. */ virtual bool FileCreate(char* pFileName); /** Close file. * \return Return true if file is closed successfully, false otherwise. */ virtual bool FileClose(); /** Check if current file is open. * \return Return true if file is open, false otherwise. */ virtual bool IsFileOpen(); //@} /** * \name Write Functions */ //@{ /** Get Collada export options settings. */ virtual void GetWriteOptions(){} /** Export the FBX document to Collada file, according to the given options settings. * \param pDocument FBX Document to export. * \return true on success, false otherwise. */ virtual bool Write(FbxDocument* pDocument); /** Process FBX scene before exporting FBX scene to Collada file. * \param pScene the FBX scene to precess. * \return Return true if the given scene is processed successfully. * \remarks This function is processing name clash, special transformation conversion etc. */ virtual bool PreprocessScene(FbxScene &pScene); /** Process FBX scene after exporting FBX scene to Collada file. * \param pScene the FBX scene to precess. * \return Return true if the given scene is processed successfully. */ virtual bool PostprocessScene(FbxScene &pScene); //@} /***************************************************************************************************************************** ** WARNING! Anything beyond these lines is for internal use, may not be documented and is subject to change without notice! ** *****************************************************************************************************************************/ #ifndef DOXYGEN_SHOULD_SKIP_THIS private: /** * \name Export Functions */ //@{ /** Export FBX scene info to Collada asset. * \param pXmlNode the XML Node to export asset, asset nodes will be added as children to this XML node. * \param pSceneInfo Pointer to the FBX scene information object. * \return Return pointer to XML asset node. * \remarks Asset here contains user-defined summary data, such as: * contributor, author, authoring tool, created time, Axis System, etc. */ xmlNode* ExportAsset(xmlNode* pXmlNode, FbxDocumentInfo* pSceneInfo); /** Export FBX scene. * \param pScene Pointer to the FBX scene object. * \return The pointer to XML scene element. */ xmlNode * ExportScene(FbxScene* pScene); /** Export Libraries to the Collada document. * \param pXmlNode Pointer to XML Node, it should be the asset node. * \return Return true if all libraries are exported successfully. * \remarks After the libraries are created, call this function to add libraries to the Collada document. * Libraries are added as the siblings just after the given pXmlNode. */ bool ExportLibraries(xmlNode* pXmlNode); /** Export the given FBX node and its hierarchy to Collada XML nodes. * \param pXmlNode Pointer to XML Node, created XML nodes hierarchy will be added as children to this XML node. * \param pNode Pointer to FBX node, it should be one node in FBX nodes tree. * \return Return pointer to XML node. * \remarks The returned XML node is corresponding to the given FBX node, * the returned XML node will be added as child to the given pXmlNode, * this method is called recursively. */ xmlNode* ExportNodeRecursive(xmlNode* pXmlNode, const FbxNode* pNode); /** Export a Collada visual_scene MAX3D extension for the given FBX scene. * \param pExtraElement The parent COLLADA extra element. * \param pScene The FBX scene to be exported. */ void ExportVisualSceneMAX3DExtension(xmlNode * pExtraElement, FbxScene * pScene); /** Export a Collada visual_scene FCOLLADA extension for the given FBX scene. * \param pExtraElement The parent COLLADA extra element. * \param pScene The FBX scene to be exported. */ void ExportVisualSceneFCOLLADAExtension(xmlNode * pExtraElement, FbxScene * pScene); /** Export the given FBX node and its node attributes to Collada XML node. * \param pXmlNode Pointer to XML Node, created XML node will be added as child to this XML node. * \param pNode Pointer to FBX node, it should be one node in FBX nodes tree. * \return Return pointer to the created XML node. * \remarks The returned XML node is corresponding to the given FBX node, * the returned XML node will be added as child to the given pXmlNode. */ xmlNode* ExportNode(xmlNode* pXmlNode, const FbxNode* pNode); /** Export the given FBX node's default transformation. * \param pXmlNode Pointer to XML Node. * \param pNode Pointer to FBX node. * \return Return true if transformation is exported successfully. * \remarks FBX node transformation info is exported to properties of pXmlNode and its children, * according to the Collada transformation structures. */ bool ExportTransform(xmlNode* pXmlNode, const FbxNode* pNode); /** Export FBX node attributes, create different libraries according to different node attribute type. * \param pXmlNode Pointer to XML Node. * \param pNode Pointer to FBX node. * \return Return true if FBX node attributes is exported successfully, false otherwise. * \remarks According to different FBX node attribute type, different libraries will be created, such as: * light, camera, geometry. See more details in CreateMeshLibrary(FbxNode* pNode), CreateCameraLibrary(FbxNode* pNode), CreateLightLibrary(FbxNode* pNode). */ bool ExportNodeAttribute(xmlNode* pXmlNode, const FbxNode* pNode); /** Create geometry library for the given FBX node. * \param pNode Pointer to FBX node, its node attribute type should be FbxNodeAttribute::eMesh, or FbxNodeAttribute::eNurbs, or FbxNodeAttribute::ePatch. * \return Return pointer to XML mesh library node. * \remarks The returned XML node will be added to the geometry library, * the geometry library will be added to the Collada document by ExportLibraries(xmlNode* pXmlNode). */ xmlNode* CreateMeshLibrary(const FbxNode* pNode); /** Create camera library for the given FBX node. * \param pNode Pointer to FBX node, its node attribute type should be FbxNodeAttribute::eCamera. * \return Return pointer to XML camera library node. * \remarks The returned XML node will be added to the camera library, * the camera library will be added to the Collada document by ExportLibraries(xmlNode* pXmlNode). */ xmlNode* CreateCameraLibrary(const FbxNode* pNode); /** Create light library for the given FBX node. * \param pNode Pointer to FBX node, its node attribute type should be FbxNodeAttribute::eLight. * \return Return pointer to XML light library node. * \remarks The returned XML node will be added to the light library, * the light library will be added to the Collada document by ExportLibraries(xmlNode* pXmlNode). */ xmlNode* CreateLightLibrary(const FbxNode* pNode); /** Export the given FBX mesh node to Collada XML node. * \param pNode Pointer to FBX node, its node attribute type should be FbxNodeAttribute::eMesh. * \return Return pointer to XML mesh node. * \remarks Vertex, polygons of the mesh will be exported. * Textures, materials, controllers, and shapes which linked to the mesh will also be exported. */ xmlNode* ExportMesh(const FbxNode* pNode); /** Export the given shape's geometry to Collada XML node. * \param pMeshShape, Pointer to FBX mesh, corresponding to shape. * \param pShapeId, a string to identify shape from internal shape meshes list. * \return Return pointer to XML shape geometry node. * \remarks The geometry of shape will be exported, materials of shape will not be exported. */ xmlNode* ExportShapeGeometry(FbxMesh* pMeshShape, FbxString pShapeId); /** Export the given mesh's vertex position to Collada XML node. * \param pXmlNode Pointer to XML Node, created XML node will be added as child to this XML node. * \param pMesh Pointer to FBX mesh object, position info of all the vertices of this mesh will be exported. * \param pMeshName Name of the XML node to export, usually it's the name of FBX mesh node. * \param pInGeometry True if vertices are inside an ordinary geometry, false if vertices are in a binded geometry. * \param pExportControlPoints True if pMesh is an ordinary geometry, false if pMesh is a binded geometry. * \return Return pointer to XML vertex position node, the returned XML node will be added as child to the given pXmlNode. * \remarks In an ordinary geometry, pExportControlPoints should be true, export the position of the control points; * in a binded geometry, pExportControlPoints should be false, export the position of the transformed control points. */ //Note why internally set pExportControlPoints to true? xmlNode* ExportVertexPositions(xmlNode* pXmlNode, FbxMesh* pMesh, FbxString pMeshName, bool pInGeometry, bool pExportControlPoints); /** Export all layer elements of the given mesh to Collada XML node. * \param pXmlMesh Pointer to XML Node, created XML layer elements nodes will be added as child to this XML node. * \param pMesh Pointer to FBX mesh object, all layer elements of this mesh node will be exported. * \param pName String which used to construct the names of XML layer elements nodes. * \return Return the modified pXmlMesh. * \remarks Layer elements including Normals, UVs, Vertex Colors are covered, * polygon groups and other undefined layer elements are NOT supported. */ xmlNode* ExportLayerElements(xmlNode* pXmlMesh, FbxMesh* pMesh, FbxString pName); /** Export Normals of specified layer of the given mesh to Collada XML node. * \param pXmlNode Pointer to XML Node, created XML Normals node will be added as child to this XML node. * \param pMesh Pointer to FBX mesh object, normals layer element of this mesh node will be exported. * \param pName String which used to construct the names of XML normals nodes. * \param pExt Extension string which used to construct the names of XML normals nodes. * \param pLayerIndex Specify an index of layers to export, normals of other layers will NOT be exported. * \return Return pointer to XML Normals node. * \remarks The returned XML node will be added as child to the given pXmlNode. */ xmlNode* ExportNormals(xmlNode* pXmlNode, FbxMesh* pMesh, FbxString pName, FbxString pExt, int pLayerIndex); /** Export UVs of specified layer of the given mesh to Collada XML node. * \param pXmlNode Pointer to XML Node, created XML UVs node will be added as child to this XML node. * \param pMesh Pointer to FBX mesh object, UVs layer element of this mesh node will be exported. * \param pName String which used to construct the names of XML UVs nodes. * \param pLayerIndex Specify an index of layers to export, UVs of other layers will NOT be exported. * \return Return pointer to XML UVs node. * \remarks The returned XML node will be added as child to the given pXmlNode. */ xmlNode* ExportUVs(xmlNode* pXmlNode, FbxMesh* pMesh, FbxString pName, int pLayerIndex); /** Export VertexColors of specified layer of the given mesh to Collada XML node. * \param pXmlNode Pointer to XML Node, created XML VertexColors node will be added as child to this XML node. * \param pMesh Pointer to FBX mesh object, VertexColors layer element of this mesh node will be exported. * \param pName String which used to construct the names of XML VertexColors nodes. * \param pLayerIndex Specify an index of layers to export, VertexColors of other layers will NOT be exported. * \return Return pointer to XML VertexColors node. * \remarks The returned XML node will be added as child to the given pXmlNode. */ xmlNode* ExportVertexColors(xmlNode* pXmlNode, FbxMesh* pMesh, FbxString pName, int pLayerIndex); /** Export the given mesh's vertex to Collada XML node. * \param pXmlNode Pointer to XML Node. * \param pMesh Pointer to FBX mesh object. * \param pName Name of the XML node to export, usually it's the name of FBX mesh node. * \return Return pointer to the created XML vertex node. */ xmlNode* ExportVertices(xmlNode* pXmlNode, FbxMesh* pMesh, FbxString pName); /** Export the given mesh's polygons to Collada XML node. * \param pMeshElement Pointer to XML Node. * \param pMesh Pointer to FBX mesh object. * \param pMaterialName Specify the name of materials property. * \param pMaterialIndexInNode Specify the material index in the FBXNode (will be ignored if there is only 1 material in the node) * \param pName String which used to construct the names of created XML nodes. * \param pShape true for shape node, false for general node, the default value is false; * don't write out the materials if pShape is true. * \return Return pointer to the created XML Polygons node. */ xmlNode* ExportPolygons(xmlNode* pMeshElement, FbxMesh* pMesh, FbxString pMaterialName, int pMaterialIndexInNode, FbxString pName, bool pShape = false); /** Export all the materials used by the given mesh. * \param pMesh FBX mesh to export. * \param pNbMat materials count of pMesh. * \return true on success, false otherwise. */ bool ExportMeshMaterials(FbxMesh *pMesh, int pNbMat); /** Export the given material to the Material library. * \param pMaterial Specify the surface material to export. * \return Return pointer to the corresponding XML material node. * \remarks If the given material is already in the materials library, return the XML node; * otherwise, create and add XML material node to the Material library. */ xmlNode* ExportMaterial(FbxSurfaceMaterial *pMaterial); /** Export the given material to the Effect library. * \param pMaterial Specify the surface material to export. * \param pEffectId Specify the effect ID to export. * \return Return pointer to the corresponding XML effect node. * \remarks Material is an instance of an effect. * If the given material is already in the Effect library, return the XML node; * otherwise, create and add XML effect node to the Effect library. * Collada Effect support: Ambient Color, Diffuse Color, Emissive Color, Specular Color, Shiness, Reflective / Reflectivity, * Opacity / Transparency. */ xmlNode* ExportEffect(FbxSurfaceMaterial *pMaterial, FbxString pEffectId); /** Add the given texture as input to the given XML material node. * \param pXmlMaterial Pointer to XML material node. * \param pTexture FBX texture to export. * \param pImageId A string to identify image from the image library. * \param pLayerIndex Specify an index of layers to export. * \param pLayerElementType Specify the layer element type. * \return true on success, false otherwise. */ //Note why return true when failed and popped waring? bool AddMaterialTextureInput(xmlNode *pXmlMaterial, FbxFileTexture *pTexture, FbxString pImageId, int pLayerIndex, int pLayerElementType); /** Export the given texture to Collada XML node. * \param pTexture FBX texture to export. * \param pImageId A string to identify image from the image library. * \param pLayerIndex Specify an index of layers to export. * \return Return pointer to the created XML texture node. */ xmlNode* ExportTexture(FbxFileTexture *pTexture, FbxString pImageId, int pLayerIndex); /** Export all the textures used by the given mesh. * \param pMesh FBX mesh to export. * \return true on success, false otherwise. * \remarks The materials will also be Exported if needed. */ bool ExportMeshTextures(FbxMesh *pMesh); /** Export the given FBX camera node to Collada XML node. * \param pNode Pointer to FBX node, its node attribute type should be FbxNodeAttribute::eCamera. * \return Return pointer to XML node. * \remarks Camera parameters and properties will be exported. */ xmlNode* ExportCamera(const FbxNode* pNode); /** Export the given FBX light node to Collada XML node. * \param pNode Pointer to FBX node, its node attribute type should be FbxNodeAttribute::eLight. * \return Return pointer to XML node. * \remarks Light parameters and properties will be exported. */ xmlNode* ExportLight(const FbxNode* pNode); /** Export the global ambient to Collada XML light node. */ void ExportSceneAmbient(xmlNode * pVisualSceneElement); /** Export controllers of the given mesh to Collada XML node. * \param pMesh FBX mesh to export, it should be a binded skin. * \return true on success. * \remarks A morph controller will be exported by ExportControllerShape(). */ bool ExportController(FbxMesh *pMesh); /** Export morph controllers of the given mesh to Collada XML node. * \param pMesh FBX mesh to export, it should has more than one shape. * \return true on success. * \remarks Morph controller is also called shape deformer. */ bool ExportControllerShape(FbxMesh *pMesh); /** . * \param . * \param . * \return . * \remarks . */ //Note : empty method now xmlNode* ExportJointWeights(xmlNode* pXmlNode, FbxMesh* pMesh, FbxString pExt); /** Update mesh library with the shapes found, and add shapes as nodes in the scene. * \param pXmlNode Pointer to XML Node, created shape node will be added as child to this XML node. * \return true on success, false otherwise. * \remarks This method will create a geometry node in geometry library for every shape as needed, * XML shape nodes will also be created and added to scene. */ bool UpdateMeshLibraryWithShapes(xmlNode* pXmlNode); /** Export animations of the given node and its children, if they are animated. * \param pNode FBX node to export, it should be animated. * \return true on success, false otherwise. * \remarks This method is called recursively, the animations of all the children of pXmlNode will also be exported. */ bool ExportAnimation(FbxNode* pNode); /** Export all the animation curves of the given node to Collada XML node. * \param pNode FBX node to export, it should be animated. * \param pAnimationNode Pointer to XML Node, created sub-animation nodes will be added as children to this XML node. * \return true on success. */ bool ExportAnimationCurves(FbxNode* pNode, xmlNode* pAnimationNode); /** Export the texture into library_images. * \param pTexture The texture whose file name to be exported. * \return Return the ID of the create image element. */ const FbxString ExportImage(FbxFileTexture * pTexture); /** Export the given animation curve (FCurve) to Collada XML node. * \param pAnimationNode Pointer to XML Node, created sub-animation node will be added as child to this XML node. * \param pCurve Animation Curve to export. * \param pChannelName The name of animation channel. * \param pSubChannelName The name of animation sub-channel. * \param pExportShape Shape animation flag, default value is false; When it's true, Id nomenclature is a bit different. * \param pExportIntensity Intensity flag, default value is false; When it's true, FCurve values are divided by 100. * \param pExportLib Library flag, default value is false; When it's true, Id nomenclature is a bit different. * \return true on success. * \remarks When pExportShape or pExportIntensity is true, FCurve values are divided by 100. */ bool ExportCurve(xmlNode* pAnimationNode, FbxAnimCurve* pCurve, const char* pChannelName, const char* pSubChannelName, bool pExportShape=false, bool pExportIntensity=false, bool pExportLib=false); /** Check whether the first three elements of the given vector are both zero. * \param pV the FBX vector4 to check. * \return Return true if one of the first three elements of pV is not zero, return false if all of the three elements are both zero. * \remarks If the absolute value of element is less than a tolerance, the element will be considered as zero. */ bool NotZero(FbxVector4 pV); /** Check whether the first three elements of the given vector are both equal to the given value. * \param pV the FBX vector4 to check. * \param pValue the value to check. * \return Return true if one of the first three elements of pV is NOT equal to pValue, return false if all of the three elements are both equal to pValue. */ bool NotValue(FbxVector4 pV, double pValue); /** Check whether the given value is zero. * \param pD the value to check. * \return Return true if pD is NOT zero, return false if pD is zero. * \remarks If the absolute value of pD is less than a tolerance, pD is considered as zero. */ bool NotZero(double pD); /** Check whether the given node's translation is animated. * \param pNode the FBX node to check. * \return Return true if one of Translation X/Y/Z is animated, return false if both of Translation X/Y/Z are not animated. * \remarks If there is no key on one property, this property is not animated. */ bool IsTranslationAnimated(const FbxNode *pNode); /** Check whether the given node's rotation is animated. * \param pNode the FBX node to check. * \return Return true if one of Rotation X/Y/Z is animated, return false if both of Rotation X/Y/Z are not animated. * \remarks If there is no key on one property, this property is not animated. */ bool IsRotationAnimated(const FbxNode *pNode); /** Check whether the given node's rotation of specified axis is animated. * \param pNode the FBX node to check. * \param pAxis Specify index of rotation axis, 0 for Rotation X, 1 for Rotation Y, 2 for Rotation Z. * \return Return true if the rotation of specified axis is animated, return false if it is not animated. * \remarks If there is no key on one property, this property is not animated. */ bool IsRotationAnimated(const FbxNode *pNode, int pAxis); /** Check whether the given node's scale is animated. * \param pNode the FBX node to check. * \return Return true if one of Scale X/Y/Z is animated, return false if both of Scale X/Y/Z are not animated. * \remarks If there is no key on one property, this property is not animated. */ bool IsScaleAnimated(const FbxNode *pNode); /** Copy mesh parameters from pRefMesh to pNewMesh. * \param lNewMesh New FBX mesh. * \param lRefMesh Referenced FBX mesh. * \remarks Vertices, polygons, layers will be copied. */ void CopyMesh(FbxMesh *lNewMesh, FbxMesh *lRefMesh); /** Convert camera focal length animation curve to camera field of view animation curve. * \param pFOVCurve A curve that represents camera field of view. * \param pFLCurve A curve that represents camera focal length animation. * \param pCamera FBX camera to convert. */ void ConvertFocalLengthCurveToFOV(FbxAnimCurve *pFOVCurve, FbxAnimCurve *pFLCurve, FbxCamera *pCamera); /** Preprocess the given FBX node and its hierarchy. * \param pNode Pointer to FBX node. * \remarks To correctly export FBX scene to Collada, this method process FBX nodes, * such as set pivot state for every FBX node, do special transformation conversion for FBX lights and cameras. * This method is called recursively. */ void PreprocessNodeRecursive(FbxNode* pNode); /** Export the value of the specific property as a child element of an element. * \param pProperty The property whose value to be exported. * \param pParentElement The parent element of the created element. */ void ExportPropertyValue(const FbxProperty & pProperty, xmlNode * pParentElement); //@} /** * \name Error Management */ //@{ /** Add notification error info to notify users. * \param pError String of error info. */ void AddNotificationError( FbxString pError ); /** Add notification warning info to notify users. * \param pWarning String of warning info. */ void AddNotificationWarning( FbxString pWarning ); //@} FbxFile* mFileObject; FbxString mFileName; bool mStatus; // XML lib stuff // xmlDocPtr mXmlDoc; // Scene information FbxScene* mScene; // AnimStack/Layer holding the animation FbxAnimStack* mAnimStack; FbxAnimLayer* mAnimLayer; // Libraries // NB: CODE and PROGRAM libraries are unused, so they are not created. xmlNode* mLibraryAnimation; xmlNode* mLibraryCamera; xmlNode* mLibraryController; xmlNode* mLibraryGeometry; xmlNode* mLibraryImage; xmlNode* mLibraryLight; xmlNode* mLibraryMaterial; xmlNode* mLibraryEffect; xmlNode* mLibraryTexture; xmlNode* mLibraryVisualScene; // Shape information FbxStringList *mShapeMeshesList; // export options bool mTriangulate; bool mSingleMatrix; FbxTime mSamplingPeriod; #endif /* !DOXYGEN_SHOULD_SKIP_THIS *****************************************************************************************/ }; #include <fbxsdk/fbxsdk_nsend.h> #endif /* _FBXSDK_FILEIO_COLLADA_WRITER_H_ */
{ "language": "C" }
/* * Copyright 2010 Intel Corporation * * Permission to use, copy, modify, distribute, and sell this software * and its documentation for any purpose is hereby granted without * fee, 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 * Intel not be used in advertising or publicity pertaining to * distribution of the software without specific, written prior * permission. Intel makes no representations about the * suitability of this software for any purpose. It is provided "as * is" without express or implied warranty. * * INTEL CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS, IN NO EVENT SHALL INTEL CORPORATION 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. * * Author: Chris Wilson <chris@chris-wilson.co.uk> */ #include "cairo-test.h" static cairo_test_status_t draw (cairo_t *cr, int width, int height) { cairo_surface_t *region, *similar; cairo_t *cr_region, *cr_similar; cairo_set_source_rgb (cr, .5, .5, .5); cairo_paint (cr); similar = cairo_surface_create_similar (cairo_get_target (cr), CAIRO_CONTENT_COLOR_ALPHA, 20, 20); /* copy the centre */ cr_similar = cairo_create (similar); cairo_surface_destroy (similar); cairo_set_source_surface (cr_similar, cairo_get_target (cr), -20, -20); cairo_paint (cr_similar); similar = cairo_surface_reference (cairo_get_target (cr_similar)); cairo_destroy (cr_similar); /* fill the centre */ region = cairo_surface_create_for_rectangle (cairo_get_target (cr), 20, 20, 20, 20); cr_region = cairo_create (region); cairo_surface_destroy (region); cairo_set_source_rgb (cr_region, 1, 1, 1); cairo_rectangle (cr_region, 0, 0, 10, 10); cairo_fill (cr_region); cairo_set_source_rgb (cr_region, 1, 0, 0); cairo_rectangle (cr_region, 10, 0, 10, 10); cairo_fill (cr_region); cairo_set_source_rgb (cr_region, 0, 1, 0); cairo_rectangle (cr_region, 0, 10, 10, 10); cairo_fill (cr_region); cairo_set_source_rgb (cr_region, 0, 0, 1); cairo_rectangle (cr_region, 10, 10, 10, 10); cairo_fill (cr_region); cairo_destroy (cr_region); /* copy the centre, again */ cr_similar = cairo_create (similar); cairo_surface_destroy (similar); cairo_set_source_surface (cr_similar, cairo_get_target (cr), -20, -20); cairo_paint (cr_similar); similar = cairo_surface_reference (cairo_get_target (cr_similar)); cairo_destroy (cr_similar); /* repeat the pattern around the outside, but do not overwrite...*/ cairo_set_source_surface (cr, similar, 20, 20); cairo_pattern_set_extend (cairo_get_source (cr), CAIRO_EXTEND_REPEAT); cairo_rectangle (cr, 0, 0, width, height); cairo_rectangle (cr, 20, 40, 20, -20); cairo_fill (cr); cairo_surface_destroy (similar); return CAIRO_TEST_SUCCESS; } CAIRO_TEST (subsurface_modify_child, "Tests source clipping with later modifications", "subsurface", /* keywords */ "target=raster", /* FIXME! recursion bug in subsurface/snapshot (with pdf backend) */ /* requirements */ 60, 60, NULL, draw)
{ "language": "C" }