2 * Copyright (C) 2001-2003 by NBMK Encryption Technologies.
5 * NBMK Encryption Technologies provides no support of any kind for
6 * this software. Questions or concerns about it may be addressed to
7 * the members of the relevant open-source community at
8 * <tech-crypto@netbsd.org>.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions are
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above
18 * copyright notice, this list of conditions and the following
19 * disclaimer in the documentation and/or other materials provided
20 * with the distribution.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 static char const n8_id
[] = "$Id: config.c,v 1.2 2008/11/12 12:36:16 ad Exp $";
36 /*****************************************************************************/
38 * @brief NSP2000 Device Driver Configuration Manager.
40 * This file implements the configuration management routines for the NSP2000
43 *****************************************************************************/
45 /*****************************************************************************
47 * 02/15/04 jpw Dynamically allocate queue size based on the number of
48 * chips installed as counted by NSPcount_g. Note that FreeBSD
49 * currently requires this value to be forced since it doesn't
50 * know how to properly count devices.
51 * 05/15/03 brr Enable RNG interrupt, enable interrupts only in
52 * n8_enableInterrupts().
53 * 05/09/03 brr Add user pool count to driver infomation.
54 * 05/07/03 brr Do not fail HW resource allocation if SKS is not present.
55 * 04/30/03 brr Reconcile differences between 2.4 & 3.0 baselines.
56 * 04/21/03 brr Added support for multiple memory banks.
57 * 03/19/03 brr Modified N8_ConfigInterrupts to always enble the AMBA timer
58 * and the PK command complete interrupt.
59 * 03/03/03 jpw Added N8_EnableAmbaTimer_g param to N8_ConfigInterrupts
60 * 03/11/03 brr Added N8_CloseDevice so N8_InitializeAPI can be common.
61 * 03/10/03 brr Added N8_OpenDevice so N8_InitializeAPI can be common.
62 * 02/20/03 brr Removed references to shared memory.
63 * 11/25/02 brr Reworked initialization to us common functions to allocate
64 * all resources for NSP2000 driver and each chip.
65 * 10/23/02 brr Modified N8_ConfigInterrupts to accept parameter for
66 * the AMBA timer preset.
67 * 10/25/02 brr Clean up function prototypes & include files.
68 * 10/22/02 brr Retrieve driverMode in N8_GetConfig.
69 * 09/25/02 brr Eliminate references to EVENT_WAIT_TYPE.
70 * 09/10/02 brr Conditionally enable either the amba timer interrupt or
71 * the command completion interrupts.
72 * 07/08/02 brr Added N8_GetFD to return NULL fd for kernel API.
73 * 06/26/02 brr Remove bank parameter from calls to N8_PhysToVirt.
74 * 06/25/02 brr Rework user pool allocation to only mmap portion used by
75 * the individual process.
76 * 06/12/02 hml Calls to N8_PhysToVirt now take the bank parameter.
77 * 06/10/02 hml Calls to pmalloc now use the bank parameter
78 * 06/07/02 brr Call SKS_Remove to deallocate SKS resources.
79 * 05/30/02 brr Enable interrupts for error conditions.
80 * 05/22/02 hml Passed memCtlBank parameter to call to n8_pmalloc
82 * 05/09/02 brr Allocate and setup BNC constants.
83 * 05/02/02 brr Call SKS_Init to perform all SKS initialization. Do not
84 * allocate SKS map from memory pool.
85 * 04/03/02 brr Use N8_VERSION as defined in n8_version.h.
86 * 04/03/02 spm Removed #include of daemon headers.
87 * 03/29/02 brr Modified N8_ConfigInterrupts to use N8_AMBA_TIMER_CHIP.
88 * 03/20/02 msz Don't do consecutive 32 bit writes.
89 * 03/20/02 brr Modified N8_ConfigInterrupts to configure & enable
90 * interrupts on all detected devices.
91 * 03/19/02 msz Shadow memory is now called shared memory, and is not
93 * 03/18/02 brr Pass null session ID into pmalloc function.
94 * 03/18/02 msz We no longer need the shadow queue nor its memory
95 * 03/12/02 brr Moved daemon initialization to base.c
96 * 03/08/02 brr Memset SKS & shadow memory allocations to zero since
97 * n8_pmalloc is no longer clearing allocations.
98 * 03/01/02 brr Added N8_DisableInterrupts.
99 * 02/22/02 spm Converted printk's to DBG's. Added include of n8_OS_intf.h
100 * 02/25/02 brr Removed references to qmgrData & modified N8_GetConfig to
101 * return all driver information in a single call.
102 * 02/15/02 brr Moved context memory functions to contextMem.c.
103 * 02/14/02 brr Reconcile memory management differences with 2.0.
104 * 02/04/02 msz Enable interrupts for errors, pass hwidx so timer is enabled
106 * 01/25/02 bac Added include of bigalloc_support.h as required.
107 * 01/30/02 brr Modified to support changes in bigalloc.
108 * 01/21/02 msz Set up event wait type based on header options
109 * 01/21/02 brr Modified to remove the mmap on each buffer on allocation.
110 * 02/13/02 brr Conditionally initialize the daemon.
111 * 02/15/02 brr Moved context memory functions to contextMem.c.
112 * 01/21/02 spm Moved SKS_Prom2Cache to n8_sksInit.c.
113 * 01/19/02 spm Changed n8_daemon_kernel.h to n8_daemon_internals.h
114 * 01/17/02 spm Added call to n8_daemon_init to N8_AllocateHardwareResources.
115 * This does initialization of the N8 daemon.
116 * 01/17/02 brr Updated for new memory management scheme.
117 * 01/16/02 brr Removed FPGA support.
118 * 01/14/02 brr Correctly pass shadow register pointers to QMGR.
119 * 01/10/02 mmd Removed fixed context memory size. Modified
120 * N8_GetContextMemSize to simply return a size, and no longer
121 * return any kind of error. If Context Memory accesses fail,
122 * it now indicates 0 bytes available. Corrected the Context
123 * memory read/write routines to correctly read/write (no longer
124 * clearing pending ops, and no longer sleeping, but instead
125 * expecting any pending ops to complete within a reasonable
127 * 01/10/02 msz Disable bridge timer when we are done.
128 * 01/03/02 brr Setup and enable bridge timer.
129 * 12/21/01 brr Fix context memory size to 64MB.
130 * 12/20/01 brr Perform all static allocation with sessionID 0.
131 * 12/18/01 brr Perform all static allocation from n8_pmalloc.
132 * 12/14/01 brr Support dynamic queue sizing & memory management performance
134 * 12/06/01 brr Added seperate define for RNG queue sizing, moved SKS init
135 * to the driver, and correct context memory detection.
136 * 12/05/01 brr Move queue initialization to the driver.
137 * 11/26/01 mmd Updated parms for N8_ConfigInit to accomodate new PCIinfo
138 * field of NspInstance_t. Generally updated N8_ConfigInit and
139 * N8_GetConfig to ensure full support of both ASIC and FPGA.
140 * 11/14/01 mmd Using global parm defines from n8_driver_parms.h.
141 * 11/13/01 mmd Implemented N8_AllocateHardwareResources and
142 * N8_ReleaseHardwareResources;
143 * 11/10/01 brr Modified to support static allocations of persistant data
145 * 11/06/01 mmd Now calls admxrc_eeprom_read to determine values for
146 * FPGA_Type and FPGA_CrystalType.
147 * 10/29/01 mmd N8_OpenRulesChecker now uses N8_UTIL_MALLOC instead of
148 * N8_VIRT_MALLOC. N8_CloseRulesChecker now uses N8_UTIL_FREE.
149 * 10/22/01 mmd Implemented N8_ClaimHardwareInstance and
150 * N8_ReleaseHardwareInstance.
151 * 10/12/01 mmd Renamed Atomic*() routines to N8_Atomic*().
152 * 10/12/01 mmd Implemented N8_OpenRulesChecker, N8_CloseRulesChecker, and
153 * N8_PurgeNextRelatedSession, as well as the global process
154 * table. Also now initializing the programmed field of
156 * 09/25/01 mmd Creation.
157 ****************************************************************************/
158 /** @defgroup NSP2000Driver NSP2000 Device Driver Configuration Manager.
161 #include <sys/param.h>
162 #include <sys/systm.h>
163 #include <sys/proc.h>
164 #include <sys/endian.h>
166 #define letoh16 htole16
167 #define letoh32 htole32
169 #include <sys/errno.h>
170 #include <sys/malloc.h>
171 #include <sys/kernel.h>
172 #include <sys/mbuf.h>
173 #include <sys/device.h>
174 #include <sys/queue.h>
175 #include <sys/module.h>
178 #include <uvm/uvm_extern.h>
180 #include <opencrypto/cryptodev.h>
181 #include <opencrypto/xform.h>
184 #include <sys/sha1.h>
186 #include <dev/pci/pcireg.h>
187 #include <dev/pci/pcivar.h>
188 #include <dev/pci/pcidevs.h>
190 #include "n8_pub_errors.h"
191 #include "n8_driver_main.h"
193 #include "n8_manage_memory.h"
194 #include "n8_pk_common.h"
195 #include "n8_rn_common.h"
196 #include "n8_ea_common.h"
197 #include "n8_sksInit.h"
198 #include "QMgrInit.h"
200 #include "nsp2000_regs.h"
201 #include "n8_version.h"
202 #include "n8_memory.h"
203 #include "userPool.h"
204 #include "n8_driver_api.h"
206 #include "n8_OS_intf.h"
208 #include "n8_driver_main.h"
209 #include "n8_driver_parms.h"
211 #include "displayRegs.h"
212 #include "n8_memory.h"
213 #include "nsp_ioctl.h"
214 #include "n8_daemon_common.h"
215 #include "n8_sksInit.h"
216 #include "contextMem.h"
217 #include "n8_version.h"
218 #include "n8_pk_common.h"
219 #include "n8_rn_common.h"
221 #include "n8_driver_api.h"
222 #include "userPool.h"
223 #include "QMgrInit.h"
224 #include "n8_semaphore.h"
227 extern int NSPcount_g
;
228 extern NspInstance_t NSPDeviceTable_g
[];
231 unsigned long bncAddr
= 0;
232 n8_WaitQueue_t requestBlock
;
233 n8_WaitQueue_t nsp2000_wait
;
234 /*****************************************************************************
236 *****************************************************************************/
237 /** @ingroup NSP2000Driver
238 * @brief Allocates and initializes resources used by each nsp2000 core.
240 * This function allocates and initializes resources used by each nsp2000 core.
241 * It should be called once per chip detected as the driver is initialized.
244 * @param NSPinstance_p RO: Pointer to the information structure for an
245 * NSP2000 hardware instance, containing a
246 * pointer to its control register set.
247 * @param HWidx RO: Specifies the chip index.
248 * @param queueSize RO: The size of the command queue to allocate
249 * for the EA & PK cores.
250 * @param Debug RO: The value of the N8_Debug_g flag.
256 * See return section for error information.
257 *****************************************************************************/
259 int n8_chipInit( NspInstance_t
*NSPinstance_p
,
264 volatile NSP2000REGS_t
*nsp
= (NSP2000REGS_t
*)NSPinstance_p
->NSPregs_p
;
265 int queueLength
; /* Number of entries */
267 /* First store model identifiers */
268 DBG(("store model id\n"));
269 NSPinstance_p
->hardwareType
= N8_NSP2000_HW
;
270 NSPinstance_p
->HardwareVersion
= NSPinstance_p
->PCIinfo
.device_id
;
271 NSPinstance_p
->RevisionID
= NSPinstance_p
->PCIinfo
.revision_id
;
273 /* Initialize bus error statistics */
274 DBG(("bus error stats\n"));
275 NSPinstance_p
->RNHbuserrors
= 0;
276 NSPinstance_p
->PKHbuserrors
= 0;
277 NSPinstance_p
->CCHbuserrors
= 0;
279 /* Set the amba PCI endian mode register */
280 nsp
->amba_pci_endian_mode
= 0;
282 queueLength
= 1 << queueSize
;
284 /* Initialize sizes for allocated resources */
285 NSPinstance_p
->RNqueue_size
= 0;
286 NSPinstance_p
->PKqueue_size
= 0;
287 NSPinstance_p
->EAqueue_size
= 0;
289 /* Initialize physical base address of each queue and struct */
290 NSPinstance_p
->RNqueue_base
= 0;
291 NSPinstance_p
->PKqueue_base
= 0;
292 NSPinstance_p
->EAqueue_base
= 0;
294 NSPinstance_p
->chip
= HWidx
;
296 /* Allocate static resources */
299 bncAddr
= n8_pmalloc(N8_MEMBANK_QUEUE
, PKDIGITS_TO_BYTES(2), 0);
300 DBG(("n8_pmalloc(N8_MEMBANK_QUEUE) -> 0x%x\n",
305 bnc_one_p
= N8_PhysToVirt(bncAddr
);
306 DBG(("bncAddr 0x%x -> virt 0x%x\n",
308 (uint32_t)bnc_one_p
));
309 memset(bnc_one_p
, 0x0, PKDIGITS_TO_BYTES(2));
310 bnc_one_p
[PK_Bytes_Per_BigNum_Digit
- 1] = 1;
314 DBG(( "NSP2000: Failed BNC constant allocation.\n"));
318 NSPinstance_p
->RNqueue_base
= n8_pmalloc(N8_MEMBANK_QUEUE
,
319 N8_DEF_RNG_QUE_SIZE
*sizeof(RNG_Sample_t
),
321 if (!NSPinstance_p
->RNqueue_base
)
323 N8_PRINT(KERN_CRIT
"NSP2000: Failed RN queue allocation.\n");
326 NSPinstance_p
->PKqueue_base
= n8_pmalloc(N8_MEMBANK_QUEUE
,
327 queueLength
*sizeof(PK_CMD_BLOCK_t
),
329 if (!NSPinstance_p
->PKqueue_base
)
331 N8_PRINT(KERN_CRIT
"NSP2000: Failed PK queue allocation.\n");
334 NSPinstance_p
->EAqueue_base
= n8_pmalloc(N8_MEMBANK_QUEUE
,
335 queueLength
*sizeof(EA_CMD_BLOCK_t
),
337 if (!NSPinstance_p
->EAqueue_base
)
339 N8_PRINT(KERN_CRIT
"NSP2000: Failed EA queue allocation.\n");
343 /* Update sizes of allocated resources */
344 NSPinstance_p
->RNqueue_size
= N8_DEF_RNG_QUE_SIZE
;
345 NSPinstance_p
->PKqueue_size
= queueLength
;
346 NSPinstance_p
->EAqueue_size
= queueLength
;
349 /* Convert physical base address of each struct to a kernel virtual address*/
350 NSPinstance_p
->RNqueue_p
= N8_PhysToVirt(NSPinstance_p
->RNqueue_base
);
351 NSPinstance_p
->PKqueue_p
= N8_PhysToVirt(NSPinstance_p
->PKqueue_base
);
352 NSPinstance_p
->EAqueue_p
= N8_PhysToVirt(NSPinstance_p
->EAqueue_base
);
354 /* EAshared_p and PKshared_p are owned by QMgr and are thus set by QMgr */
356 /* Set the queue pointers */
361 nsp
->pkh_q_bar0
= NSPinstance_p
->PKqueue_base
;
362 nsp
->cch_q_bar0
= NSPinstance_p
->EAqueue_base
;
363 nsp
->rnh_q_bar0
= NSPinstance_p
->RNqueue_base
;
365 nsp
->pkh_q_length
= queueSize
;
366 nsp
->cch_q_length
= queueSize
;
367 nsp
->rnh_q_length
= N8_DEF_RNG_QUE_EXP
;
369 /* Initialize the SKS data structures. */
370 if (!SKS_Init(NSPinstance_p
))
372 N8_PRINT(KERN_CRIT
"NSP2000: Failed to Initialize SKS.\n");
375 /* Enable the EA & PK Queues since they need no parameters to start. */
376 nsp
->pkh_control_status
|= NSP_CORE_ENABLE
;
377 nsp
->cch_control_status
|= NSP_CORE_ENABLE
;
381 /* Announce allocations */
382 N8_PRINT(KERN_CRIT
"NSP2000: Allocated RN queue - %ld entries @ %08lx.\n",
383 NSPinstance_p
->RNqueue_size
, NSPinstance_p
->RNqueue_base
);
384 N8_PRINT(KERN_CRIT
"NSP2000: Allocated PK queue - %ld entries @ %08lx.\n",
385 NSPinstance_p
->PKqueue_size
, NSPinstance_p
->PKqueue_base
);
386 N8_PRINT(KERN_CRIT
"NSP2000: Allocated EA queue - %ld entries @ %08lx.\n",
387 NSPinstance_p
->EAqueue_size
, NSPinstance_p
->EAqueue_base
);
390 /* Allocate resources to manage the context memory */
391 N8_ContextMemInit(HWidx
);
393 /* Initialize QMgr. */
396 /* Initialize wait queue for each core */
397 N8_InitWaitQueue(&NSPinstance_p
->RNHblock
);
398 N8_InitWaitQueue(&NSPinstance_p
->CCHblock
);
399 N8_InitWaitQueue(&NSPinstance_p
->PKHblock
);
400 N8_InitWaitQueue(&NSPinstance_p
->AMBAblock
);
407 /*****************************************************************************
409 *****************************************************************************/
410 /** @ingroup NSP2000Driver
411 * @brief Deallocates resources for each chip.
413 * This funciton deallocates the resources used by each chip. Upon driver exit
414 * this function should be called once for each chip initialized.
416 * @param NSPinstance_p RO: Pointer to the information structure for an
417 * NSP2000 hardware instance, containing a
418 * pointer to its control register set.
419 * @param HWidx RO: Specifies the chip index.
425 * See return section for error information.
426 *****************************************************************************/
428 N8_Status_t
n8_chipRemove(NspInstance_t
*NSPinstance_p
, int HWidx
)
431 volatile NSP2000REGS_t
*nsp
= (NSP2000REGS_t
*)NSPinstance_p
->NSPregs_p
;
433 /* Disable each of the Cores */
434 nsp
->pkh_control_status
= 0;
435 nsp
->cch_control_status
= 0;
436 nsp
->rnh_control_status
= 0;
438 /* Reset the queue pointers */
443 /* Deallocate the resources used by the context memory management */
444 N8_ContextMemRemove(HWidx
);
446 /* Remove the SKS data structures. */
447 SKS_Remove(NSPinstance_p
);
449 /* Free static resources */
452 n8_pfree(N8_MEMBANK_QUEUE
, (void *)bncAddr
);
455 n8_pfree(N8_MEMBANK_QUEUE
, (void *)NSPinstance_p
->RNqueue_base
);
456 n8_pfree(N8_MEMBANK_QUEUE
, (void *)NSPinstance_p
->PKqueue_base
);
457 n8_pfree(N8_MEMBANK_QUEUE
, (void *)NSPinstance_p
->EAqueue_base
);
459 /* Reset sizes for allocated resources */
460 NSPinstance_p
->RNqueue_size
= 0;
461 NSPinstance_p
->PKqueue_size
= 0;
462 NSPinstance_p
->EAqueue_size
= 0;
464 /* Reset physical base address of each queue and struct */
465 NSPinstance_p
->RNqueue_base
= 0;
466 NSPinstance_p
->PKqueue_base
= 0;
467 NSPinstance_p
->EAqueue_base
= 0;
469 /* Disable the timer and its interrupt */
470 nsp
->amba_pci_timer_preset
= 0;
471 nsp
->amba_pci_control
= 0;
475 /* Deallocate wait queue for each core */
476 N8_DelWaitQueue(NSPinstance_p
->RNHblock
);
477 N8_DelWaitQueue(NSPinstance_p
->CCHblock
);
478 N8_DelWaitQueue(NSPinstance_p
->PKHblock
);
479 N8_DelWaitQueue(NSPinstance_p
->AMBAblock
);
481 return(N8_STATUS_OK
);
484 /*****************************************************************************
486 *****************************************************************************/
487 /** @ingroup NSP2000Driver
488 * @brief Configuration manager.
490 * This routine retrieves information about the device(s) installed and running
491 * under this driver and writes it to the location requested by the caller.
493 * @param *driverInfo_p RO: Address where the caller has requested the data
501 * See return section for error information.
502 *****************************************************************************/
504 void N8_GetConfig(NSPdriverInfo_t
*driverInfo_p
)
509 /* Make sure the pointer is not NULL */
513 /* Collect information about this driver installation. */
514 driverInfo_p
->numChips
= NSPcount_g
;
515 driverInfo_p
->driverVersion
= N8_VERSION
;
517 /* Collect information about each memory region. */
518 driverInfo_p
->eaMemoryBase
= memBankCtl_gp
[N8_MEMBANK_EA
]->memBaseAddress
;
519 driverInfo_p
->eaMemorySize
= memBankCtl_gp
[N8_MEMBANK_EA
]->allocSize
;
520 driverInfo_p
->pkMemoryBase
= memBankCtl_gp
[N8_MEMBANK_PK
]->memBaseAddress
;
521 driverInfo_p
->pkMemorySize
= memBankCtl_gp
[N8_MEMBANK_PK
]->allocSize
;
523 driverInfo_p
->bncAddress
= bncAddr
;
524 driverInfo_p
->sessionID
= N8_GET_SESSION_ID
;
525 driverInfo_p
->userPools
= userPoolCount();
527 /* Collect information about each chip. */
528 for (ctr
= 0; ctr
< NSPcount_g
; ctr
++)
530 driverInfo_p
->chipInfo
[ctr
].contextMemsize
= NSPDeviceTable_g
[ctr
].contextMemSize
;
531 driverInfo_p
->chipInfo
[ctr
].SKS_size
= NSPDeviceTable_g
[ctr
].SKS_size
;
532 driverInfo_p
->chipInfo
[ctr
].HardwareVersion
= NSPDeviceTable_g
[ctr
].HardwareVersion
;
533 driverInfo_p
->chipInfo
[ctr
].hardwareType
= NSPDeviceTable_g
[ctr
].hardwareType
;
534 driverInfo_p
->chipInfo
[ctr
].RevisionID
= NSPDeviceTable_g
[ctr
].RevisionID
;
535 driverInfo_p
->chipInfo
[ctr
].RNqueueSize
= NSPDeviceTable_g
[ctr
].RNqueue_size
;
536 driverInfo_p
->chipInfo
[ctr
].PKqueueSize
= NSPDeviceTable_g
[ctr
].PKqueue_size
;
537 driverInfo_p
->chipInfo
[ctr
].EAqueueSize
= NSPDeviceTable_g
[ctr
].EAqueue_size
;
540 driverInfo_p
->mode
= driverMode
;
546 /*****************************************************************************
548 *****************************************************************************/
549 /** @ingroup NSP2000Driver
550 * @brief Configuration manager.
552 * This routine mirrors the user level function that is required to open the
553 * NSP2000 device and mmap its resources.
555 * @param *driverInfo_p RO: Address where the caller has requested the data
563 * See return section for error information.
564 *****************************************************************************/
566 N8_Status_t
N8_OpenDevice(NSPdriverInfo_t
*driverInfo_p
,
567 N8_Boolean_t allocUserPool
,
570 N8_GetConfig(driverInfo_p
);
571 return (N8_STATUS_OK
);
575 /*****************************************************************************
577 *****************************************************************************/
578 /** @ingroup NSP2000Driver
579 * @brief Configuration manager.
581 * This routine mirrors the user level function that is required to close the
582 * NSP2000 device and deallocates its resources.
587 * See return section for error information.
588 *****************************************************************************/
590 void N8_CloseDevice(void)
596 /*****************************************************************************
597 * n8_enableInterrupts
598 *****************************************************************************/
599 /** @ingroup NSP2000Driver
600 * @brief Configuration of interrupts
602 * Configures and enables interrupts all detected NSP2000's. Must be called
603 * after * the driver has registered its interrupt handler with the OS.
610 * See return section for error information.
611 *****************************************************************************/
613 void n8_enableInterrupts(int timer_preset
)
617 NspInstance_t
*NSPinstance_p
;
618 unsigned long amba_pci_control
;
619 volatile NSP2000REGS_t
*nsp
;
621 for (counter
= 0; counter
< NSPcount_g
; counter
++)
623 NSPinstance_p
= &NSPDeviceTable_g
[counter
];
624 nsp
= (NSP2000REGS_t
*)NSPinstance_p
->NSPregs_p
;
626 /* Set up for error interrupts */
627 amba_pci_control
= AMBAIRQ_PKP
| AMBAIRQ_CCH
| AMBAIRQ_RNG
;
629 /* Configure the timer interrupt on the first NSP2000. */
630 if (counter
== N8_AMBA_TIMER_CHIP
)
632 /* Set up the timer preset */
633 nsp
->amba_pci_timer_preset
= timer_preset
;
636 /* Enable interrupt on error and PK command complete */
637 nsp
->pkh_intr_enable
= PK_Status_Halting_Error_Mask
|
638 PK_Enable_Cmd_Complete_Enable
;
639 nsp
->cch_intr_enable
= EA_Status_Halting_Error_Mask
;
641 nsp
->amba_pci_control
= amba_pci_control
;
646 /*****************************************************************************
647 * n8_disableInterrupts
648 *****************************************************************************/
649 /** @ingroup NSP2000Driver
650 * @brief Configuration of interrupts
652 * Disables interrupts on the hardware. Must be called before deallocating
653 * the resources referenced by the IRQ.
658 * See return section for error information.
659 *****************************************************************************/
661 void n8_disableInterrupts(void)
664 unsigned long amba_pci_control
;
665 volatile NSP2000REGS_t
*nsp
;
668 /* Set up for error interrupts */
669 amba_pci_control
= 0;
671 for (ctr
= 0; ctr
< NSPcount_g
; ctr
++)
674 /* Disable all interrupts for each device */
675 nsp
= (NSP2000REGS_t
*)NSPDeviceTable_g
[ctr
].NSPregs_p
;
676 nsp
->amba_pci_control
= amba_pci_control
;
682 /*****************************************************************************
684 *****************************************************************************/
685 /** @ingroup NSP2000Driver
686 * @brief Return NULL file descriptor.
688 * Returns a NULL file descriptor for the kernel API.
693 * See return section for error information.
694 *****************************************************************************/
703 /*****************************************************************************
705 *****************************************************************************/
706 /** @ingroup NSP2000Driver
707 * @brief Allocation and initialization of drivers resources.
709 * This function should be called once at driver installation. It is
710 * responsible for the allocation and initialization of global structures
711 * used by the NSP2000 device driver.
713 * @param eaPoolSize R0: Size (in KB) of the EA memory pool.
714 * pkPoolSize R0: Size (in KB) of the PK memory pool.
722 * See return section for error information.
724 * NOTE: All resources allocated here should be removed in n8_driverRemove.
725 *****************************************************************************/
727 int n8_driverInit(int eaPoolSize
, int pkPoolSize
)
730 /* Allocate physically contiguous blocks of memory that are locked down */
731 /* This pool of memory will be accessed by the NSP2000's DMA engine. */
733 /* The first allocation is for the command queues */
734 if (!n8_memoryInit(N8_MEMBANK_QUEUE
,
735 N8_QUEUE_POOL_SIZE
* N8_ONE_KILOBYTE
* NSPcount_g
,
736 N8_QUEUE_GRANULARITY
))
740 /* The second allocation is for the EA requests */
741 if (!n8_memoryInit(N8_MEMBANK_EA
,
742 eaPoolSize
* N8_ONE_KILOBYTE
,
745 n8_memoryRelease(N8_MEMBANK_QUEUE
);
749 /* The third allocation is for the PK requests */
750 if (!n8_memoryInit(N8_MEMBANK_PK
,
751 pkPoolSize
* N8_ONE_KILOBYTE
,
754 n8_memoryRelease(N8_MEMBANK_EA
);
755 n8_memoryRelease(N8_MEMBANK_QUEUE
);
759 /* Create the user pool */
760 userPoolInit( DEF_USER_POOL_BANKS
,
762 DEF_USER_GRANULARITY
);
765 /* Initialize the process init semaphore */
766 n8_create_process_init_sem();
769 /* Initialize driver wait queues */
770 N8_InitWaitQueue(&nsp2000_wait
);
771 N8_InitWaitQueue(&requestBlock
);
777 /*****************************************************************************
779 *****************************************************************************/
780 /** @ingroup NSP2000Driver
781 * @brief Deallocation and removal of drivers resources.
783 * This function should be called once at driver removal. It is
784 * responsible for the deallocation and removal of global structures
785 * used by the NSP2000 device driver.
795 * See return section for error information.
796 *****************************************************************************/
798 int n8_driverRemove(void)
802 /* Delete the process init semaphore */
803 n8_delete_process_init_sem();
806 /* Remove the user pool */
809 /* Remove the driver memory pools */
810 DBG(("n8_driverRemove: n8_memoryRelease(PK=%d)\n", N8_MEMBANK_PK
));
811 n8_memoryRelease(N8_MEMBANK_PK
);
812 DBG(("n8_driverRemove: n8_memoryRelease(EA=%d)\n", N8_MEMBANK_EA
));
813 n8_memoryRelease(N8_MEMBANK_EA
);
814 DBG(("n8_driverRemove: n8_memoryRelease(QUEUE=%d)\n", N8_MEMBANK_QUEUE
));
815 n8_memoryRelease(N8_MEMBANK_QUEUE
);
817 /* Deallocate driver wait queues */
818 N8_DelWaitQueue(nsp2000_wait
);
819 N8_DelWaitQueue(requestBlock
);