Re: GCC 7.1 Released

2017-05-11 Thread Sebastian Huber

On 11/05/17 17:29, Joel Sherrill wrote:

Ok to

On May 11, 2017 5:09 AM, "Sebastian Huber" 
> wrote:


Hello,

if someone wants to use GCC 7.1 for RTEMS 4.12, then the RSB
should be updated accordingly as soon as possible.


Chris posted a patch to bump gcc and binutils. He just needs to push it.


I didn't see the patch. According to

contrib/download_prerequisites

we should use

gmp='gmp-6.1.0.tar.bz2'
mpfr='mpfr-3.1.4.tar.bz2'
mpc='mpc-1.0.3.tar.gz'
isl='isl-0.16.1.tar.bz2'

for GCC 7.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH 00/32] LEON

2017-05-11 Thread Sebastian Huber

Looks good except 32/32.

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 32/32] score: remove part of an assertion that cannot compile with Clang

2017-05-11 Thread Sebastian Huber

On 11/05/17 16:26, Daniel Hellstrom wrote:

From: Jacob Hansen 

---
  cpukit/score/include/rtems/score/threadqimpl.h | 4 +---
  1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/cpukit/score/include/rtems/score/threadqimpl.h 
b/cpukit/score/include/rtems/score/threadqimpl.h
index 574221c..975221c 100644
--- a/cpukit/score/include/rtems/score/threadqimpl.h
+++ b/cpukit/score/include/rtems/score/threadqimpl.h
@@ -1140,9 +1140,7 @@ typedef struct {
  #define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member ) \
RTEMS_STATIC_ASSERT( \
  offsetof( object_type, wait_queue_member ) \
-  == offsetof( Thread_queue_Object, Wait_queue ) \
-&& ( &( ( (object_type *) 0 )->wait_queue_member ) \
-  == ( &( (Thread_queue_Object *) 0 )->Wait_queue ) ), \
+  == offsetof( Thread_queue_Object, Wait_queue ), \
  object_type \
)
  


This assertion checks two things.

1. That the member offset of both structures is equal.

2. That the type of the members is identical.

You remove (2). A quick test of

struct s {
int i;
};

_Static_assert(__builtin_types_compatible_p(__typeof(((struct s 
*)0)->i), int), "s");


struct t {
int i;
};

_Static_assert(&(((struct s *)4096)->i) == &(((struct t *)4096)->i), "t");

struct u {
int i;
};

_Static_assert(&(((struct s *)0)->i) == &(((struct u *)0)->i), "u");

with clang results in

clang -S test.c -o -
test.c:11:16: error: static_assert expression is not an integral 
constant expression

_Static_assert(&(((struct s *)4096)->i) == &(((struct t *)4096)->i), "t");
   ^~~~
test.c:11:19: note: cast that performs the conversions of a 
reinterpret_cast is not allowed in a constant expression

_Static_assert(&(((struct s *)4096)->i) == &(((struct t *)4096)->i), "t");
  ^
test.c:17:16: error: static_assert expression is not an integral 
constant expression

_Static_assert(&(((struct s *)0)->i) == &(((struct u *)0)->i), "u");
   ^~
test.c:17:35: note: cannot access field of null pointer
_Static_assert(&(((struct s *)0)->i) == &(((struct u *)0)->i), "u");
  ^
2 errors generated.

with gcc results in

gcc -S -o - test.c -std=c11
.file   "test.c"
.ident  "GCC: (SUSE Linux) 4.8.1 20130909 [gcc-4_8-branch 
revision 202388]"

.section.note.GNU-stack,"",@progbits

So, maybe use |__builtin_types_compatible_p() and typeof (should be done 
via ). Maybe ask on the LLVM mailing list on how 
to check structure member types.


|

--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


RE: suggested changes and bug fixes for RTEMS

2017-05-11 Thread Pham, Phong

Hi Gedare,

Enclosed are your requests for items 1-3.  I logged a ticket for item 4 but 
feel free to postpone or close the ticket.  Just curious, in general when will 
the committed changes (after sending you the patch like above) be available for 
someone to git clone the latest rtems tree?

Phong.

-Original Message-
From: ged...@gwmail.gwu.edu [mailto:ged...@gwmail.gwu.edu] On Behalf Of Gedare 
Bloom
Sent: Tuesday, May 09, 2017 12:26 PM
To: Pham, Phong
Cc: devel@rtems.org
Subject: Re: suggested changes and bug fixes for RTEMS

On Tue, May 9, 2017 at 12:16 PM, Pham, Phong  wrote:
>
>
> Hi RTEMS Maintainers,
>
>
>
> Pls. let me know which of these item # changes below (or delta within
> a given item #) you do not wish to accommodate in the main line so
> that I will provide it as part of my BSP.  I am porting RTEMS to IBM
> PowerPC 750 chip; very similar to MPC750 but there are minute differences.
>
>
>
> 1)  Bug: In
> rtems\c\src\lib\libbsp\shared\src\irq-generic.c:bsp_interrupt_allocate_handler_index().
> See attachment irq-generic.c vs. irq-generic.c.orig
>
Please open a ticket on our Trac and attach a git-commit patch there or here, 
with "Close #." in the commit message. You can see the git-log for examples 
of how to format the commit message.

>
>
> 2)  Enhancement: Add support for IBM PowerPC 750 chip in
> rtems\c\src\lib\libcpu\powerpc\shared\include\cpuIdent.[c,h] and
> rtems\c\src\lib\libcpu\powerpc\new-exceptions\bspsupport\ppc_exc_categ
> ories.c
>
Should be fine.

>
>
> 3)  Bug: Missing a couple registers when DLAB is 1 in
> rtems\c\src\libchip\serial\ns16550_p.h.  Also add a #ifndef ASM around
> libchip/serial.h inclusion.
>
Ditto on Trac.

>
>
> 4)  Suggestion: In pci.h, there are references to BSP_pci_configuration
> data structure which is in pci.c.  However, in this file, there are
> also references to detect_host_bridge () in detect_raven_bridge.c.
> For folks that are just interested in pci_read_config_dword() + its
> brothers, all they need is to include pci.h and content for where
> BSP_pci_configuration is defined.  The rest of the stuff in pci.c
> should be separate.  Or in another word, data structures and #defines
> involving with BSP_pci_configuration needs to be in separate files
> rather all stuffed in pci.c
>
Refactoring pci.c is acceptable.

>
>
> 5)  rtems\c\src\lib\libcpu\powerpc\mpc6xx\mmu\pte121.c:triv121PgTblMap()
> implementation only map virtual address to be the same as physical
> address for a given address range (start + numPages).  It also assume
> an increment of page size for a given address range.  I suggest that
> an argument of
> triv121PgTblMap() is needed to specify the physical address to be
> mapped to for a given range of addresses.  Also another parameter is
> whether or not to increment PhysAddr for each page.  Enclosed in
> pte121.c is an implementation of triv121PgTblMapPhysAddr() where a
> physical address is provided and it is hard coded not to increase the 
> physical address for a given address range.
> So APIs are needed for these requests.  Don’t know if and how much you
> want to support me.  If not, I’ll just add whatever you’re not
> supporting in my BSP.
>
RTEMS does not have support for a non-identity mapping of virtual-physical 
memory. It is not clear that a non-identity mapping will work correctly, 
although I see no reason why it would not. You are welcome to suggest/implement 
improvements in this space. We have investigated some efforts to create BSP 
level memory management, see the ARM bsps for some ideas, and there are 
previous attempts to create APIs for memory management/protection, but nothing 
that has been mergeable. https://devel.rtems.org/wiki/Projects/MMU_Support

>
>
> Thanks,
>
> Phong.
>
>
>
> PS: There are a couple more items but the first five should get things
> rolling.
>
> Notice: This e-mail and any files transmitted with it may contain Data
> Device Corporation's privileged and proprietary information. It is
> intended solely for the use of the individual or entity to whom it is
> addressed. If you are not the named recipient of this transmission,
> any disclosure, copying, distribution or reliance on the contents of
> this message is prohibited. If you received this e-mail in error,
> please destroy it and any attached files and notify me immediately.
>
See if you can disable this notice for messages sent to the mailing list.

>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
Notice: This e-mail and any files transmitted with it may contain Data Device 
Corporation's privileged and proprietary information. It is intended solely for 
the use of the individual or entity to whom it is addressed. If you are not the 
named recipient of this transmission, any disclosure, copying, distribution or 
reliance on the contents of this message is prohibited. If you received this 

Re: [PATCH 32/32] score: remove part of an assertion that cannot compile with Clang

2017-05-11 Thread Gedare Bloom
On Thu, May 11, 2017 at 10:26 AM, Daniel Hellstrom  wrote:
> From: Jacob Hansen 
>
> ---
>  cpukit/score/include/rtems/score/threadqimpl.h | 4 +---
>  1 file changed, 1 insertion(+), 3 deletions(-)
>
> diff --git a/cpukit/score/include/rtems/score/threadqimpl.h 
> b/cpukit/score/include/rtems/score/threadqimpl.h
> index 574221c..975221c 100644
> --- a/cpukit/score/include/rtems/score/threadqimpl.h
> +++ b/cpukit/score/include/rtems/score/threadqimpl.h
> @@ -1140,9 +1140,7 @@ typedef struct {
>  #define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member ) \
>RTEMS_STATIC_ASSERT( \
>  offsetof( object_type, wait_queue_member ) \
> -  == offsetof( Thread_queue_Object, Wait_queue ) \
> -&& ( &( ( (object_type *) 0 )->wait_queue_member ) \
> -  == ( &( (Thread_queue_Object *) 0 )->Wait_queue ) ), \
> +  == offsetof( Thread_queue_Object, Wait_queue ), \
>  object_type \
>)
>
Seems oK although it does lose some check. What was llvm/clangs
problem with the second condition?

> --
> 2.7.4
>
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH 00/32] LEON

2017-05-11 Thread Joel Sherrill
If this touches nothing but LEON BSP code and you have tested it, then I am
ok with it assuming it has been adequately tested and doesn't introduce
warnings.

Did you build smp and uniprocessor?

Have you run Chris' BSP tester?

Answer yes to all and give until Monday (to give weekend for comments) and
then push them. IMO

--joel

On May 11, 2017 9:26 AM, "Daniel Hellstrom"  wrote:

> The third set of patches for LEON. In short it contains:
>  * GRCAN API changed from I/O system to C functions API, better error
> handling,
>other improvements and SMP support.
>  * GRETH ethernet reset/autonegotiation improvements for GR740
>  * Possible to have LEON3 SMP kernel to boot on other than CPU0.
>  * SMP support and warnings fixes in: GRTC, GRTM, PCI peripherals,
>GR1553BM & BC. Still need to update GRSPW and GR1553RT.
>  * Removed old unused APBUART RAW driver to reduce code duplication.
>  * Patches to make RTEMS build using LLVM Clang for sparc.
>
> Best Regards,
> Daniel Hellstrom
>
>
> ---
>
>  c/src/lib/libbsp/sparc/Makefile.am |1 -
>  c/src/lib/libbsp/sparc/leon2/Makefile.am   |1 -
>  c/src/lib/libbsp/sparc/leon3/Makefile.am   |3 +-
>  .../libbsp/sparc/leon3/console/printk_support.c|   34 +-
>  c/src/lib/libbsp/sparc/leon3/include/leon.h|2 +-
>  c/src/lib/libbsp/sparc/leon3/startup/bspstart.c|5 +
>  c/src/lib/libbsp/sparc/shared/1553/gr1553bc.c  |  123 +-
>  c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c  |   53 +-
>  c/src/lib/libbsp/sparc/shared/amba/ahbstat.c   |4 +-
>  c/src/lib/libbsp/sparc/shared/can/grcan.c  | 2206
> +++-
>  c/src/lib/libbsp/sparc/shared/include/apbuart.h|   33 -
>  c/src/lib/libbsp/sparc/shared/include/genirq.h |   47 +-
>  c/src/lib/libbsp/sparc/shared/include/grcan.h  |  268 ++-
>  c/src/lib/libbsp/sparc/shared/include/greth.h  |   11 +
>  c/src/lib/libbsp/sparc/shared/irq/genirq.c |   58 +-
>  c/src/lib/libbsp/sparc/shared/irq/irq-shared.c |   11 +-
>  c/src/lib/libbsp/sparc/shared/irq_asm.S|   12 +-
>  c/src/lib/libbsp/sparc/shared/net/greth.c  |  134 +-
>  c/src/lib/libbsp/sparc/shared/pci/gr_701.c |   67 +-
>  c/src/lib/libbsp/sparc/shared/pci/gr_cpci_gr740.c  |   76 +-
>  c/src/lib/libbsp/sparc/shared/pci/gr_leon4_n2x.c   |   66 +-
>  .../lib/libbsp/sparc/shared/pci/gr_rasta_adcdac.c  |   68 +-
>  c/src/lib/libbsp/sparc/shared/pci/gr_rasta_io.c|   68 +-
>  .../libbsp/sparc/shared/pci/gr_rasta_spw_router.c  |   66 +-
>  c/src/lib/libbsp/sparc/shared/pci/gr_rasta_tmtc.c  |   68 +-
>  c/src/lib/libbsp/sparc/shared/pci/gr_tmtc_1553.c   |   75 +-
>  c/src/lib/libbsp/sparc/shared/start/start.S|   20 +-
>  c/src/lib/libbsp/sparc/shared/tmtc/grtc.c  |  135 +-
>  c/src/lib/libbsp/sparc/shared/tmtc/grtm.c  |  198 +-
>  c/src/lib/libbsp/sparc/shared/uart/apbuart.c   |  897 
>  c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c  |8 +-
>  c/src/lib/libcpu/sparc/access/access.S |6 +-
>  c/src/lib/libcpu/sparc/reg_win/window.S|2 +-
>  c/src/lib/libcpu/sparc/syscall/syscall.S   |2 +-
>  cpukit/score/include/rtems/score/threadqimpl.h |4 +-
>  35 files changed, 2382 insertions(+), 2450 deletions(-)
>
> --
> 2.7.4
> ___
> devel mailing list
> devel@rtems.org
> http://lists.rtems.org/mailman/listinfo/devel
>
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: GCC 7.1 Released

2017-05-11 Thread Joel Sherrill
Ok to

On May 11, 2017 5:09 AM, "Sebastian Huber" <
sebastian.hu...@embedded-brains.de> wrote:

Hello,

if someone wants to use GCC 7.1 for RTEMS 4.12, then the RSB should be
updated accordingly as soon as possible.


Chris posted a patch to bump gcc and binutils. He just needs to push it.

I had a local patch to just do gcc but thanks to timezone differences, he
posted first. :)



-- 
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH 23/32] leon, ahbstat: remove printf warnings

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/amba/ahbstat.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/amba/ahbstat.c 
b/c/src/lib/libbsp/sparc/shared/amba/ahbstat.c
index ee697f6..11bccb9 100644
--- a/c/src/lib/libbsp/sparc/shared/amba/ahbstat.c
+++ b/c/src/lib/libbsp/sparc/shared/amba/ahbstat.c
@@ -186,8 +186,8 @@ void ahbstat_isr(void *arg)
" at 0x%08lx\n",
status & AHBSTAT_STS_CE ? "single" : "non-correctable",
status & AHBSTAT_STS_HW ? "write" : "read",
-   (int) (status & AHBSTAT_STS_HS) >> AHBSTAT_STS_HS_BIT,
-   (int) (status & AHBSTAT_STS_HM) >> AHBSTAT_STS_HM_BIT,
+   (status & AHBSTAT_STS_HS) >> AHBSTAT_STS_HS_BIT,
+   (status & AHBSTAT_STS_HM) >> AHBSTAT_STS_HM_BIT,
fadr);
}
 
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 31/32] sparc: only define start if it is different from SYM(start)

2017-05-11 Thread Daniel Hellstrom
From: Jacob Hansen 

The SYM define concatenates the input with the compiler set
__USER_LABEL_PREFIX__ define. This define appears to be '_' in GCC but
empty in Clang. Therefore when compiling with Clang/LLVM 'SYM(start)'
and 'start' defines the same symbol, and the compiler complains that the
symbol is defined twice.
---
 c/src/lib/libbsp/sparc/shared/start/start.S | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/c/src/lib/libbsp/sparc/shared/start/start.S 
b/c/src/lib/libbsp/sparc/shared/start/start.S
index d9044b2..3b9f841 100644
--- a/c/src/lib/libbsp/sparc/shared/start/start.S
+++ b/c/src/lib/libbsp/sparc/shared/start/start.S
@@ -79,7 +79,9 @@
   .global start, __bsp_mem_init
 
 SYM(start):
+#if SYM(start) != start
 start:
+#endif 
 
 /*
  *  The trap table has to be the first code in a boot PROM.  But because
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 28/32] leon, grtc: updated overrun condition handling

2017-05-11 Thread Daniel Hellstrom
The following functions now reports to the user that an overrun has
occured by returning errno EIO:
 * grtc_read, on overrun and no more data in the DMA buffer
 * ioctl(GRTC_IOC_RECV), on overrun and no more frames in the DMA buffer
 * ioctl(GRTC_IOC_ISSTARTED), EIO is returned on overrun
---
 c/src/lib/libbsp/sparc/shared/tmtc/grtc.c | 44 +++
 1 file changed, 33 insertions(+), 11 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/tmtc/grtc.c 
b/c/src/lib/libbsp/sparc/shared/tmtc/grtc.c
index e2661c8..3cceb60 100644
--- a/c/src/lib/libbsp/sparc/shared/tmtc/grtc.c
+++ b/c/src/lib/libbsp/sparc/shared/tmtc/grtc.c
@@ -523,7 +523,7 @@ static int __inline__ grtc_hw_data_avail(unsigned int rrp, 
unsigned rwp, unsigne
return rwp+(bufsize-rrp);
 }
 
-/* Reads as much as possib�e but not more than 'max' bytes from the TC receive 
buffer.
+/* Reads as much as possible but not more than 'max' bytes from the TC receive 
buffer.
  * Number of bytes put into 'buf' is returned.
  */
 static int grtc_hw_read_try(struct grtc_priv *pDev, char *buf, int max)
@@ -599,7 +599,7 @@ static int grtc_hw_read_try(struct grtc_priv *pDev, char 
*buf, int max)
return count;
 }
 
-/* Reads as much as possib�e but not more than 'max' bytes from the TC receive 
buffer.
+/* Reads as much as possible but not more than 'max' bytes from the TC receive 
buffer.
  * Number of bytes put into 'buf' is returned.
  */
 static int grtc_data_avail(struct grtc_priv *pDev)
@@ -659,6 +659,12 @@ static int grtc_start(struct grtc_priv *pDev)
return RTEMS_IO_ERROR;
}
 
+   /* make sure the RX semaphore is in the correct state when starting.
+* In case of a previous overrun condition it could be in incorrect
+* state (where rtems_semaphore_flush was used).
+*/
+   rtems_semaphore_obtain(pDev->sem_rx, RTEMS_NO_WAIT, 0);
+
/* Set operating modes */
tmp = 0;
if ( pDev->config.psr_enable )
@@ -814,6 +820,7 @@ static rtems_device_driver grtc_open(
pDev->ready.cnt = 0;
 
pDev->running = 0;
+   pDev->overrun_condition = 0;
 
memset(>config,0,sizeof(pDev->config));
 
@@ -841,7 +848,7 @@ static rtems_device_driver 
grtc_close(rtems_device_major_number major, rtems_dev
grtc_stop(pDev);
pDev->running = 0;
}
-   
+
/* Reset core */
grtc_hw_reset(pDev);

@@ -910,16 +917,22 @@ read_from_buffer:
/* Non-blocking mode and no data read. */
return RTEMS_TIMEOUT;
}
-   
+
/* Tell caller how much was read. */
-   
+
DBG("READ returning %d bytes, left: %d\n",rw_args->count-left,left);
-   
+
rw_args->bytes_moved = rw_args->count - left;
-   if ( rw_args->bytes_moved == 0 ){
+   if ( rw_args->bytes_moved == 0 ) {
+   if ( pDev->overrun_condition ) {
+   /* signal to the user that overrun has happend when
+* no more data can be read out.
+*/
+   return RTEMS_IO_ERROR;
+   }
return RTEMS_TIMEOUT;
}
-   
+
return RTEMS_SUCCESSFUL;
 }
 
@@ -1569,6 +1582,8 @@ static rtems_device_driver 
grtc_ioctl(rtems_device_major_number major, rtems_dev
case GRTC_IOC_ISSTARTED:
if ( !pDev->running ) {
return RTEMS_RESOURCE_IN_USE;
+   } else if ( pDev->overrun_condition ) {
+   return RTEMS_IO_ERROR;
}
break;
 
@@ -1850,13 +1865,20 @@ static rtems_device_driver 
grtc_ioctl(rtems_device_major_number major, rtems_dev
frmlist->head = pDev->ready.head;
frmlist->tail = pDev->ready.tail;
frmlist->cnt = pDev->ready.cnt;
-   
+
/* Empty list */
pDev->ready.head = NULL;
pDev->ready.tail = NULL;
pDev->ready.cnt = 0;
+
+   if ((frmlist->cnt == 0) && pDev->overrun_condition) {
+   /* signal to the user that overrun has happend when
+* no more data can be read out.
+*/
+   return RTEMS_IO_ERROR;
+   }
break;
-   
+
case GRTC_IOC_GET_CLCW_ADR:
if ( !data ) {
return RTEMS_INVALID_NAME;
@@ -1878,7 +1900,7 @@ static void grtc_interrupt(void *arg)
 
/* Clear interrupt by reading it */
status = READ_REG(>pisr);
-   
+
/* Spurious Interrupt? */
if ( !pDev->running )
return;
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

[PATCH 26/32] leon, gr1553bc: SMP support by using spin-locks

2017-05-11 Thread Daniel Hellstrom
Since DMA buffers are managed by the user, responsibility is put on
the user to cope with SMP in the application.
---
 c/src/lib/libbsp/sparc/shared/1553/gr1553bc.c | 123 ++
 1 file changed, 84 insertions(+), 39 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/1553/gr1553bc.c 
b/c/src/lib/libbsp/sparc/shared/1553/gr1553bc.c
index bce5bb4..3b967d0 100644
--- a/c/src/lib/libbsp/sparc/shared/1553/gr1553bc.c
+++ b/c/src/lib/libbsp/sparc/shared/1553/gr1553bc.c
@@ -10,30 +10,54 @@
 
 #include 
 #include 
+#include 
 #include 
 #include 
 
 #include 
 #include 
 
+/* Use interrupt lock privmitives compatible with SMP defined in
+ * RTEMS 4.11.99 and higher.
+ */
+#if (((__RTEMS_MAJOR__ << 16) | (__RTEMS_MINOR__ << 8) | __RTEMS_REVISION__) 
>= 0x040b63)
+
+/* map via rtems_interrupt_lock_* API: */
+#define SPIN_DECLARE(lock) RTEMS_INTERRUPT_LOCK_MEMBER(lock)
+#define SPIN_INIT(lock, name) rtems_interrupt_lock_initialize(lock, name)
+#define SPIN_LOCK(lock, level) rtems_interrupt_lock_acquire_isr(lock, )
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_lock_acquire(lock, )
+#define SPIN_UNLOCK(lock, level) rtems_interrupt_lock_release_isr(lock, )
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_lock_release(lock, )
+#define SPIN_IRQFLAGS(k) rtems_interrupt_lock_context k
+#define SPIN_ISR_IRQFLAGS(k) SPIN_IRQFLAGS(k)
+#define SPIN_FREE(lock) rtems_interrupt_lock_destroy(lock)
+
+#else
+
+/* maintain single-core compatibility with older versions of RTEMS: */
+#define SPIN_DECLARE(name)
+#define SPIN_INIT(lock, name)
+#define SPIN_LOCK(lock, level)
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_disable(level)
+#define SPIN_UNLOCK(lock, level)
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_enable(level)
+#define SPIN_IRQFLAGS(k) rtems_interrupt_level k
+#define SPIN_ISR_IRQFLAGS(k)
+#define SPIN_FREE(lock)
+
+#ifdef RTEMS_SMP
+#error SMP mode not compatible with these interrupt lock primitives
+#endif
+
+#endif
+
 #define GR1553BC_WRITE_MEM(adr, val) *(volatile uint32_t *)(adr) = 
(uint32_t)(val)
 #define GR1553BC_READ_MEM(adr) (*(volatile uint32_t *)(adr))
 
 #define GR1553BC_WRITE_REG(adr, val) *(volatile uint32_t *)(adr) = 
(uint32_t)(val)
 #define GR1553BC_READ_REG(adr) (*(volatile uint32_t *)(adr))
 
-#ifndef IRQ_GLOBAL_PREPARE
- #define IRQ_GLOBAL_PREPARE(level) rtems_interrupt_level level
-#endif
-
-#ifndef IRQ_GLOBAL_DISABLE
- #define IRQ_GLOBAL_DISABLE(level) rtems_interrupt_disable(level)
-#endif
-
-#ifndef IRQ_GLOBAL_ENABLE
- #define IRQ_GLOBAL_ENABLE(level) rtems_interrupt_enable(level)
-#endif
-
 /* Needed by list for data pinter and BD translation */
 struct gr1553bc_priv {
struct drvmgr_dev **pdev;
@@ -41,6 +65,7 @@ struct gr1553bc_priv {
struct gr1553bc_list *list;
struct gr1553bc_list *alist;
int started;
+   SPIN_DECLARE(devlock);
 
/* IRQ log management */
void *irq_log_p;
@@ -1276,6 +1301,8 @@ void *gr1553bc_open(int minor)
pnpinfo = >info;
priv->regs = (struct gr1553b_regs *)pnpinfo->apb_slv->start;
 
+   SPIN_INIT(>devlock, "gr1553bc");
+
gr1553bc_device_init(priv);
 
/* Register ISR handler (unmask at IRQ controller) */
@@ -1310,6 +1337,7 @@ void gr1553bc_close(void *bc)
 
/* Free device */
gr1553_bc_close(priv->pdev);
+   SPIN_FREE(>devlock);
free(priv->irq_log_p);
free(priv);
 }
@@ -1340,7 +1368,7 @@ int gr1553bc_start(void *bc, struct gr1553bc_list *list, 
struct gr1553bc_list *l
struct gr1553bc_priv *priv = bc;
union gr1553bc_bd *bd = NULL, *bd_async = NULL;
uint32_t ctrl, irqmask;
-   IRQ_GLOBAL_PREPARE(oldLevel);
+   SPIN_IRQFLAGS(irqflags);
 
if ( (list == NULL) && (list_async == NULL) )
return 0;
@@ -1365,7 +1393,8 @@ int gr1553bc_start(void *bc, struct gr1553bc_list *list, 
struct gr1553bc_list *l
}
 
/* Do "hot-swapping" of lists */
-   IRQ_GLOBAL_DISABLE(oldLevel);
+   SPIN_LOCK_IRQ(>devlock, irqflags);
+
if ( list ) {
priv->list = list;
GR1553BC_WRITE_REG(>regs->bc_bd, (uint32_t)bd);
@@ -1386,7 +1415,7 @@ int gr1553bc_start(void *bc, struct gr1553bc_list *list, 
struct gr1553bc_list *l
GR1553BC_WRITE_REG(>regs->imask, irqmask);
}
 
-   IRQ_GLOBAL_ENABLE(oldLevel);
+   SPIN_UNLOCK_IRQ(>devlock, irqflags);
 
return 0;
 }
@@ -1396,13 +1425,13 @@ int gr1553bc_pause(void *bc)
 {
struct gr1553bc_priv *priv = bc;
uint32_t ctrl;
-   IRQ_GLOBAL_PREPARE(oldLevel);
+   SPIN_IRQFLAGS(irqflags);
 
/* Do "hot-swapping" of lists */
-   IRQ_GLOBAL_DISABLE(oldLevel);
+   SPIN_LOCK_IRQ(>devlock, irqflags);
ctrl = GR1553BC_KEY | GR1553B_BC_ACT_SCSUS;
GR1553BC_WRITE_REG(>regs->bc_ctrl, ctrl);
-   IRQ_GLOBAL_ENABLE(oldLevel);
+   SPIN_UNLOCK_IRQ(>devlock, irqflags);
 
return 0;
 }
@@ -1412,12 +1441,12 

[PATCH 30/32] sparc: Adjust assembly to improve compability with LLVM

2017-05-11 Thread Daniel Hellstrom
From: Jacob Hansen 

- All references of %0 changed to %g0

- 'call label,0' changed to 'call label'. According to the sparc
  specification call does not take any registers

- '.seg "text"' changed to '.section ".text"'

- the synonym stub is replaced with stb

- the synonym stuh is replaced with sth
---
 c/src/lib/libbsp/sparc/shared/irq_asm.S | 12 ++--
 c/src/lib/libbsp/sparc/shared/start/start.S |  4 ++--
 c/src/lib/libcpu/sparc/access/access.S  |  6 +++---
 c/src/lib/libcpu/sparc/reg_win/window.S |  2 +-
 c/src/lib/libcpu/sparc/syscall/syscall.S|  2 +-
 5 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/irq_asm.S 
b/c/src/lib/libbsp/sparc/shared/irq_asm.S
index 17a77d6..3d83431 100644
--- a/c/src/lib/libbsp/sparc/shared/irq_asm.S
+++ b/c/src/lib/libbsp/sparc/shared/irq_asm.S
@@ -459,7 +459,7 @@ dont_do_the_window:
 #if defined(RTEMS_PROFILING)
  sethi   %hi(_SPARC_Counter), %o5
 ld   [%o5 + %lo(_SPARC_Counter)], %l4
-call %l4, 0
+call %l4
  nop
 mov  %o0, %o5
 #else
@@ -542,7 +542,7 @@ pil_fixed:
 ! o1 = 2nd arg = address of the ISF
 !   WAS LOADED WHEN ISF WAS SAVED!!!
 mov  %l3, %o0   ! o0 = 1st arg = vector number
-call %g4, 0
+call %g4
 #if defined(RTEMS_PROFILING)
  mov %o5, %l3   ! save interrupt entry instant
 #else
@@ -560,11 +560,11 @@ pil_fixed:
 cmp  %l7, 0
 bne  profiling_not_outer_most_exit
  nop
-call %l4, 0 ! Call _SPARC_Counter.counter_read
+call %l4! Call _SPARC_Counter.counter_read
  mov %g1, %l4   ! Save previous interrupt status
 mov  %o0, %o2   ! o2 = 3rd arg = interrupt exit instant
 mov  %l3, %o1   ! o1 = 2nd arg = interrupt entry 
instant
-call SYM(_Profiling_Outer_most_interrupt_entry_and_exit), 0
+call SYM(_Profiling_Outer_most_interrupt_entry_and_exit)
  mov %g6, %o0   ! o0 = 1st arg = per-CPU control
 profiling_not_outer_most_exit:
 #endif
@@ -647,7 +647,7 @@ isr_dispatch:
 std %f28, [%sp + FP_FRAME_OFFSET_F28_F29]
 std %f30, [%sp + FP_FRAME_OFFSET_F3O_F31]
 st  %fsr, [%sp + FP_FRAME_OFFSET_FSR]
-callSYM(_Thread_Do_dispatch), 0
+callSYM(_Thread_Do_dispatch)
  mov%g6, %o0
 
 /*
@@ -677,7 +677,7 @@ isr_dispatch:
 non_fp_thread_dispatch:
 #endif
 
-callSYM(_Thread_Do_dispatch), 0
+callSYM(_Thread_Do_dispatch)
  mov%g6, %o0
 
 #if SPARC_HAS_FPU == 1 && defined(SPARC_USE_SAFE_FP_SUPPORT)
diff --git a/c/src/lib/libbsp/sparc/shared/start/start.S 
b/c/src/lib/libbsp/sparc/shared/start/start.S
index 6a9faaf..d9044b2 100644
--- a/c/src/lib/libbsp/sparc/shared/start/start.S
+++ b/c/src/lib/libbsp/sparc/shared/start/start.S
@@ -74,7 +74,7 @@
 
 #define SOFT_TRAP BAD_TRAP
 
-  .seg"text"
+  .section".text"
   PUBLIC(start)
   .global start, __bsp_mem_init
 
@@ -352,7 +352,7 @@ zerobss:
 bleu,a zerobss
 nop
 
-mov %0, %o0 ! command line
+mov %g0, %o0! command line
 callSYM(boot_card)  ! does not return
  sub %sp, 0x60, %sp ! room for boot_card to save args
 
diff --git a/c/src/lib/libcpu/sparc/access/access.S 
b/c/src/lib/libcpu/sparc/access/access.S
index f52e693..cb8693b 100644
--- a/c/src/lib/libcpu/sparc/access/access.S
+++ b/c/src/lib/libcpu/sparc/access/access.S
@@ -24,7 +24,7 @@
 #include 
 
.align 4
-   .seg "text"
+   .section ".text"
PUBLIC(_ld8)
PUBLIC(_ld16)
PUBLIC(_ld32)
@@ -61,12 +61,12 @@ SYM(_ld64):
 
 SYM(_st8):
retl
-stub %o1, [%o0]
+stb %o1, [%o0]
 
 SYM(_st_be16):
 SYM(_st16):
retl
-stuh %o1, [%o0]
+sth %o1, [%o0]
 
 SYM(_st_be32):
 SYM(_st32):
diff --git a/c/src/lib/libcpu/sparc/reg_win/window.S 
b/c/src/lib/libcpu/sparc/reg_win/window.S
index f57fbe1..b874559 100644
--- a/c/src/lib/libcpu/sparc/reg_win/window.S
+++ b/c/src/lib/libcpu/sparc/reg_win/window.S
@@ -23,7 +23,7 @@
 
 #include 
 
-.seg"text"
+.section".text"
 /*
  *  Window overflow trap handler.
  *
diff --git a/c/src/lib/libcpu/sparc/syscall/syscall.S 
b/c/src/lib/libcpu/sparc/syscall/syscall.S
index d00aa03..d5e1f43 100644
--- a/c/src/lib/libcpu/sparc/syscall/syscall.S
+++ b/c/src/lib/libcpu/sparc/syscall/syscall.S
@@ -19,7 +19,7 @@
 #include 
 #include "syscall.h"
 
-   .seg"text"
+   .section".text"
/*
 *  system call - halt
 *
-- 
2.7.4

___

[PATCH 29/32] leon, grtc: SMP support by using spin-locks

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/tmtc/grtc.c | 91 ++-
 1 file changed, 54 insertions(+), 37 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/tmtc/grtc.c 
b/c/src/lib/libbsp/sparc/shared/tmtc/grtc.c
index 3cceb60..c01d7d8 100644
--- a/c/src/lib/libbsp/sparc/shared/tmtc/grtc.c
+++ b/c/src/lib/libbsp/sparc/shared/tmtc/grtc.c
@@ -23,17 +23,20 @@
 #include 
 #include 
 
-#ifndef IRQ_GLOBAL_PREPARE
- #define IRQ_GLOBAL_PREPARE(level) rtems_interrupt_level level
-#endif
-
-#ifndef IRQ_GLOBAL_DISABLE
- #define IRQ_GLOBAL_DISABLE(level) rtems_interrupt_disable(level)
-#endif
-
-#ifndef IRQ_GLOBAL_ENABLE
- #define IRQ_GLOBAL_ENABLE(level) rtems_interrupt_enable(level)
-#endif
+/* map via rtems_interrupt_lock_* API: */
+#define SPIN_DECLARE(lock) RTEMS_INTERRUPT_LOCK_MEMBER(lock)
+#define SPIN_INIT(lock, name) rtems_interrupt_lock_initialize(lock, name)
+#define SPIN_LOCK(lock, level) rtems_interrupt_lock_acquire_isr(lock, )
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_lock_acquire(lock, )
+#define SPIN_UNLOCK(lock, level) rtems_interrupt_lock_release_isr(lock, )
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_lock_release(lock, )
+#define SPIN_IRQFLAGS(k) rtems_interrupt_lock_context k
+#define SPIN_ISR_IRQFLAGS(k) SPIN_IRQFLAGS(k)
+
+/* turn on/off local CPU's interrupt to ensure HW timing - not SMP safe. */
+#define IRQ_LOCAL_DECLARE(_level) rtems_interrupt_level _level
+#define IRQ_LOCAL_DISABLE(_level) rtems_interrupt_local_disable(_level)
+#define IRQ_LOCAL_ENABLE(_level) rtems_interrupt_local_enable(_level)
 
 /*
 #define DEBUG
@@ -236,6 +239,7 @@ struct grtc_priv {
chardevName[32];/* Device Name */
struct grtc_regs*regs;  /* TC Hardware Register MAP */
int irq;/* IRQ number of TC core */
+   SPIN_DECLARE(devlock);  /* spin-lock of registers */
 
int major;  /* Driver major */
int minor;  /* Device Minor */
@@ -398,6 +402,8 @@ static int grtc_init3(struct drvmgr_dev *dev)
sprintf(priv->devName, "/dev/%sgrtc%d", prefix, dev->minor_bus);
}
 
+   SPIN_INIT(>devlock, priv->devName);
+
/* Register Device */
status = rtems_io_register_name(priv->devName, grtc_driver_io_major, 
dev->minor_drv);
if (status != RTEMS_SUCCESSFUL) {
@@ -703,9 +709,12 @@ static int grtc_start(struct grtc_priv *pDev)
return 0;
 }
 
-static void grtc_stop(struct grtc_priv *pDev)
+static void grtc_stop(struct grtc_priv *pDev, int overrun)
 {
struct grtc_regs *regs = pDev->regs;
+   SPIN_IRQFLAGS(irqflags);
+
+   SPIN_LOCK_IRQ(>devlock, irqflags);
 
/* Disable the receiver */
regs->cor = GRTC_SEB;
@@ -717,6 +726,14 @@ static void grtc_stop(struct grtc_priv *pDev)
 
DBG("GRTC: STOPPED\n");
 
+   if (overrun) {
+   pDev->overrun_condition = 1;
+   } else {
+   pDev->running = 0;
+   }
+
+   SPIN_UNLOCK_IRQ(>devlock, irqflags);
+
/* Flush semaphores in case a thread is stuck waiting for CLTUs (RX 
data) */
rtems_semaphore_flush(pDev->sem_rx);
 }
@@ -728,14 +745,14 @@ static int grtc_wait_data(struct grtc_priv *pDev, int 
count, rtems_interval time
 {
int avail;
int ret;
-   IRQ_GLOBAL_PREPARE(oldLevel);
+   SPIN_IRQFLAGS(irqflags);
 
FUNCDBG();
 
if ( count < 1 )
return 0;
 
-   IRQ_GLOBAL_DISABLE(oldLevel);
+   SPIN_LOCK_IRQ(>devlock, irqflags);
 
/* Enable interrupts when receiving CLTUs, Also clear old pending CLTUs 
store
 * interrupts.
@@ -747,7 +764,7 @@ static int grtc_wait_data(struct grtc_priv *pDev, int 
count, rtems_interval time
if ( avail < count ) {
/* Wait for interrupt. */
 
-   IRQ_GLOBAL_ENABLE(oldLevel);
+   SPIN_UNLOCK_IRQ(>devlock, irqflags);
 
if ( timeout == 0 ){
timeout = RTEMS_NO_TIMEOUT;
@@ -759,7 +776,7 @@ static int grtc_wait_data(struct grtc_priv *pDev, int 
count, rtems_interval time
 * which should cancel this operation.
 * RTEMS_OBJECT_WAS_DELETED, RTEMS_INVALID_ID = driver error.
 */
-   IRQ_GLOBAL_DISABLE(oldLevel);
+   SPIN_LOCK_IRQ(>devlock, irqflags);
}else{
ret = RTEMS_SUCCESSFUL; 
}
@@ -767,7 +784,7 @@ static int grtc_wait_data(struct grtc_priv *pDev, int 
count, rtems_interval time
/* Disable interrupts when receiving CLTUs */
pDev->regs->imr = READ_REG(>regs->imr) & ~GRTC_INT_CS;
 
-   IRQ_GLOBAL_ENABLE(oldLevel);
+   SPIN_UNLOCK_IRQ(>devlock, irqflags);
 
return ret;
 }
@@ -845,8 +862,7 @@ static rtems_device_driver 
grtc_close(rtems_device_major_number major, rtems_dev
pDev = (struct 

[PATCH 27/32] leon, gr1553bm: SMP support by using spin-locks

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c | 53 ---
 1 file changed, 39 insertions(+), 14 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c 
b/c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c
index d1b208f..d63983b 100644
--- a/c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c
+++ b/c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c
@@ -23,21 +23,45 @@
 #define GR1553BM_WRITE_REG(adr, val) *(volatile uint32_t *)(adr) = 
(uint32_t)(val)
 #define GR1553BM_READ_REG(adr) (*(volatile uint32_t *)(adr))
 
-#ifndef IRQ_GLOBAL_PREPARE
- #define IRQ_GLOBAL_PREPARE(level) rtems_interrupt_level level
-#endif
-
-#ifndef IRQ_GLOBAL_DISABLE
- #define IRQ_GLOBAL_DISABLE(level) rtems_interrupt_disable(level)
+/* Use interrupt lock privmitives compatible with SMP defined in
+ * RTEMS 4.11.99 and higher.
+ */
+#if (((__RTEMS_MAJOR__ << 16) | (__RTEMS_MINOR__ << 8) | __RTEMS_REVISION__) 
>= 0x040b63)
+
+/* map via rtems_interrupt_lock_* API: */
+#define SPIN_DECLARE(lock) RTEMS_INTERRUPT_LOCK_MEMBER(lock)
+#define SPIN_INIT(lock, name) rtems_interrupt_lock_initialize(lock, name)
+#define SPIN_LOCK(lock, level) rtems_interrupt_lock_acquire_isr(lock, )
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_lock_acquire(lock, )
+#define SPIN_UNLOCK(lock, level) rtems_interrupt_lock_release_isr(lock, )
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_lock_release(lock, )
+#define SPIN_IRQFLAGS(k) rtems_interrupt_lock_context k
+#define SPIN_ISR_IRQFLAGS(k) SPIN_IRQFLAGS(k)
+#define SPIN_FREE(lock) rtems_interrupt_lock_destroy(lock)
+
+#else
+
+/* maintain single-core compatibility with older versions of RTEMS: */
+#define SPIN_DECLARE(name)
+#define SPIN_INIT(lock, name)
+#define SPIN_LOCK(lock, level)
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_disable(level)
+#define SPIN_UNLOCK(lock, level)
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_enable(level)
+#define SPIN_IRQFLAGS(k) rtems_interrupt_level k
+#define SPIN_ISR_IRQFLAGS(k)
+#define SPIN_FREE(lock)
+
+#ifdef RTEMS_SMP
+#error SMP mode not compatible with these interrupt lock primitives
 #endif
 
-#ifndef IRQ_GLOBAL_ENABLE
- #define IRQ_GLOBAL_ENABLE(level) rtems_interrupt_enable(level)
 #endif
 
 struct gr1553bm_priv {
struct drvmgr_dev **pdev;
struct gr1553b_regs *regs;
+   SPIN_DECLARE(devlock);
 
void *buffer;
unsigned int buffer_base_hw;
@@ -80,10 +104,10 @@ void gr1553bm_register(void)
 
 static void gr1553bm_hw_start(struct gr1553bm_priv *priv)
 {
-   IRQ_GLOBAL_PREPARE(oldLevel);
+   SPIN_IRQFLAGS(irqflags);
 
/* Enable IRQ source and mark running state */
-   IRQ_GLOBAL_DISABLE(oldLevel);
+   SPIN_LOCK_IRQ(>devlock, irqflags);
 
priv->started = 1;
 
@@ -103,14 +127,14 @@ static void gr1553bm_hw_start(struct gr1553bm_priv *priv)

(GR1553B_BM_CTRL_MANL|GR1553B_BM_CTRL_UDWL|GR1553B_BM_CTRL_IMCL))
| GR1553B_BM_CTRL_BMEN;
 
-   IRQ_GLOBAL_ENABLE(oldLevel);
+   SPIN_UNLOCK_IRQ(>devlock, irqflags);
 }
 
 static void gr1553bm_hw_stop(struct gr1553bm_priv *priv)
 {
-   IRQ_GLOBAL_PREPARE(oldLevel);
+   SPIN_IRQFLAGS(irqflags);
 
-   IRQ_GLOBAL_DISABLE(oldLevel);
+   SPIN_LOCK_IRQ(>devlock, irqflags);
 
/* Stop Logging */
priv->regs->bm_ctrl = 0;
@@ -123,7 +147,7 @@ static void gr1553bm_hw_stop(struct gr1553bm_priv *priv)
 
priv->started = 0;
 
-   IRQ_GLOBAL_ENABLE(oldLevel);
+   SPIN_UNLOCK_IRQ(>devlock, irqflags);
 }
 
 /* Open device by number */
@@ -152,6 +176,7 @@ void *gr1553bm_open(int minor)
ambadev = (struct amba_dev_info *)(*pdev)->businfo;
pnpinfo = >info;
priv->regs = (struct gr1553b_regs *)pnpinfo->apb_slv->start;
+   SPIN_INIT(>devlock, "gr1553bm");
 
/* Start with default configuration */
priv->cfg = gr1553bm_default_config;
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 25/32] leon, apbuart: remove old RAW UART driver

2017-05-11 Thread Daniel Hellstrom
This driver was initially intended for APBUART access on GRLIB PCI
peripherals (AMBA-over-PCI). There are already many APBUART drivers
for LEON. Instead of using this one the termios APBUART should work
on AMBA-over-PCI systems with recent changes on LEON3, however that
has not been tested yet.
---
 c/src/lib/libbsp/sparc/Makefile.am  |   1 -
 c/src/lib/libbsp/sparc/leon2/Makefile.am|   1 -
 c/src/lib/libbsp/sparc/leon3/Makefile.am|   3 +-
 c/src/lib/libbsp/sparc/shared/include/apbuart.h |  33 -
 c/src/lib/libbsp/sparc/shared/uart/apbuart.c| 897 
 5 files changed, 1 insertion(+), 934 deletions(-)
 delete mode 100644 c/src/lib/libbsp/sparc/shared/uart/apbuart.c

diff --git a/c/src/lib/libbsp/sparc/Makefile.am 
b/c/src/lib/libbsp/sparc/Makefile.am
index a894f34..d17d691 100644
--- a/c/src/lib/libbsp/sparc/Makefile.am
+++ b/c/src/lib/libbsp/sparc/Makefile.am
@@ -83,7 +83,6 @@ EXTRA_DIST += shared/uart/cons.c
 EXTRA_DIST += shared/uart/apbuart_cons.c
 EXTRA_DIST += shared/include/cons.h
 EXTRA_DIST += shared/include/apbuart_cons.h
-EXTRA_DIST += shared/uart/apbuart.c
 EXTRA_DIST += shared/include/apbuart.h
 
 # CAN (OC_CAN, GRCAN)
diff --git a/c/src/lib/libbsp/sparc/leon2/Makefile.am 
b/c/src/lib/libbsp/sparc/leon2/Makefile.am
index 94e10cd..349b44d 100644
--- a/c/src/lib/libbsp/sparc/leon2/Makefile.am
+++ b/c/src/lib/libbsp/sparc/leon2/Makefile.am
@@ -154,7 +154,6 @@ libbsp_a_SOURCES += ../../sparc/shared/spw/grspw_router.c
 
 # UART (RAW)
 include_bsp_HEADERS += ../../sparc/shared/include/apbuart.h
-libbsp_a_SOURCES += ../../sparc/shared/uart/apbuart.c
 
 # I2CMST
 include_bsp_HEADERS += ../../sparc/shared/include/i2cmst.h
diff --git a/c/src/lib/libbsp/sparc/leon3/Makefile.am 
b/c/src/lib/libbsp/sparc/leon3/Makefile.am
index 83e1dff..52f6b56 100644
--- a/c/src/lib/libbsp/sparc/leon3/Makefile.am
+++ b/c/src/lib/libbsp/sparc/leon3/Makefile.am
@@ -170,8 +170,7 @@ libbsp_a_SOURCES += ../../sparc/shared/spw/grspw_router.c
 # UART
 include_bsp_HEADERS += ../../sparc/shared/include/apbuart.h \
 ../../sparc/shared/include/apbuart_termios.h
-libbsp_a_SOURCES += ../../sparc/shared/uart/apbuart.c \
-../../sparc/shared/uart/apbuart_termios.c
+libbsp_a_SOURCES += ../../sparc/shared/uart/apbuart_termios.c
 
 # I2CMST
 include_bsp_HEADERS += ../../sparc/shared/include/i2cmst.h
diff --git a/c/src/lib/libbsp/sparc/shared/include/apbuart.h 
b/c/src/lib/libbsp/sparc/shared/include/apbuart.h
index 326e769..a324805 100644
--- a/c/src/lib/libbsp/sparc/shared/include/apbuart.h
+++ b/c/src/lib/libbsp/sparc/shared/include/apbuart.h
@@ -25,33 +25,6 @@
 extern "C" {
 #endif
 
-typedef struct {
-  unsigned int hw_dovr;
-  unsigned int hw_parity;
-  unsigned int hw_frame;
-  unsigned int sw_dovr;
-  unsigned int rx_cnt;
-  unsigned int tx_cnt;
-} apbuart_stats;
-
-#define APBUART_START0
-#define APBUART_STOP 1
-#define APBUART_SET_RXFIFO_LEN 2
-#define APBUART_SET_TXFIFO_LEN 3
-#define APBUART_SET_BAUDRATE   4
-#define APBUART_SET_SCALER 5
-#define APBUART_SET_BLOCKING   6
-#define APBUART_SET_ASCII_MODE 7
-
-
-#define APBUART_GET_STATS 16
-#define APBUART_CLR_STATS 17
-
-#define APBUART_BLK_RX 0x1
-#define APBUART_BLK_TX 0x2
-#define APBUART_BLK_FLUSH 0x4
-
-
 #define APBUART_CTRL_RE 0x1
 #define APBUART_CTRL_TE 0x2
 #define APBUART_CTRL_RI 0x4
@@ -80,12 +53,6 @@ typedef struct {
 #define APBUART_STATUS_TF 0x200
 #define APBUART_STATUS_RF 0x400
 
-/* Register APBUART driver
- * bus =  pointer to AMBA bus description used to search for APBUART(s).
- *(_plb for LEON3), (LEON2: see amba_scan)
- */
-int apbuart_register (struct ambapp_bus *bus);
-
 #ifdef __cplusplus
 }
 #endif
diff --git a/c/src/lib/libbsp/sparc/shared/uart/apbuart.c 
b/c/src/lib/libbsp/sparc/shared/uart/apbuart.c
deleted file mode 100644
index 171f114..000
--- a/c/src/lib/libbsp/sparc/shared/uart/apbuart.c
+++ /dev/null
@@ -1,897 +0,0 @@
-/*
- *  This file contains the driver for the APBUART serial port.
- *  No console driver, only char driver.
- *
- *  COPYRIGHT (c) 2007.
- *  Gaisler Research.
- *
- *  The license and distribution terms for this file may be
- *  found in the file LICENSE in this distribution or at
- *  http://www.rtems.org/license/LICENSE.
- *
- *
- *  2007-07-11, Daniel Hellstrom 
- *Added ioctl command APBUART_CLR_STATS
- */
-
-#include 
-#include 
-#include 
-#include 
-#include 
-#include 
-
-#include 
-#include 
-#include 
-
-#ifndef DEFAULT_TXBUF_SIZE
- #define DEFAULT_TXBUF_SIZE 32
-#endif
-#ifndef DEFAULT_RXBUF_SIZE
- #define DEFAULT_RXBUF_SIZE 32
-#endif
-
-#ifndef APBUART_PREFIX
- #define APBUART_PREFIX(name) apbuart##name
-#else
- #define APBUART_REGISTER_STATIC
-#endif
-
-#if !defined(APBUART_DEVNAME) || !defined(APBUART_DEVNAME_NO)
- #undef APBUART_DEVNAME
- #undef APBUART_DEVNAME_NO
- #define APBUART_DEVNAME "/dev/apbuart0"
- #define APBUART_DEVNAME_NO(devstr,no) ((devstr)[12]='0'+(no))
-#endif
-
-#ifndef APBUART_REG_INT
- 

[PATCH 32/32] score: remove part of an assertion that cannot compile with Clang

2017-05-11 Thread Daniel Hellstrom
From: Jacob Hansen 

---
 cpukit/score/include/rtems/score/threadqimpl.h | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/cpukit/score/include/rtems/score/threadqimpl.h 
b/cpukit/score/include/rtems/score/threadqimpl.h
index 574221c..975221c 100644
--- a/cpukit/score/include/rtems/score/threadqimpl.h
+++ b/cpukit/score/include/rtems/score/threadqimpl.h
@@ -1140,9 +1140,7 @@ typedef struct {
 #define THREAD_QUEUE_OBJECT_ASSERT( object_type, wait_queue_member ) \
   RTEMS_STATIC_ASSERT( \
 offsetof( object_type, wait_queue_member ) \
-  == offsetof( Thread_queue_Object, Wait_queue ) \
-&& ( &( ( (object_type *) 0 )->wait_queue_member ) \
-  == ( &( (Thread_queue_Object *) 0 )->Wait_queue ) ), \
+  == offsetof( Thread_queue_Object, Wait_queue ), \
 object_type \
   )
 
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 24/32] leon, grtm: SMP support by using spin-locks

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/tmtc/grtm.c | 198 +-
 1 file changed, 115 insertions(+), 83 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/tmtc/grtm.c 
b/c/src/lib/libbsp/sparc/shared/tmtc/grtm.c
index a1038d4..bd7d98f 100644
--- a/c/src/lib/libbsp/sparc/shared/tmtc/grtm.c
+++ b/c/src/lib/libbsp/sparc/shared/tmtc/grtm.c
@@ -23,17 +23,15 @@
 #include 
 #include 
 
-#ifndef IRQ_GLOBAL_PREPARE
- #define IRQ_GLOBAL_PREPARE(level) rtems_interrupt_level level
-#endif
-
-#ifndef IRQ_GLOBAL_DISABLE
- #define IRQ_GLOBAL_DISABLE(level) rtems_interrupt_disable(level)
-#endif
-
-#ifndef IRQ_GLOBAL_ENABLE
- #define IRQ_GLOBAL_ENABLE(level) rtems_interrupt_enable(level)
-#endif
+/* map via rtems_interrupt_lock_* API: */
+#define SPIN_DECLARE(lock) RTEMS_INTERRUPT_LOCK_MEMBER(lock)
+#define SPIN_INIT(lock, name) rtems_interrupt_lock_initialize(lock, name)
+#define SPIN_LOCK(lock, level) rtems_interrupt_lock_acquire_isr(lock, )
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_lock_acquire(lock, )
+#define SPIN_UNLOCK(lock, level) rtems_interrupt_lock_release_isr(lock, )
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_lock_release(lock, )
+#define SPIN_IRQFLAGS(k) rtems_interrupt_lock_context k
+#define SPIN_ISR_IRQFLAGS(k) SPIN_IRQFLAGS(k)
 
 /*
 #define DEBUG
@@ -364,6 +362,7 @@ struct grtm_priv {
int irq;
int minor;
int subrev; /* GRTM Revision */
+   SPIN_DECLARE(devlock);  /* spin-lock ISR protection */
 
int open;
int running;
@@ -511,6 +510,8 @@ static int grtm_init3(struct drvmgr_dev *dev)
sprintf(priv->devName, "/dev/%sgrtm%d", prefix, dev->minor_bus);
}
 
+   SPIN_INIT(>devlock, priv->devName);
+
/* Register Device */
status = rtems_io_register_name(priv->devName, grtm_driver_io_major, 
dev->minor_drv);
if (status != RTEMS_SUCCESSFUL) {
@@ -938,10 +939,11 @@ static rtems_device_driver 
grtm_close(rtems_device_major_number major, rtems_dev
pDev = (struct grtm_priv *)dev->priv;
 
if ( pDev->running ){
+   drvmgr_interrupt_unregister(dev, 0, grtm_interrupt, pDev);
grtm_stop(pDev);
pDev->running = 0;
}
-   
+
/* Reset core */
grtm_hw_reset(pDev);
 
@@ -1067,13 +1069,12 @@ static int grtm_free_sent(struct grtm_priv *pDev)
  * Return Value
  * Returns number of frames moved from ready to scheduled queue 
  */
-static int grtm_schedule_ready(struct grtm_priv *pDev, int ints_off)
+static int grtm_schedule_ready(struct grtm_priv *pDev)
 {
int cnt;
unsigned int ctrl, dmactrl;
struct grtm_ring *curr_bd;
struct grtm_frame *curr_frm, *last_frm;
-   IRQ_GLOBAL_PREPARE(oldLevel);
 
if ( !pDev->ready.head ){
return 0;
@@ -1165,23 +1166,83 @@ static int grtm_schedule_ready(struct grtm_priv *pDev, 
int ints_off)
 
/* Update TX ring posistion */
pDev->ring = curr_bd;
-   if ( !ints_off ) {
-   IRQ_GLOBAL_DISABLE(oldLevel);
-   }
 
/* Make hardware aware of the newly enabled descriptors */
dmactrl = READ_REG(>regs->dma_ctrl);
dmactrl &= ~(GRTM_DMA_CTRL_TXRST | GRTM_DMA_CTRL_RST);
dmactrl |= GRTM_DMA_CTRL_EN;
pDev->regs->dma_ctrl = dmactrl;
-   
-   if ( !ints_off ) {
-   IRQ_GLOBAL_ENABLE(oldLevel);
-   }
}
+
return cnt;
 }
 
+static void grtm_tx_process(struct grtm_priv *pDev)
+{
+   int num;
+
+   /* Free used descriptors and put the sent frame into the "Sent queue"  
+*   (SCHEDULED->SENT)
+*/
+   num = grtm_free_sent(pDev);
+   pDev->scheduled_cnt -= num;
+   pDev->sent_cnt += num;
+
+   /* Use all available free descriptors there are frames for
+* in the ready queue.
+*   (READY->SCHEDULED)
+*/
+   if (pDev->running) {
+   num = grtm_schedule_ready(pDev);
+   pDev->ready_cnt -= num;
+   pDev->scheduled_cnt += num;
+   }
+}
+
+/*
+ * The TX lock protects user tasks from the ISR. If TX DMA interrupt occurs
+ * while the user task is processing the TX DMA descriptors the ISR will
+ * ignore interrupt the request by not processing the DMA table since that
+ * is done by the user task anyway. In SMP, when a user task enters the TX DMA
+ * processing while the ISR (on another CPU) is also processing the user task
+ * will loop waiting for the ISR to complete.
+ */
+static int grtm_request_txlock(struct grtm_priv *pDev, int block)
+{
+   SPIN_IRQFLAGS(irqflags);
+   int got_lock = 0;
+
+   do {
+   SPIN_LOCK_IRQ(>devlock, irqflags);
+   if 

[PATCH 22/32] leon, pci-peripherals: SMP support by spin-locks and updated genirq

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/pci/gr_701.c | 67 ++-
 c/src/lib/libbsp/sparc/shared/pci/gr_cpci_gr740.c  | 76 --
 c/src/lib/libbsp/sparc/shared/pci/gr_leon4_n2x.c   | 66 ++-
 .../lib/libbsp/sparc/shared/pci/gr_rasta_adcdac.c  | 68 ++-
 c/src/lib/libbsp/sparc/shared/pci/gr_rasta_io.c| 68 ++-
 .../libbsp/sparc/shared/pci/gr_rasta_spw_router.c  | 66 ++-
 c/src/lib/libbsp/sparc/shared/pci/gr_rasta_tmtc.c  | 68 ++-
 c/src/lib/libbsp/sparc/shared/pci/gr_tmtc_1553.c   | 75 +++--
 8 files changed, 412 insertions(+), 142 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/pci/gr_701.c 
b/c/src/lib/libbsp/sparc/shared/pci/gr_701.c
index 40a0a25..a6c9ebc 100644
--- a/c/src/lib/libbsp/sparc/shared/pci/gr_701.c
+++ b/c/src/lib/libbsp/sparc/shared/pci/gr_701.c
@@ -23,6 +23,7 @@
 
 #include 
 #include 
+#include  /* spin-lock */
 #include 
 #include 
 
@@ -37,6 +38,16 @@
 
 #include 
 
+/* map via rtems_interrupt_lock_* API: */
+#define SPIN_DECLARE(lock) RTEMS_INTERRUPT_LOCK_MEMBER(lock)
+#define SPIN_INIT(lock, name) rtems_interrupt_lock_initialize(lock, name)
+#define SPIN_LOCK(lock, level) rtems_interrupt_lock_acquire_isr(lock, )
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_lock_acquire(lock, )
+#define SPIN_UNLOCK(lock, level) rtems_interrupt_lock_release_isr(lock, )
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_lock_release(lock, )
+#define SPIN_IRQFLAGS(k) rtems_interrupt_lock_context k
+#define SPIN_ISR_IRQFLAGS(k) SPIN_IRQFLAGS(k)
+
 /* Offset from 0x8000 (dual bus version) */
 #define AHB1_BASE_ADDR 0x8000
 #define AHB1_IOAREA_BASE_ADDR 0x8010
@@ -87,8 +98,9 @@ struct pci_bridge_regs {
 /* Private data structure for driver */
 struct gr701_priv {
/* Driver management */
-   struct drvmgr_dev   *dev;
+   struct drvmgr_dev   *dev;
charprefix[16];
+   SPIN_DECLARE(devlock);
 
struct pci_bridge_regs  *pcib;
struct amba_bridge_regs *ambab;
@@ -200,7 +212,9 @@ void gr701_interrupt(void *arg)
struct gr701_priv *priv = arg;
unsigned int status;
int irq = 0;
+   SPIN_ISR_IRQFLAGS(irqflags);
 
+   SPIN_LOCK(>devlock, irqflags);
while ( (status=priv->pcib->istatus) != 0 ) {
priv->interrupt_cnt++;  /* An interrupt was generated */
irq = status;
@@ -208,6 +222,7 @@ void gr701_interrupt(void *arg)
/* ACK interrupt */
priv->pcib->istatus = 0;
}
+   SPIN_UNLOCK(>devlock, irqflags);
 
/* ACK interrupt, this is because PCI is Level, so the IRQ Controller 
still drives the IRQ. */
if ( irq )
@@ -347,6 +362,12 @@ int gr701_init1(struct drvmgr_dev *dev)
if ((bar0_size == 0) || (bar1_size == 0))
return DRVMGR_ENORES;
 
+   /* Initialize spin-lock for this PCI perihperal device. This is to
+* protect the Interrupt Controller Registers. The genirq layer is
+ * protecting its own internals and ISR dispatching.
+ */
+   SPIN_INIT(>devlock, priv->prefix);
+
priv->genirq = genirq_init(16);
if ( priv->genirq == NULL ) {
free(priv);
@@ -410,12 +431,17 @@ int ambapp_gr701_int_register(
void *arg)
 {
struct gr701_priv *priv = dev->parent->dev->priv;
-   rtems_interrupt_level level;
+   SPIN_IRQFLAGS(irqflags);
int status;
+   void *h;
+
+   h = genirq_alloc_handler(handler, arg);
+   if ( h == NULL )
+   return DRVMGR_FAIL;
 
-   rtems_interrupt_disable(level);
+   SPIN_LOCK_IRQ(>devlock, irqflags);
 
-   status = genirq_register(priv->genirq, irq, handler, arg);
+   status = genirq_register(priv->genirq, irq, h);
if ( status == 0 ) {
/* Clear IRQ for first registered handler */
priv->pcib->iclear = (1<devlock, irqflags);
+   genirq_free_handler(h);
return DRVMGR_FAIL;
}
 
@@ -434,7 +461,7 @@ int ambapp_gr701_int_register(
} else if ( status == 1 )
status = DRVMGR_OK;
 
-   rtems_interrupt_enable(level);
+   SPIN_UNLOCK_IRQ(>devlock, irqflags);
 
return status;
 }
@@ -446,10 +473,11 @@ int ambapp_gr701_int_unregister(
void *arg)
 {
struct gr701_priv *priv = dev->parent->dev->priv;
-   rtems_interrupt_level level;
+   SPIN_IRQFLAGS(irqflags);
int status;
+   void *handler;
 
-   rtems_interrupt_disable(level);
+   SPIN_LOCK_IRQ(>devlock, irqflags);
 
status = genirq_disable(priv->genirq, irq, isr, arg);
if ( 

[PATCH 09/32] leon, grcan: use RTEMS 4.12 SMP interrupt lock

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 71 +++
 1 file changed, 44 insertions(+), 27 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index e955b20..409e68b 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -22,6 +22,32 @@
 #include 
 #include 
 
+#if (((__RTEMS_MAJOR__ << 16) | (__RTEMS_MINOR__ << 8) | __RTEMS_REVISION__) 
>= 0x040b63)
+
+/* Spin locks mapped via rtems_interrupt_lock_* API: */
+#define SPIN_DECLARE(lock) RTEMS_INTERRUPT_LOCK_MEMBER(lock)
+#define SPIN_INIT(lock, name) rtems_interrupt_lock_initialize(lock, name)
+#define SPIN_LOCK(lock, level) rtems_interrupt_lock_acquire_isr(lock, )
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_lock_acquire(lock, )
+#define SPIN_UNLOCK(lock, level) rtems_interrupt_lock_release_isr(lock, )
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_lock_release(lock, )
+#define SPIN_IRQFLAGS(k) rtems_interrupt_lock_context k
+#define SPIN_ISR_IRQFLAGS(k) SPIN_IRQFLAGS(k)
+
+#else
+
+/* maintain compatibility with older versions of RTEMS: */
+#define SPIN_DECLARE(name)
+#define SPIN_INIT(lock, name)
+#define SPIN_LOCK(lock, level)
+#define SPIN_LOCK_IRQ(lock, level) rtems_interrupt_disable(level)
+#define SPIN_UNLOCK(lock, level)
+#define SPIN_UNLOCK_IRQ(lock, level) rtems_interrupt_enable(level)
+#define SPIN_IRQFLAGS(k) rtems_interrupt_level k
+#define SPIN_ISR_IRQFLAGS(k)
+
+#endif
+
 /* Maximum number of GRCAN devices supported by driver */
 #define GRCAN_COUNT_MAX 8
 
@@ -43,18 +69,6 @@
  #define RX_BUF_SIZE ((3*BLOCK_SIZE)*16)
 #endif
 
-#ifndef IRQ_GLOBAL_PREPARE
- #define IRQ_GLOBAL_PREPARE(level) rtems_interrupt_level level
-#endif
-
-#ifndef IRQ_GLOBAL_DISABLE
- #define IRQ_GLOBAL_DISABLE(level) rtems_interrupt_disable(level)
-#endif
-
-#ifndef IRQ_GLOBAL_ENABLE
- #define IRQ_GLOBAL_ENABLE(level) rtems_interrupt_enable(level)
-#endif
-
 #ifndef IRQ_CLEAR_PENDING
  #define IRQ_CLEAR_PENDING(irqno)
 #endif
@@ -137,6 +151,7 @@ struct grcan_priv {
struct grcan_stats stats;
 
rtems_id rx_sem, tx_sem, txempty_sem, dev_sem;
+   SPIN_DECLARE(devlock);
 };
 
 static void __inline__ grcan_hw_reset(struct grcan_regs *regs);
@@ -384,7 +399,7 @@ static rtems_device_driver grcan_hw_start(struct grcan_priv 
*pDev)
 */
unsigned int tmp RTEMS_UNUSED;
 
-   IRQ_GLOBAL_PREPARE(oldLevel);
+   SPIN_IRQFLAGS(oldLevel);
 
FUNCDBG();
 
@@ -428,11 +443,11 @@ static rtems_device_driver grcan_hw_start(struct 
grcan_priv *pDev)
pDev->regs->imr = 0x1601f;
 
/* Enable routing of the IRQs */
-   IRQ_GLOBAL_DISABLE(oldLevel);
+   SPIN_LOCK_IRQ(>devlock, oldLevel);
IRQ_UNMASK(pDev->irq + GRCAN_IRQ_TXSYNC);
IRQ_UNMASK(pDev->irq + GRCAN_IRQ_RXSYNC);
IRQ_UNMASK(pDev->irq + GRCAN_IRQ_IRQ);
-   IRQ_GLOBAL_ENABLE(oldLevel);
+   SPIN_UNLOCK_IRQ(>devlock, oldLevel);
 
/* Reset some software data */
/*pDev->txerror = 0;
@@ -868,7 +883,7 @@ static int grcan_wait_rxdata(struct grcan_priv *pDev, int 
min)
unsigned int wp, rp, size, irq;
unsigned int irq_trunk, dataavail;
int wait;
-   IRQ_GLOBAL_PREPARE(oldLevel);
+   SPIN_IRQFLAGS(oldLevel);
 
FUNCDBG();
 
@@ -876,7 +891,7 @@ static int grcan_wait_rxdata(struct grcan_priv *pDev, int 
min)
 * Set up a valid IRQ point so that an IRQ is received
 * when one or more messages are received
 */
-   IRQ_GLOBAL_DISABLE(oldLevel);
+   SPIN_LOCK_IRQ(>devlock, oldLevel);
 
size = READ_REG(>regs->rx0size);
rp = READ_REG(>regs->rx0rd);
@@ -909,7 +924,7 @@ static int grcan_wait_rxdata(struct grcan_priv *pDev, int 
min)
/* enough message has been received, abort sleep - don't unmask 
interrupt */
wait = 0;
}
-   IRQ_GLOBAL_ENABLE(oldLevel);
+   SPIN_UNLOCK_IRQ(>devlock, oldLevel);
 
/* Wait for IRQ to fire only if has been triggered */
if (wait) {
@@ -938,12 +953,12 @@ static int grcan_wait_txspace(struct grcan_priv *pDev, 
int min)
int wait;
unsigned int irq, rp, wp, size, space_left;
unsigned int irq_trunk;
-   IRQ_GLOBAL_PREPARE(oldLevel);
+   SPIN_IRQFLAGS(oldLevel);
 
DBGC(DBG_TX, "\n");
/*FUNCDBG(); */
 
-   IRQ_GLOBAL_DISABLE(oldLevel);
+   SPIN_LOCK_IRQ(>devlock, oldLevel);
 
pDev->regs->tx0ctrl = GRCAN_TXCTRL_ENABLE;
 
@@ -985,7 +1000,7 @@ static int grcan_wait_txspace(struct grcan_priv *pDev, int 
min)
/* There are enough room in buffer, abort wait - don't unmask 
interrupt */
wait = 0;
}
-   IRQ_GLOBAL_ENABLE(oldLevel);
+   SPIN_UNLOCK_IRQ(>devlock, oldLevel);
 
/* Wait for IRQ to fire only if it has been triggered */
if (wait) {
@@ -1005,7 +1020,7 @@ 

[PATCH 20/32] leon: allow SMP boot from any CPU

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

---
 c/src/lib/libbsp/sparc/leon3/startup/bspstart.c |  5 +
 c/src/lib/libbsp/sparc/shared/start/start.S | 14 +-
 2 files changed, 14 insertions(+), 5 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/leon3/startup/bspstart.c 
b/c/src/lib/libbsp/sparc/leon3/startup/bspstart.c
index 80c2bc0..6353ca3 100644
--- a/c/src/lib/libbsp/sparc/leon3/startup/bspstart.c
+++ b/c/src/lib/libbsp/sparc/leon3/startup/bspstart.c
@@ -36,6 +36,11 @@ int CPU_SPARC_HAS_SNOOPING;
 /* Index of CPU, in an AMP system CPU-index may be non-zero */
 uint32_t LEON3_Cpu_Index = 0;
 
+#if defined(RTEMS_SMP)
+/* Index of the boot CPU. Set by the first CPU at boot to its CPU ID. */
+int LEON3_Boot_Cpu = -1;
+#endif
+
 /*
  * set_snooping
  *
diff --git a/c/src/lib/libbsp/sparc/shared/start/start.S 
b/c/src/lib/libbsp/sparc/shared/start/start.S
index 529a3c7..6a9faaf 100644
--- a/c/src/lib/libbsp/sparc/shared/start/start.S
+++ b/c/src/lib/libbsp/sparc/shared/start/start.S
@@ -281,13 +281,16 @@ SYM(hard_reset):
rd  %asr17, %o0 ! get CPU identifier
srl %o0, LEON3_ASR17_PROCESSOR_INDEX_SHIFT, %o0
 
-   cmp %o0, 0
-   beq cpu0
-nop
-
sll %o0, PER_CPU_CONTROL_SIZE_LOG2, %l0
add %g6, %l0, %g6
 
+   /* If LEON3_Boot_Cpu < 0 then assign us as boot CPU and continue. */
+   set SYM(LEON3_Boot_Cpu), %o1
+   ld  [%o1], %o2
+   tst %o2
+   bneg.Lbootcpu
+nop
+
ld  [%g6 + PER_CPU_INTERRUPT_STACK_HIGH], %sp ! set stack pointer
sub %sp, 4, %sp ! stack starts at end of area - 4
andn%sp, 0x0f, %sp  ! align stack on 16-byte boundary
@@ -295,7 +298,8 @@ SYM(hard_reset):
 
callSYM(bsp_start_on_secondary_processor) ! does not return
 sub%sp, SPARC_MINIMUM_STACK_FRAME_SIZE, %sp
-cpu0:
+.Lbootcpu:
+   st  %o0, [%o1]
 #endif
 
set (SYM(rdb_start)), %g5   ! End of RAM
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 21/32] leon, genirq: SMP support for PCI peripherals

2017-05-11 Thread Daniel Hellstrom
The common interrupt layer for GRLIB PCI perihperals is prepared for SMP
support by this patch. The existing locking (interrupt disabling) is
replaced by a new requirement on the user to implement locking before
calling the genirq API. This approach avoids taking more locks than
necessary.

The split up of the locks also introduces that the user must allocate
memory to describe ISR handlers, to avoid calling malloc()/free() while
possessing a spin-lock and interrupts are globally disabled.
---
 c/src/lib/libbsp/sparc/shared/include/genirq.h | 47 -
 c/src/lib/libbsp/sparc/shared/irq/genirq.c | 58 --
 2 files changed, 63 insertions(+), 42 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/include/genirq.h 
b/c/src/lib/libbsp/sparc/shared/include/genirq.h
index d03b812..673be17 100644
--- a/c/src/lib/libbsp/sparc/shared/include/genirq.h
+++ b/c/src/lib/libbsp/sparc/shared/include/genirq.h
@@ -35,7 +35,7 @@ struct genirq_stats {
 extern genirq_t genirq_init(int number_of_irqs);
 
 /* Free the dynamically allocated memory that the genirq interface has 
- * allocated.
+ * allocated. Also the handlers will be freed.
  *
  * Returns zero on success, otherwise failure.
  */
@@ -47,33 +47,54 @@ extern void genirq_destroy(genirq_t d);
  */
 extern int genirq_check(genirq_t d, int irq);
 
-/* Register shared interrupt handler.
+/* Allocate one ISR handler and initialize it. Input to genirq_register().
  *
- * \param irqThe interrupt number to register ISR on
  * \param isrThe interrupt service routine called upon IRQ
  * \param argThe argument given to isr() when called.
  *
+ * Returns a pointer on success, on failure NULL is returned.
+ */
+extern void *genirq_alloc_handler(genirq_handler isr, void *arg);
+
+/* Free handler memory */
+#define genirq_free_handler(handler) free(handler)
+
+/* Register shared interrupt handler previously initialized with
+ * genirq_alloc_handler().
+ *
+ * NOTE: internal list structures are accessed and needs to be protected by
+ *   spin-locks/IRQ disable by the user to guarantee a correct behaviour.
+ *
+ * \param irqThe interrupt number to register ISR on
+ * \param handler Install the pre- allocated and initialized handler.
+ *
  * Return Values
  * -1  = Failed
  * 0   = Handler registered Successfully, first handler on this IRQ
  * 1   = Handler registered Successfully, _not_ first handler on this IRQ
  */
-extern int genirq_register(genirq_t d, int irq, genirq_handler isr, void *arg);
+extern int genirq_register(genirq_t d, int irq, void *handler);
 
-/* Unregister an previous registered interrupt handler 
+/* Unregister an previous registered interrupt handler. It is the user's
+ * responsibility to free the handler returned by genirq_unregister().
+ *
+ * NOTE: internal list structures are accessed and needs to be protected by
+ *   spin-locks/IRQ disable by the user to guarantee a correct behaviour.
  *
  * Return Values
- *  -1 = ISR not registered before
- *  0  = ISR unregistered
- *  1  = Unable to unregister enabled ISR
+ * NULL= ISR not registered before or unable to unregister enabled ISR
+ * Pointer = ISR sucessfully unregistered. Returned is the handler pointer
+ *   previously allocated with genirq_alloc_handler().
  */
-extern int genirq_unregister(genirq_t d, int irq, genirq_handler isr, void 
*arg);
+extern void *genirq_unregister(genirq_t d, int irq,
+   genirq_handler isr, void *arg);
 
 /* Enables IRQ only for this isr[arg] combination. Records if this 
  * is the first interrupt enable, only then must interrupts be enabled
  * on the interrupt controller.
  *
- * IRQs must be disabled before entering this function.
+ * NOTE: internal list structures are accessed and needs to be protected by
+ *   spin-locks/IRQ disable by the user to guarantee a correct behaviour.
  *
  * Return values
  *  -1 = Failure, for example isr[arg] not registered on this irq
@@ -86,7 +107,8 @@ extern int genirq_enable(genirq_t d, int irq, genirq_handler 
isr, void *arg);
  * is the only interrupt handler that is enabled on this IRQ, only then
  * must interrupts be disabled on the interrupt controller.
  *
- * IRQs must be disabled before entering this function.
+ * NOTE: internal list structures are accessed and needs to be protected by
+ *   spin-locks/IRQ disable by the user to guarantee a correct behaviour.
  *
  * Return values
  *  -1 = Failure, for example isr[arg] not registered on this irq
@@ -97,6 +119,9 @@ extern int genirq_disable(genirq_t d, int irq, 
genirq_handler isr, void *arg);
 
 /* Must be called by user when an IRQ has fired, the argument 'irq' 
  * is the IRQ number of the IRQ which was fired.
+ *
+ * NOTE: internal list structures are accessed and needs to be protected by
+ *   spin-locks/IRQ disable by the user to guarantee a correct behaviour.
  */
 extern void genirq_doirq(genirq_t d, int irq);
 
diff --git 

[PATCH 16/32] leon, grcan: split hw_stop() into hw and sw stop

2017-05-11 Thread Daniel Hellstrom
this is to avoid owning the spin-lock during semaphore operations.
---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 13 +
 1 file changed, 13 insertions(+)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index 1348d7a..1050934 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -488,7 +488,10 @@ static void grcan_hw_stop(struct grcan_priv *pDev)
/* Disable receiver & transmitter */
pDev->regs->rx0ctrl = 0;
pDev->regs->tx0ctrl = 0;
+}
 
+static void grcan_sw_stop(struct grcan_priv *pDev)
+{
/* Reset semaphores to the initial state and wakeing
 * all threads waiting for an IRQ. The threads that
 * get woken up must check for RTEMS_UNSATISFIED in
@@ -1577,6 +1580,7 @@ int grcan_stop(void *d)
 {
struct grcan_priv *pDev = d;
SPIN_IRQFLAGS(oldLevel);
+   int do_sw_stop;
 
FUNCDBG();
 
@@ -1586,6 +1590,7 @@ int grcan_stop(void *d)
SPIN_LOCK_IRQ(>devlock, oldLevel);
if (pDev->started == STATE_STARTED) {
grcan_hw_stop(pDev);
+   do_sw_stop = 1;
DBGC(DBG_STATE, "STARTED->STOPPED\n");
} else {
/*
@@ -1593,10 +1598,14 @@ int grcan_stop(void *d)
 * might already been called from ISR.
 */
DBGC(DBG_STATE, "[STOPPED|BUSOFF|AHBERR]->STOPPED\n");
+   do_sw_stop = 0;
}
pDev->started = STATE_STOPPED;
SPIN_UNLOCK_IRQ(>devlock, oldLevel);
 
+   if (do_sw_stop)
+   grcan_sw_stop(pDev);
+
/* Disable interrupts */
drvmgr_interrupt_unregister(pDev->dev, 0, grcan_interrupt, pDev);
 
@@ -1932,6 +1941,10 @@ static void grcan_interrupt(void *arg)
 * again with grcan_start().
 */
SPIN_UNLOCK(>devlock, irqflags);
+
+   /* flush semaphores to wake blocked threads */
+   grcan_sw_stop(pDev);
+
/*
 * NOTE: Another interrupt may be pending now so ISR could be
 * executed one more time aftert this (first) return.
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 17/32] leon, grcan: semaphore reset count required after flushing

2017-05-11 Thread Daniel Hellstrom
It is also required to use semaphore release instead of flush when stopping
or on BUSOFF/AHBERR condition. Otherwise a task just about to wait
(taking the semaphore) could end up locked because the semaphore count is
still the same.

There was previously a scenario where the semaphore flush would not always make
semaphore obtain to return in case of BUSOFF, AHBERROR or grcan_stop. It has to
do with the rtems_semaphore_flush() not releasing the semaphore but just aborts
any _current_ waiter.
---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 62 ---
 1 file changed, 32 insertions(+), 30 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index 1050934..ac1c718 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -492,15 +492,19 @@ static void grcan_hw_stop(struct grcan_priv *pDev)
 
 static void grcan_sw_stop(struct grcan_priv *pDev)
 {
-   /* Reset semaphores to the initial state and wakeing
-* all threads waiting for an IRQ. The threads that
-* get woken up must check for RTEMS_UNSATISFIED in
+   /*
+* Release semaphores to wake all threads waiting for an IRQ.
+* The threads that
+* get woken up must check started state in
 * order to determine that they should return to
 * user space with error status.
+*
+* Entering into started mode again will reset the
+* semaphore count.
 */
-   rtems_semaphore_flush(pDev->rx_sem);
-   rtems_semaphore_flush(pDev->tx_sem);
-   rtems_semaphore_flush(pDev->txempty_sem);
+   rtems_semaphore_release(pDev->rx_sem);
+   rtems_semaphore_release(pDev->tx_sem);
+   rtems_semaphore_release(pDev->txempty_sem);
 }
 
 static void grcan_hw_config(struct grcan_regs *regs, struct grcan_config *conf)
@@ -962,17 +966,14 @@ static int grcan_wait_rxdata(struct grcan_priv *pDev, int 
min)
 
/* Wait for IRQ to fire only if has been triggered */
if (wait) {
-   if (
-   rtems_semaphore_obtain(
-   pDev->rx_sem,
-   RTEMS_WAIT,
-   RTEMS_NO_TIMEOUT
-   ) == RTEMS_UNSATISFIED
-   ) {
-   DBGC(DBG_STATE, "UNSATISFIED\n");
-   /* Device driver has been closed or stopped, return 
with error status */
-   return state2err[pDev->started];
-   }
+   rtems_semaphore_obtain(pDev->rx_sem, RTEMS_WAIT, 
RTEMS_NO_TIMEOUT);
+   /*
+* The semaphore is released either due to the expected IRQ
+* condition or by BUSOFF, AHBERROR or another thread calling
+* grcan_stop(). In either case, state2err[] has the correnct
+* return value.
+*/
+   return state2err[pDev->started];
}
 
return 0;
@@ -1054,13 +1055,8 @@ static int grcan_wait_txspace(struct grcan_priv *pDev, 
int min)
 
/* Wait for IRQ to fire only if it has been triggered */
if (wait) {
-   if (rtems_semaphore_obtain(pDev->tx_sem, RTEMS_WAIT, 
RTEMS_NO_TIMEOUT) ==
-   RTEMS_UNSATISFIED) {
-   /* Device driver has flushed us, this may be due to 
another thread has
-* closed the device, this is to avoid deadlock */
-   DBGC(DBG_STATE, "UNSATISFIED\n");
-   return state2err[pDev->started];
-   }
+   rtems_semaphore_obtain(pDev->tx_sem, RTEMS_WAIT, 
RTEMS_NO_TIMEOUT);
+   return state2err[pDev->started];
}
 
/* At this point the TxIRQ has been masked, we ned not to mask it */
@@ -1117,11 +1113,10 @@ static int grcan_tx_flush(struct grcan_priv *pDev)
break;
 
/* Wait for IRQ to wake us */
-   if (rtems_semaphore_obtain
-   (pDev->txempty_sem, RTEMS_WAIT,
-RTEMS_NO_TIMEOUT) == RTEMS_UNSATISFIED) {
-   DBGC(DBG_STATE, "UNSATISFIED\n");
-   return state2err[pDev->started];
+   rtems_semaphore_obtain(pDev->txempty_sem, RTEMS_WAIT, 
RTEMS_NO_TIMEOUT);
+   state = pDev->started;
+   if (state != STATE_STARTED) {
+   return state2err[state];
}
}
return 0;
@@ -1565,6 +1560,13 @@ int grcan_start(void *d)
return -2;
}
 
+   /* Clear semaphore state. This is to avoid effects from previous
+* bus-off/stop where semahpores where flushed() but the count remained.
+*/
+   rtems_semaphore_obtain(pDev->rx_sem, RTEMS_NO_WAIT, 0);
+   rtems_semaphore_obtain(pDev->tx_sem, RTEMS_NO_WAIT, 0);
+   

[PATCH 19/32] leon, grcan: removed unused txerror, rxerror

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 13 -
 1 file changed, 13 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index b1eacc0..da236ef 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -149,7 +149,6 @@ struct grcan_priv {
 
int txblock, rxblock;
int txcomplete, rxcomplete;
-   int txerror, rxerror;
 
struct grcan_filter sfilter;
struct grcan_filter afilter;
@@ -458,10 +457,6 @@ static rtems_device_driver grcan_hw_start(struct 
grcan_priv *pDev)
IRQ_UNMASK(pDev->irq + GRCAN_IRQ_IRQ);
SPIN_UNLOCK_IRQ(>devlock, oldLevel);
 
-   /* Reset some software data */
-   /*pDev->txerror = 0;
-  pDev->rxerror = 0; */
-
/* Enable receiver/transmitter */
pDev->regs->rx0ctrl = GRCAN_RXCTRL_ENABLE;
pDev->regs->tx0ctrl = GRCAN_TXCTRL_ENABLE;
@@ -1519,14 +1514,6 @@ int grcan_write(void *d, CANMsg *msg, size_t ucount)
return nwritten;
}
 
-   if ( pDev->txerror ){
-   /* Return number of bytes sent, compare write pointers 
*/
-   pDev->txerror = 0;
-#if 0 
-#error HANDLE AMBA error
-#endif
-   }
-
/* Try read bytes from circular buffer */
nwritten = grcan_hw_write_try(
pDev,
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 18/32] leon, grcan: fixed historical comment

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 7 +++
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index ac1c718..b1eacc0 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -979,12 +979,11 @@ static int grcan_wait_rxdata(struct grcan_priv *pDev, int 
min)
return 0;
 }
 
-/* Wait until min bytes available in TX circular buffer. TXIRQ is used to pin
+/* Wait for TX circular buffer to have room for min CAN messagges. TXIRQ is 
used to pin
  * point the location of the CAN message corresponding to min.
  *
- * min must be at least WRAP_AROUND_TX_BYTES bytes less
- * than max buffer for this algo to work.
- *
+ * min must be at least WRAP_AROUND_TX_MSGS less than max buffer capacity
+ * (pDev->txbuf_size/GRCAN_MSG_SIZE) for this algo to work.
  */
 static int grcan_wait_txspace(struct grcan_priv *pDev, int min)
 {
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 14/32] leon, grcan: redesigned bus-off and AHB error handling

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

When bus-off condition is detected by the ISR, it sets the started flag to
STATE_BUSOFF. This is monitored by the user functions grcan_read() and
grcan_write() each time they want to enable DMA or update interrupt mask. If
they detect that ISR has detected bus-off then they will return either with an
error or with the number of CAN messages processed. Future calls to functions
which require STARTED mode will be rejected and grcan_isstarted() will return
0. The next call to grcan_stop() will do the transition from BUSOFF->STOPPED
and the device can then be started again with grcan_start().

Similar to a bus-off condition, the AHB error condition detected by the ISR
will trigger the same shut-down logic of the driver. The difference is that
the state entered is STATE_AHBERR and the routines will return a different
value to indicate AHB error state.

This commit also fixes an issue where ISR was not always unregistered on close.

User functions can cause these transitions:
  STATE_STOPPED -> STATE_STARTED (grcan_start)
  STATE_STARTED -> STATE_STOPPED (grcan_stop)
  STATE_BUSOFF  -> STATE_STOPPED (grcan_stop, grcan_close)
  STATE_AHBERR  -> STATE_STOPPED (grcan_stop, grcan_close)

ISR can cause these transition
  STATE_STARTED -> STATE_BUSOFF (grcan_interrupt)
  STATE_STARTED -> STATE_AHBERR (grcan_interrupt)

STATE_BUSOFF/AHBERR is entered from ISR on bus-off condition. At transition
the ISR disables DMA, masks all interrupts and flushes semaphores.

Other related updates:

 * Statistics are updated from the ISR. Update is now spin-locked to ensure a
   consistent user view.
 * The debug output has been updated to include state changes.
 * For read/write/flush, return error (-4) if driver aborted the operation
   due to bus-off. Likewise if abourted due to AHB error -5 is returned.
 * Collect bus-off statistics

Related to the new BUSOFF and AHBERR states the API has been updated to
reflect the current SW driver state. The isstarted() function has been
replaced with get_state().
---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 408 +-
 c/src/lib/libbsp/sparc/shared/include/grcan.h |  80 -
 2 files changed, 334 insertions(+), 154 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index 515efa3..45b7af1 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -92,11 +92,11 @@
 
 /* Uncomment for debug output */
 /** DEBUG Definitions /
-#define DBG_IOCTRL 1
 #define DBG_TX 2
 #define DBG_RX 4
+#define DBG_STATE 8
 
-#define DEBUG_FLAGS (DBG_IOCTRL | DBG_RX | DBG_TX )
+#define DEBUG_FLAGS (DBG_STATE | DBG_RX | DBG_TX )
 /*
 #define DEBUG
 #define DEBUGFUNCS
@@ -105,6 +105,13 @@
 
 /*/
 
+int state2err[4] = {
+   /* STATE_STOPPED */ GRCAN_RET_NOTSTARTED,
+   /* STATE_STARTED */ GRCAN_RET_OK,
+   /* STATE_BUSOFF  */ GRCAN_RET_BUSOFF,
+   /* STATE_AHBERR  */ GRCAN_RET_AHBERR
+};
+
 struct grcan_msg {
unsigned int head[2];
unsigned char data[8];
@@ -156,13 +163,13 @@ struct grcan_priv {
 
 static void __inline__ grcan_hw_reset(struct grcan_regs *regs);
 
-static unsigned int grcan_hw_read_try(
+static int grcan_hw_read_try(
struct grcan_priv *pDev,
struct grcan_regs *regs,
CANMsg *buffer,
int max);
 
-static unsigned int grcan_hw_write_try(
+static int grcan_hw_write_try(
struct grcan_priv *pDev,
struct grcan_regs *regs,
CANMsg *buffer,
@@ -601,17 +608,6 @@ static unsigned int grcan_hw_txspace(
return left / GRCAN_MSG_SIZE - WRAP_AROUND_TX_MSGS;
 }
 
-static int grcan_hw_rx_ongoing(struct grcan_regs *regs)
-{
-   return READ_REG(>rx0ctrl) & GRCAN_RXCTRL_ONGOING;
-}
-
-static int grcan_hw_tx_ongoing(struct grcan_regs *regs)
-{
-   return READ_REG(>tx0ctrl) & GRCAN_TXCTRL_ONGOING;
-}
-
-
 #define MIN_TSEG1 1
 #define MIN_TSEG2 2
 #define MAX_TSEG1 14
@@ -723,7 +719,7 @@ static int grcan_calc_timing(
return 0;
 }
 
-static unsigned int grcan_hw_read_try(
+static int grcan_hw_read_try(
struct grcan_priv *pDev,
struct grcan_regs *regs,
CANMsg * buffer,
@@ -733,7 +729,8 @@ static unsigned int grcan_hw_read_try(
int i, j;
CANMsg *dest;
struct grcan_msg *source, tmp;
-   unsigned int wp, rp, size, rxmax, addr, trunk_msg_cnt;
+   unsigned int wp, rp, size, rxmax, addr;
+   int trunk_msg_cnt;
 
FUNCDBG();
 
@@ -775,6 +772,15 @@ static unsigned int grcan_hw_read_try(
/* Read CAN message from DMA buffer */
tmp.head[0] = READ_DMA_WORD(>head[0]);
tmp.head[1] = READ_DMA_WORD(>head[1]);
+   if (tmp.head[1] & 0x4) {
+   DBGC(DBG_RX, "overrun\n");
+   

[PATCH 15/32] leon, grcan: RTEMS_NO_TIMEOUT on tx_sem

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index 45b7af1..1348d7a 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -1051,7 +1051,7 @@ static int grcan_wait_txspace(struct grcan_priv *pDev, 
int min)
 
/* Wait for IRQ to fire only if it has been triggered */
if (wait) {
-   if (rtems_semaphore_obtain(pDev->tx_sem, RTEMS_WAIT, 100) ==
+   if (rtems_semaphore_obtain(pDev->tx_sem, RTEMS_WAIT, 
RTEMS_NO_TIMEOUT) ==
RTEMS_UNSATISFIED) {
/* Device driver has flushed us, this may be due to 
another thread has
 * closed the device, this is to avoid deadlock */
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 13/32] leon, grcan: updated device name and use it for ISR

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 28 ---
 c/src/lib/libbsp/sparc/shared/include/grcan.h | 11 +++
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index 9e1c05d..515efa3 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -217,6 +217,8 @@ static unsigned int __inline__ _grcan_read_nocache(unsigned 
int address)
 }
 #endif
 
+#define NELEM(a) ((int) (sizeof (a) / sizeof (a[0])))
+
 static int grcan_count = 0;
 static struct grcan_priv *priv_tab[GRCAN_COUNT_MAX];
 
@@ -307,12 +309,12 @@ int grcan_init3(struct drvmgr_dev *dev)
/* Failed to get prefix, make sure of a unique FS name
 * by using the driver minor.
 */
-   sprintf(priv->devName, "/dev/grcan%d", dev->minor_drv);
+   sprintf(priv->devName, "grcan%d", dev->minor_drv);
} else {
/* Got special prefix, this means we have a bus prefix
 * And we should use our "bus minor"
 */
-   sprintf(priv->devName, "/dev/%sgrcan%d", prefix, 
dev->minor_bus);
+   sprintf(priv->devName, "%sgrcan%d", prefix, dev->minor_bus);
}
 
return DRVMGR_OK;
@@ -1177,6 +1179,25 @@ int grcan_dev_count(void)
return grcan_count;
 }
 
+void *grcan_open_by_name(char *name, int *dev_no)
+{
+   int i;
+   for (i = 0; i < grcan_count; i++){
+   struct grcan_priv *pDev;
+
+   pDev = priv_tab[i];
+   if (NULL == pDev) {
+   continue;
+   }
+   if (strncmp(pDev->devName, name, NELEM(pDev->devName)) == 0) {
+   if (dev_no)
+   *dev_no = i;
+   return grcan_open(i);
+   }
+   }
+   return NULL;
+}
+
 void *grcan_open(int dev_no)
 {
struct grcan_priv *pDev;
@@ -1463,7 +1484,8 @@ int grcan_start(void *d)
pDev->started = 1;
 
/* Register interrupt routine and enable IRQ at IRQ ctrl */
-   drvmgr_interrupt_register(pDev->dev, 0, "grcan", grcan_interrupt, pDev);
+   drvmgr_interrupt_register(pDev->dev, 0, pDev->devName,
+   grcan_interrupt, pDev);
 
return 0;
 }
diff --git a/c/src/lib/libbsp/sparc/shared/include/grcan.h 
b/c/src/lib/libbsp/sparc/shared/include/grcan.h
index 08e6638..7de76a7 100644
--- a/c/src/lib/libbsp/sparc/shared/include/grcan.h
+++ b/c/src/lib/libbsp/sparc/shared/include/grcan.h
@@ -171,6 +171,17 @@ extern int grcan_dev_count(void);
 extern void *grcan_open(int dev_no);
 
 /*
+ * Open a GRCAN device by name. Finds device index then calls
+ * grcan_open(index).
+ *
+ * name:   Device name to open
+ * dev_no: Device number matching name. Will be set if device found.
+ * return: Device handle to use with all other grcan_ API functions. The
+ * function returns NULL if device can not be opened or not found.
+ */
+extern void *grcan_open_by_name(char *name, int *dev_no);
+
+/*
  * Close a GRCAN device
  *
  * return: This function always returns 0 (success)
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 12/32] leon, grcan: fixed race on interrupt mask register

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

There was a potential read-modify-write race on the interrupt mask (imr)
register between the ISR and user functions.
---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 14 ++
 1 file changed, 14 insertions(+)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index c7aadae..9e1c05d 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -1712,6 +1712,7 @@ int grcan_set_afilter(void *d, const struct grcan_filter 
*filter)
 int grcan_set_sfilter(void *d, const struct grcan_filter *filter)
 {
struct grcan_priv *pDev = d;
+   SPIN_IRQFLAGS(oldLevel);
 
FUNCDBG();
 
@@ -1721,13 +1722,17 @@ int grcan_set_sfilter(void *d, const struct 
grcan_filter *filter)
pDev->sfilter.mask = 0;
 
 /* disable Sync interrupt */
+   SPIN_LOCK_IRQ(>devlock, oldLevel);
pDev->regs->imr = READ_REG(>regs->imr) & 
~(GRCAN_RXSYNC_IRQ|GRCAN_TXSYNC_IRQ);
+   SPIN_UNLOCK_IRQ(>devlock, oldLevel);
}else{
/* Save filter */
pDev->sfilter = *filter;
 
/* Enable Sync interrupt */
+   SPIN_LOCK_IRQ(>devlock, oldLevel);
pDev->regs->imr = READ_REG(>regs->imr) | 
(GRCAN_RXSYNC_IRQ|GRCAN_TXSYNC_IRQ);
+   SPIN_UNLOCK_IRQ(>devlock, oldLevel);
}
/* Set Sync RX/TX filter */
grcan_hw_sync(pDev->regs,>sfilter);
@@ -1756,6 +1761,7 @@ static void grcan_interrupt(void *arg)
struct grcan_priv *pDev = arg;
unsigned int status = READ_REG(>regs->pimsr);
unsigned int canstat = READ_REG(>regs->stat);
+   SPIN_ISR_IRQFLAGS(irqflags);
 
/* Spurious IRQ call? */
if ( !status && !canstat )
@@ -1777,8 +1783,10 @@ static void grcan_interrupt(void *arg)
 * that is blocked in read/write calls and stop futher calls
 * to read/write until user has called ioctl(fd,START,0).
 */
+   SPIN_LOCK(>devlock, irqflags);
pDev->started = 0;
grcan_hw_stop(pDev); /* this mask all IRQ sources */
+   SPIN_UNLOCK(>devlock, irqflags);
status=0x1; /* clear all interrupts */
goto out;
}
@@ -1803,13 +1811,17 @@ static void grcan_interrupt(void *arg)
if ( status & GRCAN_RXIRQ_IRQ ){
/* RX IRQ pointer interrupt */
/*printk("RxIrq 0x%x\n",status);*/
+   SPIN_LOCK(>devlock, irqflags);
pDev->regs->imr = READ_REG(>regs->imr) & ~GRCAN_RXIRQ_IRQ;
+   SPIN_UNLOCK(>devlock, irqflags);
rtems_semaphore_release(pDev->rx_sem);
}
 
if ( status & GRCAN_TXIRQ_IRQ ){
/* TX IRQ pointer interrupt */
+   SPIN_LOCK(>devlock, irqflags);
pDev->regs->imr = READ_REG(>regs->imr) & ~GRCAN_TXIRQ_IRQ;
+   SPIN_UNLOCK(>devlock, irqflags);
rtems_semaphore_release(pDev->tx_sem);
}
 
@@ -1824,7 +1836,9 @@ static void grcan_interrupt(void *arg)
}
 
if ( status & GRCAN_TXEMPTY_IRQ ){
+   SPIN_LOCK(>devlock, irqflags);
pDev->regs->imr = READ_REG(>regs->imr) & 
~GRCAN_TXEMPTY_IRQ;
+   SPIN_UNLOCK(>devlock, irqflags);
rtems_semaphore_release(pDev->txempty_sem);
}
 
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 11/32] leon, grcan: unregister interrupt handler at close

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 6 +-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index 003cecf..c7aadae 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -1275,8 +1275,12 @@ int grcan_close(void *d)
 
FUNCDBG();
 
-   if ( pDev->started )
+   if ( pDev->started ) {
+   /* Disable interrupts */
+   drvmgr_interrupt_unregister(pDev->dev, 0, grcan_interrupt, 
pDev);
grcan_hw_stop(pDev);
+   pDev->started = 0;
+   }
 
grcan_hw_reset(pDev->regs);
 
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 10/32] leon, grcan: protect statistics on copy to user

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

Locking the stats structure when copying to user buffer ensures a consistent
view to the user.
---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index 409e68b..003cecf 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -1612,13 +1612,16 @@ int grcan_set_rxcomplete(void *d, int complete)
 int grcan_get_stats(void *d, struct grcan_stats *stats)
 {
struct grcan_priv *pDev = d;
+   SPIN_IRQFLAGS(oldLevel);
 
FUNCDBG();
 
if ( !stats )
return -1;
 
+   SPIN_LOCK_IRQ(>devlock, oldLevel);
*stats = pDev->stats;
+   SPIN_UNLOCK_IRQ(>devlock, oldLevel);
 
return 0;
 }
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 07/32] leon, grcan: function based user interface

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

This commit preserves all driver services, using a function based user
interface instead of the I/O interface.

The messages count parameter is now number of CAN messages instead of
number of bytes.
---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 661 +-
 c/src/lib/libbsp/sparc/shared/include/grcan.h | 131 -
 2 files changed, 436 insertions(+), 356 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index 46599dc..d1573b2 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -10,7 +10,6 @@
  */
 
 #include 
-#include 
 #include 
 #include 
 #include 
@@ -23,6 +22,9 @@
 #include 
 #include 
 
+/* Maximum number of GRCAN devices supported by driver */
+#define GRCAN_COUNT_MAX 8
+
 #define WRAP_AROUND_TX_MSGS 1
 #define WRAP_AROUND_RX_MSGS 2
 #define GRCAN_MSG_SIZE sizeof(struct grcan_msg)
@@ -137,15 +139,6 @@ struct grcan_priv {
rtems_id rx_sem, tx_sem, txempty_sem, dev_sem;
 };
 
-static rtems_device_driver grcan_initialize(rtems_device_major_number  major, 
rtems_device_minor_number  minor, void *arg);
-static rtems_device_driver grcan_open(rtems_device_major_number major, 
rtems_device_minor_number minor, void *arg);
-static rtems_device_driver grcan_close(rtems_device_major_number major, 
rtems_device_minor_number minor, void *arg);
-static rtems_device_driver grcan_read(rtems_device_major_number major, 
rtems_device_minor_number minor, void *arg);
-static rtems_device_driver grcan_write(rtems_device_major_number major, 
rtems_device_minor_number minor, void *arg);
-static rtems_device_driver grcan_ioctl(rtems_device_major_number major, 
rtems_device_minor_number minor, void *arg);
-
-#define GRCAN_DRIVER_TABLE_ENTRY { grcan_initialize, grcan_open, grcan_close, 
grcan_read, grcan_write, grcan_ioctl }
-
 static void __inline__ grcan_hw_reset(struct grcan_regs *regs);
 
 static unsigned int grcan_hw_read_try(
@@ -209,15 +202,12 @@ static unsigned int __inline__ 
_grcan_read_nocache(unsigned int address)
 }
 #endif
 
-
-static rtems_driver_address_table grcan_driver = GRCAN_DRIVER_TABLE_ENTRY;
-static int grcan_driver_io_registered = 0;
-static rtems_device_major_number grcan_driver_io_major = 0;
+static int grcan_count = 0;
+static struct grcan_priv *priv_tab[GRCAN_COUNT_MAX];
 
 /*** Driver manager interface ***/
 
 /* Driver prototypes */
-int grcan_register_io(rtems_device_major_number *m);
 int grcan_device_init(struct grcan_priv *pDev);
 
 int grcan_init2(struct drvmgr_dev *dev);
@@ -265,6 +255,8 @@ int grcan_init2(struct drvmgr_dev *dev)
struct grcan_priv *priv;
 
DBG("GRCAN[%d] on bus %s\n", dev->minor_drv, dev->parent->dev->name);
+   if (GRCAN_COUNT_MAX <= grcan_count)
+   return DRVMGR_ENORES;
priv = dev->priv = malloc(sizeof(struct grcan_priv));
if ( !priv )
return DRVMGR_NOMEM;
@@ -280,24 +272,10 @@ int grcan_init3(struct drvmgr_dev *dev)
 {
struct grcan_priv *priv;
char prefix[32];
-   rtems_status_code status;
 
priv = dev->priv;
 
-   /* Do initialization */
-
-   if ( grcan_driver_io_registered == 0) {
-   /* Register the I/O driver only once for all cores */
-   if ( grcan_register_io(_driver_io_major) ) {
-   /* Failed to register I/O driver */
-   dev->priv = NULL;
-   return DRVMGR_FAIL;
-   }
-
-   grcan_driver_io_registered = 1;
-   }
-
-   /* I/O system registered and initialized 
+   /*
 * Now we take care of device initialization.
 */
 
@@ -305,6 +283,9 @@ int grcan_init3(struct drvmgr_dev *dev)
return DRVMGR_FAIL;
}
 
+   priv_tab[grcan_count] = priv;
+   grcan_count++;
+
/* Get Filesystem name prefix */
prefix[0] = '\0';
if ( drvmgr_get_dev_prefix(dev, prefix) ) {
@@ -319,42 +300,9 @@ int grcan_init3(struct drvmgr_dev *dev)
sprintf(priv->devName, "/dev/%sgrcan%d", prefix, 
dev->minor_bus);
}
 
-   /* Register Device */
-   status = rtems_io_register_name(priv->devName, grcan_driver_io_major, 
dev->minor_drv);
-   if (status != RTEMS_SUCCESSFUL) {
-   return DRVMGR_FAIL;
-   }
-
return DRVMGR_OK;
 }
 
-/*** Driver Implementation ***/
-
-int grcan_register_io(rtems_device_major_number *m)
-{
-   rtems_status_code r;
-
-   if ((r = rtems_io_register_driver(0, _driver, m)) == 
RTEMS_SUCCESSFUL) {
-   DBG("GRCAN driver successfully registered, major: %d\n", *m);
-   } else {
-   switch(r) {
-   case RTEMS_TOO_MANY:
-   printk("GRCAN rtems_io_register_driver failed: 
RTEMS_TOO_MANY\n");
-   

[PATCH 05/32] leon, irq: single CPU SMP configuration does not need IPI ISR

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/irq/irq-shared.c | 11 ---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/irq/irq-shared.c 
b/c/src/lib/libbsp/sparc/shared/irq/irq-shared.c
index 174324f..f219e49 100644
--- a/c/src/lib/libbsp/sparc/shared/irq/irq-shared.c
+++ b/c/src/lib/libbsp/sparc/shared/irq/irq-shared.c
@@ -47,9 +47,14 @@ void BSP_shared_interrupt_init(void)
   for (i=0; i <= BSP_INTERRUPT_VECTOR_MAX_STD; i++) {
 #if defined(LEON3) && \
 (defined(RTEMS_SMP) || defined(RTEMS_MULTIPROCESSING))
-/* Don't install IRQ handler on IPI interrupt */
-if (i == LEON3_mp_irq)
-  continue;
+/* Don't install IRQ handler on IPI interrupt. An SMP kernel with max one
+ * CPU does not use IPIs
+ */
+#ifdef RTEMS_SMP
+if (rtems_configuration_get_maximum_processors() > 1)
+#endif
+  if (i == LEON3_mp_irq)
+continue;
 #endif
 vector = SPARC_ASYNCHRONOUS_TRAP(i) + 0x10;
 rtems_interrupt_catch(bsp_isr_handler, vector, _isr);
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 06/32] bsp/leon3: Cleaner namespace for LEON3 debug UART

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

Prefix BSP specific symbols with BSP name:
dbg_uart -> leon3_debug_uart
debug_uart_index -> leon3_debug_uart_index
---
 .../libbsp/sparc/leon3/console/printk_support.c| 34 +++---
 c/src/lib/libbsp/sparc/leon3/include/leon.h|  2 +-
 c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c  |  8 +++--
 3 files changed, 23 insertions(+), 21 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/leon3/console/printk_support.c 
b/c/src/lib/libbsp/sparc/leon3/console/printk_support.c
index 27c2a72..f7e1fb6 100644
--- a/c/src/lib/libbsp/sparc/leon3/console/printk_support.c
+++ b/c/src/lib/libbsp/sparc/leon3/console/printk_support.c
@@ -25,8 +25,8 @@
 #include 
 #include 
 
-int debug_uart_index __attribute__((weak)) = 0;
-struct apbuart_regs *dbg_uart = NULL;
+int leon3_debug_uart_index __attribute__((weak)) = 0;
+struct apbuart_regs *leon3_debug_uart = NULL;
 
 /* Before UART driver has registered (or when no UART is available), calls to
  * printk that gets to bsp_out_char() will be filling data into the
@@ -45,24 +45,24 @@ static void bsp_debug_uart_init(void)
   struct ambapp_dev *adev;
   struct ambapp_apb_info *apb;
 
-  /* Update debug_uart_index to index used as debug console.
-   * Let user select Debug console by setting debug_uart_index. If the
-   * BSP is to provide the default UART (debug_uart_index==0):
+  /* Update leon3_debug_uart_index to index used as debug console. Let user
+   * select Debug console by setting leon3_debug_uart_index. If the BSP is to
+   * provide the default UART (leon3_debug_uart_index==0):
*   non-MP: APBUART[0] is debug console
*   MP: LEON CPU index select UART
*/
-  if (debug_uart_index == 0) {
+  if (leon3_debug_uart_index == 0) {
 #if defined(RTEMS_MULTIPROCESSING)
-debug_uart_index = LEON3_Cpu_Index;
+leon3_debug_uart_index = LEON3_Cpu_Index;
 #else
-debug_uart_index = 0;
+leon3_debug_uart_index = 0;
 #endif
   } else {
-debug_uart_index = debug_uart_index - 1; /* User selected dbg-console */
+leon3_debug_uart_index--; /* User selected dbg-console */
   }
 
   /* Find APBUART core for System Debug Console */
-  i = debug_uart_index;
+  i = leon3_debug_uart_index;
   adev = (void *)ambapp_for_each(_plb, (OPTIONS_ALL|OPTIONS_APB_SLVS),
  VENDOR_GAISLER, GAISLER_APBUART,
  ambapp_find_by_idx, (void *));
@@ -71,9 +71,9 @@ static void bsp_debug_uart_init(void)
  * for printk
  */
 apb = (struct ambapp_apb_info *)adev->devinfo;
-dbg_uart = (struct apbuart_regs *)apb->start;
-dbg_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE;
-dbg_uart->status = 0;
+leon3_debug_uart = (struct apbuart_regs *)apb->start;
+leon3_debug_uart->ctrl |= APBUART_CTRL_RE | APBUART_CTRL_TE;
+leon3_debug_uart->status = 0;
   }
 }
 
@@ -86,14 +86,14 @@ RTEMS_SYSINIT_ITEM(
 /* putchar/getchar for printk */
 static void bsp_out_char(char c)
 {
-  if (dbg_uart == NULL) {
+  if (leon3_debug_uart == NULL) {
 /* Local debug buffer when UART driver has not registered */
 pre_printk_dbgbuf[pre_printk_pos++] = c;
 pre_printk_pos = pre_printk_pos & (sizeof(pre_printk_dbgbuf)-1);
 return;
   }
 
-  apbuart_outbyte_polled(dbg_uart, c, 1, 1);
+  apbuart_outbyte_polled(leon3_debug_uart, c, 1, 1);
 }
 
 /*
@@ -108,10 +108,10 @@ static int bsp_in_char(void)
 {
   int tmp;
 
-  if (dbg_uart == NULL)
+  if (leon3_debug_uart == NULL)
 return EOF;
 
-  while ((tmp = apbuart_inbyte_nonblocking(dbg_uart)) < 0)
+  while ((tmp = apbuart_inbyte_nonblocking(leon3_debug_uart)) < 0)
 ;
   return tmp;
 }
diff --git a/c/src/lib/libbsp/sparc/leon3/include/leon.h 
b/c/src/lib/libbsp/sparc/leon3/include/leon.h
index 36f9495..9b2597f 100644
--- a/c/src/lib/libbsp/sparc/leon3/include/leon.h
+++ b/c/src/lib/libbsp/sparc/leon3/include/leon.h
@@ -364,7 +364,7 @@ extern int syscon_uart_index;
  * 3 = APBUART[2]
  * ...
  */
-extern int debug_uart_index;
+extern int leon3_debug_uart_index;
 
 /* Let user override which on-chip TIMER core will be used for system clock
  * timer. This controls which timer core will be accociated with
diff --git a/c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c 
b/c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c
index c79d408..e406bc0 100644
--- a/c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c
+++ b/c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c
@@ -48,7 +48,9 @@ extern void apbuart_outbyte_polled(
   int do_cr_on_newline,
   int wait_sent);
 extern int apbuart_inbyte_nonblocking(struct apbuart_regs *regs);
-extern struct apbuart_regs *dbg_uart; /* The debug UART */
+#ifdef LEON3
+extern struct apbuart_regs *leon3_debug_uart; /* The debug UART */
+#endif
 
 /* Probed hardware capabilities */
 enum {
@@ -263,7 +265,7 @@ int apbuart_init1(struct drvmgr_dev *dev)
 */
db = 0;
 #ifdef LEON3
-   if (priv->regs == dbg_uart) {
+   if (priv->regs == leon3_debug_uart) {

[PATCH 08/32] leon, grcan: consistent indentation

2017-05-11 Thread Daniel Hellstrom
From: Martin Aberg 

This commit does not contain any change of functionality.
---
 c/src/lib/libbsp/sparc/shared/can/grcan.c | 1162 -
 c/src/lib/libbsp/sparc/shared/include/grcan.h |   76 +-
 2 files changed, 618 insertions(+), 620 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/can/grcan.c 
b/c/src/lib/libbsp/sparc/shared/can/grcan.c
index d1573b2..e955b20 100644
--- a/c/src/lib/libbsp/sparc/shared/can/grcan.c
+++ b/c/src/lib/libbsp/sparc/shared/can/grcan.c
@@ -142,28 +142,28 @@ struct grcan_priv {
 static void __inline__ grcan_hw_reset(struct grcan_regs *regs);
 
 static unsigned int grcan_hw_read_try(
-  struct grcan_priv *pDev,
-  struct grcan_regs *regs,
-  CANMsg *buffer,
-  int max);
+   struct grcan_priv *pDev,
+   struct grcan_regs *regs,
+   CANMsg *buffer,
+   int max);
 
 static unsigned int grcan_hw_write_try(
-  struct grcan_priv *pDev,
-  struct grcan_regs *regs,
-  CANMsg *buffer,
-  int count);
+   struct grcan_priv *pDev,
+   struct grcan_regs *regs,
+   CANMsg *buffer,
+   int count);
 
 static void grcan_hw_config(
-  struct grcan_regs *regs,
-  struct grcan_config *conf);
+   struct grcan_regs *regs,
+   struct grcan_config *conf);
 
 static void grcan_hw_accept(
-  struct grcan_regs *regs,
-  struct grcan_filter *afilter);
+   struct grcan_regs *regs,
+   struct grcan_filter *afilter);
 
 static void grcan_hw_sync(
-  struct grcan_regs *regs,
-  struct grcan_filter *sfilter);
+   struct grcan_regs *regs,
+   struct grcan_filter *sfilter);
 
 static void grcan_interrupt(void *arg);
 
@@ -378,227 +378,221 @@ static void __inline__ grcan_hw_reset(struct grcan_regs 
*regs)
 
 static rtems_device_driver grcan_hw_start(struct grcan_priv *pDev)
 {
-  /*
-   * tmp is set but never used. GCC gives a warning for this
-   * and we need to tell GCC not to complain.
-   */
-  unsigned int tmp RTEMS_UNUSED;
+   /*
+* tmp is set but never used. GCC gives a warning for this
+* and we need to tell GCC not to complain.
+*/
+   unsigned int tmp RTEMS_UNUSED;
 
-  IRQ_GLOBAL_PREPARE(oldLevel);
+   IRQ_GLOBAL_PREPARE(oldLevel);
 
-  FUNCDBG();
+   FUNCDBG();
 
-  /* Check that memory has been allocated successfully */
-  if ( !pDev->tx || !pDev->rx )
-return RTEMS_NO_MEMORY;
+   /* Check that memory has been allocated successfully */
+   if (!pDev->tx || !pDev->rx)
+   return RTEMS_NO_MEMORY;
 
-  /* Configure FIFO configuration register
-   * and Setup timing
-   */
-  if ( pDev->config_changed ){
-grcan_hw_config(pDev->regs,>config);
-pDev->config_changed = 0;
-  }
+   /* Configure FIFO configuration register
+* and Setup timing
+*/
+   if (pDev->config_changed) {
+   grcan_hw_config(pDev->regs, >config);
+   pDev->config_changed = 0;
+   }
 
-  /* Setup receiver */
-  pDev->regs->rx0addr = (unsigned int)pDev->_rx_hw;
-  pDev->regs->rx0size = pDev->rxbuf_size;
+   /* Setup receiver */
+   pDev->regs->rx0addr = (unsigned int)pDev->_rx_hw;
+   pDev->regs->rx0size = pDev->rxbuf_size;
 
-  /* Setup Transmitter */
-  pDev->regs->tx0addr = (unsigned int)pDev->_tx_hw;
-  pDev->regs->tx0size = pDev->txbuf_size;
+   /* Setup Transmitter */
+   pDev->regs->tx0addr = (unsigned int)pDev->_tx_hw;
+   pDev->regs->tx0size = pDev->txbuf_size;
 
-  /* Setup acceptance filters */
-  grcan_hw_accept(pDev->regs,>afilter);
+   /* Setup acceptance filters */
+   grcan_hw_accept(pDev->regs, >afilter);
 
-  /* Sync filters */
-  grcan_hw_sync(pDev->regs,>sfilter);
+   /* Sync filters */
+   grcan_hw_sync(pDev->regs, >sfilter);
 
-  /* Clear status bits */
-  tmp = READ_REG(>regs->stat);
-  pDev->regs->stat = 0;
+   /* Clear status bits */
+   tmp = READ_REG(>regs->stat);
+   pDev->regs->stat = 0;
 
-  /* Setup IRQ handling */
+   /* Setup IRQ handling */
 
-  /* Clear all IRQs */
-  tmp = READ_REG(>regs->pir);
-  pDev->regs->picr = 0x1;
+   /* Clear all IRQs */
+   tmp = READ_REG(>regs->pir);
+   pDev->regs->picr = 0x1;
 
-  /* unmask TxLoss|TxErrCntr|RxErrCntr|TxAHBErr|RxAHBErr|OR|OFF|PASS */
-  pDev->regs->imr = 0x1601f;
+   /* unmask TxLoss|TxErrCntr|RxErrCntr|TxAHBErr|RxAHBErr|OR|OFF|PASS */
+   pDev->regs->imr = 0x1601f;
 
-  /* Enable routing of the IRQs */
-  IRQ_GLOBAL_DISABLE(oldLevel);
-  IRQ_UNMASK(pDev->irq+GRCAN_IRQ_TXSYNC);
-  IRQ_UNMASK(pDev->irq+GRCAN_IRQ_RXSYNC);
-  IRQ_UNMASK(pDev->irq+GRCAN_IRQ_IRQ);
-  IRQ_GLOBAL_ENABLE(oldLevel);
+   /* Enable routing of the IRQs */
+   IRQ_GLOBAL_DISABLE(oldLevel);
+   IRQ_UNMASK(pDev->irq + GRCAN_IRQ_TXSYNC);
+   IRQ_UNMASK(pDev->irq + GRCAN_IRQ_RXSYNC);
+   IRQ_UNMASK(pDev->irq + GRCAN_IRQ_IRQ);
+   IRQ_GLOBAL_ENABLE(oldLevel);
 
-  /* Reset some software data */
-  /*pDev->txerror = 0;
-  pDev->rxerror = 0;*/
+   /* Reset 

[PATCH 04/32] leon, greth: new option and change soft-reset logic for EDCL

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/net/greth.c | 67 ++-
 1 file changed, 49 insertions(+), 18 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/net/greth.c 
b/c/src/lib/libbsp/sparc/shared/net/greth.c
index 2e479ed..5e2ee49 100644
--- a/c/src/lib/libbsp/sparc/shared/net/greth.c
+++ b/c/src/lib/libbsp/sparc/shared/net/greth.c
@@ -155,6 +155,7 @@ struct greth_softc
int minor;
int phyaddr;  /* PHY Address configured by user (or -1 to autodetect) */
unsigned int edcl_dis;
+   int greth_rst;
 
int acceptBroadcast;
rtems_id daemonTid;
@@ -353,7 +354,7 @@ greth_initialize_hardware (struct greth_softc *sc)
 int tmp2;
 struct timespec tstart, tnow;
 greth_regs *regs;
-unsigned int advmodes;
+unsigned int advmodes, speed;
 
 regs = sc->regs;
 
@@ -361,10 +362,18 @@ greth_initialize_hardware (struct greth_softc *sc)
 sc->rxInterrupts = 0;
 sc->rxPackets = 0;
 
-regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD | GRETH_CTRL_ED; /* Reset ON */
-for (i = 0; i<100 && (regs->ctrl & GRETH_CTRL_RST); i++)
-;
-regs->ctrl = GRETH_CTRL_DD | GRETH_CTRL_ED; /* Reset OFF. SW do PHY Init */
+if (sc->greth_rst) {
+/* Reset ON */
+regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD | GRETH_CTRL_ED;
+for (i = 0; i<100 && (regs->ctrl & GRETH_CTRL_RST); i++)
+;
+speed = 0; /* probe mode below */
+} else {
+/* inherit EDCL mode for now */
+speed = sc->regs->ctrl & 
(GRETH_CTRL_GB|GRETH_CTRL_SP|GRETH_CTRL_FULLD);
+}
+/* Reset OFF and RX/TX DMA OFF. SW do PHY Init */
+regs->ctrl = GRETH_CTRL_DD | GRETH_CTRL_ED | speed;
 
 /* Check if mac is gbit capable*/
 sc->gbit_mac = (regs->ctrl >> 27) & 1;
@@ -526,10 +535,15 @@ auto_neg_done:
 }
 while ((read_mii(sc, phyaddr, 0)) & 0x8000) {}
 
-regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD | GRETH_CTRL_ED; /* Reset ON */
-for (i = 0; i < 100 && (regs->ctrl & GRETH_CTRL_RST); i++)
-;
-regs->ctrl = GRETH_CTRL_DD | sc->edcl_dis; /* Reset OFF. SW do PHY Init */
+if (sc->greth_rst) {
+/* Reset ON */
+regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD | GRETH_CTRL_ED;
+for (i = 0; i < 100 && (regs->ctrl & GRETH_CTRL_RST); i++)
+;
+}
+/* Reset OFF. Set mode matching PHY settings. */
+speed = (sc->gb << 8) | (sc->sp << 7) | (sc->fd << 4);
+regs->ctrl = GRETH_CTRL_DD | sc->edcl_dis | speed;
 
 /* Initialize rx/tx descriptor table pointers. Due to alignment we 
  * always allocate maximum table size.
@@ -616,7 +630,7 @@ auto_neg_done:
 /* install interrupt handler */
 drvmgr_interrupt_register(sc->dev, 0, "greth", greth_interrupt, sc);
 
-regs->ctrl |= GRETH_CTRL_RXEN | (sc->fd << 4) | GRETH_CTRL_RXIRQ | (sc->sp 
<< 7) | (sc->gb << 8);
+regs->ctrl |= GRETH_CTRL_RXEN | GRETH_CTRL_RXIRQ;
 
 print_init_info(sc);
 }
@@ -1178,17 +1192,20 @@ greth_stop (struct greth_softc *sc)
 {
 struct ifnet *ifp = >arpcom.ac_if;
 SPIN_IRQFLAGS(flags);
+unsigned int speed;
 
 SPIN_LOCK_IRQ(>devlock, flags);
 ifp->if_flags &= ~IFF_RUNNING;
 
+speed = sc->regs->ctrl & (GRETH_CTRL_GB | GRETH_CTRL_SP | 
GRETH_CTRL_FULLD);
+
 /* RX/TX OFF */
-sc->regs->ctrl = GRETH_CTRL_DD | GRETH_CTRL_ED;
+sc->regs->ctrl = GRETH_CTRL_DD | GRETH_CTRL_ED | speed;
 /* Reset ON */
-sc->regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD | GRETH_CTRL_ED;
+if (sc->greth_rst)
+sc->regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD | GRETH_CTRL_ED | 
speed;
 /* Reset OFF and restore link settings previously detected if any */
-sc->regs->ctrl = GRETH_CTRL_DD | sc->edcl_dis |
- (sc->gb << 8) | (sc->sp << 7) | (sc->fd << 4);
+sc->regs->ctrl = GRETH_CTRL_DD | sc->edcl_dis | speed;
 SPIN_UNLOCK_IRQ(>devlock, flags);
 
 sc->next_tx_mbuf = NULL;
@@ -1460,6 +1477,7 @@ int greth_device_init(struct greth_softc *sc)
 pnpinfo = >info;
 sc->regs = (greth_regs *)pnpinfo->apb_slv->start;
 sc->minor = sc->dev->minor_drv;
+sc->greth_rst = 1;
 
 /* Remember EDCL enabled/disable state before reset */
 sc->edcl_dis = sc->regs->ctrl & GRETH_CTRL_ED;
@@ -1468,19 +1486,32 @@ int greth_device_init(struct greth_softc *sc)
 value = drvmgr_dev_key_get(sc->dev, "edclDis", DRVMGR_KT_INT);
 if ( value ) {
 /* Force EDCL mode. Has an effect later when GRETH+PHY is initialized 
*/
-if (value->i > 0)
+if (value->i > 0) {
 sc->edcl_dis = GRETH_CTRL_ED;
-else
+} else {
+/* Default to avoid soft-reset the GRETH when EDCL is forced */
 sc->edcl_dis = 0;
+sc->greth_rst = 0;
+   }
+}
+
+/* let user control soft-reset of GRETH (for debug) */
+value = drvmgr_dev_key_get(sc->dev, "soft-reset", DRVMGR_KT_INT);
+if ( value) {
+sc->greth_rst = value->i ? 1 : 0;
 }
 
 /* clear control 

[PATCH 03/32] leon, greth: 10/100 modes should be assigned in fastest priority

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/net/greth.c | 10 --
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/net/greth.c 
b/c/src/lib/libbsp/sparc/shared/net/greth.c
index 9f41a51..2e479ed 100644
--- a/c/src/lib/libbsp/sparc/shared/net/greth.c
+++ b/c/src/lib/libbsp/sparc/shared/net/greth.c
@@ -485,14 +485,12 @@ greth_initialize_hardware (struct greth_softc *sc)
  (sc->phydev.part & GRETH_MII_100TXFD)) {
 sc->sp = 1;
 sc->fd = 1;
-}
-if ( (sc->phydev.adv & GRETH_MII_100TXHD) &&
- (sc->phydev.part & GRETH_MII_100TXHD)) {
+} else if ( (sc->phydev.adv & GRETH_MII_100TXHD) &&
+(sc->phydev.part & GRETH_MII_100TXHD)) {
 sc->sp = 1;
 sc->fd = 0;
-}
-if ( (sc->phydev.adv & GRETH_MII_10FD) &&
- (sc->phydev.part & GRETH_MII_10FD)) {
+} else if ( (sc->phydev.adv & GRETH_MII_10FD) &&
+(sc->phydev.part & GRETH_MII_10FD)) {
 sc->fd = 1;
 }
 }
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 00/32] LEON

2017-05-11 Thread Daniel Hellstrom
The third set of patches for LEON. In short it contains:
 * GRCAN API changed from I/O system to C functions API, better error handling,
   other improvements and SMP support.
 * GRETH ethernet reset/autonegotiation improvements for GR740
 * Possible to have LEON3 SMP kernel to boot on other than CPU0.
 * SMP support and warnings fixes in: GRTC, GRTM, PCI peripherals,
   GR1553BM & BC. Still need to update GRSPW and GR1553RT.
 * Removed old unused APBUART RAW driver to reduce code duplication.
 * Patches to make RTEMS build using LLVM Clang for sparc.

Best Regards,
Daniel Hellstrom


---

 c/src/lib/libbsp/sparc/Makefile.am |1 -
 c/src/lib/libbsp/sparc/leon2/Makefile.am   |1 -
 c/src/lib/libbsp/sparc/leon3/Makefile.am   |3 +-
 .../libbsp/sparc/leon3/console/printk_support.c|   34 +-
 c/src/lib/libbsp/sparc/leon3/include/leon.h|2 +-
 c/src/lib/libbsp/sparc/leon3/startup/bspstart.c|5 +
 c/src/lib/libbsp/sparc/shared/1553/gr1553bc.c  |  123 +-
 c/src/lib/libbsp/sparc/shared/1553/gr1553bm.c  |   53 +-
 c/src/lib/libbsp/sparc/shared/amba/ahbstat.c   |4 +-
 c/src/lib/libbsp/sparc/shared/can/grcan.c  | 2206 +++-
 c/src/lib/libbsp/sparc/shared/include/apbuart.h|   33 -
 c/src/lib/libbsp/sparc/shared/include/genirq.h |   47 +-
 c/src/lib/libbsp/sparc/shared/include/grcan.h  |  268 ++-
 c/src/lib/libbsp/sparc/shared/include/greth.h  |   11 +
 c/src/lib/libbsp/sparc/shared/irq/genirq.c |   58 +-
 c/src/lib/libbsp/sparc/shared/irq/irq-shared.c |   11 +-
 c/src/lib/libbsp/sparc/shared/irq_asm.S|   12 +-
 c/src/lib/libbsp/sparc/shared/net/greth.c  |  134 +-
 c/src/lib/libbsp/sparc/shared/pci/gr_701.c |   67 +-
 c/src/lib/libbsp/sparc/shared/pci/gr_cpci_gr740.c  |   76 +-
 c/src/lib/libbsp/sparc/shared/pci/gr_leon4_n2x.c   |   66 +-
 .../lib/libbsp/sparc/shared/pci/gr_rasta_adcdac.c  |   68 +-
 c/src/lib/libbsp/sparc/shared/pci/gr_rasta_io.c|   68 +-
 .../libbsp/sparc/shared/pci/gr_rasta_spw_router.c  |   66 +-
 c/src/lib/libbsp/sparc/shared/pci/gr_rasta_tmtc.c  |   68 +-
 c/src/lib/libbsp/sparc/shared/pci/gr_tmtc_1553.c   |   75 +-
 c/src/lib/libbsp/sparc/shared/start/start.S|   20 +-
 c/src/lib/libbsp/sparc/shared/tmtc/grtc.c  |  135 +-
 c/src/lib/libbsp/sparc/shared/tmtc/grtm.c  |  198 +-
 c/src/lib/libbsp/sparc/shared/uart/apbuart.c   |  897 
 c/src/lib/libbsp/sparc/shared/uart/apbuart_cons.c  |8 +-
 c/src/lib/libcpu/sparc/access/access.S |6 +-
 c/src/lib/libcpu/sparc/reg_win/window.S|2 +-
 c/src/lib/libcpu/sparc/syscall/syscall.S   |2 +-
 cpukit/score/include/rtems/score/threadqimpl.h |4 +-
 35 files changed, 2382 insertions(+), 2450 deletions(-)

-- 
2.7.4
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 02/32] leon, greth: speed modes advertising now configurable

2017-05-11 Thread Daniel Hellstrom
---
 c/src/lib/libbsp/sparc/shared/include/greth.h | 10 
 c/src/lib/libbsp/sparc/shared/net/greth.c | 36 ---
 2 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/include/greth.h 
b/c/src/lib/libbsp/sparc/shared/include/greth.h
index 648f51f..9209d82 100644
--- a/c/src/lib/libbsp/sparc/shared/include/greth.h
+++ b/c/src/lib/libbsp/sparc/shared/include/greth.h
@@ -81,6 +81,8 @@ typedef struct _greth_regs {
 #define GRETH_CTRL_FULLD0x0010 /* Full Duplex */
 #define GRETH_CTRL_PRO  0x0020 /* Promiscuous (receive all) */
 #define GRETH_CTRL_RST  0x0040 /* Reset MAC */
+#define GRETH_CTRL_SP   0x0080 /* 100MBit speed mode */
+#define GRETH_CTRL_GB   0x0100 /* 1GBit speed mode */
 #define GRETH_CTRL_DD   0x1000 /* Disable EDCL Duplex Detection */
 #define GRETH_CTRL_ED   0x4000 /* EDCL Disable */
 
@@ -133,6 +135,14 @@ struct phy_device_info
int extpart;
 };
 
+/* Limit speed modes advertised during auto-negotiation */
+#define GRETH_ADV_10_HD0x0001
+#define GRETH_ADV_10_FD0x0002
+#define GRETH_ADV_100_HD   0x0004
+#define GRETH_ADV_100_FD   0x0008
+#define GRETH_ADV_1000_HD  0x0010
+#define GRETH_ADV_1000_FD  0x0020
+#define GRETH_ADV_ALL  0x003f
 /*
 #ifdef CPU_U32_FIX
 void ipalign(struct mbuf *m);
diff --git a/c/src/lib/libbsp/sparc/shared/net/greth.c 
b/c/src/lib/libbsp/sparc/shared/net/greth.c
index 87162a2..9f41a51 100644
--- a/c/src/lib/libbsp/sparc/shared/net/greth.c
+++ b/c/src/lib/libbsp/sparc/shared/net/greth.c
@@ -188,6 +188,7 @@ struct greth_softc
int gb;
int gbit_mac;
int auto_neg;
+   unsigned int advmodes; /* advertise ethernet speed modes. 0 = all modes. */
struct timespec auto_neg_time;
 
/*
@@ -352,6 +353,7 @@ greth_initialize_hardware (struct greth_softc *sc)
 int tmp2;
 struct timespec tstart, tnow;
 greth_regs *regs;
+unsigned int advmodes;
 
 regs = sc->regs;
 
@@ -394,6 +396,13 @@ greth_initialize_hardware (struct greth_softc *sc)
 /* Wait for reset to complete and get default values */
 while ((phyctrl = read_mii(sc, phyaddr, 0)) & 0x8000) {}
 
+/* Set up PHY advertising modes for auto-negotiation */
+advmodes = sc->advmodes;
+if (advmodes == 0)
+advmodes = GRETH_ADV_ALL;
+if (!sc->gbit_mac)
+advmodes &= ~(GRETH_ADV_1000_FD | GRETH_ADV_1000_HD);
+
 /* Enable/Disable GBit auto-neg advetisement so that the link partner
  * know that we have/haven't GBit capability. The MAC may not support
  * Gbit even though PHY does...
@@ -401,12 +410,27 @@ greth_initialize_hardware (struct greth_softc *sc)
 phystatus = read_mii(sc, phyaddr, 1);
 if (phystatus & 0x0100) {
 tmp1 = read_mii(sc, phyaddr, 9);
-if (sc->gbit_mac)
-write_mii(sc, phyaddr, 9, tmp1 | 0x300);
-else
-write_mii(sc, phyaddr, 9, tmp1 & ~(0x300));
+tmp1 &= ~0x300;
+if (advmodes & GRETH_ADV_1000_FD)
+tmp1 |= 0x200;
+if (advmodes & GRETH_ADV_1000_HD)
+tmp1 |= 0x100;
+write_mii(sc, phyaddr, 9, tmp1);
 }
 
+/* Optionally limit the 10/100 modes as configured by user */
+tmp1 = read_mii(sc, phyaddr, 4);
+tmp1 &= ~0x1e0;
+if (advmodes & GRETH_ADV_100_FD)
+tmp1 |= 0x100;
+if (advmodes & GRETH_ADV_100_HD)
+tmp1 |= 0x080;
+if (advmodes & GRETH_ADV_10_FD)
+tmp1 |= 0x040;
+if (advmodes & GRETH_ADV_10_HD)
+tmp1 |= 0x020;
+write_mii(sc, phyaddr, 4, tmp1);
+
 /* If autonegotiation implemented we start it */
 if (phystatus & 0x0008) {
 write_mii(sc, phyaddr, 0, phyctrl | 0x1200);
@@ -1480,6 +1504,10 @@ int greth_device_init(struct greth_softc *sc)
 if ( value && (value->i < 32) )
 sc->phyaddr = value->i;
 
+value = drvmgr_dev_key_get(sc->dev, "advModes", DRVMGR_KT_INT);
+if ( value )
+sc->advmodes = value->i;
+
 return 0;
 }
 
-- 
2.7.4

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH 01/32] leon, greth: EDCL and DD is disabled during reset

2017-05-11 Thread Daniel Hellstrom
The EDCL and Duplex-Detection are now disabled during soft-reset
of the GRETH core.

The speed settings are preserved on boot and greth_stop() also,
this is required to keep EDCL operational when DD is set.
---
 c/src/lib/libbsp/sparc/shared/include/greth.h |  1 +
 c/src/lib/libbsp/sparc/shared/net/greth.c | 47 +++
 2 files changed, 34 insertions(+), 14 deletions(-)

diff --git a/c/src/lib/libbsp/sparc/shared/include/greth.h 
b/c/src/lib/libbsp/sparc/shared/include/greth.h
index 904f60c..648f51f 100644
--- a/c/src/lib/libbsp/sparc/shared/include/greth.h
+++ b/c/src/lib/libbsp/sparc/shared/include/greth.h
@@ -82,6 +82,7 @@ typedef struct _greth_regs {
 #define GRETH_CTRL_PRO  0x0020 /* Promiscuous (receive all) */
 #define GRETH_CTRL_RST  0x0040 /* Reset MAC */
 #define GRETH_CTRL_DD   0x1000 /* Disable EDCL Duplex Detection */
+#define GRETH_CTRL_ED   0x4000 /* EDCL Disable */
 
 /* Status Register */
 #define GRETH_STATUS_RXERR  0x0001 /* Receive Error */
diff --git a/c/src/lib/libbsp/sparc/shared/net/greth.c 
b/c/src/lib/libbsp/sparc/shared/net/greth.c
index b2ecf90..87162a2 100644
--- a/c/src/lib/libbsp/sparc/shared/net/greth.c
+++ b/c/src/lib/libbsp/sparc/shared/net/greth.c
@@ -154,6 +154,7 @@ struct greth_softc
greth_regs *regs;
int minor;
int phyaddr;  /* PHY Address configured by user (or -1 to autodetect) */
+   unsigned int edcl_dis;
 
int acceptBroadcast;
rtems_id daemonTid;
@@ -350,19 +351,18 @@ greth_initialize_hardware (struct greth_softc *sc)
 int tmp1;
 int tmp2;
 struct timespec tstart, tnow;
-
 greth_regs *regs;
 
 regs = sc->regs;
-
+
 /* Reset the controller.  */
 sc->rxInterrupts = 0;
 sc->rxPackets = 0;
 
-regs->ctrl = GRETH_CTRL_RST;   /* Reset ON */
+regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD | GRETH_CTRL_ED; /* Reset ON */
 for (i = 0; i<100 && (regs->ctrl & GRETH_CTRL_RST); i++)
 ;
-regs->ctrl = GRETH_CTRL_DD;/* Reset OFF. SW do PHY Init */
+regs->ctrl = GRETH_CTRL_DD | GRETH_CTRL_ED; /* Reset OFF. SW do PHY Init */
 
 /* Check if mac is gbit capable*/
 sc->gbit_mac = (regs->ctrl >> 27) & 1;
@@ -504,10 +504,10 @@ auto_neg_done:
 }
 while ((read_mii(sc, phyaddr, 0)) & 0x8000) {}
 
-regs->ctrl = GRETH_CTRL_RST;   /* Reset ON */
+regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD | GRETH_CTRL_ED; /* Reset ON */
 for (i = 0; i < 100 && (regs->ctrl & GRETH_CTRL_RST); i++)
 ;
-regs->ctrl = GRETH_CTRL_DD;
+regs->ctrl = GRETH_CTRL_DD | sc->edcl_dis; /* Reset OFF. SW do PHY Init */
 
 /* Initialize rx/tx descriptor table pointers. Due to alignment we 
  * always allocate maximum table size.
@@ -584,7 +584,7 @@ auto_neg_done:
 sc->tx_int_gen = sc->tx_int_gen_cur = sc->txbufs/2;
 }
 sc->next_tx_mbuf = NULL;
-
+
 if ( !sc->gbit_mac )
 sc->max_fragsize = 1;
 
@@ -1160,9 +1160,13 @@ greth_stop (struct greth_softc *sc)
 SPIN_LOCK_IRQ(>devlock, flags);
 ifp->if_flags &= ~IFF_RUNNING;
 
-sc->regs->ctrl = 0;/* RX/TX OFF */
-sc->regs->ctrl = GRETH_CTRL_RST;   /* Reset ON */
-sc->regs->ctrl = 0;/* Reset OFF */
+/* RX/TX OFF */
+sc->regs->ctrl = GRETH_CTRL_DD | GRETH_CTRL_ED;
+/* Reset ON */
+sc->regs->ctrl = GRETH_CTRL_RST | GRETH_CTRL_DD | GRETH_CTRL_ED;
+/* Reset OFF and restore link settings previously detected if any */
+sc->regs->ctrl = GRETH_CTRL_DD | sc->edcl_dis |
+ (sc->gb << 8) | (sc->sp << 7) | (sc->fd << 4);
 SPIN_UNLOCK_IRQ(>devlock, flags);
 
 sc->next_tx_mbuf = NULL;
@@ -1424,6 +1428,7 @@ int greth_device_init(struct greth_softc *sc)
 struct amba_dev_info *ambadev;
 struct ambapp_core *pnpinfo;
 union drvmgr_key_value *value;
+unsigned int speed;
 
 /* Get device information from AMBA PnP information */
 ambadev = (struct amba_dev_info *)sc->dev->businfo;
@@ -1434,13 +1439,27 @@ int greth_device_init(struct greth_softc *sc)
 sc->regs = (greth_regs *)pnpinfo->apb_slv->start;
 sc->minor = sc->dev->minor_drv;
 
-/* clear control register and reset NIC 
+/* Remember EDCL enabled/disable state before reset */
+sc->edcl_dis = sc->regs->ctrl & GRETH_CTRL_ED;
+
+/* Default is to inherit EDCL Disable bit from HW. User can force En/Dis */
+value = drvmgr_dev_key_get(sc->dev, "edclDis", DRVMGR_KT_INT);
+if ( value ) {
+/* Force EDCL mode. Has an effect later when GRETH+PHY is initialized 
*/
+if (value->i > 0)
+sc->edcl_dis = GRETH_CTRL_ED;
+else
+sc->edcl_dis = 0;
+}
+
+/* clear control register and reset NIC and keep current speed modes.
  * This should be done as quick as possible during startup, this is to
  * stop DMA transfers after a reboot.
  */
-sc->regs->ctrl = 0;
-sc->regs->ctrl = 

Re: GCC 7.1 Released

2017-05-11 Thread Sebastian Huber

Hello,

if someone wants to use GCC 7.1 for RTEMS 4.12, then the RSB should be 
updated accordingly as soon as possible.


--
Sebastian Huber, embedded brains GmbH

Address : Dornierstr. 4, D-82178 Puchheim, Germany
Phone   : +49 89 189 47 41-16
Fax : +49 89 189 47 41-09
E-Mail  : sebastian.hu...@embedded-brains.de
PGP : Public key available on request.

Diese Nachricht ist keine geschäftliche Mitteilung im Sinne des EHUG.

___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


Re: [PATCH] confdefs.h: CONFIGURE_DISABLE_SMP_CONFIGURATION

2017-05-11 Thread Chris Johns
On 11/5/17 7:56 pm, Sebastian Huber wrote:
> Enable the SMP configuration by default in case SMP is enabled.  Add
> configuration option CONFIGURE_DISABLE_SMP_CONFIGURATION to disable it
> explicitly.
> 
> Add CONFIGURE_DISABLE_SMP_CONFIGURATION to all test which would fail
> otherwise.
> 
> Update #3001.

+1

Nice.

Chris
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel


[PATCH] confdefs.h: CONFIGURE_DISABLE_SMP_CONFIGURATION

2017-05-11 Thread Sebastian Huber
Enable the SMP configuration by default in case SMP is enabled.  Add
configuration option CONFIGURE_DISABLE_SMP_CONFIGURATION to disable it
explicitly.

Add CONFIGURE_DISABLE_SMP_CONFIGURATION to all test which would fail
otherwise.

Update #3001.
---
 cpukit/sapi/include/confdefs.h | 8 ++--
 testsuites/libtests/block08/system.h   | 2 ++
 testsuites/psxtests/psx05/system.h | 2 ++
 testsuites/sptests/sp04/system.h   | 2 ++
 testsuites/sptests/sp07/system.h   | 2 ++
 testsuites/sptests/sp12/system.h   | 2 ++
 testsuites/sptests/sp13/system.h   | 2 ++
 testsuites/sptests/sp16/system.h   | 2 ++
 testsuites/sptests/spfatal29/testcase.h| 2 ++
 testsuites/sptests/spintrcritical06/init.c | 2 ++
 testsuites/sptests/spintrcritical15/init.c | 2 ++
 testsuites/sptests/spmrsp01/init.c | 2 ++
 testsuites/sptests/spsimplesched02/init.c  | 2 ++
 testsuites/tmtests/tm04/system.h   | 2 ++
 testsuites/tmtests/tm15/system.h   | 2 ++
 testsuites/tmtests/tm20/system.h   | 2 ++
 testsuites/tmtests/tm24/system.h   | 2 ++
 17 files changed, 38 insertions(+), 2 deletions(-)

diff --git a/cpukit/sapi/include/confdefs.h b/cpukit/sapi/include/confdefs.h
index 239ddd9..06938b1 100755
--- a/cpukit/sapi/include/confdefs.h
+++ b/cpukit/sapi/include/confdefs.h
@@ -224,8 +224,12 @@ extern rtems_initialization_tasks_table 
Initialization_tasks[];
  * An internal define to indicate that this is an SMP application
  * configuration.
  */
-#if defined(RTEMS_SMP) && CONFIGURE_MAXIMUM_PROCESSORS > 1
-  #define _CONFIGURE_SMP_APPLICATION
+#ifdef RTEMS_SMP
+  #if !defined(CONFIGURE_DISABLE_SMP_CONFIGURATION)
+#define _CONFIGURE_SMP_APPLICATION
+  #elif CONFIGURE_MAXIMUM_PROCESSORS > 1
+#error "CONFIGURE_DISABLE_SMP_CONFIGURATION and 
CONFIGURE_MAXIMUM_PROCESSORS > 1 makes no sense"
+  #endif
 #endif
 
 #ifdef CONFIGURE_SMP_APPLICATION
diff --git a/testsuites/libtests/block08/system.h 
b/testsuites/libtests/block08/system.h
index 60cf9c8..f2ba2ec 100644
--- a/testsuites/libtests/block08/system.h
+++ b/testsuites/libtests/block08/system.h
@@ -54,6 +54,8 @@ rtems_task Init(
 
 #define CONFIGURE_EXTRA_TASK_STACKS (13 * RTEMS_MINIMUM_STACK_SIZE)
 
+#define CONFIGURE_DISABLE_SMP_CONFIGURATION
+
 #include 
 
 /* end of include file */
diff --git a/testsuites/psxtests/psx05/system.h 
b/testsuites/psxtests/psx05/system.h
index 9ce25e0..a3615d4 100644
--- a/testsuites/psxtests/psx05/system.h
+++ b/testsuites/psxtests/psx05/system.h
@@ -43,6 +43,8 @@ void *Task_3(
 
 #define CONFIGURE_POSIX_INIT_THREAD_TABLE
 
+#define CONFIGURE_DISABLE_SMP_CONFIGURATION
+
 #include 
 
 /* global variables */
diff --git a/testsuites/sptests/sp04/system.h b/testsuites/sptests/sp04/system.h
index 2181b8c..9606368 100644
--- a/testsuites/sptests/sp04/system.h
+++ b/testsuites/sptests/sp04/system.h
@@ -52,6 +52,8 @@ void Task_switch(
 #define CONFIGURE_MAXIMUM_TASKS 4
 #define CONFIGURE_MAXIMUM_TIMERS1
 
+#define CONFIGURE_DISABLE_SMP_CONFIGURATION
+
 #include 
 
 /* global variables */
diff --git a/testsuites/sptests/sp07/system.h b/testsuites/sptests/sp07/system.h
index 8bea0fb..3f8cb26 100644
--- a/testsuites/sptests/sp07/system.h
+++ b/testsuites/sptests/sp07/system.h
@@ -74,6 +74,8 @@ void Task_exit_extension(
 #define CONFIGURE_EXTRA_TASK_STACKS (4 * RTEMS_MINIMUM_STACK_SIZE)
 #define CONFIGURE_MAXIMUM_TASKS 5
 
+#define CONFIGURE_DISABLE_SMP_CONFIGURATION
+
 #include 
 
 /* global variables */
diff --git a/testsuites/sptests/sp12/system.h b/testsuites/sptests/sp12/system.h
index c91a8bd..299169f 100644
--- a/testsuites/sptests/sp12/system.h
+++ b/testsuites/sptests/sp12/system.h
@@ -65,6 +65,8 @@ rtems_task Task5(
 
 #define CONFIGURE_EXTRA_TASK_STACKS (6 * RTEMS_MINIMUM_STACK_SIZE)
 
+#define CONFIGURE_DISABLE_SMP_CONFIGURATION
+
 #include 
 
 /* global variables */
diff --git a/testsuites/sptests/sp13/system.h b/testsuites/sptests/sp13/system.h
index 20ecc2f..e8632e4 100644
--- a/testsuites/sptests/sp13/system.h
+++ b/testsuites/sptests/sp13/system.h
@@ -97,6 +97,8 @@ TEST_EXTERN rtems_name Queue_name[ 4 ];  /* array of 
queue names */
 
 #define CONFIGURE_EXTRA_TASK_STACKS (3 * RTEMS_MINIMUM_STACK_SIZE)
 
+#define CONFIGURE_DISABLE_SMP_CONFIGURATION
+
 #include 
 
 /* end of include file */
diff --git a/testsuites/sptests/sp16/system.h b/testsuites/sptests/sp16/system.h
index 139c757..a812663 100644
--- a/testsuites/sptests/sp16/system.h
+++ b/testsuites/sptests/sp16/system.h
@@ -54,6 +54,8 @@ rtems_task Task5(
 
 #define CONFIGURE_EXTRA_TASK_STACKS (1 * RTEMS_MINIMUM_STACK_SIZE)
 
+#define CONFIGURE_DISABLE_SMP_CONFIGURATION
+
 #include 
 
 /* global variables */
diff --git a/testsuites/sptests/spfatal29/testcase.h 
b/testsuites/sptests/spfatal29/testcase.h
index 63f74f8..87545f7 100644
--- a/testsuites/sptests/spfatal29/testcase.h
+++