Commit 050a6f34 authored by Ohad Sharabi's avatar Ohad Sharabi Committed by Greg Kroah-Hartman

habanalabs: add user API to get valid DRAM page sizes

Future devices will support multiple device memory page sizes.
In addition, an API for the user was added for it to be able to control
the device memory allocation page size.

This patch is a complementary patch to inform the user of the available
page size supported by the device.
Signed-off-by: default avatarOhad Sharabi <osharabi@habana.ai>
Reviewed-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarOded Gabbay <ogabbay@kernel.org>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 06926dbe
...@@ -1304,6 +1304,7 @@ struct fw_load_mgr { ...@@ -1304,6 +1304,7 @@ struct fw_load_mgr {
* @get_stream_master_qid_arr: get pointer to stream masters QID array * @get_stream_master_qid_arr: get pointer to stream masters QID array
* @is_valid_dram_page_size: return true if page size is supported in device * @is_valid_dram_page_size: return true if page size is supported in device
* memory allocation, otherwise false. * memory allocation, otherwise false.
* @get_valid_dram_page_orders: get valid device memory allocation page orders
*/ */
struct hl_asic_funcs { struct hl_asic_funcs {
int (*early_init)(struct hl_device *hdev); int (*early_init)(struct hl_device *hdev);
...@@ -1432,6 +1433,7 @@ struct hl_asic_funcs { ...@@ -1432,6 +1433,7 @@ struct hl_asic_funcs {
bool (*is_valid_dram_page_size)(u32 page_size); bool (*is_valid_dram_page_size)(u32 page_size);
int (*mmu_get_real_page_size)(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop, int (*mmu_get_real_page_size)(struct hl_device *hdev, struct hl_mmu_properties *mmu_prop,
u32 page_size, u32 *real_page_size, bool is_dram_addr); u32 page_size, u32 *real_page_size, bool is_dram_addr);
void (*get_valid_dram_page_orders)(struct hl_info_dev_memalloc_page_sizes *info);
}; };
......
...@@ -591,6 +591,27 @@ static int razwi_info(struct hl_fpriv *hpriv, struct hl_info_args *args) ...@@ -591,6 +591,27 @@ static int razwi_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
return copy_to_user(out, &info, min_t(size_t, max_size, sizeof(info))) ? -EFAULT : 0; return copy_to_user(out, &info, min_t(size_t, max_size, sizeof(info))) ? -EFAULT : 0;
} }
static int dev_mem_alloc_page_sizes_info(struct hl_fpriv *hpriv, struct hl_info_args *args)
{
void __user *out = (void __user *) (uintptr_t) args->return_pointer;
struct hl_info_dev_memalloc_page_sizes info = {0};
struct hl_device *hdev = hpriv->hdev;
u32 max_size = args->return_size;
if ((!max_size) || (!out))
return -EINVAL;
/*
* Future ASICs that will support multiple DRAM page sizes will support only "powers of 2"
* pages (unlike some of the ASICs before supporting multiple page sizes).
* For this reason for all ASICs that not support multiple page size the function will
* return an empty bitmask indicating that multiple page sizes is not supported.
*/
hdev->asic_funcs->get_valid_dram_page_orders(&info);
return copy_to_user(out, &info, min_t(size_t, max_size, sizeof(info))) ? -EFAULT : 0;
}
static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data, static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data,
struct device *dev) struct device *dev)
{ {
...@@ -641,6 +662,9 @@ static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data, ...@@ -641,6 +662,9 @@ static int _hl_info_ioctl(struct hl_fpriv *hpriv, void *data,
case HL_INFO_RAZWI_EVENT: case HL_INFO_RAZWI_EVENT:
return razwi_info(hpriv, args); return razwi_info(hpriv, args);
case HL_INFO_DEV_MEM_ALLOC_PAGE_SIZES:
return dev_mem_alloc_page_sizes_info(hpriv, args);
default: default:
break; break;
} }
......
...@@ -9378,6 +9378,12 @@ static u32 *gaudi_get_stream_master_qid_arr(void) ...@@ -9378,6 +9378,12 @@ static u32 *gaudi_get_stream_master_qid_arr(void)
return gaudi_stream_master; return gaudi_stream_master;
} }
static void gaudi_get_valid_dram_page_orders(struct hl_info_dev_memalloc_page_sizes *info)
{
/* set 0 since multiple pages are not supported */
info->page_order_bitmask = 0;
}
static ssize_t infineon_ver_show(struct device *dev, struct device_attribute *attr, char *buf) static ssize_t infineon_ver_show(struct device *dev, struct device_attribute *attr, char *buf)
{ {
struct hl_device *hdev = dev_get_drvdata(dev); struct hl_device *hdev = dev_get_drvdata(dev);
...@@ -9489,6 +9495,7 @@ static const struct hl_asic_funcs gaudi_funcs = { ...@@ -9489,6 +9495,7 @@ static const struct hl_asic_funcs gaudi_funcs = {
.get_stream_master_qid_arr = gaudi_get_stream_master_qid_arr, .get_stream_master_qid_arr = gaudi_get_stream_master_qid_arr,
.is_valid_dram_page_size = NULL, .is_valid_dram_page_size = NULL,
.mmu_get_real_page_size = hl_mmu_get_real_page_size, .mmu_get_real_page_size = hl_mmu_get_real_page_size,
.get_valid_dram_page_orders = gaudi_get_valid_dram_page_orders,
}; };
/** /**
......
...@@ -5679,6 +5679,12 @@ static u32 *goya_get_stream_master_qid_arr(void) ...@@ -5679,6 +5679,12 @@ static u32 *goya_get_stream_master_qid_arr(void)
return NULL; return NULL;
} }
static void goya_get_valid_dram_page_orders(struct hl_info_dev_memalloc_page_sizes *info)
{
/* set 0 since multiple pages are not supported */
info->page_order_bitmask = 0;
}
static const struct hl_asic_funcs goya_funcs = { static const struct hl_asic_funcs goya_funcs = {
.early_init = goya_early_init, .early_init = goya_early_init,
.early_fini = goya_early_fini, .early_fini = goya_early_fini,
...@@ -5767,6 +5773,7 @@ static const struct hl_asic_funcs goya_funcs = { ...@@ -5767,6 +5773,7 @@ static const struct hl_asic_funcs goya_funcs = {
.get_stream_master_qid_arr = goya_get_stream_master_qid_arr, .get_stream_master_qid_arr = goya_get_stream_master_qid_arr,
.is_valid_dram_page_size = NULL, .is_valid_dram_page_size = NULL,
.mmu_get_real_page_size = hl_mmu_get_real_page_size, .mmu_get_real_page_size = hl_mmu_get_real_page_size,
.get_valid_dram_page_orders = goya_get_valid_dram_page_orders,
}; };
/* /*
......
...@@ -348,33 +348,35 @@ enum hl_server_type { ...@@ -348,33 +348,35 @@ enum hl_server_type {
* The address which accessing it caused the razwi. * The address which accessing it caused the razwi.
* Razwi initiator. * Razwi initiator.
* Razwi cause, was it a page fault or MMU access error. * Razwi cause, was it a page fault or MMU access error.
* HL_INFO_DEV_MEM_ALLOC_PAGE_SIZES - Retrieve valid page sizes for device memory allocation
*/ */
#define HL_INFO_HW_IP_INFO 0 #define HL_INFO_HW_IP_INFO 0
#define HL_INFO_HW_EVENTS 1 #define HL_INFO_HW_EVENTS 1
#define HL_INFO_DRAM_USAGE 2 #define HL_INFO_DRAM_USAGE 2
#define HL_INFO_HW_IDLE 3 #define HL_INFO_HW_IDLE 3
#define HL_INFO_DEVICE_STATUS 4 #define HL_INFO_DEVICE_STATUS 4
#define HL_INFO_DEVICE_UTILIZATION 6 #define HL_INFO_DEVICE_UTILIZATION 6
#define HL_INFO_HW_EVENTS_AGGREGATE 7 #define HL_INFO_HW_EVENTS_AGGREGATE 7
#define HL_INFO_CLK_RATE 8 #define HL_INFO_CLK_RATE 8
#define HL_INFO_RESET_COUNT 9 #define HL_INFO_RESET_COUNT 9
#define HL_INFO_TIME_SYNC 10 #define HL_INFO_TIME_SYNC 10
#define HL_INFO_CS_COUNTERS 11 #define HL_INFO_CS_COUNTERS 11
#define HL_INFO_PCI_COUNTERS 12 #define HL_INFO_PCI_COUNTERS 12
#define HL_INFO_CLK_THROTTLE_REASON 13 #define HL_INFO_CLK_THROTTLE_REASON 13
#define HL_INFO_SYNC_MANAGER 14 #define HL_INFO_SYNC_MANAGER 14
#define HL_INFO_TOTAL_ENERGY 15 #define HL_INFO_TOTAL_ENERGY 15
#define HL_INFO_PLL_FREQUENCY 16 #define HL_INFO_PLL_FREQUENCY 16
#define HL_INFO_POWER 17 #define HL_INFO_POWER 17
#define HL_INFO_OPEN_STATS 18 #define HL_INFO_OPEN_STATS 18
#define HL_INFO_DRAM_REPLACED_ROWS 21 #define HL_INFO_DRAM_REPLACED_ROWS 21
#define HL_INFO_DRAM_PENDING_ROWS 22 #define HL_INFO_DRAM_PENDING_ROWS 22
#define HL_INFO_LAST_ERR_OPEN_DEV_TIME 23 #define HL_INFO_LAST_ERR_OPEN_DEV_TIME 23
#define HL_INFO_CS_TIMEOUT_EVENT 24 #define HL_INFO_CS_TIMEOUT_EVENT 24
#define HL_INFO_RAZWI_EVENT 25 #define HL_INFO_RAZWI_EVENT 25
#define HL_INFO_DEV_MEM_ALLOC_PAGE_SIZES 26
#define HL_INFO_VERSION_MAX_LEN 128
#define HL_INFO_CARD_NAME_MAX_LEN 16 #define HL_INFO_VERSION_MAX_LEN 128
#define HL_INFO_CARD_NAME_MAX_LEN 16
/** /**
* struct hl_info_hw_ip_info - hardware information on various IPs in the ASIC * struct hl_info_hw_ip_info - hardware information on various IPs in the ASIC
...@@ -643,6 +645,15 @@ struct hl_info_razwi_event { ...@@ -643,6 +645,15 @@ struct hl_info_razwi_event {
__u8 pad[2]; __u8 pad[2];
}; };
/**
* struct hl_info_dev_memalloc_page_sizes - valid page sizes in device mem alloc information.
* @page_order_bitmask: bitmap in which a set bit represents the order of the supported page size
* (e.g. 0x2100000 means that 1MB and 32MB pages are supported).
*/
struct hl_info_dev_memalloc_page_sizes {
__u64 page_order_bitmask;
};
enum gaudi_dcores { enum gaudi_dcores {
HL_GAUDI_WS_DCORE, HL_GAUDI_WS_DCORE,
HL_GAUDI_WN_DCORE, HL_GAUDI_WN_DCORE,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment