source: rtems/c/src/lib/libbsp/sparc/shared/pci/gr_rasta_tmtc.c @ 3c236cc

4.115
Last change on this file since 3c236cc was 819de55b, checked in by Daniel Hellstrom <daniel@…>, on 03/18/13 at 07:29:39

PCI-RASTA: set GRPCI1 target cache-line-size to avoid poor performance

  • Property mode set to 100644
File size: 18.6 KB
Line 
1/*  GR-RASTA-TMTC PCI Target driver.
2 *
3 *  COPYRIGHT (c) 2008.
4 *  Cobham Gaisler AB.
5 *
6 *  Configures the GR-RASTA-TMTC interface PCI board.
7 *  This driver provides a AMBA PnP bus by using the general part
8 *  of the AMBA PnP bus driver (ambapp_bus.c).
9 *
10 *  Driver resources for the AMBA PnP bus provided can be set by overriding
11 *  the defaults by declaring gr_rasta_tmtc_resources[].
12 *
13 *  The license and distribution terms for this file may be
14 *  found in found in the file LICENSE in this distribution or at
15 *  http://www.rtems.com/license/LICENSE.
16 */
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <sys/types.h>
22#include <sys/stat.h>
23
24#include <bsp.h>
25#include <rtems/bspIo.h>
26#include <pci.h>
27
28#include <ambapp.h>
29#include <grlib.h>
30#include <drvmgr/drvmgr.h>
31#include <drvmgr/ambapp_bus.h>
32#include <drvmgr/pci_bus.h>
33#include <genirq.h>
34
35#include <gr_rasta_tmtc.h>
36
37/* Determines which PCI address the AHB masters will access, it should be
38 * set so that the masters can access the CPU RAM. Default is base of CPU RAM,
39 * CPU RAM is mapped 1:1 to PCI space.
40 */
41extern unsigned int _RAM_START;
42#define AHBMST2PCIADR (((unsigned int)&_RAM_START) & 0xf0000000)
43
44#define GAISLER_GPIO         0x01a
45#define AHB1_BASE_ADDR 0x80000000
46#define AHB1_IOAREA_BASE_ADDR 0x80200000
47
48/* #define DEBUG 1 */
49
50#ifdef DEBUG
51#define DBG(x...) printk(x)
52#else
53#define DBG(x...)
54#endif
55
56int gr_rasta_tmtc_init1(struct drvmgr_dev *dev);
57int gr_rasta_tmtc_init2(struct drvmgr_dev *dev);
58
59struct grpci_regs {
60        volatile unsigned int cfg_stat;
61        volatile unsigned int bar0;
62        volatile unsigned int page0;
63        volatile unsigned int bar1;
64        volatile unsigned int page1;
65        volatile unsigned int iomap;
66        volatile unsigned int stat_cmd;
67};
68
69struct gr_rasta_tmtc_ver {
70        const unsigned int      amba_freq_hz;   /* The frequency */
71        const unsigned int      amba_ioarea;    /* The address where the PnP IOAREA starts at */
72};
73
74/* Private data structure for driver */
75struct gr_rasta_tmtc_priv {
76        /* Driver management */
77        struct drvmgr_dev       *dev;
78        char                            prefix[20];
79
80        /* PCI */
81        pci_dev_t                       pcidev;
82        struct pci_dev_info             *devinfo;
83        uint32_t                        ahbmst2pci_map;
84
85        /* IRQ */
86        genirq_t                        genirq;
87
88        /* GR-RASTA-TMTC */
89        struct gr_rasta_tmtc_ver        *version;
90        struct irqmp_regs               *irq;
91        struct grpci_regs               *grpci;
92        struct grgpio_regs              *gpio;
93        struct drvmgr_map_entry         bus_maps_down[3];
94        struct drvmgr_map_entry         bus_maps_up[2];
95
96        /* AMBA Plug&Play information on GR-RASTA-TMTC */
97        struct ambapp_bus               abus;
98        struct ambapp_mmap              amba_maps[4];
99        struct ambapp_config            config;
100};
101
102struct gr_rasta_tmtc_ver gr_rasta_tmtc_ver0 = {
103        .amba_freq_hz           = 30000000,
104        .amba_ioarea            = AHB1_IOAREA_BASE_ADDR,
105};
106
107int ambapp_rasta_tmtc_int_register(
108        struct drvmgr_dev *dev,
109        int irq,
110        const char *info,
111        drvmgr_isr handler,
112        void *arg);
113int ambapp_rasta_tmtc_int_unregister(
114        struct drvmgr_dev *dev,
115        int irq,
116        drvmgr_isr handler,
117        void *arg);
118int ambapp_rasta_tmtc_int_unmask(
119        struct drvmgr_dev *dev,
120        int irq);
121int ambapp_rasta_tmtc_int_mask(
122        struct drvmgr_dev *dev,
123        int irq);
124int ambapp_rasta_tmtc_int_clear(
125        struct drvmgr_dev *dev,
126        int irq);
127int ambapp_rasta_tmtc_get_params(
128        struct drvmgr_dev *dev,
129        struct drvmgr_bus_params *params);
130
131struct ambapp_ops ambapp_rasta_tmtc_ops = {
132        .int_register = ambapp_rasta_tmtc_int_register,
133        .int_unregister = ambapp_rasta_tmtc_int_unregister,
134        .int_unmask = ambapp_rasta_tmtc_int_unmask,
135        .int_mask = ambapp_rasta_tmtc_int_mask,
136        .int_clear = ambapp_rasta_tmtc_int_clear,
137        .get_params = ambapp_rasta_tmtc_get_params
138};
139
140struct drvmgr_drv_ops gr_rasta_tmtc_ops =
141{
142        .init = {gr_rasta_tmtc_init1, gr_rasta_tmtc_init2, NULL, NULL},
143        .remove = NULL,
144        .info = NULL,
145};
146
147struct pci_dev_id_match gr_rasta_tmtc_ids[] =
148{
149        PCIID_DEVVEND(PCIID_VENDOR_GAISLER, PCIID_DEVICE_GR_RASTA_TMTC),
150        PCIID_END_TABLE /* Mark end of table */
151};
152
153struct pci_drv_info gr_rasta_tmtc_info =
154{
155        {
156                DRVMGR_OBJ_DRV,                 /* Driver */
157                NULL,                           /* Next driver */
158                NULL,                           /* Device list */
159                DRIVER_PCI_GAISLER_RASTATMTC_ID,/* Driver ID */
160                "GR-RASTA-TMTC_DRV",            /* Driver Name */
161                DRVMGR_BUS_TYPE_PCI,            /* Bus Type */
162                &gr_rasta_tmtc_ops,
163                NULL,                           /* Funcs */
164                0,                              /* No devices yet */
165                sizeof(struct gr_rasta_tmtc_priv) /* Let drvmgr alloc private */
166        },
167        &gr_rasta_tmtc_ids[0]
168};
169
170/* Driver resources configuration for the AMBA bus on the GR-RASTA-TMTC board.
171 * It is declared weak so that the user may override it from the project file,
172 * if the default settings are not enough.
173 *
174 * The configuration consists of an array of configuration pointers, each
175 * pointer determine the configuration of one GR-RASTA-TMTC board. Pointer
176 * zero is for board0, pointer 1 for board1 and so on.
177 *
178 * The array must end with a NULL pointer.
179 */
180struct drvmgr_bus_res *gr_rasta_tmtc_resources[] __attribute__((weak)) =
181{
182        NULL,
183};
184int gr_rasta_tmtc_resources_cnt = 0;
185
186void gr_rasta_tmtc_register_drv(void)
187{
188        DBG("Registering GR-RASTA-TMTC PCI driver\n");
189        drvmgr_drv_register(&gr_rasta_tmtc_info.general);
190}
191
192void gr_rasta_tmtc_isr (void *arg)
193{
194        struct gr_rasta_tmtc_priv *priv = arg;
195        unsigned int status, tmp;
196        int irq;
197        tmp = status = priv->irq->ipend;
198
199        /* printk("GR-RASTA-TMTC: IRQ 0x%x\n",status); */
200
201        for(irq=0; irq<32; irq++) {
202                if ( status & (1<<irq) ) {
203                        genirq_doirq(priv->genirq, irq);
204                        priv->irq->iclear = (1<<irq);
205                        status &= ~(1<<irq);
206                        if ( status == 0 )
207                                break;
208                }
209        }
210
211        /* ACK interrupt, this is because PCI is Level, so the IRQ Controller still drives the IRQ. */
212        if ( tmp )
213                drvmgr_interrupt_clear(priv->dev, 0);
214
215        DBG("RASTA-TMTC-IRQ: 0x%x\n", tmp);
216}
217
218int gr_rasta_tmtc_hw_init(struct gr_rasta_tmtc_priv *priv)
219{
220        unsigned int *page0 = NULL;
221        struct ambapp_dev *tmp;
222        struct ambapp_ahb_info *ahb;
223        unsigned int pci_freq_hz;
224        pci_dev_t pcidev = priv->pcidev;
225        struct pci_dev_info *devinfo = priv->devinfo;
226        uint32_t bar0, bar0_size;
227
228        /* Select version of GR-RASTA-TMTC board */
229        switch (devinfo->rev) {
230                case 0:
231                        priv->version = &gr_rasta_tmtc_ver0;
232                        break;
233                default:
234                        return -2;
235        }
236
237        bar0 = devinfo->resources[0].address;
238        bar0_size = devinfo->resources[0].size;
239        page0 = (unsigned int *)(bar0 + bar0_size/2);
240
241        /* Point PAGE0 to start of Plug and Play information */
242        *page0 = priv->version->amba_ioarea & 0xf0000000;
243
244#if 0
245        {
246                uint32_t data;
247                /* set parity error response */
248                pci_cfg_r32(pcidev, PCI_COMMAND, &data);
249                pci_cfg_w32(pcidev, PCI_COMMAND, (data|PCI_COMMAND_PARITY));
250        }
251#endif
252
253        /* Setup cache line size. Default cache line size will result in
254         * poor performance (256 word fetches), 0xff will set it according
255         * to the max size of the PCI FIFO.
256         */
257        pci_cfg_w8(pcidev, PCI_CACHE_LINE_SIZE, 0xff);
258
259        /* Scan AMBA Plug&Play */
260
261        /* AMBA MAP bar0 (in CPU) ==> 0x80000000(remote amba address) */
262        priv->amba_maps[0].size = 0x10000000;
263        priv->amba_maps[0].local_adr = bar0;
264        priv->amba_maps[0].remote_adr = AHB1_BASE_ADDR;
265
266        /* AMBA MAP bar1 (in CPU) ==> 0x40000000(remote amba address) */
267        priv->amba_maps[1].size = devinfo->resources[1].size;
268        priv->amba_maps[1].local_adr = devinfo->resources[1].address;
269        priv->amba_maps[1].remote_adr = 0x40000000;
270
271        /* Addresses not matching with map be untouched */
272        priv->amba_maps[2].size = 0xfffffff0;
273        priv->amba_maps[2].local_adr = 0;
274        priv->amba_maps[2].remote_adr = 0;
275
276        /* Mark end of table */
277        priv->amba_maps[3].size=0;
278        priv->amba_maps[3].local_adr = 0;
279        priv->amba_maps[3].remote_adr = 0;
280
281        /* Start AMBA PnP scan at first AHB bus */
282        ambapp_scan(&priv->abus,
283                bar0 + (priv->version->amba_ioarea & ~0xf0000000),
284                NULL, &priv->amba_maps[0]);
285
286        /* Frequency is the same as the PCI bus frequency */
287        drvmgr_freq_get(priv->dev, 0, &pci_freq_hz);
288
289        /* Initialize Frequency of AMBA bus */
290        ambapp_freq_init(&priv->abus, NULL, pci_freq_hz);
291
292        /* Point PAGE0 to start of APB area */
293        *page0 = AHB1_BASE_ADDR;
294
295        /* Find GRPCI controller */
296        tmp = (void *)ambapp_for_each(&priv->abus,
297                                        (OPTIONS_ALL|OPTIONS_APB_SLVS),
298                                        VENDOR_GAISLER, GAISLER_PCIFBRG,
299                                        ambapp_find_by_idx, NULL);
300        if ( !tmp ) {
301                return -3;
302        }
303        priv->grpci = (struct grpci_regs *)((struct ambapp_apb_info *)tmp->devinfo)->start;
304
305        /* Set GRPCI mmap so that AMBA masters can access CPU-RAM over
306         * the PCI window.
307         */
308        priv->grpci->cfg_stat = (priv->grpci->cfg_stat & 0x0fffffff) |
309                                (priv->ahbmst2pci_map & 0xf0000000);
310        priv->grpci->page1 = 0x40000000;
311
312        /* Find IRQ controller, Clear all current IRQs */
313        tmp = (void *)ambapp_for_each(&priv->abus,
314                                        (OPTIONS_ALL|OPTIONS_APB_SLVS),
315                                        VENDOR_GAISLER, GAISLER_IRQMP,
316                                        ambapp_find_by_idx, NULL);
317        if ( !tmp ) {
318                return -4;
319        }
320        priv->irq = (struct irqmp_regs *)DEV_TO_APB(tmp)->start;
321        /* Set up GR-RASTA-TMTC irq controller */
322        priv->irq->mask[0] = 0;
323        priv->irq->iclear = 0xffffffff;
324        priv->irq->ilevel = 0;
325
326        /* Find First GPIO controller */
327        tmp = (void *)ambapp_for_each(&priv->abus,
328                                        (OPTIONS_ALL|OPTIONS_APB_SLVS),
329                                        VENDOR_GAISLER, GAISLER_GPIO,
330                                        ambapp_find_by_idx, NULL);
331        if ( !tmp ) {
332                return -5;
333        }
334        priv->gpio = (struct grgpio_regs *) (((struct ambapp_apb_info *)tmp->devinfo)->start);
335        /* Clear GR-RASTA-TMTC GPIO controller */
336        priv->gpio->imask = 0;
337        priv->gpio->ipol = 0;
338        priv->gpio->iedge = 0;
339        priv->gpio->bypass = 0;
340        /* Set up GR-RASTA-TMTC GPIO controller to select GRTM and GRTC */
341        priv->gpio->output = (GR_TMTC_GPIO_GRTM_SEL|GR_TMTC_GPIO_TRANSP_CLK) | (GR_TMTC_GPIO_TC_BIT_LOCK|GR_TMTC_GPIO_TC_RF_AVAIL|GR_TMTC_GPIO_TC_ACTIVE_HIGH|GR_TMTC_GPIO_TC_RISING_CLK);
342        priv->gpio->dir = 0xffffffff;
343        DBG("GR-TMTC GPIO: 0x%x\n", (unsigned int)priv->gpio);
344
345        /* Enable DMA by enabling PCI target as master */
346        pci_master_enable(pcidev);
347
348        /* DOWN streams translation table */
349        priv->bus_maps_down[0].name = "PCI BAR0 -> AMBA";
350        priv->bus_maps_down[0].size = priv->amba_maps[0].size;
351        priv->bus_maps_down[0].from_adr = (void *)priv->amba_maps[0].local_adr;
352        priv->bus_maps_down[0].to_adr = (void *)priv->amba_maps[0].remote_adr;
353
354        priv->bus_maps_down[1].name = "PCI BAR1 -> AMBA";
355        priv->bus_maps_down[1].size = priv->amba_maps[1].size;
356        priv->bus_maps_down[1].from_adr = (void *)priv->amba_maps[1].local_adr;
357        priv->bus_maps_down[1].to_adr = (void *)priv->amba_maps[1].remote_adr;
358
359        /* Mark end of translation table */
360        priv->bus_maps_down[2].size = 0;
361
362        /* Find GRPCI controller AHB Slave interface */
363        tmp = (struct ambapp_dev *)ambapp_for_each(&priv->abus,
364                                (OPTIONS_ALL|OPTIONS_AHB_SLVS),
365                                VENDOR_GAISLER, GAISLER_PCIFBRG,
366                                ambapp_find_by_idx, NULL);
367        if ( !tmp ) {
368                return -6;
369        }
370        ahb = (struct ambapp_ahb_info *)tmp->devinfo;
371
372        /* UP streams translation table */
373        priv->bus_maps_up[0].name = "AMBA GRPCI Window";
374        priv->bus_maps_up[0].size = ahb->mask[0]; /* AMBA->PCI Window on GR-RASTA-TMTC board */
375        priv->bus_maps_up[0].from_adr = (void *)ahb->start[0];
376        priv->bus_maps_up[0].to_adr = (void *)
377                                        (priv->ahbmst2pci_map & 0xf0000000);
378
379        /* Mark end of translation table */
380        priv->bus_maps_up[1].size = 0;
381
382        /* Successfully registered the RASTA board */
383        return 0;
384}
385
386void gr_rasta_tmtc_hw_init2(struct gr_rasta_tmtc_priv *priv)
387{
388        /* Enable DMA by enabling PCI target as master */
389        pci_master_enable(priv->pcidev);
390}
391
392/* Called when a PCI target is found with the PCI device and vendor ID
393 * given in gr_rasta_tmtc_ids[].
394 */
395int gr_rasta_tmtc_init1(struct drvmgr_dev *dev)
396{
397        struct gr_rasta_tmtc_priv *priv;
398        struct pci_dev_info *devinfo;
399        int status;
400        uint32_t bar0, bar1, bar0_size, bar1_size;
401        union drvmgr_key_value *value;
402
403        priv = dev->priv;
404        if (!priv)
405                return DRVMGR_NOMEM;
406        priv->dev = dev;
407
408        /* Determine number of configurations */
409        if ( gr_rasta_tmtc_resources_cnt == 0 ) {
410                while ( gr_rasta_tmtc_resources[gr_rasta_tmtc_resources_cnt] )
411                        gr_rasta_tmtc_resources_cnt++;
412        }
413
414        /* Generate Device prefix */
415
416        strcpy(priv->prefix, "/dev/rastatmtc0");
417        priv->prefix[14] += dev->minor_drv;
418        mkdir(priv->prefix, S_IRWXU | S_IRWXG | S_IRWXO);
419        priv->prefix[15] = '/';
420        priv->prefix[16] = '\0';
421
422        priv->devinfo = devinfo = (struct pci_dev_info *)dev->businfo;
423        priv->pcidev = devinfo->pcidev;
424        bar0 = devinfo->resources[0].address;
425        bar0_size = devinfo->resources[0].size;
426        bar1 = devinfo->resources[1].address;
427        bar1_size = devinfo->resources[1].size;
428        printf("\n\n--- GR-RASTA-TMTC[%d] ---\n", dev->minor_drv);
429        printf(" PCI BUS: 0x%x, SLOT: 0x%x, FUNCTION: 0x%x\n",
430                PCI_DEV_EXPAND(priv->pcidev));
431        printf(" PCI VENDOR: 0x%04x, DEVICE: 0x%04x\n",
432                devinfo->id.vendor, devinfo->id.device);
433        printf(" PCI BAR[0]: 0x%lx - 0x%lx\n", bar0, bar0 + bar0_size - 1);
434        printf(" PCI BAR[1]: 0x%lx - 0x%lx\n", bar1, bar1 + bar1_size - 1);
435        printf(" IRQ: %d\n\n\n", devinfo->irq);
436
437        /* all neccessary space assigned to GR-RASTA-IO target? */
438        if ((bar0_size == 0) || (bar1_size == 0))
439                return DRVMGR_ENORES;
440
441        /* Let user override which PCI address the AHB masters of the
442         * GR-RASTA-TMTC board access when doing DMA to CPU RAM. The AHB masters
443         * access the PCI Window of the AMBA bus, the MSB 4-bits of that address
444         * is translated according this config option before the address
445         * goes out on the PCI bus.
446         * Only the 4 MSB bits have an effect;
447         */
448        value = drvmgr_dev_key_get(priv->dev, "ahbmst2pci", KEY_TYPE_INT);
449        if (value)
450                priv->ahbmst2pci_map = value->i;
451        else
452                priv->ahbmst2pci_map = AHBMST2PCIADR; /* default */     
453
454        priv->genirq = genirq_init(32);
455        if ( priv->genirq == NULL )
456                return DRVMGR_FAIL;
457
458        status = gr_rasta_tmtc_hw_init(priv);
459        if ( status != 0 ) {
460                genirq_destroy(priv->genirq);
461                printf(" Failed to initialize GR-RASTA-TMTC HW: %d\n", status);
462                return DRVMGR_FAIL;
463        }
464
465        /* Init amba bus */
466        priv->config.abus = &priv->abus;
467        priv->config.ops = &ambapp_rasta_tmtc_ops;
468        priv->config.maps_up = &priv->bus_maps_up[0];
469        priv->config.maps_down = &priv->bus_maps_down[0];
470        if ( priv->dev->minor_drv < gr_rasta_tmtc_resources_cnt ) {
471                priv->config.resources = gr_rasta_tmtc_resources[priv->dev->minor_drv];
472        } else {
473                priv->config.resources = NULL;
474        }
475
476        return ambapp_bus_register(dev, &priv->config);
477}
478
479int gr_rasta_tmtc_init2(struct drvmgr_dev *dev)
480{
481        struct gr_rasta_tmtc_priv *priv = dev->priv;
482
483        /* Clear any old interrupt requests */
484        drvmgr_interrupt_clear(priv->dev, 0);
485
486        /* Enable System IRQ so that GR-RASTA-TMTC PCI target interrupt goes
487         * through.
488         *
489         * It is important to enable it in stage init2. If interrupts were
490         * enabled in init1 this might hang the system when more than one
491         * PCI target is connected, this is because PCI interrupts might
492         * be shared and PCI board 2 have not initialized and
493         * might therefore drive interrupt already when entering init1().
494         */
495        drvmgr_interrupt_register(
496                priv->dev,
497                0,
498                "gr_rasta_tmtc",
499                gr_rasta_tmtc_isr,
500                (void *)priv);
501
502        gr_rasta_tmtc_hw_init2(priv);
503
504        return DRVMGR_OK;
505}
506
507int ambapp_rasta_tmtc_int_register(
508        struct drvmgr_dev *dev,
509        int irq,
510        const char *info,
511        drvmgr_isr handler,
512        void *arg)
513{
514        struct gr_rasta_tmtc_priv *priv = dev->parent->dev->priv;
515        rtems_interrupt_level level;
516        int status;
517
518        rtems_interrupt_disable(level);
519
520        status = genirq_register(priv->genirq, irq, handler, arg);
521        if ( status == 0 ) {
522                /* Disable and clear IRQ for first registered handler */
523                priv->irq->iclear = (1<<irq);
524        } else if ( status == 1 )
525                status = 0;
526
527        if (status != 0) {
528                rtems_interrupt_enable(level);
529                return DRVMGR_FAIL;
530        }
531
532        status = genirq_enable(priv->genirq, irq, handler, arg);
533        if ( status == 0 ) {
534                /* Enable IRQ for first enabled handler only */
535                priv->irq->mask[0] |= (1<<irq); /* unmask interrupt source */
536        } else if ( status == 1 )
537                status = 0;
538
539        rtems_interrupt_enable(level);
540
541        return status;
542}
543
544int ambapp_rasta_tmtc_int_unregister(
545        struct drvmgr_dev *dev,
546        int irq,
547        drvmgr_isr isr,
548        void *arg)
549{
550        struct gr_rasta_tmtc_priv *priv = dev->parent->dev->priv;
551        rtems_interrupt_level level;
552        int status;
553
554        rtems_interrupt_disable(level);
555
556        status = genirq_disable(priv->genirq, irq, isr, arg);
557        if ( status == 0 ) {
558                /* Disable IRQ only when no enabled handler exists */
559                priv->irq->mask[0] &= ~(1<<irq); /* mask interrupt source */
560        } else if ( status == 1 )
561                status = 0;
562
563        status = genirq_unregister(priv->genirq, irq, isr, arg);
564        if ( status != 0 )
565                status = DRVMGR_FAIL;
566
567        rtems_interrupt_enable(level);
568
569        return status;
570}
571
572int ambapp_rasta_tmtc_int_unmask(
573        struct drvmgr_dev *dev,
574        int irq)
575{
576        struct gr_rasta_tmtc_priv *priv = dev->parent->dev->priv;
577        rtems_interrupt_level level;
578
579        DBG("RASTA-TMTC IRQ %d: unmask\n", irq);
580
581        if ( genirq_check(priv->genirq, irq) )
582                return DRVMGR_EINVAL;
583
584        rtems_interrupt_disable(level);
585
586        /* Enable IRQ */
587        priv->irq->mask[0] |= (1<<irq); /* unmask interrupt source */
588
589        rtems_interrupt_enable(level);
590
591        return DRVMGR_OK;
592}
593
594int ambapp_rasta_tmtc_int_mask(
595        struct drvmgr_dev *dev,
596        int irq)
597{
598        struct gr_rasta_tmtc_priv *priv = dev->parent->dev->priv;
599        rtems_interrupt_level level;
600
601        DBG("RASTA-TMTC IRQ %d: mask\n", irq);
602
603        if ( genirq_check(priv->genirq, irq) )
604                return DRVMGR_EINVAL;
605
606        rtems_interrupt_disable(level);
607
608        /* Disable IRQ */
609        priv->irq->mask[0] &= ~(1<<irq); /* mask interrupt source */
610
611        rtems_interrupt_enable(level);
612
613        return DRVMGR_OK;
614}
615
616int ambapp_rasta_tmtc_int_clear(
617        struct drvmgr_dev *dev,
618        int irq)
619{
620        struct gr_rasta_tmtc_priv *priv = dev->parent->dev->priv;
621
622        if ( genirq_check(priv->genirq, irq) )
623                return DRVMGR_FAIL;
624
625        priv->irq->iclear = (1<<irq);
626
627        return DRVMGR_OK;
628}
629
630int ambapp_rasta_tmtc_get_params(struct drvmgr_dev *dev, struct drvmgr_bus_params *params)
631{
632        struct gr_rasta_tmtc_priv *priv = dev->parent->dev->priv;
633
634        /* Device name prefix pointer, skip /dev */
635        params->dev_prefix = &priv->prefix[5];
636
637        return 0;
638}
639
640void gr_rasta_tmtc_print_dev(struct drvmgr_dev *dev, int options)
641{
642        struct gr_rasta_tmtc_priv *priv = dev->priv;
643        struct pci_dev_info *devinfo = priv->devinfo;
644        uint32_t bar0, bar1, bar0_size, bar1_size;
645
646        /* Print */
647        printf("--- GR-RASTA-TMTC [bus 0x%x, dev 0x%x, fun 0x%x] ---\n",
648                PCI_DEV_EXPAND(priv->pcidev));
649
650        bar0 = devinfo->resources[0].address;
651        bar0_size = devinfo->resources[0].size;
652        bar1 = devinfo->resources[1].address;
653        bar1_size = devinfo->resources[1].size;
654
655        printf(" PCI BAR[0]: 0x%lx - 0x%lx\n", bar0, bar0 + bar0_size - 1);
656        printf(" PCI BAR[1]: 0x%lx - 0x%lx\n", bar1, bar1 + bar1_size - 1);
657        printf(" IRQ:             %d\n", devinfo->irq);
658        printf(" PCI REVISION:    %d\n", devinfo->rev);
659        printf(" FREQ:            %d Hz\n", priv->version->amba_freq_hz);
660        printf(" IMASK:           0x%08x\n", priv->irq->mask[0]);
661        printf(" IPEND:           0x%08x\n", priv->irq->ipend);
662
663        /* Print amba config */
664        if ( options & RASTA_TMTC_OPTIONS_AMBA ) {
665                ambapp_print(&priv->abus, 10);
666        }
667
668#if 0
669        /* Print IRQ handlers and their arguments */
670        if ( options & RASTA_TMTC_OPTIONS_IRQ ) {
671                int i;
672                for(i=0; i<16; i++) {
673                        printf(" IRQ[%02d]:         0x%x, arg: 0x%x\n",
674                                i, (unsigned int)priv->isrs[i].handler, (unsigned int)priv->isrs[i].arg);
675                }
676        }
677#endif
678}
679
680void gr_rasta_tmtc_print(int options)
681{
682        struct pci_drv_info *drv = &gr_rasta_tmtc_info;
683        struct drvmgr_dev *dev;
684
685        dev = drv->general.dev;
686        while(dev) {
687                gr_rasta_tmtc_print_dev(dev, options);
688                dev = dev->next_in_drv;
689        }
690}
Note: See TracBrowser for help on using the repository browser.