History log of /haiku/src/add-ons/kernel/bus_managers/usb/PhysicalMemoryAllocator.cpp
Revision Date Author Comments
# 93904285 23-Dec-2019 Augustin Cavalier <waddlesplash@gmail.com>

USB: Add overall timeout to the PhysicalMemoryAllocator.

The within-an-attempt timeout did not successfully break up
deadlocks that occur on a system with a lot of USB transfers
going, as we may never hit 2 seconds in between wake-ups,
but the size requested may be un-fulfillable regardless.

So, now we have a 2-second overall timeout. This fixes
the system freeze in #15569, but now attached USB disk
drives enter a Stall state, making the system unusable
anyway.


# a77769a5 23-Dec-2019 Augustin Cavalier <waddlesplash@gmail.com>

USB: Rework the PhysicalMemoryAllocator to use MutexLocker.

No functional change, but will make some subsequent
changes easier and more fail-proof.


# da8c1a9a 22-Feb-2019 Augustin Cavalier <waddlesplash@gmail.com>

USB: Don't loop endlessly waiting for a physical buffer.

This is used quite a lot in critical transfer paths, so we don't
want to lock things up if no buffers are available for whatever reason.
Wait 2 seconds, and if we didn't get anything by then, return B_NO_MEMORY.

Possibly fixes or helps with certain USB-related lockups.


# 21c87a5d 09-Sep-2018 Jérôme Duval <jerome.duval@gmail.com>

drivers: remove some non-haiku support code.

Change-Id: Ic55bb4832adabeb807f763c87ad938e74fb3a97d
Reviewed-on: https://review.haiku-os.org/520
Reviewed-by: Axel Dörfler <axeld@pinc-software.de>
Reviewed-by: waddlesplash <waddlesplash@gmail.com>


# ce0ef8c8 07-Aug-2018 Augustin Cavalier <waddlesplash@gmail.com>

USB: Remove BeOSCompatibility.h and associated cruft.


# 05a859eb 14-Jan-2018 Jérôme Duval <jerome.duval@gmail.com>

usb: map registers or allocate area for the kernel only.


# 5fa80ab6 02-Sep-2014 Paweł Dziepak <pdziepak@quarnos.org>

usb: fix format string

fDebugChunkSize is an uint32.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>


# b0e1d28d 31-Aug-2014 Michael Lotz <mmlr@mlotz.ch>

USB: Cleanup hardcoded bitmap size.


# 2747989d 31-Aug-2014 Michael Lotz <mmlr@mlotz.ch>

USB: Warn if debug allocation does not fit debug chunk size.


# 9c0623a8 31-Aug-2014 Michael Lotz <mmlr@mlotz.ch>

USB: Increase debug chunk size from 64 to 128 bytes.

The queue head structure in EHCI is bigger than the previous debug
chunk size. Multiple allocations therefore overwrote eachother.


# d8b4cfc9 04-Aug-2012 Rene Gollent <anevilyak@gmail.com>

Get USB functional on x86-64.

- Various changes to printf format specifiers to make them 32/64 safe.
- Adjustments to various descriptor structures since addr_t is not 32-bit
on x86-64, and consequently this breaks the physical structure that's
expected. Also adjusted padding to accomodate 32-byte boundaries when
64-bit pointers are in use.
- Adjustments to make use of phys_addr_t where needed.


# b9a6b784 02-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

Make the USB physical memory allocator more robust. Wait for space to become
available when there is none instead of spinning around. Might help with #8053
and #8058, though it's possible that leaks or interrupt issues are the cause
for these.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43125 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9fb2d737 23-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Replaced B_32_BIT_MEMORY by B_32_BIT_FULL_LOCK and B_32_BIT_CONTIGUOUS, so
the constraint can be expressed more precisely. ATM B_32_BIT_FULL_LOCK is
implemented as B_32_BIT_CONTIGUOUS when B_HAIKU_PHYSICAL_BITS > 32, though.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37226 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 64cf56f5 21-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Force allocation of physical memory < 4 GB until the related TODOs are fixed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37201 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 64d79eff 27-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed physical_entry::{address,size} to phys_{addr,size}_t and changed
map_physical_memory()'s physicalAddress parameter type from void* to
phys_addr_t. This breaks source compatibility, but -- as long as
phys_{addr,size}_t remain 32 bit wide -- keeps binary compatibility with
BeOS.
* Adjusted all code using the affected interfaces (Oh what fun!). Added a few
TODOs in places where the wrong types (e.g. void* for physical addresses
are used). Looks like quite a few drivers aren't 64 bit safe and others
will break with PAE.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36960 a95241bf-73f2-0310-859d-f6bbb57e9c96


# eb01fb72 08-Apr-2009 Michael Lotz <mmlr@mlotz.ch>

* Add the kernel debugger extensions only for the haiku target.
* Acknowledge non-enabled interrupts in UHCI as done in EHCI as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30063 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6eba0636 22-Feb-2009 Michael Lotz <mmlr@mlotz.ch>

* Added simplified possibility to schedule UHCI transfers from within KDL.
* Added debugger commands to resolve usb_ids to pipes.
* Adjusted the physical memory allocator to be usable in a slimmed down mode
when running inside the kernel debugger.
* Implemented USB keyboard support for KDL through a kernel debugger add-on.
* Added kgetc() and made use of it where previously individual methods were used
to ensure that reading characters always goes through the kernel debugger
add-ons and the other methods.

This has some preconditions to meet though:
1) The keyboard must be in the boot protocol (currently the case but needs to
be revisited once we have a full usb_hid).
2) The keyboard must be attached to a UHCI root port (i.e. not use EHCI or OHCI,
also not through hubs unless those are USB 1.1).
3) the usb_hid driver has to be opened for this to work. This means that for the
time between initializing USB and when usb_hid is opened by the input_server
there is no keyboard support.

Also note that this has no way of detecting hot-plug, meaning that you can't
re-attach your USB keyboard from the hub to the root port once in KDL.

On the bright side of things, since this is a non-destructive mechanism it is
possible to enter and leave KDL without loosing the USB state.

Tested OK in QEMU, not tested on real hardware yet, will see in a few minutes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29291 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b0884f0c 07-Aug-2008 Axel Dörfler <axeld@pinc-software.de>

* Fixed a ton of wrong usages of B_CONTIGUOUS + B_FULL_LOCK.
* The use of B_{READ|WRITE}_AREA throughout the drivers is surely alarming.
Defining these flags means that *every user* application can access these
buffers read/write, it becomes visible in userspace like any other memory
(just shared among all apps). I would like to ask each driver maintainer
to see if that is really wished here. If you only need one app to be able
to access it, cloning the area would be more appropriate.
* I came across the use of B_ANY_KERNEL_BLOCK_ADDRESS a number of times. This
is almost completely useless for most usages, as it tries to align the
virtual to a multiple of the size of the area. It just makes the allocation
more likely to fail. Please only use where appropriate, and please review
your code.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26858 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2b07b8e0 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced all instances of benaphores in the kernel code by mutexes.
* Removed kernel benaphores.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25690 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a8be7d1e 06-Jan-2007 Michael Lotz <mmlr@mlotz.ch>

* Added some more debug output to the hub code
* Report and clear yet unhandled port changes in hubs
* Fixed the way devices that vanish on port reset are handled
* Added a status field to the memory allocator and check it creating it

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19732 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a183e866 25-Sep-2006 Michael Lotz <mmlr@mlotz.ch>

Oops, this was the very conservative value. Testing with my laptop (that has a slow EHCI controller) reveals that we need some more room here.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18930 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4330ef22 25-Sep-2006 Michael Lotz <mmlr@mlotz.ch>

* Added retries to the PhysicalMemoryAllocator. Memory is allocated and freed at a very high frequency, so low memory conditions shouldn't last very long.
* Added a separate thread for cleaning up EHCI transfers. This makes it possible to actually always wait for the async advance interrupt without hindering execution of transfers.
This pushes performance again and fixes the bug I introduced in the last change, that we could free yet cached descriptors when a previous async advance timed out.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18929 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6f52af5f 15-Sep-2006 Michael Lotz <mmlr@mlotz.ch>

Adding compatibility headers to enable R5 build of the USB stack again.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18856 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f452f9dc 14-Sep-2006 Michael Lotz <mmlr@mlotz.ch>

* Implemented most qTD and qH functions for EHCI async transfers.
* Implementing control and bulk (async) transfers. They don't work yet though.
* Corrected the legacy support handling in EHCI
* Fixed the bit mask for total bytes in qTDs and added the data toggle bit
* Changed the boolean low speed flags to usb_speed enum that allows for low, full and highspeed

Also wrote a memory allocator that takes over memory management from the stack. It is similar to a buddy allocator. This does on the one hand remove some ugly code from the stack and is on the other hand far more scalable than the previous free list approach. This scalability is needed for proper EHCI support where buffers can go up to a size of 5 pages. The allocator is not perfect and it's memory overhead is quite high compared to the managed memory (depends on the managed block sizes), but it's quik and works well so far.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18849 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 5fa80ab69177a235fb4cb9cb71922bca5211799e 02-Sep-2014 Paweł Dziepak <pdziepak@quarnos.org>

usb: fix format string

fDebugChunkSize is an uint32.

Signed-off-by: Paweł Dziepak <pdziepak@quarnos.org>


# b0e1d28d2ba8381183bfe392daabcb9d89b9b8d6 31-Aug-2014 Michael Lotz <mmlr@mlotz.ch>

USB: Cleanup hardcoded bitmap size.


# 2747989d9e838a5619fee37f70f5ffbcc7e82c55 31-Aug-2014 Michael Lotz <mmlr@mlotz.ch>

USB: Warn if debug allocation does not fit debug chunk size.


# 9c0623a8f243b55e8679fa703bfc11347cad66d7 31-Aug-2014 Michael Lotz <mmlr@mlotz.ch>

USB: Increase debug chunk size from 64 to 128 bytes.

The queue head structure in EHCI is bigger than the previous debug
chunk size. Multiple allocations therefore overwrote eachother.


# d8b4cfc9829119291e68cfe0152c239fd8850b3d 04-Aug-2012 Rene Gollent <anevilyak@gmail.com>

Get USB functional on x86-64.

- Various changes to printf format specifiers to make them 32/64 safe.
- Adjustments to various descriptor structures since addr_t is not 32-bit
on x86-64, and consequently this breaks the physical structure that's
expected. Also adjusted padding to accomodate 32-byte boundaries when
64-bit pointers are in use.
- Adjustments to make use of phys_addr_t where needed.


# b9a6b7844d7f8bc5b7918e0bf274a649ece6b282 02-Nov-2011 Michael Lotz <mmlr@mlotz.ch>

Make the USB physical memory allocator more robust. Wait for space to become
available when there is none instead of spinning around. Might help with #8053
and #8058, though it's possible that leaks or interrupt issues are the cause
for these.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@43125 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 9fb2d73772382ea2ccfb62e912f9bfb9c39ac26d 23-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Replaced B_32_BIT_MEMORY by B_32_BIT_FULL_LOCK and B_32_BIT_CONTIGUOUS, so
the constraint can be expressed more precisely. ATM B_32_BIT_FULL_LOCK is
implemented as B_32_BIT_CONTIGUOUS when B_HAIKU_PHYSICAL_BITS > 32, though.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37226 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 64cf56f5cd6a85321651e58ac0bf8d15f8007cf8 21-Jun-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

Force allocation of physical memory < 4 GB until the related TODOs are fixed.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37201 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 64d79eff7290437d24b1a420537c3ed5c144ab96 27-May-2010 Ingo Weinhold <ingo_weinhold@gmx.de>

* Changed physical_entry::{address,size} to phys_{addr,size}_t and changed
map_physical_memory()'s physicalAddress parameter type from void* to
phys_addr_t. This breaks source compatibility, but -- as long as
phys_{addr,size}_t remain 32 bit wide -- keeps binary compatibility with
BeOS.
* Adjusted all code using the affected interfaces (Oh what fun!). Added a few
TODOs in places where the wrong types (e.g. void* for physical addresses
are used). Looks like quite a few drivers aren't 64 bit safe and others
will break with PAE.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@36960 a95241bf-73f2-0310-859d-f6bbb57e9c96


# eb01fb72f6d90bf6a083941ace087bdd6803a516 08-Apr-2009 Michael Lotz <mmlr@mlotz.ch>

* Add the kernel debugger extensions only for the haiku target.
* Acknowledge non-enabled interrupts in UHCI as done in EHCI as well.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@30063 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6eba063647cc4ff5aa863e1b5dc5093c22a3acb0 22-Feb-2009 Michael Lotz <mmlr@mlotz.ch>

* Added simplified possibility to schedule UHCI transfers from within KDL.
* Added debugger commands to resolve usb_ids to pipes.
* Adjusted the physical memory allocator to be usable in a slimmed down mode
when running inside the kernel debugger.
* Implemented USB keyboard support for KDL through a kernel debugger add-on.
* Added kgetc() and made use of it where previously individual methods were used
to ensure that reading characters always goes through the kernel debugger
add-ons and the other methods.

This has some preconditions to meet though:
1) The keyboard must be in the boot protocol (currently the case but needs to
be revisited once we have a full usb_hid).
2) The keyboard must be attached to a UHCI root port (i.e. not use EHCI or OHCI,
also not through hubs unless those are USB 1.1).
3) the usb_hid driver has to be opened for this to work. This means that for the
time between initializing USB and when usb_hid is opened by the input_server
there is no keyboard support.

Also note that this has no way of detecting hot-plug, meaning that you can't
re-attach your USB keyboard from the hub to the root port once in KDL.

On the bright side of things, since this is a non-destructive mechanism it is
possible to enter and leave KDL without loosing the USB state.

Tested OK in QEMU, not tested on real hardware yet, will see in a few minutes.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29291 a95241bf-73f2-0310-859d-f6bbb57e9c96


# b0884f0cb812cdaf8035e6028f69dcf0d7721953 07-Aug-2008 Axel Dörfler <axeld@pinc-software.de>

* Fixed a ton of wrong usages of B_CONTIGUOUS + B_FULL_LOCK.
* The use of B_{READ|WRITE}_AREA throughout the drivers is surely alarming.
Defining these flags means that *every user* application can access these
buffers read/write, it becomes visible in userspace like any other memory
(just shared among all apps). I would like to ask each driver maintainer
to see if that is really wished here. If you only need one app to be able
to access it, cloning the area would be more appropriate.
* I came across the use of B_ANY_KERNEL_BLOCK_ADDRESS a number of times. This
is almost completely useless for most usages, as it tries to align the
virtual to a multiple of the size of the area. It just makes the allocation
more likely to fail. Please only use where appropriate, and please review
your code.
* Minor cleanup.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26858 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 2b07b8e0f1a7f1e76f31db24a21a42cbb01d7b9c 28-May-2008 Ingo Weinhold <ingo_weinhold@gmx.de>

* Replaced all instances of benaphores in the kernel code by mutexes.
* Removed kernel benaphores.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@25690 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a8be7d1ea3297974cb80d1dfd700510375704c67 06-Jan-2007 Michael Lotz <mmlr@mlotz.ch>

* Added some more debug output to the hub code
* Report and clear yet unhandled port changes in hubs
* Fixed the way devices that vanish on port reset are handled
* Added a status field to the memory allocator and check it creating it

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19732 a95241bf-73f2-0310-859d-f6bbb57e9c96


# a183e86663de1a3faab36b91e703ed84440d94b9 25-Sep-2006 Michael Lotz <mmlr@mlotz.ch>

Oops, this was the very conservative value. Testing with my laptop (that has a slow EHCI controller) reveals that we need some more room here.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18930 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 4330ef22d5cffd443a7af847124557a803d15327 25-Sep-2006 Michael Lotz <mmlr@mlotz.ch>

* Added retries to the PhysicalMemoryAllocator. Memory is allocated and freed at a very high frequency, so low memory conditions shouldn't last very long.
* Added a separate thread for cleaning up EHCI transfers. This makes it possible to actually always wait for the async advance interrupt without hindering execution of transfers.
This pushes performance again and fixes the bug I introduced in the last change, that we could free yet cached descriptors when a previous async advance timed out.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18929 a95241bf-73f2-0310-859d-f6bbb57e9c96


# 6f52af5f5cb91ce9dab99f326bb967eee8379e83 15-Sep-2006 Michael Lotz <mmlr@mlotz.ch>

Adding compatibility headers to enable R5 build of the USB stack again.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18856 a95241bf-73f2-0310-859d-f6bbb57e9c96


# f452f9dc783e647ece105a379564d9ce6a05de2b 14-Sep-2006 Michael Lotz <mmlr@mlotz.ch>

* Implemented most qTD and qH functions for EHCI async transfers.
* Implementing control and bulk (async) transfers. They don't work yet though.
* Corrected the legacy support handling in EHCI
* Fixed the bit mask for total bytes in qTDs and added the data toggle bit
* Changed the boolean low speed flags to usb_speed enum that allows for low, full and highspeed

Also wrote a memory allocator that takes over memory management from the stack. It is similar to a buddy allocator. This does on the one hand remove some ugly code from the stack and is on the other hand far more scalable than the previous free list approach. This scalability is needed for proper EHCI support where buffers can go up to a size of 5 pages. The allocator is not perfect and it's memory overhead is quite high compared to the managed memory (depends on the managed block sizes), but it's quik and works well so far.

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@18849 a95241bf-73f2-0310-859d-f6bbb57e9c96