Jump to content

HP DVx AppleACPIBatteryManager Driver


gsly
 Share

74 posts in this topic

Recommended Posts

Hi Gsly,

 

As you suggested I am posting my issue with battery detection in this thread. I have an asus g53SW the battery portion does not seem to work. Not only I get garbage for model information, it always show the battery condition as "Replace Now" , this is a brand new less than 4 weeks machine.

 

By looking at the code, it seems to me perhaps the right events are not implemented or not being triggered correctly.

I do appreciate any help you could give me.

 

Thanks

rog53

asusBattery.dsl.zip

Link to comment
Share on other sites

The following implements a battery manager driver for HP DVx laptops. There are two pieces required to make this work, the AppleACPIBatteryManager.kext (driver) and a DSDT edit.

 

The driver is generic and will probably work on other platforms that properly implement the _BST and _BIF methods in their DSDT. As the HP _BST method on DVx isn't (IMHO) implemented correctly, DVx owners will also have to implement the DSDT edit so that the _BST method returns proper values to the driver in order to calculate the time remaining (to charge or discharge) value.

 

This was tested on an HP DV8 but will likely work on any DVx model that implements a similar DSDT method. Also, I have only tested this on a 32-bit kernel, but it should work on a 64-bit kernel as the driver has been compiled to a 10.6 32/64-bit universal (FAT) binary.

 

There are two zip files below, a debug and release version. The debug version outputs messages to kernel.log and the release version does not, otherwise they are identical.

 

Step 1: DSDT Edit

 

In your DSDT.dsl, locate the method UPBS that should look like this:

 

			Method (UPBS, 0, NotSerialized)
		 {
			 Store (^^PCI0.LPCB.EC0.MBRM, Local5)
			 If (LNot (And (Local5, 0x8000)))
			 {
				 ShiftRight (Local5, 0x05, Local5)
				 ShiftLeft (Local5, 0x05, Local5)
				 If (LNotEqual (Local5, DerefOf (Index (PBST, 0x02))))
				 {
					 If (LEqual (^^PCI0.LPCB.EC0.BACR, One))
					 {
						 Store (FABL, Index (PBST, 0x02))
					 }
					 Else
					 {
						 Store (Local5, Index (PBST, 0x02))
					 }
				 }
			 }

			 Store (^^PCI0.LPCB.EC0.MBCV, Index (PBST, 0x03))
			 Store (^^PCI0.LPCB.EC0.MBST, Index (PBST, Zero))
		 }

If your method matches the above, replace it with:

			Method (UPBS, 0, NotSerialized)
		 {
			 Store (^^PCI0.LPCB.EC0.MBST, Index (PBST, Zero))
			 ^^PCI0.LPCB.EC0.SMRD (0x09, 0x16, 0x0A, RefOf (Local0))
			 Store (Local0, Index (PBST, One))
			 ^^PCI0.LPCB.EC0.SMRD (0x09, 0x16, 0x0F, RefOf (Local1))
			 Store (Local1, Index (PBST, 0x02))
			 ^^PCI0.LPCB.EC0.SMRD (0x09, 0x16, 0x09, RefOf (Local2))
			 Store (Local2, Index (PBST, 0x03))
		 }

Compile it and install as usual.

 

Step 2: Install Driver

 

Install the kext in /Extra/Extensions, set the permissions and rebuild your kext cache. Reboot.

Hi Gysly,

 

Would be possible to have a version of your kext with the possibilty printing trace info?

For example calling a method and passing an string or variable to be printed in a log?

After hours of tracing the code I believe mine is corrupting some of the infomation that is used by your kext to report battery states.

 

Thanks,

Rog53

Link to comment
Share on other sites

I know Lion is not out yet but any chance you've tried the kext on Lion?

What is the current situation of the development both on Lion and Snow Leopard?

Thanks,

I was able to install Lion DP3 on my DV8 last week and then DP4 came out so I'm going to start over with that (and make some install notes for a thread). Once I do that, my next goal is to get this battery driver working in Lion as well as testing the auto-sleep functionality in a relatively virgin OS (no third party software, etc) as I think in my SL environment, some piece of software is causing cancellation of the auto-sleep.

 

I hope to update this thread soon with the current version of the driver that adds some more functionality/options. Maybe in the next week or two.

 

 

Hi Gysly,

 

Would be possible to have a version of your kext with the possibilty printing trace info?

For example calling a method and passing an string or variable to be printed in a log?

After hours of tracing the code I believe mine is corrupting some of the infomation that is used by your kext to report battery states.

 

Thanks,

Rog53

I'll try to update this thread soon with the current version that had more debug output than the first one. I'll also look at your DSDT and maybe post some commented code/fixes if I can spot anything.

Link to comment
Share on other sites

Recently, I experienced power loss on low battery and now my battery is being reported as service battery, which is another way of saying that "I am dying" :). I guess it was just trigger as I was already expecting such a thing.

It's been more than two years so it will die eventually.

Weird enough is that my battery, after one week, went back to normal. It was a temporary glitch I guess.

I was able to install Lion DP3 on my DV8 last week and then DP4 came out so I'm going to start over with that (and make some install notes for a thread). Once I do that, my next goal is to get this battery driver working in Lion as well as testing the auto-sleep functionality in a relatively virgin OS (no third party software, etc) as I think in my SL environment, some piece of software is causing cancellation of the auto-sleep.

For auto sleep, have you tried using Please Sleep. I tried that on my desktop and it works as expected. Also, there is a CHUD application, which comes with Xcode, called SpindownHDD.app. It shows you the current status of devices connected through SATA. As it is already known that some dvd drives cause auto sleep problem, it might be better off checking it first.

 

I was planing to install DP3 and then came out DP4. I hope to give it a try soon though.

Thank you for your time and effort.

Link to comment
Share on other sites

Weird enough is that my battery, after one week, went back to normal. It was a temporary glitch I guess.

 

For auto sleep, have you tried using Please Sleep. I tried that on my desktop and it works as expected. Also, there is a CHUD application, which comes with Xcode, called SpindownHDD.app. It shows you the current status of devices connected through SATA. As it is already known that some dvd drives cause auto sleep problem, it might be better off checking it first.

 

I was planing to install DP3 and then came out DP4. I hope to give it a try soon though.

Thank you for your time and effort.

The current version of the driver (I can't recall if the one posted here does this) will pull the number of cycles and manufacture date from the battery and these combined with the "design capacity" (what the battery should hold when new) and the "last full charge capacity" (what the battery currently holds for a charge) should be a good indicator of battery health.

 

Interestingly, Apple's driver polls their batteries for health information as well, but it uses proprietary Smart Battery commands specific to the battery controller they use. I wasn't able to find a data-sheet or any other information for the HP battery controller to implement the same functionality.

 

I did play with Please Sleep but I recall it didn't help on my system. I will check into the SpindownHDD tool though to see what it shows...

 

I was able to get my DP4 USB installer to boot last night, but I haven't tried an install yet. For DP3 I just did a GPT install to an external drive, but for DP4 I'm going to try an MBR install (via Nawcom patch) to external drive as it seems the HP BIOS (F.25) in my DV8 won't show a GPT as a bootable drive, only MBR.

Link to comment
Share on other sites

The current version of the driver (I can't recall if the one posted here does this) will pull the number of cycles and manufacture date from the battery and these combined with the "design capacity" (what the battery should hold when new) and the "last full charge capacity" (what the battery currently holds for a charge) should be a good indicator of battery health.

 

Interestingly, Apple's driver polls their batteries for health information as well, but it uses proprietary Smart Battery commands specific to the battery controller they use. I wasn't able to find a data-sheet or any other information for the HP battery controller to implement the same functionality.

 

I did play with Please Sleep but I recall it didn't help on my system. I will check into the SpindownHDD tool though to see what it shows...

 

I was able to get my DP4 USB installer to boot last night, but I haven't tried an install yet. For DP3 I just did a GPT install to an external drive, but for DP4 I'm going to try an MBR install (via Nawcom patch) to external drive as it seems the HP BIOS (F.25) in my DV8 won't show a GPT as a bootable drive, only MBR.

I am using the one in the first page and it shows the following. No Cycle Count.

post-562417-1308079377_thumb.png

The patched version of iStat Pro shows the health level of the battery as 83% but I don't know how accurate it is.

Link to comment
Share on other sites

I am using the one in the first page and it shows the following. No Cycle Count.

post-562417-1308079377_thumb.png

The patched version of iStat Pro shows the health level of the battery as 83% but I don't know how accurate it is.

Here is what the current driver shows for my DV8:

 

post-60978-1308441740_thumb.png

 

I was able to install Lion DP4 today and I put the current driver on it but the OS doesn't seem to recognize there is a battery installed :) Looks like Apple changed something and I can't compile anything until I can get the Xcode version that will install on Lion as the current 4.0 tells me to update to 10.6.6 in order to install on 10.7 :D

 

I suspect 10.6.8 will be out *real* soon so I'll probably wait until I can update to 10.6.8 and test before updating this thread with the current driver. Hopefully by then, 10.7 will be official and I can figure out what changed...

Link to comment
Share on other sites

Here is what the current driver shows for my DV8:

 

I was able to install Lion DP4 today and I put the current driver on it but the OS doesn't seem to recognize there is a battery installed :( Looks like Apple changed something and I can't compile anything until I can get the Xcode version that will install on Lion as the current 4.0 tells me to update to 10.6.6 in order to install on 10.7 :)

 

I suspect 10.6.8 will be out *real* soon so I'll probably wait until I can update to 10.6.8 and test before updating this thread with the current driver. Hopefully by then, 10.7 will be official and I can figure out what changed...

I want to install DP4 as well but then I know that Lion will come out next month so I don't want to spend too much time on it as it is likely that there wil one or two releases before the final version. Things might change. For now, at least, as you said, it is better to wait for 10.6.8. As far as I've read, it includes some changes that we will see on Lion i.e power management and speed step, audio.

 

Whenever you have something we could test, please let us know.

 

Thank you.

Link to comment
Share on other sites

We were right about 10.6.8 being available soon! :)

 

However, Apple ain't making this easy ;) I cloned my 10.6.7 install yesterday and installed the 10.6.8 combo update (installed fine), but at reboot it looks like they changed the kernel enough that Meklort's LAPIC kernel patcher in his Chameleon branch doesn't work anymore and I got a kernel panic. Then I tried to use the "cpus=1" option to boot so the kernel wouldn't try to initialize the interrupts incorrectly but I still got a kernel panic :(

 

I'm thinking I may have to go on a little side project and dig into this stupid HP BIOS and see if I can patch/rewrite the processor initialization functionality so I don't have to deal with this {censored}!

 

I'll probably revert to 10.6.7 for now until I can get a look at the kernel source to see WTF has changed.

 

JBraddock, I see you have updated to 10.6.8 from another thread. Does the battery driver still work on 10.6.8? Thanks.

Link to comment
Share on other sites

Does the battery driver still work on 10.6.8? Thanks.
50/50. No battery symbol is displayed in the menu bar (or whatever it is called), but if we look in System Preferences > Energy saver, the battery info is there. Go figure..

 

EDIT:

Battery info is also displayed (correctly) in System Profiler > Power

 

EDIT2:

Solved the other problem with no networking (renamed Apple80211Monitor.bundle) and GUESS WHAT... the icon is in the place again! Bottom line, it is working in 10.6.8.

Link to comment
Share on other sites

JBraddock, I see you have updated to 10.6.8 from another thread. Does the battery driver still work on 10.6.8? Thanks.

Out of curiosity, is it a bug in HP Bios? If so, how come they don't fix it right away. I am not a developer or pro user but when I come across an apparent and yet crucial bug in an application, I wonder why the developer doesn't just fix it. If it is that obvious, it should be fixed right away. Like the problem I have when I use laptop on battery for a while and then plug in the power adapter. Most of the time, the fan goes crazy. I don't know, may be I am being naive ;)

 

As for the battery, I didn't have time to update my laptop. I might update tonight. I let you know the result.

It was my desktop machine at work that I updated and it went okay.

 

50/50. No battery symbol is displayed in the menu bar (or whatever it is called), but if we look in System Preferences > Energy saver, the battery info is there. Go figure...

Better than nothing :censored2:

Link to comment
Share on other sites

Out of curiosity, is it a bug in HP Bios? If so, how come they don't fix it right away. I am not a developer or pro user but when I come across an apparent and yet crucial bug in an application, I wonder why the developer doesn't just fix it. If it is that obvious, it should be fixed right away. Like the problem I have when I use laptop on battery for a while and then plug in the power adapter. Most of the time, the fan goes crazy. I don't know, may be I am being naive :D

I believe whomever it was that came up with the lapic code fix mentioned that the Intel chip-set sheets detail the proper initialization for the local APIC and having read it, the code in the kernel is definitely wrong, or needs to be exactly correct likely because the HP BIOS doesn't initialize it correctly :D I would think that if this was only an issue in the OSX kernel, then we would see ALL the i7 based machines need the kernel fix but I'm sure that isn't the case. If I can track down another i7 720QM based laptop successfully running without the patch, I should be able to look at that machines BIOS and compare to the HP one. I just need a few BIOS tools, a good disassembler and lots of time :)

 

And given what I saw in the BIOS AML/DSDT code, whomever worked on the battery methods at HP didn't read enough standards documents, or didn't understand the hardware because the code is {censored}. There is a smart battery controller in the battery and their standard ACPI functions weren't even using it (they pulled some embedded controller values). The WMI functions did a bit of SBS code, but they didn't pull out all of the available data from the battery.

 

As a professional developer, ya, I fix bugs when I know about them :) I'm sure the microcontroller/BIOS programmers at HP (and most places) rarely see the light of day or interact with the customer base in anyway, so they likely think their code is working fine and the world is still flat ;-)

 

 

 

It still works on me, but i don't have an HP and i don't use dsdt edit. It works if i use a MacbookPro 6.1 ECDT table, battery percent and time are normal.

Thanks for the feedback. Can you post or PM me the ECDT table you are using? I'm not sure if I have a MacBookPro6,1 copy or not. I know I was looking at one previously and I need to do that again before I try my next idea of getting the vanilla AppleSmartBattery driver working via embedded controller/DSDT.

 

 

@gsly, I updated to 10.6.8 and battery seems to work fine.

Cool, thanks. I guess I'll just dig up my revised posting document and recompile the current driver and get this thread updated. May not be until next (long) weekend though.

Link to comment
Share on other sites

Thanks for the feedback. Can you post or PM me the ECDT table you are using? I'm not sure if I have a MacBookPro6,1 copy or not. I know I was looking at one previously and I need to do that again before I try my next idea of getting the vanilla AppleSmartBattery driver working via embedded controller/DSDT.

Here it is: ECDT.aml.zip

Link to comment
Share on other sites

  • 1 month later...
And given what I saw in the BIOS AML/DSDT code, whomever worked on the battery methods at HP didn't read enough standards documents, or didn't understand the hardware because the code is {censored}. There is a smart battery controller in the battery and their standard ACPI functions weren't even using it (they pulled some embedded controller values). The WMI functions did a bit of SBS code, but they didn't pull out all of the available data from the battery.

Well things are not like that, I digged in many vendors DSDT's and almost all use EC for battery stuff, exception is Apple, and I can understand why is like that, the reason is simple, they(chip manufacturers, vendors, etc.) do not want to expose the SMBus methods and stuff to the curious people manly for security reasons(I can expand the paranoia(their) saying that this kind of stuff is used on military rockets and so, but i wont) :)

HP on the other hand throw the bone in DSDT, was like an invitation, this is how to do it, you curious people do it ;)

...and we did.

Link to comment
Share on other sites

Any news on support for Lion?

Thanks!

 

I'm working on it! I was going to update the thread a couple of weeks back but then I managed to get my machine up to 10.6.8 and running 64-bit and found a bug I didn't see in 10.6.7 32-bit so I'm tracking that down now. Also I'm working to get a Lion GM base install going in parallel so I can see what Apple changed and what's broken with the ACPI driver in Lion and get that compiled (now that Xcode 4.1 is available)

 

And after that, I think I'm going to go back to investigate ways of getting the Apple driver working or helping The King to fill in the missing bits so we can compile and use the Apple source. Using the vanilla driver or something much closer will also improve compatibility with other 3rd party software that is looking for the Apple driver (and/or data from it) exclusively, although I could fix that now by renaming the classes the same as Apple :angel:

Link to comment
Share on other sites

Argh! I should have known better! It turns out that the bug I've been searching for in the driver was actually a bug in HP's ACPI method that converts an Integer to string. The HP method did not ensure there was a trailing NULL/0x00 byte at the end of the converted string. Likely due to the way memory is allocated in 64-bit mode vs 32-bit, I was able to see the side effect more often in 64-bit kernel mode but I suspect I did see this once or twice in 32-bit mode but thought it was another issue :unsure:

 

So at the end of the day, there was no bug in the driver :D

 

I was able to fix the HP method and now I see the correct value on the driver side. I just need to remove some debug code, update the version details, recompile a debug/release version, update my documents with the fixed HP method/details and I will post the latest driver version. I should be able to get this done this week so keep an eye on this thread for a pointer to the new version (I plan to post it in a new thread in a more appropriate section as suggested by JBraddock)

 

I now have a Lion GM install working so I'll be working on checking the driver in that environment next.

Link to comment
Share on other sites

...I will post the latest driver version. I should be able to get this done this week so keep an eye on this thread for a pointer to the new version (I plan to post it in a new thread in a more appropriate section as suggested by JBraddock)
Good news! Thanks for update :(
Link to comment
Share on other sites

 Share

×
×
  • Create New...