This source file includes following definitions.
- zynqmp_pm_argument_value
- get_pm_api_id
- process_api_request
- zynqmp_pm_debugfs_api_write
- zynqmp_pm_debugfs_api_read
- zynqmp_pm_api_debugfs_init
- zynqmp_pm_api_debugfs_exit
   1 
   2 
   3 
   4 
   5 
   6 
   7 
   8 
   9 
  10 
  11 
  12 
  13 #include <linux/compiler.h>
  14 #include <linux/module.h>
  15 #include <linux/slab.h>
  16 #include <linux/debugfs.h>
  17 #include <linux/uaccess.h>
  18 
  19 #include <linux/firmware/xlnx-zynqmp.h>
  20 #include "zynqmp-debug.h"
  21 
  22 #define PM_API_NAME_LEN                 50
  23 
  24 struct pm_api_info {
  25         u32 api_id;
  26         char api_name[PM_API_NAME_LEN];
  27         char api_name_len;
  28 };
  29 
  30 static char debugfs_buf[PAGE_SIZE];
  31 
  32 #define PM_API(id)               {id, #id, strlen(#id)}
  33 static struct pm_api_info pm_api_list[] = {
  34         PM_API(PM_GET_API_VERSION),
  35         PM_API(PM_QUERY_DATA),
  36 };
  37 
  38 struct dentry *firmware_debugfs_root;
  39 
  40 
  41 
  42 
  43 
  44 
  45 
  46 
  47 static u64 zynqmp_pm_argument_value(char *arg)
  48 {
  49         u64 value;
  50 
  51         if (!arg)
  52                 return 0;
  53 
  54         if (!kstrtou64(arg, 0, &value))
  55                 return value;
  56 
  57         return 0;
  58 }
  59 
  60 
  61 
  62 
  63 
  64 
  65 
  66 
  67 static int get_pm_api_id(char *pm_api_req, u32 *pm_id)
  68 {
  69         int i;
  70 
  71         for (i = 0; i < ARRAY_SIZE(pm_api_list) ; i++) {
  72                 if (!strncasecmp(pm_api_req, pm_api_list[i].api_name,
  73                                  pm_api_list[i].api_name_len)) {
  74                         *pm_id = pm_api_list[i].api_id;
  75                         break;
  76                 }
  77         }
  78 
  79         
  80         if (i == ARRAY_SIZE(pm_api_list) && kstrtouint(pm_api_req, 10, pm_id))
  81                 return -EINVAL;
  82 
  83         return 0;
  84 }
  85 
  86 static int process_api_request(u32 pm_id, u64 *pm_api_arg, u32 *pm_api_ret)
  87 {
  88         const struct zynqmp_eemi_ops *eemi_ops = zynqmp_pm_get_eemi_ops();
  89         u32 pm_api_version;
  90         int ret;
  91         struct zynqmp_pm_query_data qdata = {0};
  92 
  93         switch (pm_id) {
  94         case PM_GET_API_VERSION:
  95                 ret = eemi_ops->get_api_version(&pm_api_version);
  96                 sprintf(debugfs_buf, "PM-API Version = %d.%d\n",
  97                         pm_api_version >> 16, pm_api_version & 0xffff);
  98                 break;
  99         case PM_QUERY_DATA:
 100                 qdata.qid = pm_api_arg[0];
 101                 qdata.arg1 = pm_api_arg[1];
 102                 qdata.arg2 = pm_api_arg[2];
 103                 qdata.arg3 = pm_api_arg[3];
 104 
 105                 ret = eemi_ops->query_data(qdata, pm_api_ret);
 106                 if (ret)
 107                         break;
 108 
 109                 switch (qdata.qid) {
 110                 case PM_QID_CLOCK_GET_NAME:
 111                         sprintf(debugfs_buf, "Clock name = %s\n",
 112                                 (char *)pm_api_ret);
 113                         break;
 114                 case PM_QID_CLOCK_GET_FIXEDFACTOR_PARAMS:
 115                         sprintf(debugfs_buf, "Multiplier = %d, Divider = %d\n",
 116                                 pm_api_ret[1], pm_api_ret[2]);
 117                         break;
 118                 default:
 119                         sprintf(debugfs_buf,
 120                                 "data[0] = 0x%08x\ndata[1] = 0x%08x\n data[2] = 0x%08x\ndata[3] = 0x%08x\n",
 121                                 pm_api_ret[0], pm_api_ret[1],
 122                                 pm_api_ret[2], pm_api_ret[3]);
 123                 }
 124                 break;
 125         default:
 126                 sprintf(debugfs_buf, "Unsupported PM-API request\n");
 127                 ret = -EINVAL;
 128         }
 129 
 130         return ret;
 131 }
 132 
 133 
 134 
 135 
 136 
 137 
 138 
 139 
 140 
 141 
 142 
 143 
 144 
 145 
 146 
 147 static ssize_t zynqmp_pm_debugfs_api_write(struct file *file,
 148                                            const char __user *ptr, size_t len,
 149                                            loff_t *off)
 150 {
 151         char *kern_buff, *tmp_buff;
 152         char *pm_api_req;
 153         u32 pm_id = 0;
 154         u64 pm_api_arg[4] = {0, 0, 0, 0};
 155         
 156         u32 pm_api_ret[4] = {0, 0, 0, 0};
 157 
 158         int ret;
 159         int i = 0;
 160 
 161         strcpy(debugfs_buf, "");
 162 
 163         if (*off != 0 || len <= 1 || len > PAGE_SIZE - 1)
 164                 return -EINVAL;
 165 
 166         kern_buff = memdup_user_nul(ptr, len);
 167         if (IS_ERR(kern_buff))
 168                 return PTR_ERR(kern_buff);
 169         tmp_buff = kern_buff;
 170 
 171         
 172         pm_api_req = strsep(&kern_buff, " ");
 173 
 174         ret = get_pm_api_id(pm_api_req, &pm_id);
 175         if (ret < 0)
 176                 goto err;
 177 
 178         
 179         pm_api_req = strsep(&kern_buff, " ");
 180         while ((i < ARRAY_SIZE(pm_api_arg)) && pm_api_req) {
 181                 pm_api_arg[i++] = zynqmp_pm_argument_value(pm_api_req);
 182                 pm_api_req = strsep(&kern_buff, " ");
 183         }
 184 
 185         ret = process_api_request(pm_id, pm_api_arg, pm_api_ret);
 186 
 187 err:
 188         kfree(tmp_buff);
 189         if (ret)
 190                 return ret;
 191 
 192         return len;
 193 }
 194 
 195 
 196 
 197 
 198 
 199 
 200 
 201 
 202 
 203 
 204 
 205 static ssize_t zynqmp_pm_debugfs_api_read(struct file *file, char __user *ptr,
 206                                           size_t len, loff_t *off)
 207 {
 208         return simple_read_from_buffer(ptr, len, off, debugfs_buf,
 209                                        strlen(debugfs_buf));
 210 }
 211 
 212 
 213 static const struct file_operations fops_zynqmp_pm_dbgfs = {
 214         .owner = THIS_MODULE,
 215         .write = zynqmp_pm_debugfs_api_write,
 216         .read = zynqmp_pm_debugfs_api_read,
 217 };
 218 
 219 
 220 
 221 
 222 
 223 
 224 void zynqmp_pm_api_debugfs_init(void)
 225 {
 226         
 227         firmware_debugfs_root = debugfs_create_dir("zynqmp-firmware", NULL);
 228         debugfs_create_file("pm", 0660, firmware_debugfs_root, NULL,
 229                             &fops_zynqmp_pm_dbgfs);
 230 }
 231 
 232 
 233 
 234 
 235 
 236 
 237 void zynqmp_pm_api_debugfs_exit(void)
 238 {
 239         debugfs_remove_recursive(firmware_debugfs_root);
 240 }