mirror of
https://github.com/ipxe/ipxe
synced 2025-12-23 13:30:57 +03:00
[usb] Add functions for manual device address assignment
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -26,6 +26,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <strings.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <assert.h>
|
||||
@@ -1849,6 +1850,49 @@ void free_usb_bus ( struct usb_bus *bus ) {
|
||||
free ( bus );
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* USB address assignment
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/**
|
||||
* Allocate device address
|
||||
*
|
||||
* @v bus USB bus
|
||||
* @ret address Device address, or negative error
|
||||
*/
|
||||
int usb_alloc_address ( struct usb_bus *bus ) {
|
||||
unsigned int address;
|
||||
|
||||
/* Find first free device address */
|
||||
address = ffsll ( ~bus->addresses );
|
||||
if ( ! address )
|
||||
return -ENOENT;
|
||||
|
||||
/* Mark address as used */
|
||||
bus->addresses |= ( 1ULL << ( address - 1 ) );
|
||||
|
||||
return address;
|
||||
}
|
||||
|
||||
/**
|
||||
* Free device address
|
||||
*
|
||||
* @v bus USB bus
|
||||
* @v address Device address
|
||||
*/
|
||||
void usb_free_address ( struct usb_bus *bus, unsigned int address ) {
|
||||
|
||||
/* Sanity check */
|
||||
assert ( address > 0 );
|
||||
assert ( bus->addresses & ( 1ULL << ( address - 1 ) ) );
|
||||
|
||||
/* Mark address as free */
|
||||
bus->addresses &= ~( 1ULL << ( address - 1 ) );
|
||||
}
|
||||
|
||||
/******************************************************************************
|
||||
*
|
||||
* USB bus topology
|
||||
|
||||
Reference in New Issue
Block a user