1/*
2 * Freescale Management Complex (MC) bus private declarations
3 *
4 * Copyright (C) 2014 Freescale Semiconductor, Inc.
5 * Author: German Rivera <German.Rivera@freescale.com>
6 *
7 * This file is licensed under the terms of the GNU General Public
8 * License version 2. This program is licensed "as is" without any
9 * warranty of any kind, whether express or implied.
10 */
11#ifndef _FSL_MC_PRIVATE_H_
12#define _FSL_MC_PRIVATE_H_
13
14#include "../include/mc.h"
15#include <linux/mutex.h>
16#include <linux/stringify.h>
17
18#define FSL_MC_DPRC_DRIVER_NAME    "fsl_mc_dprc"
19
20#define FSL_MC_DEVICE_MATCH(_mc_dev, _obj_desc) \
21	(strcmp((_mc_dev)->obj_desc.type, (_obj_desc)->type) == 0 && \
22	 (_mc_dev)->obj_desc.id == (_obj_desc)->id)
23
24#define FSL_MC_IS_ALLOCATABLE(_obj_type) \
25	(strcmp(_obj_type, "dpbp") == 0 || \
26	 strcmp(_obj_type, "dpmcp") == 0 || \
27	 strcmp(_obj_type, "dpcon") == 0)
28
29/**
30 * struct fsl_mc - Private data of a "fsl,qoriq-mc" platform device
31 * @root_mc_bus_dev: MC object device representing the root DPRC
32 * @addr_translation_ranges: array of bus to system address translation ranges
33 */
34struct fsl_mc {
35	struct fsl_mc_device *root_mc_bus_dev;
36	uint8_t num_translation_ranges;
37	struct fsl_mc_addr_translation_range *translation_ranges;
38};
39
40/**
41 * struct fsl_mc_addr_translation_range - bus to system address translation
42 * range
43 * @start_mc_addr: Start MC address of the range being translated
44 * @end_mc_addr: MC address of the first byte after the range (last MC
45 * address of the range is end_mc_addr - 1)
46 * @start_phys_addr: system physical address corresponding to start_mc_addr
47 */
48struct fsl_mc_addr_translation_range {
49	uint64_t start_mc_addr;
50	uint64_t end_mc_addr;
51	phys_addr_t start_phys_addr;
52};
53
54/**
55 * struct fsl_mc_resource_pool - Pool of MC resources of a given
56 * type
57 * @type: type of resources in the pool
58 * @max_count: maximum number of resources in the pool
59 * @free_count: number of free resources in the pool
60 * @mutex: mutex to serialize access to the pool's free list
61 * @free_list: anchor node of list of free resources in the pool
62 * @mc_bus: pointer to the MC bus that owns this resource pool
63 */
64struct fsl_mc_resource_pool {
65	enum fsl_mc_pool_type type;
66	int16_t max_count;
67	int16_t free_count;
68	struct mutex mutex;	/* serializes access to free_list */
69	struct list_head free_list;
70	struct fsl_mc_bus *mc_bus;
71};
72
73/**
74 * struct fsl_mc_bus - logical bus that corresponds to a physical DPRC
75 * @mc_dev: fsl-mc device for the bus device itself.
76 * @resource_pools: array of resource pools (one pool per resource type)
77 * for this MC bus. These resources represent allocatable entities
78 * from the physical DPRC.
79 * @scan_mutex: Serializes bus scanning
80 */
81struct fsl_mc_bus {
82	struct fsl_mc_device mc_dev;
83	struct fsl_mc_resource_pool resource_pools[FSL_MC_NUM_POOL_TYPES];
84	struct mutex scan_mutex;    /* serializes bus scanning */
85};
86
87#define to_fsl_mc_bus(_mc_dev) \
88	container_of(_mc_dev, struct fsl_mc_bus, mc_dev)
89
90int __must_check fsl_mc_device_add(struct dprc_obj_desc *obj_desc,
91				   struct fsl_mc_io *mc_io,
92				   struct device *parent_dev,
93				   struct fsl_mc_device **new_mc_dev);
94
95void fsl_mc_device_remove(struct fsl_mc_device *mc_dev);
96
97int dprc_scan_container(struct fsl_mc_device *mc_bus_dev);
98
99int dprc_scan_objects(struct fsl_mc_device *mc_bus_dev);
100
101int __init dprc_driver_init(void);
102
103void __exit dprc_driver_exit(void);
104
105int __init fsl_mc_allocator_driver_init(void);
106
107void __exit fsl_mc_allocator_driver_exit(void);
108
109int __must_check fsl_mc_resource_allocate(struct fsl_mc_bus *mc_bus,
110					  enum fsl_mc_pool_type pool_type,
111					  struct fsl_mc_resource
112							  **new_resource);
113
114void fsl_mc_resource_free(struct fsl_mc_resource *resource);
115
116#endif /* _FSL_MC_PRIVATE_H_ */
117