2 * CAAM control-plane driver backend
3 * Controller-level driver, kernel property detection, initialization
5 * Copyright 2008-2011 Freescale Semiconductor, Inc.
13 static int caam_remove(struct platform_device
*pdev
)
15 struct device
*ctrldev
;
16 struct caam_drv_private
*ctrlpriv
;
17 struct caam_drv_private_jr
*jrpriv
;
18 struct caam_full __iomem
*topregs
;
22 ctrlpriv
= dev_get_drvdata(ctrldev
);
23 topregs
= (struct caam_full __iomem
*)ctrlpriv
->ctrl
;
26 for (ring
= 0; ring
< ctrlpriv
->total_jobrs
; ring
++) {
27 ret
|= caam_jr_shutdown(ctrlpriv
->jrdev
[ring
]);
28 jrpriv
= dev_get_drvdata(ctrlpriv
->jrdev
[ring
]);
29 irq_dispose_mapping(jrpriv
->irq
);
32 /* Shut down debug views */
33 #ifdef CONFIG_DEBUG_FS
34 debugfs_remove_recursive(ctrlpriv
->dfs_root
);
37 /* Unmap controller region */
38 iounmap(&topregs
->ctrl
);
40 kfree(ctrlpriv
->jrdev
);
46 /* Probe routine for CAAM top (controller) level */
47 static int caam_probe(struct platform_device
*pdev
)
51 struct device_node
*nprop
, *np
;
52 struct caam_ctrl __iomem
*ctrl
;
53 struct caam_full __iomem
*topregs
;
54 struct caam_drv_private
*ctrlpriv
;
55 #ifdef CONFIG_DEBUG_FS
56 struct caam_perfmon
*perfmon
;
59 ctrlpriv
= kzalloc(sizeof(struct caam_drv_private
), GFP_KERNEL
);
64 dev_set_drvdata(dev
, ctrlpriv
);
65 ctrlpriv
->pdev
= pdev
;
66 nprop
= pdev
->dev
.of_node
;
68 /* Get configuration properties from device tree */
69 /* First, get register page */
70 ctrl
= of_iomap(nprop
, 0);
72 dev_err(dev
, "caam: of_iomap() failed\n");
75 ctrlpriv
->ctrl
= (struct caam_ctrl __force
*)ctrl
;
77 /* topregs used to derive pointers to CAAM sub-blocks only */
78 topregs
= (struct caam_full __iomem
*)ctrl
;
80 /* Get the IRQ of the controller (for security violations only) */
81 ctrlpriv
->secvio_irq
= of_irq_to_resource(nprop
, 0, NULL
);
84 * Enable DECO watchdogs and, if this is a PHYS_ADDR_T_64BIT kernel,
85 * 36-bit pointers in master configuration register
87 setbits32(&topregs
->ctrl
.mcr
, MCFGR_WDENABLE
|
88 (sizeof(dma_addr_t
) == sizeof(u64
) ? MCFGR_LONG_PTR
: 0));
90 if (sizeof(dma_addr_t
) == sizeof(u64
))
91 dma_set_mask(dev
, DMA_BIT_MASK(36));
94 * Detect and enable JobRs
95 * First, find out how many ring spec'ed, allocate references
96 * for all, then go probe each one.
99 for_each_compatible_node(np
, NULL
, "fsl,sec-v4.0-job-ring")
101 ctrlpriv
->jrdev
= kzalloc(sizeof(struct device
*) * rspec
, GFP_KERNEL
);
102 if (ctrlpriv
->jrdev
== NULL
) {
103 iounmap(&topregs
->ctrl
);
108 ctrlpriv
->total_jobrs
= 0;
109 for_each_compatible_node(np
, NULL
, "fsl,sec-v4.0-job-ring") {
110 caam_jr_probe(pdev
, np
, ring
);
111 ctrlpriv
->total_jobrs
++;
115 /* Check to see if QI present. If so, enable */
116 ctrlpriv
->qi_present
= !!(rd_reg64(&topregs
->ctrl
.perfmon
.comp_parms
) &
118 if (ctrlpriv
->qi_present
) {
119 ctrlpriv
->qi
= (struct caam_queue_if __force
*)&topregs
->qi
;
120 /* This is all that's required to physically enable QI */
121 wr_reg32(&topregs
->qi
.qi_control_lo
, QICTL_DQEN
);
124 /* If no QI and no rings specified, quit and go home */
125 if ((!ctrlpriv
->qi_present
) && (!ctrlpriv
->total_jobrs
)) {
126 dev_err(dev
, "no queues configured, terminating\n");
131 /* NOTE: RTIC detection ought to go here, around Si time */
133 /* Initialize queue allocator lock */
134 spin_lock_init(&ctrlpriv
->jr_alloc_lock
);
136 /* Report "alive" for developer to see */
137 dev_info(dev
, "device ID = 0x%016llx\n",
138 rd_reg64(&topregs
->ctrl
.perfmon
.caam_id
));
139 dev_info(dev
, "job rings = %d, qi = %d\n",
140 ctrlpriv
->total_jobrs
, ctrlpriv
->qi_present
);
142 #ifdef CONFIG_DEBUG_FS
144 * FIXME: needs better naming distinction, as some amalgamation of
145 * "caam" and nprop->full_name. The OF name isn't distinctive,
146 * but does separate instances
148 perfmon
= (struct caam_perfmon __force
*)&ctrl
->perfmon
;
150 ctrlpriv
->dfs_root
= debugfs_create_dir("caam", NULL
);
151 ctrlpriv
->ctl
= debugfs_create_dir("ctl", ctrlpriv
->dfs_root
);
153 /* Controller-level - performance monitor counters */
154 ctrlpriv
->ctl_rq_dequeued
=
155 debugfs_create_u64("rq_dequeued",
156 S_IRUSR
| S_IRGRP
| S_IROTH
,
157 ctrlpriv
->ctl
, &perfmon
->req_dequeued
);
158 ctrlpriv
->ctl_ob_enc_req
=
159 debugfs_create_u64("ob_rq_encrypted",
160 S_IRUSR
| S_IRGRP
| S_IROTH
,
161 ctrlpriv
->ctl
, &perfmon
->ob_enc_req
);
162 ctrlpriv
->ctl_ib_dec_req
=
163 debugfs_create_u64("ib_rq_decrypted",
164 S_IRUSR
| S_IRGRP
| S_IROTH
,
165 ctrlpriv
->ctl
, &perfmon
->ib_dec_req
);
166 ctrlpriv
->ctl_ob_enc_bytes
=
167 debugfs_create_u64("ob_bytes_encrypted",
168 S_IRUSR
| S_IRGRP
| S_IROTH
,
169 ctrlpriv
->ctl
, &perfmon
->ob_enc_bytes
);
170 ctrlpriv
->ctl_ob_prot_bytes
=
171 debugfs_create_u64("ob_bytes_protected",
172 S_IRUSR
| S_IRGRP
| S_IROTH
,
173 ctrlpriv
->ctl
, &perfmon
->ob_prot_bytes
);
174 ctrlpriv
->ctl_ib_dec_bytes
=
175 debugfs_create_u64("ib_bytes_decrypted",
176 S_IRUSR
| S_IRGRP
| S_IROTH
,
177 ctrlpriv
->ctl
, &perfmon
->ib_dec_bytes
);
178 ctrlpriv
->ctl_ib_valid_bytes
=
179 debugfs_create_u64("ib_bytes_validated",
180 S_IRUSR
| S_IRGRP
| S_IROTH
,
181 ctrlpriv
->ctl
, &perfmon
->ib_valid_bytes
);
183 /* Controller level - global status values */
184 ctrlpriv
->ctl_faultaddr
=
185 debugfs_create_u64("fault_addr",
186 S_IRUSR
| S_IRGRP
| S_IROTH
,
187 ctrlpriv
->ctl
, &perfmon
->faultaddr
);
188 ctrlpriv
->ctl_faultdetail
=
189 debugfs_create_u32("fault_detail",
190 S_IRUSR
| S_IRGRP
| S_IROTH
,
191 ctrlpriv
->ctl
, &perfmon
->faultdetail
);
192 ctrlpriv
->ctl_faultstatus
=
193 debugfs_create_u32("fault_status",
194 S_IRUSR
| S_IRGRP
| S_IROTH
,
195 ctrlpriv
->ctl
, &perfmon
->status
);
197 /* Internal covering keys (useful in non-secure mode only) */
198 ctrlpriv
->ctl_kek_wrap
.data
= &ctrlpriv
->ctrl
->kek
[0];
199 ctrlpriv
->ctl_kek_wrap
.size
= KEK_KEY_SIZE
* sizeof(u32
);
200 ctrlpriv
->ctl_kek
= debugfs_create_blob("kek",
204 &ctrlpriv
->ctl_kek_wrap
);
206 ctrlpriv
->ctl_tkek_wrap
.data
= &ctrlpriv
->ctrl
->tkek
[0];
207 ctrlpriv
->ctl_tkek_wrap
.size
= KEK_KEY_SIZE
* sizeof(u32
);
208 ctrlpriv
->ctl_tkek
= debugfs_create_blob("tkek",
212 &ctrlpriv
->ctl_tkek_wrap
);
214 ctrlpriv
->ctl_tdsk_wrap
.data
= &ctrlpriv
->ctrl
->tdsk
[0];
215 ctrlpriv
->ctl_tdsk_wrap
.size
= KEK_KEY_SIZE
* sizeof(u32
);
216 ctrlpriv
->ctl_tdsk
= debugfs_create_blob("tdsk",
220 &ctrlpriv
->ctl_tdsk_wrap
);
225 static struct of_device_id caam_match
[] = {
227 .compatible
= "fsl,sec-v4.0",
231 MODULE_DEVICE_TABLE(of
, caam_match
);
233 static struct platform_driver caam_driver
= {
236 .owner
= THIS_MODULE
,
237 .of_match_table
= caam_match
,
240 .remove
= __devexit_p(caam_remove
),
243 module_platform_driver(caam_driver
);
245 MODULE_LICENSE("GPL");
246 MODULE_DESCRIPTION("FSL CAAM request backend");
247 MODULE_AUTHOR("Freescale Semiconductor - NMG/STC");