Jump to content

fluid | fixed

HP DVx ACPI 3.x/4.x Battery Driver (10.6/10.7)


  • Please log in to reply
221 replies to this topic

#121
JBraddock

JBraddock

    Ph.D (Can) in Human Rights

  • Members
  • PipPipPipPipPipPipPip
  • 549 posts
  • Location:UK

View Postgsly, on 15 December 2011 - 03:53 PM, said:

This is the bug I found in the HP ITOS() method (See OP/first page) that doesn't end the ASCII string will a zero byte (terminator) and is the reason you see the garbage after the legitimate string in the log output.  I looked for this bug for a long time thinking it was in the driver but after much debugging, I finally traced it to bad HP code.  And yes, there are other bugs in the HP DSDT code as well...

Does this effect the performance or the functionality of the battery? I am planning to buy a 12 cell battery. The original one died for a while back and I got a new one from the Ebay, which is working well so far.

#122
gsly

gsly

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 133 posts
  • Gender:Male
  • Location:The Great White North

View PostJBraddock, on 15 December 2011 - 04:17 PM, said:

Does this effect the performance or the functionality of the battery? I am planning to buy a 12 cell battery. The original one dies for a while back and I got a new one from the Ebay, which is working well so far.
No it does not.  The bug just causes the string returned by ACPI to the driver code to not have a proper zero termination and when that string it passed to the Apple API to put it into the IORegistry, some check in their code generates the logging message as it detects (essentially) a buffer overflow condition.

BTW, I just purchased a 12-cell battery for my DV8 a few weeks back as my stock one decided to die after 31 cycles.  The new battery works well and this driver picked up all of the information from it no problem and everything is still calculated correctly.  I'll post a few screen shots soon.

#123
sw170

sw170

    InsanelyMac Geek

  • Members
  • PipPipPipPip
  • 197 posts
  • Gender:Male
  • Location:UK

View Postgsly, on 15 December 2011 - 03:53 PM, said:

This is the bug I found in the HP ITOS() method (See OP/first page) that doesn't end the ASCII string will a zero byte (terminator) and is the reason you see the garbage after the legitimate string in the log output.  I looked for this bug for a long time thinking it was in the driver but after much debugging, I finally traced it to bad HP code.  And yes, there are other bugs in the HP DSDT code as well...
Thanks a million again gsly !
I confess I went extra lazy way when I was doing DSDT patching with your methods - I had compilation errors with ITOS Method so I left it untouched (removed comments and errors are gone now)
And yes I am aware of that how buggy HP DSDT  can be.. spent waaay too much time fiddling and studying it..
But must say by looking at some other DSDTs - different models or laptop brands I still consider myself being lucky  ;)

Regards
s

#124
kerr

kerr

    InsanelyMac Protégé

  • Members
  • PipPip
  • 94 posts

View Postgsly, on 15 December 2011 - 03:53 PM, said:

This is the bug I found in the HP ITOS() method (See OP/first page) that doesn't end the ASCII string will a zero byte (terminator) and is the reason you see the garbage after the legitimate string in the log output.  I looked for this bug for a long time thinking it was in the driver but after much debugging, I finally traced it to bad HP code.  And yes, there are other bugs in the HP DSDT code as well...

hi gsly,

Am I to assume that your fix is not brand specific and i can fix my ITOS() method simply by adding Store(Zero, Index(Local0, Local2)) before  Return (Local0) at its end ? Like this:

Method (ITOS, 1, NotSerialized)
			{
				Store (Buffer (0x09)
					{
						/* 0000 */	0x30, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
						/* 0008 */	0x00
					}, Local0)
				Store (Buffer (0x11)
					{
						"0123456789ABCDEF"
					}, Local7)
				Store (0x08, Local1)
				Store (Zero, Local2)
				Store (Zero, Local3)
				While (Local1)
				{
					Decrement (Local1)
					And (ShiftRight (Arg0, ShiftLeft (Local1, 0x02)), 0x0F, Local4)
					If (Local4)
					{
						Store (Ones, Local3)
					}
					If (Local3)
					{
						GBFE (Local7, Local4, RefOf (Local5))
						PBFE (Local0, Local2, Local5)
						Increment (Local2)
					}
				}
			  Store(Zero, Index(Local0, Local2))
			  Return (Local0)
			}

Or there is more to do ? This is from Dell XPS L501x, Thanks

#125
gsly

gsly

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 133 posts
  • Gender:Male
  • Location:The Great White North

View Postkerr, on 21 December 2011 - 01:07 PM, said:

hi gsly,

Am I to assume that your fix is not brand specific and i can fix my ITOS() method simply by adding Store(Zero, Index(Local0, Local2)) before  Return (Local0) at its end ?
...
Or there is more to do ? This is from Dell XPS L501x, Thanks
Correct, this function is not brand specific and could be used on any platform provided the dependent supporting functions GBFE() and PBFE() are implemented as well. This method just converts a number into the ASCII string equivalent.

If you've found the same function with the same bug in Dell DSDT code, that either indicates that manufactures have access to the same set of common ACPI library functions, or more likely, manufacturers are just stealing each other's code. :dev:

#126
westendmtl

westendmtl

    InsanelyMac Protégé

  • Members
  • Pip
  • 14 posts
Hello, gsly and everyone,

First of all thanks gsly for your time and effort and thanks a lot for sharing your knowledge with us. I'm a total newbie when it comes to DSDT stuff. I tried to edit/compare the DSDT but i'm totally lost :( Can you please help me with editing my DSDT file for battery fix?
I'm attaching my DSDT file, i was able to patch it to get audio from AppleHDA but again i'm completely lost with this battery stuff. I would really appriciate if you can edit my DSDT to make my battery work.

Thanks a lot. Happy Holidays

Its Fixed! (See Post#127)

HP DV7 3080CA specs.

i7 720QM | PM55 chip | nVidia GT230m 1GB | 6GB RAM | Corsair F120 SSD | WD Black 500 HD

Attached Files



#127
westendmtl

westendmtl

    InsanelyMac Protégé

  • Members
  • Pip
  • 14 posts

View Postwestendmtl, on 26 December 2011 - 07:55 AM, said:

Hello, gsly and everyone,

First of all thanks gsly for your time and effort and thanks a lot for sharing your knowledge with us. I'm a total newbie when it comes to DSDT stuff. I tried to edit/compare the DSDT but i'm totally lost :( Can you please help me with editing my DSDT file for battery fix?
I'm attaching my DSDT file, i was able to patch it to get audio from AppleHDA but again i'm completely lost with this battery stuff. I would really appriciate if you can edit my DSDT to make my battery work.

Thanks a lot. Happy Holidays


HP DV7 3080CA specs.

i7 720QM | PM55 chip | nVidia GT230m 1GB | 6GB RAM | Corsair F120 SSD | WD Black 500 HD

Hi everyone,

I was able to fix my DSDT :D It works. Thanks gsly.
However, when i placed the kext in the E/E it was not loading but it is loading fine when i placed it in S/L/E.
The DSDTSE shows (Compilation complete. 0 Errors, 0 Warnings, 0 Remarks, 5 Optimizations) and someone here please help me to optimize my DSDT. I'm attaching my fixed DSDT file.

Attached Files



#128
gsly

gsly

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 133 posts
  • Gender:Male
  • Location:The Great White North

View Postwestendmtl, on 27 December 2011 - 07:43 AM, said:

Hi everyone,

I was able to fix my DSDT :D It works. Thanks gsly.
However, when i placed the kext in the E/E it was not loading but it is loading fine when i placed it in S/L/E.
The DSDTSE shows (Compilation complete. 0 Errors, 0 Warnings, 0 Remarks, 5 Optimizations) and someone here please help me to optimize my DSDT. I'm attaching my fixed DSDT file.
If you are using a kernel cache in Lion, that is why it is working in S/L/E only. If you are using SL or not using a kernel cache, you need to regenerate the extensions cache.  There are many other threads on here about how to do both so please search on this.
If your DSDT compiles without errors and is working then ignore the optimization. This is just compiler speak for rewriting some programmers inefficient code. :)

#129
fyodor123

fyodor123

    InsanelyMac Protégé

  • Members
  • Pip
  • 18 posts
Hello my laptop is an Asus device. Some dsdt values are different than as in HP dsdt. First i started to read acpi spesifications to understand the language. So i can dissect my code and try to understand what it means. But there is some parts that i can't understand yet. For example my _BIF method starts like this:
If (LNot (^^SBRG.EC0.BATP (Zero)))
{
	Return (NBIF)
}

And the BATP method looks like this:
Method (BATP, 1, Serialized)
{
	If (Arg0)
	{
		Return (DCP2)
	}
	Else
	{
		Return (DCPF)
	}
}

Since we send zero to BATP method it should return DCPF and DCPF is in Field (RAMW, AnyAcc, NoLock, Preserve) and declerated like DCPF 8,
Here first question is coming. What kind of data is DCPF? Is it boolean or integer or char? (I'm c/c++ programmer).
Let's assume LNot(DCPF) produces a boolean true value and then _BIF returns NBIF. According to acpi specs _BIF method returns a package. Like this:
Package {
	Power Unit						 // Integer (DWORD)
	Design Capacity					// Integer (DWORD)
	Last Full Charge Capacity		  // Integer (DWORD)
	Battery Technology				 // Integer (DWORD)
	Design Voltage					 // Integer (DWORD)
	Design Capacity of Warning		 // Integer (DWORD)
	Design Capacity of Low			 // Integer (DWORD)
	Battery Capacity Granularity 1	 // Integer (DWORD)
	Battery Capacity Granularity 2	 // Integer (DWORD)
	Model Number					   // String (ASCIIZ)
	Serial Number					  // String (ASCIIZ)
	Battery Type					   // String (ASCIIZ)
	OEM Information					// String (ASCIIZ)
}


My NBIF decleration looks like this:
Name (NBIF, Package (0x0D)
{
	Zero,
	Ones,
	Ones,
	One,
	Ones,
	Ones,
	Ones,
	Ones,
	Ones,
	"",
	"",
	"",
	""
})

How can this zero, one and ones match? what does ones mean? Is it hex looks like 0x11111111 or what? Thank you. That's all for now.

#130
gsly

gsly

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 133 posts
  • Gender:Male
  • Location:The Great White North

View Postfyodor123, on 13 January 2012 - 11:08 PM, said:

Hello my laptop is an Asus device. Some dsdt values are different than as in HP dsdt. First i started to read acpi spesifications to understand the language. So i can dissect my code and try to understand what it means. But there is some parts that i can't understand yet. For example my _BIF method starts like this:
...
Since we send zero to BATP method it should return DCPF and DCPF is in Field (RAMW, AnyAcc, NoLock, Preserve) and declerated like DCPF 8,
Here first question is coming. What kind of data is DCPF? Is it boolean or integer or char? (I'm c/c++ programmer).
DCPF is defined as 8-bits so in C speak, it would be an unsigned char. DCPF likely stands for (D)irect ©urrent (P)resence (F)lag and is likely hardwired to one of the battery battery bays. DCP2 would be for a second battery and if your laptop doesn't have this, its likely Asus is just using generic DSDT methods amoung their models and that is why Zero is always passed in as your model likely only has one battery.

View Postfyodor123, on 13 January 2012 - 11:08 PM, said:

Let's assume LNot(DCPF) produces a boolean true value and then _BIF returns NBIF. According to acpi specs _BIF method returns a package. Like this:
...
How can this zero, one and ones match? what does ones mean? Is it hex looks like 0x11111111 or what? Thank you. That's all for now.
NBIF is a package that would be returned when no battery is present (DCPF = 0) and if you look at the AML keyword "Ones", it returns a constant integer (unsigned) where all bits a set to 1. If you then look at the package spec, you'll see that 0xFFFFFFFF is "Unknown" or in C speak:
#define UNKNOWN 0xFFFFFFFF

BTW, this "unknown" value is important as the battery driver looks for this value returned by DSDT methods to determine if the value should be used or not for calculations, etc.

#131
theaussiepea

theaussiepea

    InsanelyMac Protégé

  • Members
  • Pip
  • 17 posts
I'm running a Lenovo Thinkpad T510 (currently with 10.6.8) and I've been reading lots of DSDT/battery related threads trying to solve 2 problems: 1) getting the battery fully recognized by the system and the status to show up in istats 2) better detection for my "slice battery" (the second battery that attaches to the bottom of the computer). I'm hoping some DSDT edits can help with these, and to prepare for Lion when I install it in the future.

It seems I have a similar battery section of my DSDT as gothic860 (with a Thinkpad W520 earlier in this topic), with several lines that start with "SB" (like SBCH) under the EC device. Unlike him, my battery isn't detected, except by voodoobattery. No cycle information, no health information, etc.

I've tried using the B1B2 and similar methods to break up all the SBxx lines into 8 bit chunks, then installing the modified AppleSmartBatteryManagery, but there's something I'm not doing right in the DSDT.

Besides this I have a fully working system.

Thanks to any who might be able to help. Attached is the DSDT with the battery edits I've done, and then one with my other system edits but nothing related to the battery.

Attached Files



#132
flip360

flip360

    InsanelyMac Protégé

  • Members
  • PipPip
  • 79 posts
  • Gender:Male
  • Location:Skopje
Hi glsy,

as the other user stated a few posts up i also have an Asus notebook but i am no programmer and have been banging my head about Lion`s dsdt battery fix for a week now but its a no go for me still. I have a working dsdt for 10.6.8 / 10.7 but the battery icon doesnt show (rollback form AppleACPI from 10.6.8 is working but no info in system profiler). I have made it for the battery to show in statusbar and sys info with the AppleACPISmartBatteryManager.kext, but when i unplug the power it always shows 0%. So, could you have a look in my dsdt please? :)

Thanks in advance buddy,

cheers

Attached Files



#133
gsly

gsly

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 133 posts
  • Gender:Male
  • Location:The Great White North

View Posttheaussiepea, on 17 January 2012 - 09:03 PM, said:

I'm running a Lenovo Thinkpad T510 (currently with 10.6.8) and I've been reading lots of DSDT/battery related threads trying to solve 2 problems: 1) getting the battery fully recognized by the system and the status to show up in istats 2) better detection for my "slice battery" (the second battery that attaches to the bottom of the computer). I'm hoping some DSDT edits can help with these, and to prepare for Lion when I install it in the future.

It seems I have a similar battery section of my DSDT as gothic860 (with a Thinkpad W520 earlier in this topic), with several lines that start with "SB" (like SBCH) under the EC device. Unlike him, my battery isn't detected, except by voodoobattery. No cycle information, no health information, etc.

I've tried using the B1B2 and similar methods to break up all the SBxx lines into 8 bit chunks, then installing the modified AppleSmartBatteryManagery, but there's something I'm not doing right in the DSDT.

Besides this I have a fully working system.

Thanks to any who might be able to help. Attached is the DSDT with the battery edits I've done, and then one with my other system edits but nothing related to the battery.
You still have 16-bit references. See SBDC and SBDV referenced in the GBIF method (called by _BIF).  You must remove all the 16-bit references otherwise the AppleACPIPlatform.kext's ACPI parser throws a fit...  I should probably look into building a tool based on the ACPICA parser code so people can run their DSDT through it and get a report on the issues...
Focus on getting just _BIF working (comment the rest) and then we'll see about getting multiple battery support going.  The current battery driver doesn't support more than one battery (yet) so disable one of them via the _STA method.  If you are willing to test, I think I could add multiple battery support to the driver, however I doubt Apple has multiple battery support in OSX in terms of things like the System Profiler, but you never know...

#134
gsly

gsly

    InsanelyMac Geek

  • Members
  • PipPipPip
  • 133 posts
  • Gender:Male
  • Location:The Great White North

View Postflip360, on 17 January 2012 - 09:18 PM, said:

Hi glsy, as the other user stated a few posts up i also have an Asus notebook but i am no programmer and have been banging my head about Lion`s dsdt battery fix for a week now but its a no go for me still. I have a working dsdt for 10.6.8 / 10.7 but the battery icon doesnt show (rollback form AppleACPI from 10.6.8 is working but no info in system profiler). I have made it for the battery to show in statusbar and sys info with the AppleACPISmartBatteryManager.kext, but when i unplug the power it always shows 0%. So, could you have a look in my dsdt please? :) Thanks in advance buddy, cheers
System Profiler will only show information from registry when the key/driver is named AppleSmartBatteryManager.kext, but I see you later figured that out.  Look at the _BST method if there is no battery status as more than likely this method is not correctly returning units according to the specification.  Try hardcoding some values like this:

Method (_BST, 0, NotSerialized)
{
	Store (0x01, Index (PBST, Zero))	// Battery state = discharging
	Store (0xC8, Index (PBST, One))	 // Battery present rate = 200 mW/mA
	Store (0x3E8, Index (PBST, 0x02))   // Battery remaining capacity = 1000 mWh/mAh
	Store (0x2710, Index (PBST, 0x03))  // Battery present voltage = 10000 mV or 10V

	Return (PBST)
}

and see if that shows in SP.  Then try adding in the existing code without the checks on OSFG and BAFG to make sure these aren't set incorrectly, etc.
Good luck!

#135
theaussiepea

theaussiepea

    InsanelyMac Protégé

  • Members
  • Pip
  • 17 posts
Trying to convert the remaining two references to 8-bit, SBDC and SBDV, using the technique described here by Zprood. Unfortunately, I just can't quite figure this out, as it's not working like the others--I get compile errors.

FIrst SBDC. Original code has 4 references:

					Field (ECOR, ByteAcc, NoLock, Preserve)
					{
								Offset (0xA0),
						SBDC,   16,
…

					Method (GBIF, 3, NotSerialized)
					{
…
							If (Local7)
							{
								Multiply (SBDC, 0x0A, Local0)
							}
							Else
							{
								Store (SBDC, Local0)
							}
...

		   Method (SBDC, 1, NotSerialized)
			{
				If (And (Arg0, 0x02))
				{
					BPWC (0x01)
				}
				Else
				{
					BPWC (0x00)
				}

				If (And (Arg0, 0x04))
				{
					Or (WGFL, 0x40, WGFL)
					\BLTH (0x02)
				}
				Else
				{
					And (WGFL, Not (0x40), WGFL)
					\BLTH (0x03)
				}
			}

I tried changing it to make it like the other edits, using the B1B2 Method

					Field (ECOR, ByteAcc, NoLock, Preserve)
					{
								Offset (0xA0),
						//SBDC,   16,
						BDC0,	8,
						BDC1,	8,
…

							If (Local7)
							{
								//Multiply (SBDC, 0x0A, Local0)
								Multiply (B1B2 (BDC0, BDC1), 0x0A, Local0)
							}
							Else
							{
								//Store (SBDC, Local0)
								Store (B1B2 (BDC0, BDC1), Local0)
							}

(Not sure what to do with Method (SBDC...)

Second is SBDV. This object occurs 4 times in the original code as well

					Field (ECOR, ByteAcc, NoLock, Preserve)
					{
								Offset (0xA0),
						SBDC,   16,
						SBDV,   16,
…

					Method (GBIF, 3, NotSerialized)
...
							Else
							{
								If (SBDV)
								{
									Divide (0x00030D40, SBDV, Local2, Index (Arg1, 0x06))
								}
								Else
								{
									Store (0x00, Index (Arg1, 0x06))
								}
							}
…

							Store (SBDV, Index (Arg1, 0x04))

Tried replacing it with this:

					Field (ECOR, ByteAcc, NoLock, Preserve)
					{
								Offset (0xA0),
						SBDC,   16,
						//SBDV,   16,
						BDV0,	   8,
						BDV1,	   8,
…

					Method (GBIF, 3, NotSerialized)
...
							Else
							{
								//If (SBDV)
								If (B1B2 (BDV0, BDV1))
								{
									//Divide (0x00030D40, SBDV, Local2, Index (Arg1, 0x06))
									Divide (0x00030D40, B1B2 (BDV0, BDV1), Local2, Index (Arg1, 0x06))
								}
								Else
								{
									Store (0x00, Index (Arg1, 0x06))
								}
							}
…

							//Store (SBDV, Index (Arg1, 0x04))
							Store (B1B2 (BDV0, BDV1), Index (Arg1, 0x04))

Followed the format of the other fixes, but these ones create compile errors. B1B2 Method is defined further up in the DSDT file.

Thanks, any help is appreciated. Attached is the DSDT that won't compile, and a version without any battery related edits.

Attached Files



#136
robi39

robi39

    InsanelyMac Protégé

  • Members
  • Pip
  • 27 posts
gsly,
Could you look at my DSDT, I have a HP DV7-1020US, after the edits DSDT won't compile, it has 4 errors, is that anything
special about my DSDT or something I'm not doing right. DSDT doesn't have ITOS or EC device
  Device (BAT0)
    {
    Name (_HID, EisaId ("PNP0C0A"))
    Name (_UID, One)
    Name (_PCL, Package (0x01)
    {
    _SB
    })
    Method (_STA, 0, NotSerialized)
    {
    If (ECON)
    {
    Sleep (0x40)
    If (^^PCI0.LPC.EC0.BAL0)
    {
    Sleep (0x30)
    Return (0x1F)
    }
    }
    Sleep (0x30)
    Return (0x0F)
    }
    Name (PKG1, Package (0x0D)
    {
    One,
    0x1290,
    0x1290,
    One,
    0x2A30,
    0x01DB,
    0x0100,
    0x0108,
    0x0EC4,
    "Primary",
    "",
    "Lion",
    "Hewlett-Packard"
    })
    Method (_BIF, 0, NotSerialized)
    {
    If (ECON)
    {
    Sleep (0x30)
    Store (^^PCI0.LPC.EC0.BDC0, Local0)
    Store (Local0, Index (PKG1, One))
    Sleep (0x30)
    Store (^^PCI0.LPC.EC0.BFC0, Local0)
    Store (Local0, Index (PKG1, 0x02))
    If (Local0)
    {
    Divide (Local0, 0x64, Local1, Local2)
    Multiply (Local2, 0x05, Local3)
    Store (Local3, Index (PKG1, 0x05))
    Multiply (Local2, 0x03, Local2)
    Store (Local2, Index (PKG1, 0x06))
    }
    Sleep (0x30)
    Store (^^PCI0.LPC.EC0.BDV0, Local0)
    Store (Local0, Index (PKG1, 0x04))
    }
    Return (PKG1)
    }
    Name (PKG2, Package (0x04)
    {
    Zero,
    One,
    One,
    0x39D0
    })
    Method (_BST, 0, NotSerialized)
    {
    If (ECON)
    {
    Sleep (0x30)
    Store (^^PCI0.LPC.EC0.BST0, Local0)
    And (Local0, 0x07, Local0)
    Sleep (0x30)
    Store (^^PCI0.LPC.EC0.BRC0, Local1)
    Sleep (0x30)
    Store (^^PCI0.LPC.EC0.BPV0, Local2)
    Store (Local0, Index (PKG2, Zero))
    Store (Zero, Index (PKG2, One))
    Store (Local1, Index (PKG2, 0x02))
    Store (Local2, Index (PKG2, 0x03))
    }
    Return (PKG2)
    }
    }

#137
robi39

robi39

    InsanelyMac Protégé

  • Members
  • Pip
  • 27 posts
gsly,


Here is my full DSDT.
Thank you

Attached Files



#138
Neo_01

Neo_01

    InsanelyMac Protégé

  • Members
  • Pip
  • 49 posts
Hi I have tried to make the patches but doesn't work, 62 errors....could you please help me, I attach my original DSDT. (Notebook HP DV6-6099el)
Thanks for your help.

Attached Files



#139
Chinmaya

Chinmaya

    InsanelyMac Protégé

  • Members
  • Pip
  • 33 posts
  • Gender:Male
  • Location:India
  • Interests:Hackintoshs, gadgets etc.
Hi there, I have tried to edit the DSDT but doesn't work, could you please help me to get my battery working?
I am attaching my DSDT. (Notebook HP DV6-6121tx)
Thanks in advance for your help.

Attached Files



#140
jazzyguy

jazzyguy

    InsanelyMac Geek

  • Members
  • PipPipPipPip
  • 188 posts
  • Gender:Male
  • Location:USA
Is it possible for a guide that details what keys may need changed?





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

© 2013 InsanelyMac  |   News  |   Forum  |   Downloads  |   OSx86 Wiki  |   Mac Netbook  |   Web hosting by CatN  |   Designed by Ed Gain  |   Logo by irfan  |   Privacy Policy