Florinel Iordache | ae6d852 | 2019-11-19 10:28:17 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Data Path Soft Parser |
| 4 | * |
| 5 | * Copyright 2018 NXP |
| 6 | */ |
| 7 | #include <fsl-mc/fsl_mc_sys.h> |
| 8 | #include <fsl-mc/fsl_mc_cmd.h> |
| 9 | #include <fsl-mc/fsl_dpsparser.h> |
| 10 | |
| 11 | int dpsparser_open(struct fsl_mc_io *mc_io, |
| 12 | u32 cmd_flags, |
| 13 | u16 *token) |
| 14 | { |
| 15 | struct mc_command cmd = { 0 }; |
| 16 | int err; |
| 17 | |
| 18 | /* prepare command */ |
| 19 | cmd.header = mc_encode_cmd_header(DPSPARSER_CMDID_OPEN, |
| 20 | cmd_flags, |
| 21 | 0); |
| 22 | |
| 23 | /* send command to mc*/ |
| 24 | err = mc_send_command(mc_io, &cmd); |
| 25 | if (err) |
| 26 | return err; |
| 27 | |
| 28 | /* retrieve response parameters */ |
| 29 | *token = MC_CMD_HDR_READ_TOKEN(cmd.header); |
| 30 | |
| 31 | return err; |
| 32 | } |
| 33 | |
| 34 | int dpsparser_close(struct fsl_mc_io *mc_io, |
| 35 | u32 cmd_flags, |
| 36 | u16 token) |
| 37 | { |
| 38 | struct mc_command cmd = { 0 }; |
| 39 | |
| 40 | /* prepare command */ |
| 41 | cmd.header = mc_encode_cmd_header(DPSPARSER_CMDID_CLOSE, cmd_flags, |
| 42 | token); |
| 43 | |
| 44 | /* send command to mc*/ |
| 45 | return mc_send_command(mc_io, &cmd); |
| 46 | } |
| 47 | |
| 48 | int dpsparser_create(struct fsl_mc_io *mc_io, |
| 49 | u16 token, |
| 50 | u32 cmd_flags, |
| 51 | u32 *obj_id) |
| 52 | { |
| 53 | struct mc_command cmd = { 0 }; |
| 54 | int err; |
| 55 | |
| 56 | /* prepare command */ |
| 57 | cmd.header = mc_encode_cmd_header(DPSPARSER_CMDID_CREATE, |
| 58 | cmd_flags, |
| 59 | token); |
| 60 | |
| 61 | /* send command to mc*/ |
| 62 | err = mc_send_command(mc_io, &cmd); |
| 63 | if (err) |
| 64 | return err; |
| 65 | |
| 66 | /* retrieve response parameters */ |
| 67 | MC_CMD_READ_OBJ_ID(cmd, *obj_id); |
| 68 | |
| 69 | return 0; |
| 70 | } |
| 71 | |
| 72 | int dpsparser_destroy(struct fsl_mc_io *mc_io, |
| 73 | u16 token, |
| 74 | u32 cmd_flags, |
| 75 | u32 obj_id) |
| 76 | { |
| 77 | struct mc_command cmd = { 0 }; |
| 78 | |
| 79 | /* prepare command */ |
| 80 | cmd.header = mc_encode_cmd_header(DPSPARSER_CMDID_DESTROY, |
| 81 | cmd_flags, |
| 82 | token); |
| 83 | |
| 84 | /* set object id to destroy */ |
| 85 | CMD_DESTROY_SET_OBJ_ID_PARAM0(cmd, obj_id); |
| 86 | |
| 87 | /* send command to mc*/ |
| 88 | return mc_send_command(mc_io, &cmd); |
| 89 | } |
| 90 | |
| 91 | int dpsparser_apply_spb(struct fsl_mc_io *mc_io, |
| 92 | u32 cmd_flags, |
| 93 | u16 token, |
| 94 | u64 blob_addr, |
| 95 | u16 *error) |
| 96 | { |
| 97 | struct mc_command cmd = { 0 }; |
| 98 | int err; |
| 99 | |
| 100 | /* prepare command */ |
| 101 | cmd.header = mc_encode_cmd_header(DPSPARSER_CMDID_APPLY_SPB, |
| 102 | cmd_flags, |
| 103 | token); |
| 104 | DPSPARSER_CMD_BLOB_SET_ADDR(cmd, blob_addr); |
| 105 | |
| 106 | /* send command to mc*/ |
| 107 | err = mc_send_command(mc_io, &cmd); |
| 108 | if (err) |
| 109 | return err; |
| 110 | |
| 111 | /* retrieve response parameters: MC error code */ |
| 112 | DPSPARSER_CMD_BLOB_REPORT_ERROR(cmd, *error); |
| 113 | |
| 114 | return 0; |
| 115 | } |
| 116 | |
| 117 | int dpsparser_get_api_version(struct fsl_mc_io *mc_io, |
| 118 | u32 cmd_flags, |
| 119 | u16 *major_ver, |
| 120 | u16 *minor_ver) |
| 121 | { |
| 122 | struct mc_command cmd = { 0 }; |
| 123 | int err; |
| 124 | |
| 125 | /* prepare command */ |
| 126 | cmd.header = mc_encode_cmd_header(DPSPARSER_CMDID_GET_API_VERSION, |
| 127 | cmd_flags, 0); |
| 128 | |
| 129 | /* send command to mc */ |
| 130 | err = mc_send_command(mc_io, &cmd); |
| 131 | if (err) |
| 132 | return err; |
| 133 | |
| 134 | /* retrieve response parameters */ |
| 135 | mc_cmd_read_api_version(&cmd, major_ver, minor_ver); |
| 136 | |
| 137 | return 0; |
| 138 | } |