-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Benjamin Herrenschmidt
authored and
Paul Mackerras
committed
Dec 4, 2006
1 parent
19eb568
commit 2f21318
Showing
10 changed files
with
338 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
--- | ||
refs/heads/master: 69108cf00679716bcab58acb3135390654c5bb99 | ||
refs/heads/master: 4c75a6f441cdd1c69a6c173bc7944e12c2ba6f84 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* "Indirect" DCR access | ||
* | ||
* Copyright (c) 2004 Eugene Surovegin <ebs@ebshome.net> | ||
* | ||
* This program is free software; you can redistribute it and/or modify it | ||
* under the terms of the GNU General Public License as published by the | ||
* Free Software Foundation; either version 2 of the License, or (at your | ||
* option) any later version. | ||
*/ | ||
|
||
#include <asm/ppc_asm.h> | ||
#include <asm/processor.h> | ||
|
||
#define DCR_ACCESS_PROLOG(table) \ | ||
rlwinm r3,r3,4,18,27; \ | ||
lis r5,table@h; \ | ||
ori r5,r5,table@l; \ | ||
add r3,r3,r5; \ | ||
mtctr r3; \ | ||
bctr | ||
|
||
_GLOBAL(__mfdcr) | ||
DCR_ACCESS_PROLOG(__mfdcr_table) | ||
|
||
_GLOBAL(__mtdcr) | ||
DCR_ACCESS_PROLOG(__mtdcr_table) | ||
|
||
__mfdcr_table: | ||
mfdcr r3,0; blr | ||
__mtdcr_table: | ||
mtdcr 0,r4; blr | ||
|
||
dcr = 1 | ||
.rept 1023 | ||
mfdcr r3,dcr; blr | ||
mtdcr dcr,r4; blr | ||
dcr = dcr + 1 | ||
.endr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
/* | ||
* (c) Copyright 2006 Benjamin Herrenschmidt, IBM Corp. | ||
* <benh@kernel.crashing.org> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
* the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
#undef DEBUG | ||
|
||
#include <linux/kernel.h> | ||
#include <asm/prom.h> | ||
#include <asm/dcr.h> | ||
|
||
unsigned int dcr_resource_start(struct device_node *np, unsigned int index) | ||
{ | ||
unsigned int ds; | ||
const u32 *dr = get_property(np, "dcr-reg", &ds); | ||
|
||
if (dr == NULL || ds & 1 || index >= (ds / 8)) | ||
return 0; | ||
|
||
return dr[index * 2]; | ||
} | ||
|
||
unsigned int dcr_resource_len(struct device_node *np, unsigned int index) | ||
{ | ||
unsigned int ds; | ||
const u32 *dr = get_property(np, "dcr-reg", &ds); | ||
|
||
if (dr == NULL || ds & 1 || index >= (ds / 8)) | ||
return 0; | ||
|
||
return dr[index * 2 + 1]; | ||
} | ||
|
||
#ifndef CONFIG_PPC_DCR_NATIVE | ||
|
||
static struct device_node * find_dcr_parent(struct device_node * node) | ||
{ | ||
struct device_node *par, *tmp; | ||
const u32 *p; | ||
|
||
for (par = of_node_get(node); par;) { | ||
if (get_property(par, "dcr-controller", NULL)) | ||
break; | ||
p = get_property(par, "dcr-parent", NULL); | ||
tmp = par; | ||
if (p == NULL) | ||
par = of_get_parent(par); | ||
else | ||
par = of_find_node_by_phandle(*p); | ||
of_node_put(tmp); | ||
} | ||
return par; | ||
} | ||
|
||
u64 of_translate_dcr_address(struct device_node *dev, | ||
unsigned int dcr_n, | ||
unsigned int *out_stride) | ||
{ | ||
struct device_node *dp; | ||
const u32 *p; | ||
unsigned int stride; | ||
u64 ret; | ||
|
||
dp = find_dcr_parent(dev); | ||
if (dp == NULL) | ||
return OF_BAD_ADDR; | ||
|
||
/* Stride is not properly defined yet, default to 0x10 for Axon */ | ||
p = get_property(dp, "dcr-mmio-stride", NULL); | ||
stride = (p == NULL) ? 0x10 : *p; | ||
|
||
/* XXX FIXME: Which property name is to use of the 2 following ? */ | ||
p = get_property(dp, "dcr-mmio-range", NULL); | ||
if (p == NULL) | ||
p = get_property(dp, "dcr-mmio-space", NULL); | ||
if (p == NULL) | ||
return OF_BAD_ADDR; | ||
|
||
/* Maybe could do some better range checking here */ | ||
ret = of_translate_address(dp, p); | ||
if (ret != OF_BAD_ADDR) | ||
ret += (u64)(stride) * (u64)dcr_n; | ||
if (out_stride) | ||
*out_stride = stride; | ||
return ret; | ||
} | ||
|
||
dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n, | ||
unsigned int dcr_c) | ||
{ | ||
dcr_host_t ret = { .token = NULL, .stride = 0 }; | ||
u64 addr; | ||
|
||
pr_debug("dcr_map(%s, 0x%x, 0x%x)\n", | ||
dev->full_name, dcr_n, dcr_c); | ||
|
||
addr = of_translate_dcr_address(dev, dcr_n, &ret.stride); | ||
pr_debug("translates to addr: 0x%lx, stride: 0x%x\n", | ||
addr, ret.stride); | ||
if (addr == OF_BAD_ADDR) | ||
return ret; | ||
pr_debug("mapping 0x%x bytes\n", dcr_c * ret.stride); | ||
ret.token = ioremap(addr, dcr_c * ret.stride); | ||
if (ret.token == NULL) | ||
return ret; | ||
pr_debug("mapped at 0x%p -> base is 0x%p\n", | ||
ret.token, ret.token - dcr_n * ret.stride); | ||
ret.token -= dcr_n * ret.stride; | ||
return ret; | ||
} | ||
|
||
void dcr_unmap(dcr_host_t host, unsigned int dcr_n, unsigned int dcr_c) | ||
{ | ||
dcr_host_t h = host; | ||
|
||
if (h.token == NULL) | ||
return; | ||
h.token -= dcr_n * h.stride; | ||
iounmap(h.token); | ||
h.token = NULL; | ||
} | ||
|
||
#endif /* !defined(CONFIG_PPC_DCR_NATIVE) */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* (c) Copyright 2006 Benjamin Herrenschmidt, IBM Corp. | ||
* <benh@kernel.crashing.org> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
* the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
#ifndef _ASM_POWERPC_DCR_MMIO_H | ||
#define _ASM_POWERPC_DCR_MMIO_H | ||
#ifdef __KERNEL__ | ||
|
||
#include <asm/io.h> | ||
|
||
typedef struct { void __iomem *token; unsigned int stride; } dcr_host_t; | ||
|
||
#define DCR_MAP_OK(host) ((host).token != NULL) | ||
|
||
extern dcr_host_t dcr_map(struct device_node *dev, unsigned int dcr_n, | ||
unsigned int dcr_c); | ||
extern void dcr_unmap(dcr_host_t host, unsigned int dcr_n, unsigned int dcr_c); | ||
|
||
static inline u32 dcr_read(dcr_host_t host, unsigned int dcr_n) | ||
{ | ||
return in_be32(host.token + dcr_n * host.stride); | ||
} | ||
|
||
static inline void dcr_write(dcr_host_t host, unsigned int dcr_n, u32 value) | ||
{ | ||
out_be32(host.token + dcr_n * host.stride, value); | ||
} | ||
|
||
extern u64 of_translate_dcr_address(struct device_node *dev, | ||
unsigned int dcr_n, | ||
unsigned int *stride); | ||
|
||
#endif /* __KERNEL__ */ | ||
#endif /* _ASM_POWERPC_DCR_MMIO_H */ | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* (c) Copyright 2006 Benjamin Herrenschmidt, IBM Corp. | ||
* <benh@kernel.crashing.org> | ||
* | ||
* This program is free software; you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation; either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See | ||
* the GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
*/ | ||
|
||
#ifndef _ASM_POWERPC_DCR_NATIVE_H | ||
#define _ASM_POWERPC_DCR_NATIVE_H | ||
#ifdef __KERNEL__ | ||
|
||
#include <asm/reg.h> | ||
|
||
typedef struct {} dcr_host_t; | ||
|
||
#define DCR_MAP_OK(host) (1) | ||
|
||
#define dcr_map(dev, dcr_n, dcr_c) {} | ||
#define dcr_unmap(host, dcr_n, dcr_c) {} | ||
#define dcr_read(host, dcr_n) mfdcr(dcr_n) | ||
#define dcr_write(host, dcr_n, value) mtdcr(dcr_n, value) | ||
|
||
|
||
#endif /* __KERNEL__ */ | ||
#endif /* _ASM_POWERPC_DCR_NATIVE_H */ | ||
|
||
|
Oops, something went wrong.