Skip to content

Commit 6e69739

Browse files
Jason J. HerneAlexander Gordeev
authored andcommitted
s390/ap: Externalize AP bus specific bitmap reading function
Rename hex2bitmap() to ap_hex2bitmap() and export it for external use. This function will be used by the implementation of the vfio-ap ap_config sysfs attribute. Signed-off-by: "Jason J. Herne" <jjherne@linux.ibm.com> Reviewed-by: Tony Krowiak <akrowiak@linux.ibm.com> Reviewed-by: Harald Freudenberger <freude@linux.ibm.com> Link: https://lore.kernel.org/r/20240415152555.13152-2-jjherne@linux.ibm.com Signed-off-by: Alexander Gordeev <agordeev@linux.ibm.com>
1 parent ba05b39 commit 6e69739

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

drivers/s390/crypto/ap_bus.c

Lines changed: 3 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1043,15 +1043,7 @@ static struct notifier_block ap_bus_nb = {
10431043
.notifier_call = ap_bus_cfg_chg,
10441044
};
10451045

1046-
/*
1047-
* hex2bitmap() - parse hex mask string and set bitmap.
1048-
* Valid strings are "0x012345678" with at least one valid hex number.
1049-
* Rest of the bitmap to the right is padded with 0. No spaces allowed
1050-
* within the string, the leading 0x may be omitted.
1051-
* Returns the bitmask with exactly the bits set as given by the hex
1052-
* string (both in big endian order).
1053-
*/
1054-
static int hex2bitmap(const char *str, unsigned long *bitmap, int bits)
1046+
int ap_hex2bitmap(const char *str, unsigned long *bitmap, int bits)
10551047
{
10561048
int i, n, b;
10571049

@@ -1078,6 +1070,7 @@ static int hex2bitmap(const char *str, unsigned long *bitmap, int bits)
10781070
return -EINVAL;
10791071
return 0;
10801072
}
1073+
EXPORT_SYMBOL(ap_hex2bitmap);
10811074

10821075
/*
10831076
* modify_bitmap() - parse bitmask argument and modify an existing
@@ -1143,7 +1136,7 @@ static int ap_parse_bitmap_str(const char *str, unsigned long *bitmap, int bits,
11431136
rc = modify_bitmap(str, newmap, bits);
11441137
} else {
11451138
memset(newmap, 0, size);
1146-
rc = hex2bitmap(str, newmap, bits);
1139+
rc = ap_hex2bitmap(str, newmap, bits);
11471140
}
11481141
return rc;
11491142
}

drivers/s390/crypto/ap_bus.h

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,6 +343,28 @@ int ap_parse_mask_str(const char *str,
343343
unsigned long *bitmap, int bits,
344344
struct mutex *lock);
345345

346+
/*
347+
* ap_hex2bitmap() - Convert a string containing a hexadecimal number (str)
348+
* into a bitmap (bitmap) with bits set that correspond to the bits represented
349+
* by the hex string. Input and output data is in big endian order.
350+
*
351+
* str - Input hex string of format "0x1234abcd". The leading "0x" is optional.
352+
* At least one digit is required. Must be large enough to hold the number of
353+
* bits represented by the bits parameter.
354+
*
355+
* bitmap - Pointer to a bitmap. Upon successful completion of this function,
356+
* this bitmap will have bits set to match the value of str. If bitmap is longer
357+
* than str, then the rightmost bits of bitmap are padded with zeros. Must be
358+
* large enough to hold the number of bits represented by the bits parameter.
359+
*
360+
* bits - Length, in bits, of the bitmap represented by str. Must be a multiple
361+
* of 8.
362+
*
363+
* Returns: 0 On success
364+
* -EINVAL If str format is invalid or bits is not a multiple of 8.
365+
*/
366+
int ap_hex2bitmap(const char *str, unsigned long *bitmap, int bits);
367+
346368
/*
347369
* Interface to wait for the AP bus to have done one initial ap bus
348370
* scan and all detected APQNs have been bound to device drivers.

0 commit comments

Comments
 (0)