Changeset 8e45d55 in rtems


Ignore:
Timestamp:
Feb 15, 2017, 10:09:23 AM (3 years ago)
Author:
Javier Jalle <javier.jalle@…>
Branches:
master
Children:
31ba1f21
Parents:
9631e5a9
git-author:
Javier Jalle <javier.jalle@…> (02/15/17 10:09:23)
git-committer:
Daniel Hellstrom <daniel@…> (05/02/17 10:34:47)
Message:

leon, grpci2: Make driver SMP safe

File:
1 edited

Legend:

Unmodified
Added
Removed
  • c/src/lib/libbsp/sparc/shared/pci/grpci2.c

    r9631e5a9 r8e45d55  
    3131#include <stdio.h>
    3232#include <string.h>
     33#include <rtems.h>
    3334#include <rtems/bspIo.h>
    3435#include <libcpu/byteorder.h>
     
    4344#include <bsp/grpci2.h>
    4445
    45 #ifndef IRQ_GLOBAL_PREPARE
    46  #define IRQ_GLOBAL_PREPARE(level) rtems_interrupt_level level
     46/* Use interrupt lock privmitives compatible with SMP defined in
     47 * RTEMS 4.11.99 and higher.
     48 */
     49#if (((__RTEMS_MAJOR__ << 16) | (__RTEMS_MINOR__ << 8) | __RTEMS_REVISION__) >= 0x040b63)
     50
     51/* map via rtems_interrupt_lock_* API: */
     52#define SPIN_DECLARE(lock) RTEMS_INTERRUPT_LOCK_MEMBER(lock)
     53#define SPIN_INIT(lock, name) rtems_interrupt_lock_initialize(lock, name)
     54#define SPIN_LOCK(lock, level) rtems_interrupt_lock_acquire_isr(lock, &level)
     55#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_lock_acquire(lock, &level)
     56#define SPIN_UNLOCK(lock, level) rtems_interrupt_lock_release_isr(lock, &level)
     57#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_lock_release(lock, &level)
     58#define SPIN_IRQFLAGS(k) rtems_interrupt_lock_context k
     59#define SPIN_ISR_IRQFLAGS(k) SPIN_IRQFLAGS(k)
     60
     61#else
     62
     63/* maintain single-core compatibility with older versions of RTEMS: */
     64#define SPIN_DECLARE(name)
     65#define SPIN_INIT(lock, name)
     66#define SPIN_LOCK(lock, level)
     67#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_disable(level)
     68#define SPIN_UNLOCK(lock, level)
     69#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_enable(level)
     70#define SPIN_IRQFLAGS(k) rtems_interrupt_level k
     71#define SPIN_ISR_IRQFLAGS(k)
     72
     73#ifdef RTEMS_SMP
     74#error SMP mode not compatible with these interrupt lock primitives
    4775#endif
    48 
    49 #ifndef IRQ_GLOBAL_DISABLE
    50  #define IRQ_GLOBAL_DISABLE(level) rtems_interrupt_disable(level)
    51 #endif
    52 
    53 #ifndef IRQ_GLOBAL_ENABLE
    54  #define IRQ_GLOBAL_ENABLE(level) rtems_interrupt_enable(level)
    5576#endif
    5677
     
    234255/* Driver private data struture */
    235256struct grpci2_priv {
    236         struct drvmgr_dev       *dev;
     257        struct drvmgr_dev               *dev;
    237258        struct grpci2_regs              *regs;
    238259        unsigned char                   ver;
     
    256277        struct drvmgr_map_entry         maps_down[2];
    257278        struct pcibus_config            config;
     279
     280        SPIN_DECLARE(devlock)
    258281};
    259282
     
    305328        volatile uint32_t *pci_conf;
    306329        unsigned int tmp, devfn;
    307         IRQ_GLOBAL_PREPARE(oldLevel);
    308330        int retval, bus = PCI_DEV_BUS(dev);
     331        SPIN_IRQFLAGS(irqflags);
    309332
    310333        if ((unsigned int)ofs & 0xffffff03) {
     
    330353        pci_conf = (volatile uint32_t *) (priv->pci_conf | (devfn << 8) | ofs);
    331354
    332         IRQ_GLOBAL_DISABLE(oldLevel); /* protect regs */
     355        SPIN_LOCK_IRQ(&priv->devlock, irqflags);
    333356
    334357        /* Select bus */
     
    353376        }
    354377
    355         IRQ_GLOBAL_ENABLE(oldLevel);
     378        SPIN_UNLOCK_IRQ(&priv->devlock, irqflags);
    356379
    357380out:
     
    398421        uint32_t value, devfn;
    399422        int retval, bus = PCI_DEV_BUS(dev);
    400         IRQ_GLOBAL_PREPARE(oldLevel);
     423        SPIN_IRQFLAGS(irqflags);
    401424
    402425        if ((unsigned int)ofs & 0xffffff03)
     
    420443        pci_conf = (volatile uint32_t *) (priv->pci_conf | (devfn << 8) | ofs);
    421444
    422         IRQ_GLOBAL_DISABLE(oldLevel); /* protect regs */
     445        SPIN_LOCK_IRQ(&priv->devlock, irqflags);
    423446
    424447        /* Select bus */
     
    440463                retval = PCISTS_OK;
    441464
    442         IRQ_GLOBAL_ENABLE(oldLevel);
     465        SPIN_UNLOCK_IRQ(&priv->devlock, irqflags);
    443466
    444467        DBG("pci_write - [%x:%x:%x] reg: 0x%x => addr: 0x%x, val: 0x%x  (%d)\n",
     
    746769        priv->latency_timer = DEFAULT_LATENCY_TIMER;
    747770
     771        /* Initialize Spin-lock for GRPCI2 Device. */
     772        SPIN_INIT(&priv->devlock, "grpci2");
     773
    748774        /* Calculate the PCI windows
    749775         *  AMBA->PCI Window:                       AHB SLAVE AREA0
Note: See TracChangeset for help on using the changeset viewer.