* Copyright (c) Huawei Technologies Co., Ltd. 2025-2025. All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 and
* only version 2 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef APM_KERNEL_IOCTL_H
#define APM_KERNEL_IOCTL_H
#include "ascend_hal_define.h"
If handled by the local os, it represents the pid from getpid(), otherwise it represents the kernel's tgid.
mode bind/unbind query_slave(device) query_slave(host) query_master(device) query_master(host)
master slave master slave master slave master slave master slave
offline pid pid pid pid pid pid
online(device slave) tgid pid tgid pid pid tgid tgid pid
online(host slave) pid pid pid pid pid pid
The kernel uses the tgid as the key to store binding information.
input devid is logic devid
output devid is udevid
bind sequence: Update the slave tables and then the master tables. Update the local before updating the remote.
offline: slave tables ---> master tables
online(device slave): device slave tables ---> host slave proxy tables ---> host master tables
---> device master proxy tables
online(host slave): host slave tables ---> host master tables ---> device slave proxy tables
---> device master proxy tables
query: consider the bind sequence, if the query in the proxy tables fails, we will query the original
tables at the remote end.
*/
#define APM_CHAR_DEV_NAME "apm"
#define APM_LOGIC_DEV_MAX_NUM 64
struct apm_cmd_get_sign {
unsigned int cur_tgid;
unsigned int rsv[4];
};
struct apm_cmd_query_slave_pid {
unsigned int devid;
int proc_type;
int master_pid;
unsigned int query_in_all_stage;
int slave_pid;
int slave_tgid;
unsigned int rsv[4];
};
struct apm_cmd_bind {
unsigned int devid;
int proc_type;
int mode;
int master_pid;
int slave_pid;
unsigned int rsv[4];
};
struct apm_cmd_query_master_info {
unsigned int slave_pid;
unsigned int master_pid;
unsigned int master_tgid;
unsigned int udevid;
int mode;
unsigned int proc_type_bitmap;
unsigned int rsv[4];
};
struct apm_cmd_res_map {
unsigned int devid;
struct res_map_info_in res_info;
unsigned long va;
unsigned int len;
unsigned int rsv[8];
};
struct apm_cmd_res_unmap {
unsigned int devid;
struct res_map_info_in res_info;
unsigned int rsv[8];
};
enum apm_cmd_slave_status_type {
CMD_SLAVE_STATUS_TYPE_OOM,
CMD_SLAVE_STATUS_TYPE_MAX
};
struct apm_cmd_slave_status {
unsigned int devid;
int proc_type;
enum apm_cmd_slave_status_type type;
int status;
unsigned int rsv[4];
};
struct apm_cmd_slave_ssid {
unsigned int devid;
int proc_type;
int ssid;
unsigned int rsv[4];
};
typedef enum tagProcMemType {
PROC_MEM_TYPE_ALL = 0,
PROC_MEM_TYPE_VMRSS,
PROC_MEM_TYPE_SP,
PROC_MEM_MAX
} processMemType_t;
struct apm_cmd_slave_meminfo {
unsigned int devid;
int proc_type;
int master_pid;
processMemType_t type;
unsigned long long size;
unsigned int rsv[4];
};
struct apm_cmd_bind_cgroup {
BIND_CGROUP_TYPE bind_type;
unsigned int rsv[4];
};
#define APM_GET_SIGN _IOR('U', 0, struct apm_cmd_get_sign)
rc: device master tables; ep: host master tables(from host query), host master proxy tables(from device query) */
#define APM_QUERY_SLAVE_PID _IOWR('U', 1, struct apm_cmd_query_slave_pid)
rc: device master tables; ep: host master tables(from host query), device master tables(from device query) */
#define APM_QUERY_SLAVE_PID_BY_LOCAL_MASTER _IOWR('U', 2, struct apm_cmd_query_slave_pid)
#define APM_BIND _IOW('U', 3, struct apm_cmd_bind)
#define APM_UNBIND _IOW('U', 4, struct apm_cmd_bind)
rc: device slave tables; ep: host slave tables(from host query), device slave tables(from device query) */
#define APM_QUERY_MASTER_INFO _IOWR('U', 5, struct apm_cmd_query_master_info)
rc: not support; ep: device slave proxy tables(from host query), host slave proxy tables(from device query) */
#define APM_QUERY_MASTER_INFO_BY_DEVICE_SLAVE _IOWR('U', 6, struct apm_cmd_query_master_info)
#define APM_QUERY_MASTER_INFO_BY_HOST_SLAVE _IOWR('U', 7, struct apm_cmd_query_master_info)
#define APM_RES_ADDR_MAP _IOWR('U', 8, struct apm_cmd_res_map)
#define APM_RES_ADDR_UNMAP _IOW('U', 9, struct apm_cmd_res_unmap)
#define APM_QUERY_SLAVE_STATUS _IOWR('U', 12, struct apm_cmd_slave_status)
#define APM_QUERY_SSID _IOWR('U', 13, struct apm_cmd_slave_ssid)
#define APM_QUERY_SLAVE_MEMINFO _IOWR('U', 14, struct apm_cmd_slave_meminfo)
#define APM_BIND_CGROUP _IOW('U', 15, struct apm_cmd_bind_cgroup)
#define APM_MAX_CMD 16
#endif