s390/ap: Externalize AP bus specific bitmap reading function
authorJason J. Herne <jjherne@linux.ibm.com>
Mon, 15 Apr 2024 15:25:51 +0000 (11:25 -0400)
committerAlexander Gordeev <agordeev@linux.ibm.com>
Mon, 22 Apr 2024 10:49:17 +0000 (12:49 +0200)
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>
drivers/s390/crypto/ap_bus.c
drivers/s390/crypto/ap_bus.h

index 09059b3a3a42afea64e6bf23391d2f407ba62ca4..c20b4509207980b51ea64de3aee9eb5b7932934a 100644 (file)
@@ -1043,15 +1043,7 @@ static struct notifier_block ap_bus_nb = {
        .notifier_call = ap_bus_cfg_chg,
 };
 
-/*
- * hex2bitmap() - parse hex mask string and set bitmap.
- * Valid strings are "0x012345678" with at least one valid hex number.
- * Rest of the bitmap to the right is padded with 0. No spaces allowed
- * within the string, the leading 0x may be omitted.
- * Returns the bitmask with exactly the bits set as given by the hex
- * string (both in big endian order).
- */
-static int hex2bitmap(const char *str, unsigned long *bitmap, int bits)
+int ap_hex2bitmap(const char *str, unsigned long *bitmap, int bits)
 {
        int i, n, b;
 
@@ -1078,6 +1070,7 @@ static int hex2bitmap(const char *str, unsigned long *bitmap, int bits)
                return -EINVAL;
        return 0;
 }
+EXPORT_SYMBOL(ap_hex2bitmap);
 
 /*
  * 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,
                rc = modify_bitmap(str, newmap, bits);
        } else {
                memset(newmap, 0, size);
-               rc = hex2bitmap(str, newmap, bits);
+               rc = ap_hex2bitmap(str, newmap, bits);
        }
        return rc;
 }
index 59c7ed49aa02489593ee052b543be348f7df3027..fdbc6fdfdf576f583a09b363989a7feeae950f07 100644 (file)
@@ -343,6 +343,28 @@ int ap_parse_mask_str(const char *str,
                      unsigned long *bitmap, int bits,
                      struct mutex *lock);
 
+/*
+ * ap_hex2bitmap() - Convert a string containing a hexadecimal number (str)
+ * into a bitmap (bitmap) with bits set that correspond to the bits represented
+ * by the hex string. Input and output data is in big endian order.
+ *
+ * str - Input hex string of format "0x1234abcd". The leading "0x" is optional.
+ * At least one digit is required. Must be large enough to hold the number of
+ * bits represented by the bits parameter.
+ *
+ * bitmap - Pointer to a bitmap. Upon successful completion of this function,
+ * this bitmap will have bits set to match the value of str. If bitmap is longer
+ * than str, then the rightmost bits of bitmap are padded with zeros. Must be
+ * large enough to hold the number of bits represented by the bits parameter.
+ *
+ * bits - Length, in bits, of the bitmap represented by str. Must be a multiple
+ * of 8.
+ *
+ * Returns: 0          On success
+ *         -EINVAL     If str format is invalid or bits is not a multiple of 8.
+ */
+int ap_hex2bitmap(const char *str, unsigned long *bitmap, int bits);
+
 /*
  * Interface to wait for the AP bus to have done one initial ap bus
  * scan and all detected APQNs have been bound to device drivers.