ti_sci.c (9b98e02a3d369c5d0875338ea0717030471b5210) ti_sci.c (53bf2b0e4e4c1ff0a957474237f9dcd20036ca54)
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Texas Instruments System Control Interface Protocol Driver
4 *
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
6 * Nishanth Menon
7 */
8

--- 3194 unchanged lines hidden (view full) ---

3203 for (set = 0; set < res->sets; set++)
3204 count += res->desc[set].num;
3205
3206 return count;
3207}
3208EXPORT_SYMBOL_GPL(ti_sci_get_num_resources);
3209
3210/**
1// SPDX-License-Identifier: GPL-2.0
2/*
3 * Texas Instruments System Control Interface Protocol Driver
4 *
5 * Copyright (C) 2015-2016 Texas Instruments Incorporated - https://www.ti.com/
6 * Nishanth Menon
7 */
8

--- 3194 unchanged lines hidden (view full) ---

3203 for (set = 0; set < res->sets; set++)
3204 count += res->desc[set].num;
3205
3206 return count;
3207}
3208EXPORT_SYMBOL_GPL(ti_sci_get_num_resources);
3209
3210/**
3211 * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device
3211 * devm_ti_sci_get_resource_sets() - Get a TISCI resources assigned to a device
3212 * @handle: TISCI handle
3213 * @dev: Device pointer to which the resource is assigned
3214 * @dev_id: TISCI device id to which the resource is assigned
3212 * @handle: TISCI handle
3213 * @dev: Device pointer to which the resource is assigned
3214 * @dev_id: TISCI device id to which the resource is assigned
3215 * @of_prop: property name by which the resource are represented
3215 * @sub_types: Array of sub_types assigned corresponding to device
3216 * @sets: Number of sub_types
3216 *
3217 * Return: Pointer to ti_sci_resource if all went well else appropriate
3218 * error pointer.
3219 */
3217 *
3218 * Return: Pointer to ti_sci_resource if all went well else appropriate
3219 * error pointer.
3220 */
3220struct ti_sci_resource *
3221devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
3222 struct device *dev, u32 dev_id, char *of_prop)
3221static struct ti_sci_resource *
3222devm_ti_sci_get_resource_sets(const struct ti_sci_handle *handle,
3223 struct device *dev, u32 dev_id, u32 *sub_types,
3224 u32 sets)
3223{
3224 struct ti_sci_resource *res;
3225 bool valid_set = false;
3225{
3226 struct ti_sci_resource *res;
3227 bool valid_set = false;
3226 u32 resource_subtype;
3227 int i, ret;
3228
3229 res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
3230 if (!res)
3231 return ERR_PTR(-ENOMEM);
3232
3228 int i, ret;
3229
3230 res = devm_kzalloc(dev, sizeof(*res), GFP_KERNEL);
3231 if (!res)
3232 return ERR_PTR(-ENOMEM);
3233
3233 ret = of_property_count_elems_of_size(dev_of_node(dev), of_prop,
3234 sizeof(u32));
3235 if (ret < 0) {
3236 dev_err(dev, "%s resource type ids not available\n", of_prop);
3237 return ERR_PTR(ret);
3238 }
3239 res->sets = ret;
3240
3234 res->sets = sets;
3241 res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc),
3242 GFP_KERNEL);
3243 if (!res->desc)
3244 return ERR_PTR(-ENOMEM);
3245
3246 for (i = 0; i < res->sets; i++) {
3235 res->desc = devm_kcalloc(dev, res->sets, sizeof(*res->desc),
3236 GFP_KERNEL);
3237 if (!res->desc)
3238 return ERR_PTR(-ENOMEM);
3239
3240 for (i = 0; i < res->sets; i++) {
3247 ret = of_property_read_u32_index(dev_of_node(dev), of_prop, i,
3248 &resource_subtype);
3249 if (ret)
3250 return ERR_PTR(-EINVAL);
3251
3252 ret = handle->ops.rm_core_ops.get_range(handle, dev_id,
3241 ret = handle->ops.rm_core_ops.get_range(handle, dev_id,
3253 resource_subtype,
3242 sub_types[i],
3254 &res->desc[i].start,
3255 &res->desc[i].num);
3256 if (ret) {
3257 dev_dbg(dev, "dev = %d subtype %d not allocated for this host\n",
3243 &res->desc[i].start,
3244 &res->desc[i].num);
3245 if (ret) {
3246 dev_dbg(dev, "dev = %d subtype %d not allocated for this host\n",
3258 dev_id, resource_subtype);
3247 dev_id, sub_types[i]);
3259 res->desc[i].start = 0;
3260 res->desc[i].num = 0;
3261 continue;
3262 }
3263
3264 dev_dbg(dev, "dev = %d, subtype = %d, start = %d, num = %d\n",
3248 res->desc[i].start = 0;
3249 res->desc[i].num = 0;
3250 continue;
3251 }
3252
3253 dev_dbg(dev, "dev = %d, subtype = %d, start = %d, num = %d\n",
3265 dev_id, resource_subtype, res->desc[i].start,
3254 dev_id, sub_types[i], res->desc[i].start,
3266 res->desc[i].num);
3267
3268 valid_set = true;
3269 res->desc[i].res_map =
3270 devm_kzalloc(dev, BITS_TO_LONGS(res->desc[i].num) *
3271 sizeof(*res->desc[i].res_map), GFP_KERNEL);
3272 if (!res->desc[i].res_map)
3273 return ERR_PTR(-ENOMEM);
3274 }
3275 raw_spin_lock_init(&res->lock);
3276
3277 if (valid_set)
3278 return res;
3279
3280 return ERR_PTR(-EINVAL);
3281}
3282
3255 res->desc[i].num);
3256
3257 valid_set = true;
3258 res->desc[i].res_map =
3259 devm_kzalloc(dev, BITS_TO_LONGS(res->desc[i].num) *
3260 sizeof(*res->desc[i].res_map), GFP_KERNEL);
3261 if (!res->desc[i].res_map)
3262 return ERR_PTR(-ENOMEM);
3263 }
3264 raw_spin_lock_init(&res->lock);
3265
3266 if (valid_set)
3267 return res;
3268
3269 return ERR_PTR(-EINVAL);
3270}
3271
3272/**
3273 * devm_ti_sci_get_of_resource() - Get a TISCI resource assigned to a device
3274 * @handle: TISCI handle
3275 * @dev: Device pointer to which the resource is assigned
3276 * @dev_id: TISCI device id to which the resource is assigned
3277 * @of_prop: property name by which the resource are represented
3278 *
3279 * Return: Pointer to ti_sci_resource if all went well else appropriate
3280 * error pointer.
3281 */
3282struct ti_sci_resource *
3283devm_ti_sci_get_of_resource(const struct ti_sci_handle *handle,
3284 struct device *dev, u32 dev_id, char *of_prop)
3285{
3286 struct ti_sci_resource *res;
3287 u32 *sub_types;
3288 int sets;
3289
3290 sets = of_property_count_elems_of_size(dev_of_node(dev), of_prop,
3291 sizeof(u32));
3292 if (sets < 0) {
3293 dev_err(dev, "%s resource type ids not available\n", of_prop);
3294 return ERR_PTR(sets);
3295 }
3296
3297 sub_types = kcalloc(sets, sizeof(*sub_types), GFP_KERNEL);
3298 if (!sub_types)
3299 return ERR_PTR(-ENOMEM);
3300
3301 of_property_read_u32_array(dev_of_node(dev), of_prop, sub_types, sets);
3302 res = devm_ti_sci_get_resource_sets(handle, dev, dev_id, sub_types,
3303 sets);
3304
3305 kfree(sub_types);
3306 return res;
3307}
3308EXPORT_SYMBOL_GPL(devm_ti_sci_get_of_resource);
3309
3310/**
3311 * devm_ti_sci_get_resource() - Get a resource range assigned to the device
3312 * @handle: TISCI handle
3313 * @dev: Device pointer to which the resource is assigned
3314 * @dev_id: TISCI device id to which the resource is assigned
3315 * @suub_type: TISCI resource subytpe representing the resource.
3316 *
3317 * Return: Pointer to ti_sci_resource if all went well else appropriate
3318 * error pointer.
3319 */
3320struct ti_sci_resource *
3321devm_ti_sci_get_resource(const struct ti_sci_handle *handle, struct device *dev,
3322 u32 dev_id, u32 sub_type)
3323{
3324 return devm_ti_sci_get_resource_sets(handle, dev, dev_id, &sub_type, 1);
3325}
3326EXPORT_SYMBOL_GPL(devm_ti_sci_get_resource);
3327
3283static int tisci_reboot_handler(struct notifier_block *nb, unsigned long mode,
3284 void *cmd)
3285{
3286 struct ti_sci_info *info = reboot_to_ti_sci_info(nb);
3287 const struct ti_sci_handle *handle = &info->handle;
3288
3289 ti_sci_cmd_core_reboot(handle);
3290

--- 220 unchanged lines hidden ---
3328static int tisci_reboot_handler(struct notifier_block *nb, unsigned long mode,
3329 void *cmd)
3330{
3331 struct ti_sci_info *info = reboot_to_ti_sci_info(nb);
3332 const struct ti_sci_handle *handle = &info->handle;
3333
3334 ti_sci_cmd_core_reboot(handle);
3335

--- 220 unchanged lines hidden ---