示例#1
0
        /// <summary>
        /// constructor a acpi data from a acpi name space
        /// </summary>
        /// <param name="acpiNs">acpi name space</param>
        public AcpiData(AmlBuilder.AcpiNS acpiNs)
        {
            Type = AcpiDataType.Unknown;
            switch (acpiNs.Type)
            {
            case "Integer":
                this.Type = AcpiDataType.Int;
                Value     = acpiNs.ulValue;
                break;

            case "String":
                this.Type = AcpiDataType.String;
                strValue  = new string(acpiNs.strValue.ToArray());
                break;

            case "Buffer":
                this.Type    = AcpiDataType.Buffer;
                this.bpValue = new byte[acpiNs.pbValue.Length];
                Array.Copy(acpiNs.pbValue, 0, this.bpValue, 0, acpiNs.pbValue.Length);
                break;

            case "Package":
                this.Type    = AcpiDataType.Packge;
                this.bpValue = new byte[acpiNs.pbValue.Length];
                Array.Copy(acpiNs.pbValue, 0, this.bpValue, 0, acpiNs.pbValue.Length);
                break;
            }
        }
示例#2
0
        ///// <summary>
        ///// Get data from path - not used
        ///// </summary>
        ///// <param name="path">full path</param>
        //public void GetDataFromPath(string path)
        //{
        //    //acpiLib.GetValue();
        //}
        /// <summary>
        /// Constructor acpi data from a method arg
        /// </summary>
        /// <param name="arg">arg</param>
        public AcpiData(AcpiMethodArg arg)
        {
            switch (arg.Type)
            {
            case 0:
                this.Type  = AcpiDataType.Int;
                this.Value = arg.ulValue;
                break;

            case 1:
                Type          = AcpiDataType.String;
                this.strValue = new string(arg.strValue.ToArray());
                break;

            case 2:
                Type         = AcpiDataType.Buffer;
                this.bpValue = new byte[arg.bValue.Length];
                Array.Copy(arg.bValue, 0, this.bpValue, 0, arg.bValue.Length);
                break;

            case 3:
                Type         = AcpiDataType.Packge;
                this.bpValue = new byte[arg.bValue.Length];
                Array.Copy(arg.bValue, 0, this.bpValue, 0, arg.bValue.Length);
                break;

            default:
                //System.Diagnostics.Debug.Assert(false);
                Log.Logs("public AcpiData(AcpiMethodArg arg)");
                break;
            }
        }
示例#3
0
        /// <summary>
        /// get a integer value
        /// </summary>
        /// <param name="fullPath">full path of acpi name</param>
        private void GetInt(string fullPath)
        {
            ushort utype  = 1;
            IntPtr intPtr = acpiLib.GetValue(fullPath, ref utype);

            if (intPtr != IntPtr.Zero)
            {
                FromAcpiOutput(intPtr);
                acpiLib.FreeArg(intPtr);
                this.Type = AcpiDataType.Int;
            }
        }
示例#4
0
        /// <summary>
        /// get a string value
        /// </summary>
        /// <param name="fullPath">full path of acpi name</param>
        private void GetString(string fullPath)
        {
            ushort utype  = 2;
            IntPtr intPtr = acpiLib.GetValue(fullPath, ref utype);

            if (intPtr != IntPtr.Zero)
            {
                // acpi string is all ansi code
                FromAcpiOutput(intPtr);
                acpiLib.FreeArg(intPtr);
                this.Type = AcpiDataType.String;
            }
        }
示例#5
0
        /// <summary>
        ///  Constructor acpi data from a buffer or pacakge
        /// </summary>
        /// <param name="Value">raw data</param>
        /// <param name="bPackage">true:buffer/false:pacakge</param>
        public AcpiData(byte[] Value, Boolean bPackage)
        {
            if (bPackage)
            {
                this.Type = AcpiDataType.Packge;
            }
            else
            {
                this.Type = AcpiDataType.Buffer;
            }

            this.bpValue = Value;
        }
示例#6
0
 //public object Get()
 //{
 //    switch (Type)
 //    {
 //        case AcpiDataType.Int:
 //            return Value;
 //        case AcpiDataType.String:
 //            return strValue;
 //        case AcpiDataType.Buffer:
 //            return bpValue;
 //        case AcpiDataType.Packge:
 //            return Pkg;
 //        default:
 //            return null;
 //    }
 //}
 /// <summary>
 /// Duplicate a acpi data
 /// </summary>
 /// <param name="acpiData">acpi data</param>
 private void Duplicate(AcpiData acpiData)
 {
     this.Type  = acpiData.Type;
     this.Value = acpiData.Value;
     if (acpiData.strValue != null)
     {
         this.strValue = new string(acpiData.strValue.ToArray());
     }
     if (acpiData.bpValue != null)
     {
         this.bpValue = new byte[acpiData.bpValue.Length];
         Array.Copy(acpiData.bpValue, 0,
                    this.bpValue, 0, acpiData.bpValue.Length);
     }
     this.Pkg = acpiData.Pkg;
 }
示例#7
0
 /// <summary>
 /// Alias to a acpi data
 /// </summary>
 /// <param name="Alias">source of data to alias</param>
 public void SetAlias(AcpiData Alias)
 {
     this.Alias = Alias;
     this.Type  = AcpiDataType.Alias;
 }
示例#8
0
        /// <summary>
        /// get acpi data from a acpi output of acpilib
        /// </summary>
        /// <param name="intPtr"></param>
        /// <returns></returns>
        public Boolean FromAcpiOutput(IntPtr intPtr)
        {
            UInt32 val = (UInt32)Marshal.ReadInt32(intPtr);

            if (val != 0x426F6541)
            {
                return(false);
            }
            //
            // Check the data length..
            //
            int Length = Marshal.ReadInt32(intPtr + 0x4);
            int Count  = Marshal.ReadInt32(intPtr + 0x8);   // 0xC is type and Element Data Length;
            //DbgMessage("acpi output arg count " + Count.ToString());
            short Type = Marshal.ReadInt16(intPtr + 0xC);

            if (Count > 1)
            {
                Type = 3;   // count is more than 1, it's a package
            }
            if (Count > 0)
            {
                // get the type of data

                short DataLength = Marshal.ReadInt16(intPtr + 0xE);
                switch (Type)
                {
                case 0:
                    this.Value = (UInt64)Marshal.ReadInt64(intPtr + 0x10);
                    this.Type  = AcpiDataType.Int;
                    break;

                case 1:
                    this.Type     = AcpiDataType.String;
                    this.strValue = Marshal.PtrToStringAnsi(intPtr + 0x10);
                    break;

                case 2:
                    this.Type = AcpiDataType.Buffer;
                    bpValue   = new byte[DataLength];
                    Marshal.Copy(intPtr + 0x10, bpValue, 0, DataLength);
                    break;

                case 3:
                    this.Type = AcpiDataType.Packge;
                    bpValue   = new byte[Length];
                    Marshal.Copy(intPtr, bpValue, 0, Length);
                    if (ValidAcpiOutput())
                    {
                        Pkg = new AcpiPackage();
                        UInt32 pkgLength = BitConverter.ToUInt32(bpValue, 4);
                        byte[] pkgData   = new byte[pkgLength - 12];
                        Array.Copy(bpValue, 12, pkgData, 0, pkgLength - 12);
                        AcpiMethodArg(Pkg, pkgData);
                    }
                    break;

                case 4:
                    this.Type = AcpiDataType.Packge;
                    DbgMessage("PACKAGE EX TYPE");
                    bpValue = new byte[Length];
                    Marshal.Copy(intPtr, bpValue, 0, Length);
                    if (ValidAcpiOutput())
                    {
                        Pkg = new AcpiPackage();
                        UInt32 pkgLength = BitConverter.ToUInt32(bpValue, 4);
                        byte[] pkgData   = new byte[pkgLength - 12];
                        Array.Copy(bpValue, 12, pkgData, 0, pkgLength - 12);
                        AcpiMethodArg(Pkg, pkgData);
                    }
                    break;

                default:
                    DbgMessage("Not a valid data type");
                    break;
                }
            }
            return(true);
        }
示例#9
0
 //private const int AcpiMethodDataOffset = 4;
 /// <summary>
 /// constructor
 /// </summary>
 /// <param name="Value">initialize a integer type of acpi data</param>
 public AcpiData(UInt64 Value)
 {
     this.Type  = AcpiDataType.Int;
     this.Value = Value;
 }
示例#10
0
 /// <summary>
 ///  Constructor acpi data from a string
 /// </summary>
 /// <param name="Value">string value</param>
 public AcpiData(String Value)
 {
     this.Type     = AcpiDataType.String;
     this.strValue = Value;
 }
示例#11
0
 public AcpiPackage(byte[] val)
 {
     bpValue = val;
     Type    = AcpiDataType.Buffer;
 }
示例#12
0
 public AcpiPackage(string val)
 {
     strValue = val;
     Type     = AcpiDataType.String;
 }
示例#13
0
 public AcpiPackage(UInt64 val)
 {
     Value = val;
     Type  = AcpiDataType.Int;
 }
示例#14
0
 /// <summary>
 /// Set a field
 /// </summary>
 /// <param name="Path">path of field</param>
 /// <param name="Name">name of field</param>
 public void SetField(string Path, string Name)
 {
     this.Type = AcpiDataType.FieldUnit;
     this.Name = Name;
 }
示例#15
0
        /// <summary>
        /// set new value of acpi data with same type
        /// </summary>
        /// <param name="acpiData"></param>
        public void SetValue(AcpiData acpiData)
        {
            if (this.Type == AcpiDataType.FieldUnit)
            {
                // TODO: Write the field ojbect...
                this.Value = acpiData.Value;
            }
            else
            {
                // Local Data can be assigned to any type, if not the type must be mathcing
                if (this.Name != null)
                {
                    if (this.Name.StartsWith("InternalLocalData") || this.Name.StartsWith("InternalMethodArg"))
                    {
                        this.Type = acpiData.Type;
                    }
                }
                // Int To Int
                // String to string
                // String to Buffer
                // Buffer to String
                // Package to Buffer
                // Buffer to Package
                if (this.Type == acpiData.Type)
                {
                    this.Value = acpiData.Value;
                    if (acpiData.strValue != null)
                    {
                        this.strValue = new string(acpiData.strValue.ToArray());
                    }
                    if (acpiData.bpValue != null)
                    {
                        this.bpValue = new byte[acpiData.bpValue.Length];
                        Array.Copy(acpiData.bpValue, 0,
                                   this.bpValue, 0, acpiData.bpValue.Length);
                    }
                    this.Pkg = acpiData.Pkg;
                }
                else if (this.Type == AcpiDataType.String && acpiData.Type == AcpiDataType.Buffer)
                {
                    // Buffer to string
                    this.strValue = BitConverter.ToString(acpiData.bpValue);
                }
                else if ((this.Type == AcpiDataType.Packge && acpiData.Type == AcpiDataType.Buffer) ||
                         acpiData.Type == AcpiDataType.Packge && this.Type == AcpiDataType.Buffer)
                {
                    // Buffer to Package
                    // or package to buffer
                    this.bpValue = new byte[acpiData.bpValue.Length];
                    Array.Copy(acpiData.bpValue, 0,
                               this.bpValue, 0, acpiData.bpValue.Length);
                }
                else if (acpiData.Type == AcpiDataType.String && this.Type == AcpiDataType.Buffer)
                {
                    // string to buffer
                    //this.bpValue = new byte[acpiData.strValue.Length];

                    this.bpValue = ASCIIEncoding.ASCII.GetBytes(acpiData.strValue);
                }
                else
                {
                    //System.Diagnostics.Debug.Assert(false, "Wrong ACPI Data Type Assignment" + this.ToString() + acpiData.ToString());
                    Log.Logs("Wrong ACPI Data Type Assignment" + this.ToString() + acpiData.ToString());
                }
            }
        }
示例#16
0
        /// <summary>
        /// query a acpi data
        /// </summary>
        /// <param name="Path">path of acpi name</param>
        /// <param name="Name">acpi name</param>
        public void QueryData(string Path, string Name)
        {
            string Root = Path;

            // when driver loaded just to a evaluation to get the value in runtime
            if (acpiLib == null)
            {
                return;
            }

            int nameType = acpiLib.GetTypeFromPath(ref Root, Name);

            if (nameType == -1)
            {
                // did not find the AcpiNS from current and uplevel
                return;
            }
            // TODO: NSKNKS Enhance the acpi type code
            switch (nameType)
            {
            case 1:
                GetInt(Root + Name);
                break;

            case 2:
                GetString(Root + Name);
                break;

            case 3:
                GetBuffer(Root + Name);
                break;

            case 4:
                GetPackage(Root + Name);
                break;

            case 0xE:       // buffer field
            case 5:         // operation region feild
                this.Type = AcpiDataType.Int;
                if (acpiLib != null && acpiLib.DriverLoaded())
                {
                    // Driver is loaded get the value
                    IntPtr output = acpiLib.GetEvalOutput(Root + Name);
                    if (output != IntPtr.Zero)
                    {
                        FromAcpiOutput(output);
                    }

                    //if (GetBuffer(Root + Name, 5))
                    //{
                    //    // get the returned package from driver...
                    //    // display if possible
                    //    Log.Logs(this.bpValue);
                    //    DbgMessage("ERR 1");
                    //} else
                    //{
                    //    DbgMessage(Root + Name);
                    //}

                    //GetPackage(Root + Name);
                    //string result = "";
                    //if (acpiLib.GetEvalResult(Root + Name, ref result))
                    //{
                    //    //
                    //    result = result.Replace(" ", "");
                    //    result = result.Replace("\t", " ");
                    //    result = result.Replace("\r", " ");
                    //    result = result.Replace("\n", " ");
                    //    result = result.Replace("\t", " ");
                    //    // clear text
                    //    string[] values = result.Split(new char[] { ':' });
                    //    if (values != null && values.Length > 1)
                    //    {
                    //        switch (values[0])
                    //        {
                    //            // it's a integer
                    //            case "Integer":
                    //                UInt64 intValue = 0;
                    //                if (values[1].Contains("("))
                    //                {
                    //                    values[1] = values[1].Substring(0, values[1].IndexOf('('));
                    //                }
                    //                if (!IsIntString(values[1], ref intValue))
                    //                {
                    //                    DbgMessage("Not a integer");
                    //                } else
                    //                {
                    //                    this.Value = intValue;
                    //                }
                    //                break;
                    //            case "String":
                    //                this.strValue = values[1];
                    //                break;
                    //            default:
                    //                DbgMessage("ERR 2" + result);
                    //                break;
                    //        }
                    //    } else
                    //    {
                    //        if (values == null)
                    //        {
                    //            DbgMessage("ERR 1" + result);
                    //        } else
                    //        {
                    //            DbgMessage("ERR 1" + values.Length.ToString());
                    //        }
                    //    }
                    //}
                }
                break;

            case 9:
                this.Type = AcpiDataType.Mutex;
                break;
            }
            //if (nameType > 0 && nameType < 5)
            //{
            //    // Get Int, String, Buffer and Package data
            //    ushort nType = (ushort)nameType;
            //    IntPtr intPtr = acpiLib.GetValue(Root + Name, ref nType);

            //}

            if (acpiLib != null && acpiLib.DriverLoaded())
            {
                if (Type == AcpiDataType.FieldUnit)
                {
                    // it's field unit, need to get the refer Field and
                    // OpRegion information for method step debug at offline mode
                    // OpRegion need to put a virtual value for offline debug mode
                    // get the FieldRoot, off line mode only care about the width and offset
                    // dont need to care about the access mode
                    // int nameType = acpiLib.GetTypeFromPath(ref Root, Name);
                }
            }
        }
示例#17
0
        /// <summary>
        /// Construct of AmlMethodData
        /// </summary>
        /// <param name="amlData">amlData to AmlMethodData</param>
        public AmlMethodData(AcpiData amlData)
        {
            Name = amlData.Name;
            if (Name.StartsWith("InternalMethodArg"))
            {
                Name = Name.Substring(14);
            }
            else if (Name.StartsWith("InternalLocalData"))
            {
                Name = Name.Replace("InternalLocalData", "Local");
            }
            AcpiDataType type = amlData.Type;

            if (type == AcpiDataType.Alias)
            {
                type = amlData.Alias.Type;
            }
            switch (type)
            {
            case AcpiDataType.Int:
                Type  = "Integer";
                Value = string.Format("0x{0:X}", amlData.Value);
                break;

            case AcpiDataType.String:
                Type  = "String";
                Value = string.Format("{0}", amlData.strValue);
                break;

            case AcpiDataType.Buffer:
                Type   = "Buffer";
                Value  = string.Format("Buffer(0x{0:X})", amlData.bpValue.Length);
                Value += "{";
                for (int Index = 0; Index < amlData.bpValue.Length; Index++)
                {
                    Value += string.Format("0x{0:X}", (int)amlData.bpValue[Index]);
                    if (Index < amlData.bpValue.Length - 1)
                    {
                        Value += ",";
                    }
                }
                Value += "}";
                break;

            case AcpiDataType.Packge:
                Type = "Packge";
                break;

            case AcpiDataType.Mutex:
                Type  = "Mutex";
                Value = string.Format("0x{0:X}", amlData.Value);
                break;

            case AcpiDataType.Event:
                Type  = "Event";
                Value = string.Format("0x{0:X}", amlData.Value);
                break;

            case AcpiDataType.FieldUnit:
                Type  = "FieldUnit";
                Value = string.Format("0x{0:X}", amlData.Value);
                break;

            default:
                DebugMsg("unknow type of aml method data");
                break;
            }
        }