1 | /** |
---|
2 | * @file |
---|
3 | * |
---|
4 | * @ingroup QorIQInterCom |
---|
5 | * |
---|
6 | * @brief Inter-Processor Communication implementation. |
---|
7 | */ |
---|
8 | |
---|
9 | /* |
---|
10 | * Copyright (c) 2011 embedded brains GmbH. All rights reserved. |
---|
11 | * |
---|
12 | * embedded brains GmbH |
---|
13 | * Obere Lagerstr. 30 |
---|
14 | * 82178 Puchheim |
---|
15 | * Germany |
---|
16 | * <rtems@embedded-brains.de> |
---|
17 | * |
---|
18 | * The license and distribution terms for this file may be |
---|
19 | * found in the file LICENSE in this distribution or at |
---|
20 | * http://www.rtems.org/license/LICENSE. |
---|
21 | */ |
---|
22 | |
---|
23 | #include <assert.h> |
---|
24 | |
---|
25 | #include <libcpu/powerpc-utility.h> |
---|
26 | |
---|
27 | #include <bsp/intercom.h> |
---|
28 | |
---|
29 | #ifdef RTEMS_MULTIPROCESSING |
---|
30 | |
---|
31 | typedef struct { |
---|
32 | intercom_packet *head; |
---|
33 | intercom_packet *tail; |
---|
34 | } mpic_fifo; |
---|
35 | |
---|
36 | static mpic_fifo fifo; |
---|
37 | |
---|
38 | static void mpci_service(intercom_packet *packet, void *arg) |
---|
39 | { |
---|
40 | rtems_interrupt_level level; |
---|
41 | |
---|
42 | rtems_interrupt_disable(level); |
---|
43 | packet->glue.next = NULL; |
---|
44 | if (fifo.head != NULL) { |
---|
45 | fifo.tail->glue.next = packet; |
---|
46 | } else { |
---|
47 | fifo.head = packet; |
---|
48 | } |
---|
49 | fifo.tail = packet; |
---|
50 | rtems_interrupt_enable(level); |
---|
51 | |
---|
52 | rtems_multiprocessing_announce(); |
---|
53 | } |
---|
54 | |
---|
55 | static void mpci_init(void) |
---|
56 | { |
---|
57 | qoriq_intercom_service_install(INTERCOM_TYPE_MPCI, mpci_service, NULL); |
---|
58 | } |
---|
59 | |
---|
60 | static intercom_packet *packet_of_prefix(rtems_packet_prefix *prefix) |
---|
61 | { |
---|
62 | return (intercom_packet *) ((char *) prefix - sizeof(intercom_packet)); |
---|
63 | } |
---|
64 | |
---|
65 | static rtems_packet_prefix *prefix_of_packet(intercom_packet *packet) |
---|
66 | { |
---|
67 | return (rtems_packet_prefix *) packet->data; |
---|
68 | } |
---|
69 | |
---|
70 | static void mpci_get_packet(rtems_packet_prefix **prefix_ptr) |
---|
71 | { |
---|
72 | intercom_packet *packet = qoriq_intercom_allocate_packet( |
---|
73 | INTERCOM_TYPE_MPCI, |
---|
74 | INTERCOM_SIZE_512 |
---|
75 | ); |
---|
76 | *prefix_ptr = prefix_of_packet(packet); |
---|
77 | } |
---|
78 | |
---|
79 | static void mpci_return_packet(rtems_packet_prefix *prefix) |
---|
80 | { |
---|
81 | intercom_packet *packet = packet_of_prefix(prefix); |
---|
82 | |
---|
83 | qoriq_intercom_free_packet(packet); |
---|
84 | } |
---|
85 | |
---|
86 | static void mpci_send_packet(uint32_t destination_node, rtems_packet_prefix *prefix) |
---|
87 | { |
---|
88 | intercom_packet *packet = packet_of_prefix(prefix); |
---|
89 | if (destination_node != MPCI_ALL_NODES) { |
---|
90 | qoriq_intercom_send_packet((int) destination_node - 1, packet); |
---|
91 | } else { |
---|
92 | uint32_t self = ppc_processor_id(); |
---|
93 | int other = self == 0 ? 1 : 0; |
---|
94 | |
---|
95 | qoriq_intercom_send_packet(other, packet); |
---|
96 | } |
---|
97 | } |
---|
98 | |
---|
99 | static void mpci_receive_packet(rtems_packet_prefix **prefix_ptr) |
---|
100 | { |
---|
101 | rtems_interrupt_level level; |
---|
102 | |
---|
103 | rtems_interrupt_disable(level); |
---|
104 | intercom_packet *packet = fifo.head; |
---|
105 | if (packet != NULL) { |
---|
106 | fifo.head = packet->glue.next; |
---|
107 | *prefix_ptr = prefix_of_packet(packet); |
---|
108 | } else { |
---|
109 | *prefix_ptr = NULL; |
---|
110 | } |
---|
111 | rtems_interrupt_enable(level); |
---|
112 | } |
---|
113 | |
---|
114 | rtems_mpci_table qoriq_intercom_mpci = { |
---|
115 | .default_timeout = UINT32_MAX, |
---|
116 | .maximum_packet_size = 512, |
---|
117 | .initialization = mpci_init, |
---|
118 | .get_packet = mpci_get_packet, |
---|
119 | .return_packet = mpci_return_packet, |
---|
120 | .send_packet = mpci_send_packet, |
---|
121 | .receive_packet = mpci_receive_packet |
---|
122 | }; |
---|
123 | |
---|
124 | #endif /* RTEMS_MULTIPROCESSING */ |
---|