Skip to content

Commit 1291e49

Browse files
Zhao QiangScott Wood
authored andcommitted
QE/CPM: move muram management functions to qe_common
QE and CPM have the same muram, they use the same management functions. Now QE support both ARM and PowerPC, it is necessary to move QE to "driver/soc", so move the muram management functions from cpm_common to qe_common for preparing to move QE code to "driver/soc" Signed-off-by: Zhao Qiang <qiang.zhao@freescale.com> Signed-off-by: Scott Wood <scottwood@freescale.com>
1 parent 0e6e01f commit 1291e49

File tree

6 files changed

+290
-255
lines changed

6 files changed

+290
-255
lines changed

arch/powerpc/include/asm/cpm.h

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
#define __CPM_H
33

44
#include <linux/compiler.h>
5-
#include <linux/genalloc.h>
65
#include <linux/types.h>
76
#include <linux/errno.h>
87
#include <linux/of.h>
8+
#include <asm/qe.h>
99

1010
/*
1111
* SPI Parameter RAM common to QE and CPM.
@@ -156,51 +156,6 @@ typedef struct cpm_buf_desc {
156156
*/
157157
#define BD_I2C_START (0x0400)
158158

159-
int cpm_muram_init(void);
160-
161-
#if defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE)
162-
unsigned long cpm_muram_alloc(unsigned long size, unsigned long align);
163-
int cpm_muram_free(unsigned long offset);
164-
unsigned long cpm_muram_alloc_fixed(unsigned long offset, unsigned long size);
165-
unsigned long cpm_muram_alloc_common(unsigned long size, genpool_algo_t algo,
166-
void *data);
167-
void __iomem *cpm_muram_addr(unsigned long offset);
168-
unsigned long cpm_muram_offset(void __iomem *addr);
169-
dma_addr_t cpm_muram_dma(void __iomem *addr);
170-
#else
171-
static inline unsigned long cpm_muram_alloc(unsigned long size,
172-
unsigned long align)
173-
{
174-
return -ENOSYS;
175-
}
176-
177-
static inline int cpm_muram_free(unsigned long offset)
178-
{
179-
return -ENOSYS;
180-
}
181-
182-
static inline unsigned long cpm_muram_alloc_fixed(unsigned long offset,
183-
unsigned long size)
184-
{
185-
return -ENOSYS;
186-
}
187-
188-
static inline void __iomem *cpm_muram_addr(unsigned long offset)
189-
{
190-
return NULL;
191-
}
192-
193-
static inline unsigned long cpm_muram_offset(void __iomem *addr)
194-
{
195-
return -ENOSYS;
196-
}
197-
198-
static inline dma_addr_t cpm_muram_dma(void __iomem *addr)
199-
{
200-
return 0;
201-
}
202-
#endif /* defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE) */
203-
204159
#ifdef CONFIG_CPM
205160
int cpm_command(u32 command, u8 opcode);
206161
#else

arch/powerpc/include/asm/qe.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,16 @@
1616
#define _ASM_POWERPC_QE_H
1717
#ifdef __KERNEL__
1818

19+
#include <linux/compiler.h>
20+
#include <linux/genalloc.h>
1921
#include <linux/spinlock.h>
2022
#include <linux/errno.h>
2123
#include <linux/err.h>
2224
#include <asm/cpm.h>
2325
#include <asm/immap_qe.h>
26+
#include <linux/of.h>
27+
#include <linux/of_address.h>
28+
#include <linux/types.h>
2429

2530
#define QE_NUM_OF_SNUM 256 /* There are 256 serial number in QE */
2631
#define QE_NUM_OF_BRGS 16
@@ -92,6 +97,51 @@ extern void qe_reset(void);
9297
static inline void qe_reset(void) {}
9398
#endif
9499

100+
int cpm_muram_init(void);
101+
102+
#if defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE)
103+
unsigned long cpm_muram_alloc(unsigned long size, unsigned long align);
104+
int cpm_muram_free(unsigned long offset);
105+
unsigned long cpm_muram_alloc_fixed(unsigned long offset, unsigned long size);
106+
unsigned long cpm_muram_alloc_common(unsigned long size, genpool_algo_t algo,
107+
void *data);
108+
void __iomem *cpm_muram_addr(unsigned long offset);
109+
unsigned long cpm_muram_offset(void __iomem *addr);
110+
dma_addr_t cpm_muram_dma(void __iomem *addr);
111+
#else
112+
static inline unsigned long cpm_muram_alloc(unsigned long size,
113+
unsigned long align)
114+
{
115+
return -ENOSYS;
116+
}
117+
118+
static inline int cpm_muram_free(unsigned long offset)
119+
{
120+
return -ENOSYS;
121+
}
122+
123+
static inline unsigned long cpm_muram_alloc_fixed(unsigned long offset,
124+
unsigned long size)
125+
{
126+
return -ENOSYS;
127+
}
128+
129+
static inline void __iomem *cpm_muram_addr(unsigned long offset)
130+
{
131+
return NULL;
132+
}
133+
134+
static inline unsigned long cpm_muram_offset(void __iomem *addr)
135+
{
136+
return -ENOSYS;
137+
}
138+
139+
static inline dma_addr_t cpm_muram_dma(void __iomem *addr)
140+
{
141+
return 0;
142+
}
143+
#endif /* defined(CONFIG_CPM) || defined(CONFIG_QUICC_ENGINE) */
144+
95145
/* QE PIO */
96146
#define QE_PIO_PINS 32
97147

arch/powerpc/sysdev/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ obj-$(CONFIG_SIMPLE_GPIO) += simple_gpio.o
2727
obj-$(CONFIG_FSL_RIO) += fsl_rio.o fsl_rmu.o
2828
obj-$(CONFIG_TSI108_BRIDGE) += tsi108_pci.o tsi108_dev.o
2929
obj-$(CONFIG_QUICC_ENGINE) += qe_lib/
30+
obj-$(CONFIG_CPM) += qe_lib/
3031
mv64x60-$(CONFIG_PCI) += mv64x60_pci.o
3132
obj-$(CONFIG_MV64X60) += $(mv64x60-y) mv64x60_pic.o mv64x60_dev.o \
3233
mv64x60_udbg.o

arch/powerpc/sysdev/cpm_common.c

Lines changed: 1 addition & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* published by the Free Software Foundation.
1818
*/
1919

20-
#include <linux/genalloc.h>
2120
#include <linux/init.h>
2221
#include <linux/of_device.h>
2322
#include <linux/spinlock.h>
@@ -29,6 +28,7 @@
2928
#include <asm/udbg.h>
3029
#include <asm/io.h>
3130
#include <asm/cpm.h>
31+
#include <asm/qe.h>
3232

3333
#include <mm/mmu_decl.h>
3434

@@ -65,212 +65,6 @@ void __init udbg_init_cpm(void)
6565
}
6666
#endif
6767

68-
static struct gen_pool *muram_pool;
69-
static spinlock_t cpm_muram_lock;
70-
static u8 __iomem *muram_vbase;
71-
static phys_addr_t muram_pbase;
72-
73-
struct muram_block {
74-
struct list_head head;
75-
unsigned long start;
76-
int size;
77-
};
78-
79-
static LIST_HEAD(muram_block_list);
80-
81-
/* max address size we deal with */
82-
#define OF_MAX_ADDR_CELLS 4
83-
#define GENPOOL_OFFSET (4096 * 8)
84-
85-
int cpm_muram_init(void)
86-
{
87-
struct device_node *np;
88-
struct resource r;
89-
u32 zero[OF_MAX_ADDR_CELLS] = {};
90-
resource_size_t max = 0;
91-
int i = 0;
92-
int ret = 0;
93-
94-
if (muram_pbase)
95-
return 0;
96-
97-
spin_lock_init(&cpm_muram_lock);
98-
np = of_find_compatible_node(NULL, NULL, "fsl,cpm-muram-data");
99-
if (!np) {
100-
/* try legacy bindings */
101-
np = of_find_node_by_name(NULL, "data-only");
102-
if (!np) {
103-
pr_err("Cannot find CPM muram data node");
104-
ret = -ENODEV;
105-
goto out_muram;
106-
}
107-
}
108-
109-
muram_pool = gen_pool_create(0, -1);
110-
muram_pbase = of_translate_address(np, zero);
111-
if (muram_pbase == (phys_addr_t)OF_BAD_ADDR) {
112-
pr_err("Cannot translate zero through CPM muram node");
113-
ret = -ENODEV;
114-
goto out_pool;
115-
}
116-
117-
while (of_address_to_resource(np, i++, &r) == 0) {
118-
if (r.end > max)
119-
max = r.end;
120-
ret = gen_pool_add(muram_pool, r.start - muram_pbase +
121-
GENPOOL_OFFSET, resource_size(&r), -1);
122-
if (ret) {
123-
pr_err("QE: couldn't add muram to pool!\n");
124-
goto out_pool;
125-
}
126-
}
127-
128-
muram_vbase = ioremap(muram_pbase, max - muram_pbase + 1);
129-
if (!muram_vbase) {
130-
pr_err("Cannot map QE muram");
131-
ret = -ENOMEM;
132-
goto out_pool;
133-
}
134-
goto out_muram;
135-
out_pool:
136-
gen_pool_destroy(muram_pool);
137-
out_muram:
138-
of_node_put(np);
139-
return ret;
140-
}
141-
142-
/*
143-
* cpm_muram_alloc - allocate the requested size worth of multi-user ram
144-
* @size: number of bytes to allocate
145-
* @align: requested alignment, in bytes
146-
*
147-
* This function returns an offset into the muram area.
148-
* Use cpm_dpram_addr() to get the virtual address of the area.
149-
* Use cpm_muram_free() to free the allocation.
150-
*/
151-
unsigned long cpm_muram_alloc(unsigned long size, unsigned long align)
152-
{
153-
unsigned long start;
154-
unsigned long flags;
155-
struct genpool_data_align muram_pool_data;
156-
157-
spin_lock_irqsave(&cpm_muram_lock, flags);
158-
muram_pool_data.align = align;
159-
start = cpm_muram_alloc_common(size, gen_pool_first_fit_align,
160-
&muram_pool_data);
161-
spin_unlock_irqrestore(&cpm_muram_lock, flags);
162-
return start;
163-
}
164-
EXPORT_SYMBOL(cpm_muram_alloc);
165-
166-
/**
167-
* cpm_muram_free - free a chunk of multi-user ram
168-
* @offset: The beginning of the chunk as returned by cpm_muram_alloc().
169-
*/
170-
int cpm_muram_free(unsigned long offset)
171-
{
172-
unsigned long flags;
173-
int size;
174-
struct muram_block *tmp;
175-
176-
size = 0;
177-
spin_lock_irqsave(&cpm_muram_lock, flags);
178-
list_for_each_entry(tmp, &muram_block_list, head) {
179-
if (tmp->start == offset) {
180-
size = tmp->size;
181-
list_del(&tmp->head);
182-
kfree(tmp);
183-
break;
184-
}
185-
}
186-
gen_pool_free(muram_pool, offset + GENPOOL_OFFSET, size);
187-
spin_unlock_irqrestore(&cpm_muram_lock, flags);
188-
return size;
189-
}
190-
EXPORT_SYMBOL(cpm_muram_free);
191-
192-
/*
193-
* cpm_muram_alloc_fixed - reserve a specific region of multi-user ram
194-
* @offset: offset of allocation start address
195-
* @size: number of bytes to allocate
196-
* This function returns an offset into the muram area
197-
* Use cpm_dpram_addr() to get the virtual address of the area.
198-
* Use cpm_muram_free() to free the allocation.
199-
*/
200-
unsigned long cpm_muram_alloc_fixed(unsigned long offset, unsigned long size)
201-
{
202-
unsigned long start;
203-
unsigned long flags;
204-
struct genpool_data_fixed muram_pool_data_fixed;
205-
206-
spin_lock_irqsave(&cpm_muram_lock, flags);
207-
muram_pool_data_fixed.offset = offset + GENPOOL_OFFSET;
208-
start = cpm_muram_alloc_common(size, gen_pool_fixed_alloc,
209-
&muram_pool_data_fixed);
210-
spin_unlock_irqrestore(&cpm_muram_lock, flags);
211-
return start;
212-
}
213-
EXPORT_SYMBOL(cpm_muram_alloc_fixed);
214-
215-
/*
216-
* cpm_muram_alloc_common - cpm_muram_alloc common code
217-
* @size: number of bytes to allocate
218-
* @algo: algorithm for alloc.
219-
* @data: data for genalloc's algorithm.
220-
*
221-
* This function returns an offset into the muram area.
222-
*/
223-
unsigned long cpm_muram_alloc_common(unsigned long size, genpool_algo_t algo,
224-
void *data)
225-
{
226-
struct muram_block *entry;
227-
unsigned long start;
228-
229-
start = gen_pool_alloc_algo(muram_pool, size, algo, data);
230-
if (!start)
231-
goto out2;
232-
start = start - GENPOOL_OFFSET;
233-
memset_io(cpm_muram_addr(start), 0, size);
234-
entry = kmalloc(sizeof(*entry), GFP_KERNEL);
235-
if (!entry)
236-
goto out1;
237-
entry->start = start;
238-
entry->size = size;
239-
list_add(&entry->head, &muram_block_list);
240-
241-
return start;
242-
out1:
243-
gen_pool_free(muram_pool, start, size);
244-
out2:
245-
return (unsigned long)-ENOMEM;
246-
}
247-
248-
/**
249-
* cpm_muram_addr - turn a muram offset into a virtual address
250-
* @offset: muram offset to convert
251-
*/
252-
void __iomem *cpm_muram_addr(unsigned long offset)
253-
{
254-
return muram_vbase + offset;
255-
}
256-
EXPORT_SYMBOL(cpm_muram_addr);
257-
258-
unsigned long cpm_muram_offset(void __iomem *addr)
259-
{
260-
return addr - (void __iomem *)muram_vbase;
261-
}
262-
EXPORT_SYMBOL(cpm_muram_offset);
263-
264-
/**
265-
* cpm_muram_dma - turn a muram virtual address into a DMA address
266-
* @offset: virtual address from cpm_muram_addr() to convert
267-
*/
268-
dma_addr_t cpm_muram_dma(void __iomem *addr)
269-
{
270-
return muram_pbase + ((u8 __iomem *)addr - muram_vbase);
271-
}
272-
EXPORT_SYMBOL(cpm_muram_dma);
273-
27468
#if defined(CONFIG_CPM2) || defined(CONFIG_8xx_GPIO)
27569

27670
struct cpm2_ioports {

arch/powerpc/sysdev/qe_lib/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#
22
# Makefile for the linux ppc-specific parts of QE
33
#
4-
obj-$(CONFIG_QUICC_ENGINE)+= qe.o qe_ic.o qe_io.o
5-
4+
obj-$(CONFIG_QUICC_ENGINE)+= qe.o qe_common.o qe_ic.o qe_io.o
5+
obj-$(CONFIG_CPM) += qe_common.o
66
obj-$(CONFIG_UCC) += ucc.o
77
obj-$(CONFIG_UCC_SLOW) += ucc_slow.o
88
obj-$(CONFIG_UCC_FAST) += ucc_fast.o

0 commit comments

Comments
 (0)