LinuxPPC-Dev Archive on lore.kernel.org
 help / color / mirror / Atom feed
* RE: MPC8260ADS and linux-2.6
From: Rune Torgersen @ 2008-01-03 18:18 UTC (permalink / raw)
  To: Scott Wood, suja Baburaj; +Cc: linuxppc-embedded
In-Reply-To: <477D2255.3040803@freescale.com>

> From: Scott Wood
> Sent: Thursday, January 03, 2008 11:59 AM
> To: suja Baburaj
> Cc: linuxppc-embedded@ozlabs.org
> Subject: Re: MPC8260ADS and linux-2.6
>=20
> suja Baburaj wrote:
> > I have an MPC8260ADS board with (eldk)linux-2.4.25 working=20
> fine on it.
> > Now i want to try linux-2.6.X on the board.
>=20
> There's no support for that specific board in mainstream 2.6=20
> yet, but it=20
> should be fairly simple to get it working using the=20
> mpc8272ads support=20
> as an example.

There is support, but it is in arch/ppc not arch/powerpc
(PQ2FADS support works for this board in arch/ppc)

^ permalink raw reply

* Re: [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Timur Tabi @ 2008-01-03 18:20 UTC (permalink / raw)
  To: Grant Likely; +Cc: Liam Girdwood, alsa-devel, linuxppc-dev
In-Reply-To: <fa686aa40801031013w54b15286u8e6e2561219422f2@mail.gmail.com>

Grant Likely wrote:

> The device tree is a description of the hardware; not software.  It's
> not a good idea to break with convention due to current driver
> architecture.

I believe that with ASoC V1, I'm stuck between a rock and a hard place, and so 
the only way to make this code work is to bend some rules.  Right now, the 
CS4270 driver does not support platform drivers or the device tree, so there's 
no point in putting a child I2C node for it.  As I mentioned in other posts, I 
will be more than happy to update the CS4270 driver to support this new 
paradigm (which was invented after the CS4270 driver was written) *after* this 
current patchset is applied.


-- 
Timur Tabi
Linux Kernel Developer @ Freescale

^ permalink raw reply

* Re: [alsa-devel] [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Timur Tabi @ 2008-01-03 18:23 UTC (permalink / raw)
  To: Timur Tabi, Jon Smirl, linuxppc-dev, alsa-devel
In-Reply-To: <20080102172340.GA2007@sirena.org.uk>

Mark Brown wrote:

>> clock1 = <0, bb8000>
> 
>> Would that be better?
> 
> To cover everything you'd need to be able to specify all the clocking
> parameters, especially a PLL configuration, and also specify more than
> one of each item.  Even then you'd still have problems like...

The ASoC V1 API for communicating clock data from the fabric driver to the 
codec driver only allows for three parameters.

> According to the documentation in your patch the bus frequency should
> already be optional 

My code does not currently support that configuration, and I don't have any 
hardware that works that way, so I don't know what it would look like.  I'm 
just trying to make the driver as flexible as possible, given ASoC V1 constraints.

-- 
Timur Tabi
Linux Kernel Developer @ Freescale

^ permalink raw reply

* Re: [PATCH v2] ucc_uart: add support for Freescale QUICCEngine UART
From: Timur Tabi @ 2008-01-03 18:26 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev
In-Reply-To: <20080102181226.GA4486@loki.buserror.net>

Scott Wood wrote:

>>>> +static struct of_platform_driver ucc_uart_of_driver = {
>>>> +	.owner  	= THIS_MODULE,
>>>> +	.name   	= "ucc_uart",
>>> Maybe better fsl,ucc_uart?
> 
> fsl,qe-uart is defined by Documentation/powerpc/booting-without-of.txt.

Wait, I'm confused.  What does the of_platform_driver.name string have to do 
with the compatible field in the device tree?  Like I said earlier, I'm just 
following the example of the other QE device drivers.  If you want me to break 
that example, I'm going to need an explanation why the other drivers do it wrong.


-- 
Timur Tabi
Linux Kernel Developer @ Freescale

^ permalink raw reply

* Re: [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Grant Likely @ 2008-01-03 18:25 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linuxppc-dev, alsa-devel
In-Reply-To: <477D25F4.6020700@freescale.com>

On 1/3/08, Timur Tabi <timur@freescale.com> wrote:
> Grant Likely wrote:
>
> > Does that mean with ASoC V2 you can instantiate it with the board
> > specific platform code instead?
>
> I don't know.  I haven't really looked at V2 yet.  You'll have to ask Liam
> Girdwood.
>
> > This is one of the examples of where the compatible properties are
> > trying to be far to generic about what they are.  How do you define
> > what "fsl,ssi" is?
>
> The SSI is a specific Freescale device, so I think it's pretty well defined.
>
> > What happens when Freescale produces another
> > peripheral that can do ssi but isn't register level compatible?
>
> It won't be called the SSI.  It will be called something else.

Heh, I've seen enough to know that it's virtually impossible for a
company to maintain a consistent naming scheme all the time.  Better
to be specific now and add generic names sometime in the future rather
than the other way around.

> > In my opinion, it is far better to be specific in the device tree and
> > teach the driver about what versions it is able to bind against.  In
> > this case, I would use "fsl,mpc8610-ssi" or maybe better yet:
> > "fsl,mpc8610-ssi,i2s" (MPC8610 SSI device in I2S mode).
>
> I can work with that, but the SSI could be placed into any future 83xx, 85xx,
> or 86xx SOC, and the driver will still work with it as-is.

The have the device trees claim compatibility with the older
fsl,mpc8610-ssi device specifically.  ie: compatible =
"fsl,mpc83<whatever>-ssi,ac97", "fsl,mpc8610-ssi,ac97";

>
> > I don't like the idea of a separate fsl,mode property to describe the
> > behaviour of multifunction peripherals.  It makes probing more
> > difficult when there is a different driver for each mode.
>
> Can you propose an alternative?  The driver needs to know what mode to use
> when communicating with its codec.  How am I supposed to know if I have an I2S
> codec or an AC97 codec?

Make the compatible property tell you!  :-)  If it's connected to an
I2S codec, then it could be compatible = "fsl,mpc8610-ssi,i2s".  Or
for AC7, compatible = "fsl,mpc8610-ssi,ac97"

Cheers,
g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely@secretlab.ca
(403) 399-0195

^ permalink raw reply

* Re: [PATCH v2] ucc_uart: add support for Freescale QUICCEngine UART
From: Scott Wood @ 2008-01-03 18:26 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linuxppc-dev
In-Reply-To: <477D28D3.3000102@freescale.com>

Timur Tabi wrote:
> Scott Wood wrote:
> 
>>>>> +static struct of_platform_driver ucc_uart_of_driver = {
>>>>> +    .owner      = THIS_MODULE,
>>>>> +    .name       = "ucc_uart",
>>>> Maybe better fsl,ucc_uart?
>>
>> fsl,qe-uart is defined by Documentation/powerpc/booting-without-of.txt.
> 
> Wait, I'm confused.  What does the of_platform_driver.name string have 
> to do with the compatible field in the device tree?

Bah.  Details.

/me resolves to read the context next time.

-Scott

^ permalink raw reply

* Re: [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Timur Tabi @ 2008-01-03 18:28 UTC (permalink / raw)
  To: Grant Likely; +Cc: linuxppc-dev, alsa-devel
In-Reply-To: <fa686aa40801031025r10c31ce6x203755fe532f0c88@mail.gmail.com>

Grant Likely wrote:

> Make the compatible property tell you!  :-)  If it's connected to an
> I2S codec, then it could be compatible = "fsl,mpc8610-ssi,i2s".  Or
> for AC7, compatible = "fsl,mpc8610-ssi,ac97"

That won't work.  There are too many variations.  I think a separate property 
just makes more sense.  Frankly, I don't see what's wrong with it.



-- 
Timur Tabi
Linux Kernel Developer @ Freescale

^ permalink raw reply

* Re: [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Grant Likely @ 2008-01-03 18:32 UTC (permalink / raw)
  To: Timur Tabi; +Cc: Liam Girdwood, alsa-devel, linuxppc-dev
In-Reply-To: <477D276B.2060300@freescale.com>

On 1/3/08, Timur Tabi <timur@freescale.com> wrote:
> Grant Likely wrote:
>
> > The device tree is a description of the hardware; not software.  It's
> > not a good idea to break with convention due to current driver
> > architecture.
>
> I believe that with ASoC V1, I'm stuck between a rock and a hard place, and so
> the only way to make this code work is to bend some rules.  Right now, the
> CS4270 driver does not support platform drivers or the device tree, so there's
> no point in putting a child I2C node for it.  As I mentioned in other posts, I
> will be more than happy to update the CS4270 driver to support this new
> paradigm (which was invented after the CS4270 driver was written) *after* this
> current patchset is applied.

If you need to bend rules, then do it in a place where it won't bite
us in the butt down the road.  (ie. not with the device tree).  Do
hacky stuff in the platform code if you need to because it can be
changed easily down the road.

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely@secretlab.ca
(403) 399-0195

^ permalink raw reply

* Re: [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Grant Likely @ 2008-01-03 18:38 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linuxppc-dev, alsa-devel
In-Reply-To: <477D296A.6040202@freescale.com>

On 1/3/08, Timur Tabi <timur@freescale.com> wrote:
> Grant Likely wrote:
>
> > Make the compatible property tell you!  :-)  If it's connected to an
> > I2S codec, then it could be compatible = "fsl,mpc8610-ssi,i2s".  Or
> > for AC7, compatible = "fsl,mpc8610-ssi,ac97"
>
> That won't work.  There are too many variations.  I think a separate property
> just makes more sense.  Frankly, I don't see what's wrong with it.

Sure it will, that's exactly what I'm doing with the 5200, but I won't
argue the point.  My *opinion* is that using compatible is a more
elegant approach for this type of multifunction device, but using a
mode property is neither wrong or bad.

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely@secretlab.ca
(403) 399-0195

^ permalink raw reply

* Re: [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Scott Wood @ 2008-01-03 18:54 UTC (permalink / raw)
  To: Grant Likely; +Cc: linuxppc-dev, alsa-devel, Timur Tabi
In-Reply-To: <fa686aa40801031017n42f6fbf1nb2da5097ef13cf3c@mail.gmail.com>

Grant Likely wrote:
> On 1/3/08, Timur Tabi <timur@freescale.com> wrote:
>> Grant Likely wrote:
>>
>>> Why not be a child of the i2c bus with a phandle to the ssi bus?
>> Because when I probe the SSI node, I want to know what the attached codec is.
>>   So if anything, I would need a pointer from the SSI bus *to* the respective
>> child on the I2C bus.
> 
> That's fine too (it's what is done with Ethernet PHYs).  My preference
> is the other way around, but it's not a big issue in this case.

I'd just link in both directions, and let software follow it in 
whichever direction it prefers.

-Scott

^ permalink raw reply

* Re: Reading a config file in a driver ....
From: Carlos Munoz @ 2008-01-03 18:43 UTC (permalink / raw)
  To: Misbah khan; +Cc: linuxppc-embedded
In-Reply-To: <20080103163019.GA4223@lixom.net>

Olof Johansson wrote:
> On Wed, Jan 02, 2008 at 09:03:20PM -0800, Misbah khan wrote:
>   
>> Hi all ....
>>
>> I am writing a LCD driver in which the default configuration for LCD would
>> be loded at the Init . This default configuration if keep in the driver then
>> for a change in default configuration we need to compile the driver which we
>> never want . Hence we want a .config file in /etc/lcd.config dir which could
>> be changed and the next boot will take this configuration as the default
>> configuration. 
>>
>> I need to know How to read from the config file in the driver form the dir
>> /etc/lcd.config. The driver would be installed at boot up 
>>     
>
> The driver/kernel shouldn't read the file directly, if anything you
> should have a userspace tool that reads it and adjusts the driver via
> sysfs or similar. That tool can be run from some of the init scripts,
> or from the ramdisk in case you want to do it early.
>   
What I've done in the past is to use module_param() to define variables 
that get set when the module is loaded. Then all you need to do is edit 
the /etc/modules file and change the parameter value. However, this 
technique is only efficient if only a few parameters will ever change. 
If you need to change more than a few parameters, Olof's suggestion 
would be preferred.

Carlos

^ permalink raw reply

* Re: [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Grant Likely @ 2008-01-03 19:13 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev, alsa-devel, Timur Tabi
In-Reply-To: <477D2F52.7090306@freescale.com>

On 1/3/08, Scott Wood <scottwood@freescale.com> wrote:
> Grant Likely wrote:
> > On 1/3/08, Timur Tabi <timur@freescale.com> wrote:
> >> Grant Likely wrote:
> >>
> >>> Why not be a child of the i2c bus with a phandle to the ssi bus?
> >> Because when I probe the SSI node, I want to know what the attached codec is.
> >>   So if anything, I would need a pointer from the SSI bus *to* the respective
> >> child on the I2C bus.
> >
> > That's fine too (it's what is done with Ethernet PHYs).  My preference
> > is the other way around, but it's not a big issue in this case.
>
> I'd just link in both directions, and let software follow it in
> whichever direction it prefers.

Gah!  Don't do that!  Then you need to maintain both directions in the
dts file.  Software is good at generating reverse mappings.  Don't put
that burden on the dts author.  (the software principle of defining
things in one place only applies here)

g.

-- 
Grant Likely, B.Sc., P.Eng.
Secret Lab Technologies Ltd.
grant.likely@secretlab.ca
(403) 399-0195

^ permalink raw reply

* Re: [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Scott Wood @ 2008-01-03 19:18 UTC (permalink / raw)
  To: Grant Likely; +Cc: linuxppc-dev, alsa-devel, Timur Tabi
In-Reply-To: <fa686aa40801031113od68e2a3m6cb60b8fa6f26c17@mail.gmail.com>

Grant Likely wrote:
> On 1/3/08, Scott Wood <scottwood@freescale.com> wrote:
>> I'd just link in both directions, and let software follow it in
>> whichever direction it prefers.
> 
> Gah!  Don't do that!  Then you need to maintain both directions in the
> dts file.  Software is good at generating reverse mappings.

Software is, however, lousy at correctly wading through 
poorly-structured data (which device trees are full of) to figure out 
how to locate the link it wants to follow backwards.

-Scott

^ permalink raw reply

* Re: Drivers' probe function calling order
From: Alessandro Rubini @ 2008-01-03 21:54 UTC (permalink / raw)
  To: linuxppc-embedded
In-Reply-To: <F1F6EC0C8B75034F9E3A79FC85122E8EC2DE1E@aquib01a>


> how can I force the system to call
> probe function of the spi driver first?

You can declare their init functions at different initcall level.  For
example declaring the dataflash one as late_initcall(). Or declare
the spi one as subsys_initcall() -- whatever makes more sense.

There might be cleaner ways according to your setup, but this will
surely work.

/alessandro

^ permalink raw reply

* Re: [PATCH] IB/ehca: Forward event client-reregister-required to registered clients
From: Hoang-Nam Nguyen @ 2008-01-03 22:43 UTC (permalink / raw)
  To: Roland Dreier
  Cc: fenkes, linux-kernel, linuxppc-dev, Christoph Raisch, general,
	stefan.roscher
In-Reply-To: <200712201506.34253.hnguyen@linux.vnet.ibm.com>

Hi Roland,
Just want to make sure you've seen this patch and if it looks ok for you.
Thanks
Nam

On Thursday 20 December 2007 15:06, Hoang-Nam Nguyen wrote:
> This patch allows ehca to forward event client-reregister-required to
> registered clients. Such one event is generated by the switch eg. after
> its reboot.
> 
> Signed-off-by: Hoang-Nam Nguyen <hnguyen@de.ibm.com>
> ---
>  drivers/infiniband/hw/ehca/ehca_irq.c |   12 ++++++++++++
>  1 files changed, 12 insertions(+), 0 deletions(-)

^ permalink raw reply

* [PATCh v3] powerpc: add hugepagesz boot-time parameter
From: Jon Tollefson @ 2008-01-03 22:59 UTC (permalink / raw)
  To: Paul Mackerras; +Cc: arnd, mel, David Gibson, linuxppc-dev, csnook

Paul, please include this in 2.6.25 if there are no objections.

This patch adds the hugepagesz boot-time parameter for ppc64.  It lets
one pick the size for huge pages. The choices available are 64K and 16M
when the base page size is 4k. It defaults to 16M (previously the only
only choice) if nothing or an invalid choice is specified.

Tested 64K huge pages successfully with the libhugetlbfs 1.2.

Changes from v2:
	Moved functions from header file into hugetlbpage.c where they are used.


Signed-off-by: Jon Tollefson <kniht@linux.vnet.ibm.com>
---

diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
index 33121d6..2fc1fb8 100644
--- a/Documentation/kernel-parameters.txt
+++ b/Documentation/kernel-parameters.txt
@@ -685,6 +685,7 @@ and is between 256 and 4096 characters. It is defined in the file
 			See Documentation/isdn/README.HiSax.
 
 	hugepages=	[HW,X86-32,IA-64] Maximal number of HugeTLB pages.
+	hugepagesz=	[HW,IA-64,PPC] The size of the HugeTLB pages.
 
 	i8042.direct	[HW] Put keyboard port into non-translated mode
 	i8042.dumbkbd	[HW] Pretend that controller can only read data from
diff --git a/arch/powerpc/mm/hash_utils_64.c b/arch/powerpc/mm/hash_utils_64.c
index cbbd8b0..9326a69 100644
--- a/arch/powerpc/mm/hash_utils_64.c
+++ b/arch/powerpc/mm/hash_utils_64.c
@@ -369,18 +369,11 @@ static void __init htab_init_page_sizes(void)
 	 * on what is available
 	 */
 	if (mmu_psize_defs[MMU_PAGE_16M].shift)
-		mmu_huge_psize = MMU_PAGE_16M;
+		set_huge_psize(MMU_PAGE_16M);
 	/* With 4k/4level pagetables, we can't (for now) cope with a
 	 * huge page size < PMD_SIZE */
 	else if (mmu_psize_defs[MMU_PAGE_1M].shift)
-		mmu_huge_psize = MMU_PAGE_1M;
-
-	/* Calculate HPAGE_SHIFT and sanity check it */
-	if (mmu_psize_defs[mmu_huge_psize].shift > MIN_HUGEPTE_SHIFT &&
-	    mmu_psize_defs[mmu_huge_psize].shift < SID_SHIFT)
-		HPAGE_SHIFT = mmu_psize_defs[mmu_huge_psize].shift;
-	else
-		HPAGE_SHIFT = 0; /* No huge pages dude ! */
+		set_huge_psize(MMU_PAGE_1M);
 #endif /* CONFIG_HUGETLB_PAGE */
 }
 
diff --git a/arch/powerpc/mm/hugetlbpage.c b/arch/powerpc/mm/hugetlbpage.c
index 71efb38..a02266d 100644
--- a/arch/powerpc/mm/hugetlbpage.c
+++ b/arch/powerpc/mm/hugetlbpage.c
@@ -24,18 +24,17 @@
 #include <asm/cputable.h>
 #include <asm/spu.h>
 
+#define HPAGE_SHIFT_64K	16
+#define HPAGE_SHIFT_16M	24
+
 #define NUM_LOW_AREAS	(0x100000000UL >> SID_SHIFT)
 #define NUM_HIGH_AREAS	(PGTABLE_RANGE >> HTLB_AREA_SHIFT)
 
-#ifdef CONFIG_PPC_64K_PAGES
-#define HUGEPTE_INDEX_SIZE	(PMD_SHIFT-HPAGE_SHIFT)
-#else
-#define HUGEPTE_INDEX_SIZE	(PUD_SHIFT-HPAGE_SHIFT)
-#endif
-#define PTRS_PER_HUGEPTE	(1 << HUGEPTE_INDEX_SIZE)
-#define HUGEPTE_TABLE_SIZE	(sizeof(pte_t) << HUGEPTE_INDEX_SIZE)
+unsigned int hugepte_shift;
+#define PTRS_PER_HUGEPTE	(1 << hugepte_shift)
+#define HUGEPTE_TABLE_SIZE	(sizeof(pte_t) << hugepte_shift)
 
-#define HUGEPD_SHIFT		(HPAGE_SHIFT + HUGEPTE_INDEX_SIZE)
+#define HUGEPD_SHIFT		(HPAGE_SHIFT + hugepte_shift)
 #define HUGEPD_SIZE		(1UL << HUGEPD_SHIFT)
 #define HUGEPD_MASK		(~(HUGEPD_SIZE-1))
 
@@ -82,11 +81,35 @@ static int __hugepte_alloc(struct mm_struct *mm, hugepd_t *hpdp,
 	return 0;
 }
 
+/* Base page size affects how we walk hugetlb page tables */
+#ifdef CONFIG_PPC_64K_PAGES
+#define hpmd_offset(pud, addr)		pmd_offset(pud, addr)
+#define hpmd_alloc(mm, pud, addr)	pmd_alloc(mm, pud, addr)
+#else
+static inline
+pmd_t *hpmd_offset(pud_t *pud, unsigned long addr)
+{
+	if (HPAGE_SHIFT == HPAGE_SHIFT_64K)
+		return pmd_offset(pud, addr);
+	else
+		return (pmd_t *) pud;
+}
+static inline
+pmd_t *hpmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long addr)
+{
+	if (HPAGE_SHIFT == HPAGE_SHIFT_64K)
+		return pmd_alloc(mm, pud, addr);
+	else
+		return (pmd_t *) pud;
+}
+#endif
+
 /* Modelled after find_linux_pte() */
 pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
 {
 	pgd_t *pg;
 	pud_t *pu;
+	pmd_t *pm;
 
 	BUG_ON(get_slice_psize(mm, addr) != mmu_huge_psize);
 
@@ -96,14 +119,9 @@ pte_t *huge_pte_offset(struct mm_struct *mm, unsigned long addr)
 	if (!pgd_none(*pg)) {
 		pu = pud_offset(pg, addr);
 		if (!pud_none(*pu)) {
-#ifdef CONFIG_PPC_64K_PAGES
-			pmd_t *pm;
-			pm = pmd_offset(pu, addr);
+			pm = hpmd_offset(pu, addr);
 			if (!pmd_none(*pm))
 				return hugepte_offset((hugepd_t *)pm, addr);
-#else
-			return hugepte_offset((hugepd_t *)pu, addr);
-#endif
 		}
 	}
 
@@ -114,6 +132,7 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr)
 {
 	pgd_t *pg;
 	pud_t *pu;
+	pmd_t *pm;
 	hugepd_t *hpdp = NULL;
 
 	BUG_ON(get_slice_psize(mm, addr) != mmu_huge_psize);
@@ -124,14 +143,9 @@ pte_t *huge_pte_alloc(struct mm_struct *mm, unsigned long addr)
 	pu = pud_alloc(mm, pg, addr);
 
 	if (pu) {
-#ifdef CONFIG_PPC_64K_PAGES
-		pmd_t *pm;
-		pm = pmd_alloc(mm, pu, addr);
+		pm = hpmd_alloc(mm, pu, addr);
 		if (pm)
 			hpdp = (hugepd_t *)pm;
-#else
-		hpdp = (hugepd_t *)pu;
-#endif
 	}
 
 	if (! hpdp)
@@ -158,7 +172,6 @@ static void free_hugepte_range(struct mmu_gather *tlb, hugepd_t *hpdp)
 						 PGF_CACHENUM_MASK));
 }
 
-#ifdef CONFIG_PPC_64K_PAGES
 static void hugetlb_free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
 				   unsigned long addr, unsigned long end,
 				   unsigned long floor, unsigned long ceiling)
@@ -191,7 +204,6 @@ static void hugetlb_free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
 	pud_clear(pud);
 	pmd_free_tlb(tlb, pmd);
 }
-#endif
 
 static void hugetlb_free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
 				   unsigned long addr, unsigned long end,
@@ -210,9 +222,15 @@ static void hugetlb_free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
 			continue;
 		hugetlb_free_pmd_range(tlb, pud, addr, next, floor, ceiling);
 #else
-		if (pud_none(*pud))
-			continue;
-		free_hugepte_range(tlb, (hugepd_t *)pud);
+		if (HPAGE_SHIFT == HPAGE_SHIFT_64K) {
+			if (pud_none_or_clear_bad(pud))
+				continue;
+			hugetlb_free_pmd_range(tlb, pud, addr, next, floor, ceiling);
+		} else {
+			if (pud_none(*pud))
+				continue;
+			free_hugepte_range(tlb, (hugepd_t *)pud);
+		}
 #endif
 	} while (pud++, addr = next, addr != end);
 
@@ -526,6 +544,57 @@ repeat:
 	return err;
 }
 
+void set_huge_psize(int psize)
+{
+	/* Check that it is a page size supported by the hardware and
+	 * that it fits within pagetable limits. */
+	if (mmu_psize_defs[psize].shift && mmu_psize_defs[psize].shift < SID_SHIFT &&
+		(mmu_psize_defs[psize].shift > MIN_HUGEPTE_SHIFT ||
+			mmu_psize_defs[psize].shift == HPAGE_SHIFT_64K)) {
+		HPAGE_SHIFT = mmu_psize_defs[psize].shift;
+		mmu_huge_psize = psize;
+#ifdef CONFIG_PPC_64K_PAGES
+		hugepte_shift = (PMD_SHIFT-HPAGE_SHIFT);
+#else
+		if (HPAGE_SHIFT == HPAGE_SHIFT_64K)
+			hugepte_shift = (PMD_SHIFT-HPAGE_SHIFT);
+		else
+			hugepte_shift = (PUD_SHIFT-HPAGE_SHIFT);
+#endif
+
+	} else
+		HPAGE_SHIFT = 0;
+}
+
+static int __init hugepage_setup_sz(char *str)
+{
+	unsigned long long size;
+	int mmu_psize = -1;
+	int shift;
+
+	size = memparse(str, &str);
+
+	shift = __ffs(size);
+	switch (shift) {
+#ifndef CONFIG_PPC_64K_PAGES
+	case HPAGE_SHIFT_64K:
+		mmu_psize = MMU_PAGE_64K;
+		break;
+#endif
+	case HPAGE_SHIFT_16M:
+		mmu_psize = MMU_PAGE_16M;
+		break;
+	}
+
+	if (mmu_psize >=0 && mmu_psize_defs[mmu_psize].shift)
+		set_huge_psize(mmu_psize);
+	else
+		printk(KERN_WARNING "Invalid huge page size specified(%llu)\n", size);
+
+	return 1;
+}
+__setup("hugepagesz=", hugepage_setup_sz);
+
 static void zero_ctor(struct kmem_cache *cache, void *addr)
 {
 	memset(addr, 0, kmem_cache_size(cache));
diff --git a/include/asm-powerpc/mmu-hash64.h b/include/asm-powerpc/mmu-hash64.h
index 12e5e77..2fda33c 100644
--- a/include/asm-powerpc/mmu-hash64.h
+++ b/include/asm-powerpc/mmu-hash64.h
@@ -278,6 +278,7 @@ extern int hash_huge_page(struct mm_struct *mm, unsigned long access,
 extern int htab_bolt_mapping(unsigned long vstart, unsigned long vend,
 			     unsigned long pstart, unsigned long mode,
 			     int psize, int ssize);
+extern void set_huge_psize(int psize);
 
 extern void htab_initialize(void);
 extern void htab_initialize_secondary(void);

^ permalink raw reply related

* Re: [alsa-devel] [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Mark Brown @ 2008-01-03 23:00 UTC (permalink / raw)
  To: Timur Tabi; +Cc: linuxppc-dev, alsa-devel
In-Reply-To: <477D280C.4000800@freescale.com>

On Thu, Jan 03, 2008 at 12:23:08PM -0600, Timur Tabi wrote:
> Mark Brown wrote:

> > To cover everything you'd need to be able to specify all the clocking
> > parameters, especially a PLL configuration, and also specify more than
> > one of each item.  Even then you'd still have problems like...

> The ASoC V1 API for communicating clock data from the fabric driver to the 
> codec driver only allows for three parameters.

Each individual call to set_sysclk() only takes three parameters but it
can be called repeatedly and some configurations are going to require
this.  There's also the set_pll() call which will be required by some
things too (and again that can support multiple PLLs).  

For example, something like this isn't unknown:

 - Set PLL input to pin A.
 - Configure PLL input/output frequencies.
 - Set codec system clock source to be the PLL

and of course the ordering matters.  You can also have other dividers
and clock sources within the codec which need configuring and other
components outside the codec which need configuring to supply the clocks
to the codec.

> > According to the documentation in your patch the bus frequency should
> > already be optional 

> My code does not currently support that configuration, and I don't have any 
> hardware that works that way, so I don't know what it would look like.  I'm 
> just trying to make the driver as flexible as possible, given ASoC V1 constraints.

Indeed.  Providing the device tree stuff doesn't get set in stone I'm
not sure we need to nail this down perfectly for ASoC v1 when we're
running into trouble working around it.

^ permalink raw reply

* Re: [alsa-devel] [PATCH] ASoC drivers for the Freescale MPC8610 SoC
From: Mark Brown @ 2008-01-03 23:13 UTC (permalink / raw)
  To: Scott Wood; +Cc: linuxppc-dev, alsa-devel, Timur Tabi
In-Reply-To: <477D3507.5090906@freescale.com>

On Thu, Jan 03, 2008 at 01:18:31PM -0600, Scott Wood wrote:
> Grant Likely wrote:

> > Gah!  Don't do that!  Then you need to maintain both directions in the
> > dts file.  Software is good at generating reverse mappings.

> Software is, however, lousy at correctly wading through 
> poorly-structured data (which device trees are full of) to figure out 
> how to locate the link it wants to follow backwards.

Thinking about that from an ASoC v2 perspective the approach that this
immediately suggests is to represent the links between the devices in
the device tree and then have those links reference the attached
devices.

^ permalink raw reply

* Re: [DTC] small ftdump cleanup patch
From: David Gibson @ 2008-01-03 23:25 UTC (permalink / raw)
  To: Paul Gortmaker; +Cc: linuxppc-dev, jdl
In-Reply-To: <20080103144056.GB28644@windriver.com>

On Thu, Jan 03, 2008 at 09:40:57AM -0500, Paul Gortmaker wrote:
> Here is a small patch to clean up the usage info and the error returns
> for ftdump -- not sure what the future holds for ftdump vs. simply using
> "dtc -I dtb -O dts someblob.dtb" ...

I expect ftdump to stay around for the forseeable future as a
hacking/debugging tool; the idea is that it will be able to tell you
at least something about a malformed or corrupted dtb, whereas dtc is
likely to choke before producing any output.  Any non-debugging use is
likely a mistake, though.

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

^ permalink raw reply

* Re: [PATCh v3] powerpc: add hugepagesz boot-time parameter
From: Arnd Bergmann @ 2008-01-03 23:34 UTC (permalink / raw)
  To: linuxppc-dev; +Cc: mel, Jon Tollefson, csnook, Paul Mackerras, David Gibson
In-Reply-To: <477D68E6.2070108@linux.vnet.ibm.com>

On Thursday 03 January 2008, Jon Tollefson wrote:
> Paul, please include this in 2.6.25 if there are no objections.

No objections to this version from me, just questions.

> This patch adds the hugepagesz boot-time parameter for ppc64. =A0It lets
> one pick the size for huge pages. The choices available are 64K and 16M
> when the base page size is 4k. It defaults to 16M (previously the only
> only choice) if nothing or an invalid choice is specified.

We started discussing this in v1, but the discussion got sidetracked:
Is there a technical reason why you don't also allow 1M pages, which
may be useful in certain scenarios?

On the Cell/B.E. platforms (IBM/Mercury blades, Toshiba Celleb, PS3), the
second large page size is an option that can be set in a HID SPR
to either 64KB or 1MB. Unfortunately, we can't do these two simultaneously,
but the firmware can change the default and put it into the device tree,
or you could have the kernel override the firmware settings.

Going a lot further, do you have plans for a fully dynamic hugepage size,
e.g. using a mount option for hugetlbfs? I can see that as rather useful,
but at the same time it's probably much more complicated than the boot time
option.

	Arnd <><

^ permalink raw reply

* Re: [PATCHv3] powerpc: DBox2 Board Support
From: David Gibson @ 2008-01-03 23:35 UTC (permalink / raw)
  To: Jochen Friedrich
  Cc: Scott Wood, linuxppc-dev, linux-kernel,
	linuxppc-embedded@ozlabs.org
In-Reply-To: <477CCB0F.8020504@scram.de>

On Thu, Jan 03, 2008 at 12:46:23PM +0100, Jochen Friedrich wrote:
> Hi David,
> 
> >> +/ {
> >> +	model = "unknown,dbox2"; // boot wrapper fills in correct manufacturer
> > 
> > Probably better just to leave model out of the dts and let the
> > bootwrapper add it.
> 
> Unfortunately, dtc requires a model:
> 
> $ dtc arch/powerpc/boot/dts/dbox2.dts
> DTC: dts->dts  on file "arch/powerpc/boot/dts/dbox2.dts"
> ERROR: Missing "model" property in /

Ah.  That should be gone in newer dtc versions.  I'm pretty sure I got
rid of all checks that enforced the presence of particular properties,
precisely because they give frequent spurious errors when things are
supposed to be filled in by the bootloader.

[snip]
> >> +				label = "Flash without bootloader";
> >> +				reg = <20000 7e0000>;
> >> +			};
> >> +			ovpartition@0 {
> >> +				label = "Complete Flash";
> >> +				reg = <0 800000>;
> >> +				read-only;
> >> +			};
> >> +		};
> >> +	};
> 
> MTD handles this correctly. dbox2 uses "Flash without bootloader"
> for flashing image updates and "Complete Flash" for creating a
> backup of everything.  OpenWRT also uses overlapping partitions BTW
> (and also for flashing updates).

Heh.  Wow.  Safely?  i.e. if you access one partition then later an
overlapping partition, is mtd guaranteed to get the necessary
synchronization right?

-- 
David Gibson			| I'll have my music baroque, and my code
david AT gibson.dropbear.id.au	| minimalist, thank you.  NOT _the_ _other_
				| _way_ _around_!
http://www.ozlabs.org/~dgibson

^ permalink raw reply

* [PATCH 1/3] Add yyerrorf() for formatted error messages.
From: Scott Wood @ 2008-01-03 23:43 UTC (permalink / raw)
  To: jdl; +Cc: linuxppc-dev

Signed-off-by: Scott Wood <scottwood@freescale.com>
---
 dtc-parser.y |   16 +++++++++++++---
 srcpos.h     |    1 +
 treesource.c |    1 -
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/dtc-parser.y b/dtc-parser.y
index 002ea7f..ddb7f27 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -307,15 +307,25 @@ label:
 
 %%
 
-void yyerror (char const *s)
+void yyerrorf(char const *s, ...)
 {
 	const char *fname = srcpos_filename_for_num(yylloc.filenum);
+	va_list va;
+	va_start(va, s);
 
 	if (strcmp(fname, "-") == 0)
 		fname = "stdin";
 
-	fprintf(stderr, "%s:%d %s\n",
-		fname, yylloc.first_line, s);
+	fprintf(stderr, "%s:%d ", fname, yylloc.first_line);
+	vfprintf(stderr, s, va);
+	fprintf(stderr, "\n");
+
+	va_end(va);
+}
+
+void yyerror (char const *s)
+{
+	yyerrorf("%s", s);
 }
 
 unsigned long long eval_literal(const char *s, int base, int bits)
diff --git a/srcpos.h b/srcpos.h
index ce7ab5b..e59c788 100644
--- a/srcpos.h
+++ b/srcpos.h
@@ -63,6 +63,7 @@ typedef struct YYLTYPE {
 
 
 extern void yyerror(char const *);
+extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2)));
 
 extern int srcpos_filenum;
 
diff --git a/treesource.c b/treesource.c
index a6a7767..e7d580f 100644
--- a/treesource.c
+++ b/treesource.c
@@ -23,7 +23,6 @@
 
 extern FILE *yyin;
 extern int yyparse(void);
-extern void yyerror(char const *);
 
 struct boot_info *the_boot_info;
 
-- 
1.5.3

^ permalink raw reply related

* [PATCH 3/3] Return a non-zero exit code if an error occurs during dts parsing.
From: Scott Wood @ 2008-01-03 23:43 UTC (permalink / raw)
  To: jdl; +Cc: linuxppc-dev

Previously, only failure to parse caused the reading of the tree to fail;
semantic errors that called yyerror() but not YYERROR only emitted a message,
without signalling make to stop the build.

Signed-off-by: Scott Wood <scottwood@freescale.com>
---
 dtc-parser.y |    2 ++
 dtc.c        |    2 +-
 dtc.h        |    1 +
 livetree.c   |    1 +
 treesource.c |    3 +++
 5 files changed, 8 insertions(+), 1 deletions(-)

diff --git a/dtc-parser.y b/dtc-parser.y
index 8ed58e8..da7f6f5 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -28,6 +28,7 @@ int yylex(void);
 unsigned long long eval_literal(const char *s, int base, int bits);
 
 extern struct boot_info *the_boot_info;
+extern int treesource_error;
 
 %}
 
@@ -320,6 +321,7 @@ void yyerrorf(char const *s, ...)
 	vfprintf(stderr, s, va);
 	fprintf(stderr, "\n");
 
+	treesource_error = 1;
 	va_end(va);
 }
 
diff --git a/dtc.c b/dtc.c
index fb716f3..c1814c1 100644
--- a/dtc.c
+++ b/dtc.c
@@ -205,7 +205,7 @@ int main(int argc, char *argv[])
 	if (inf && inf->file != stdin)
 		fclose(inf->file);
 
-	if (! bi || ! bi->dt)
+	if (! bi || ! bi->dt || bi->error)
 		die("Couldn't read input tree\n");
 
 	process_checks(force, bi);
diff --git a/dtc.h b/dtc.h
index 9b89689..cba9d28 100644
--- a/dtc.h
+++ b/dtc.h
@@ -233,6 +233,7 @@ struct reserve_info *add_reserve_entry(struct reserve_info *list,
 struct boot_info {
 	struct reserve_info *reservelist;
 	struct node *dt;		/* the device tree */
+	int error;
 };
 
 struct boot_info *build_boot_info(struct reserve_info *reservelist,
diff --git a/livetree.c b/livetree.c
index 6ba0846..7610e78 100644
--- a/livetree.c
+++ b/livetree.c
@@ -172,6 +172,7 @@ struct boot_info *build_boot_info(struct reserve_info *reservelist,
 	bi = xmalloc(sizeof(*bi));
 	bi->reservelist = reservelist;
 	bi->dt = tree;
+	bi->error = 0;
 
 	return bi;
 }
diff --git a/treesource.c b/treesource.c
index e7d580f..980bda7 100644
--- a/treesource.c
+++ b/treesource.c
@@ -25,10 +25,12 @@ extern FILE *yyin;
 extern int yyparse(void);
 
 struct boot_info *the_boot_info;
+int treesource_error;
 
 struct boot_info *dt_from_source(const char *fname)
 {
 	the_boot_info = NULL;
+	treesource_error = 0;
 
 	push_input_file(fname);
 
@@ -37,6 +39,7 @@ struct boot_info *dt_from_source(const char *fname)
 
 	fill_fullpaths(the_boot_info->dt, "");
 
+	the_boot_info->error = treesource_error;
 	return the_boot_info;
 }
 
-- 
1.5.3

^ permalink raw reply related

* [PATCH 2/3] Look for include files in the directory of the including file.
From: Scott Wood @ 2008-01-03 23:43 UTC (permalink / raw)
  To: jdl; +Cc: linuxppc-dev

Looking in the diretory dtc is invoked from is not very useful behavior.

As part of the code reorganization to implement this, I removed the
uniquifying of name storage -- it seemed a rather dubious optimization
given likely usage, and some aspects of it would have been mildly awkward
to integrate with the new code.

Signed-off-by: Scott Wood <scottwood@freescale.com>
---
 dtc-lexer.l  |   64 +++++++++++++++++------------
 dtc-parser.y |    2 +-
 dtc.c        |   14 ++++--
 srcpos.c     |  126 +++++++++++++++++++++++++++++++---------------------------
 srcpos.h     |   28 +++++++++----
 5 files changed, 134 insertions(+), 100 deletions(-)

diff --git a/dtc-lexer.l b/dtc-lexer.l
index c811b22..bfb996e 100644
--- a/dtc-lexer.l
+++ b/dtc-lexer.l
@@ -74,7 +74,7 @@ static int dts_version; /* = 0 */
 		}
 
 <*>\"([^\\"]|\\.)*\"	{
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("String: %s\n", yytext);
 			yylval.data = data_copy_escape_string(yytext+1,
@@ -84,7 +84,7 @@ static int dts_version; /* = 0 */
 		}
 
 <*>"/dts-v1/"	{
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("Keyword: /dts-v1/\n");
 			dts_version = 1;
@@ -93,7 +93,7 @@ static int dts_version; /* = 0 */
 		}
 
 <*>"/memreserve/"	{
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("Keyword: /memreserve/\n");
 			BEGIN_DEFAULT();
@@ -101,7 +101,7 @@ static int dts_version; /* = 0 */
 		}
 
 <*>{LABEL}:	{
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("Label: %s\n", yytext);
 			yylval.labelref = strdup(yytext);
@@ -110,7 +110,7 @@ static int dts_version; /* = 0 */
 		}
 
 <INITIAL>[bodh]# {
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			if (*yytext == 'b')
 				yylval.cbase = 2;
@@ -125,7 +125,7 @@ static int dts_version; /* = 0 */
 		}
 
 <INITIAL>[0-9a-fA-F]+	{
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			yylval.literal = strdup(yytext);
 			DPRINT("Literal: '%s'\n", yylval.literal);
@@ -133,7 +133,7 @@ static int dts_version; /* = 0 */
 		}
 
 <V1>[0-9]+|0[xX][0-9a-fA-F]+      {
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			yylval.literal = strdup(yytext);
 			DPRINT("Literal: '%s'\n", yylval.literal);
@@ -141,7 +141,7 @@ static int dts_version; /* = 0 */
 		}
 
 \&{LABEL}	{	/* label reference */
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("Ref: %s\n", yytext+1);
 			yylval.labelref = strdup(yytext+1);
@@ -149,7 +149,7 @@ static int dts_version; /* = 0 */
 		}
 
 "&{/"{PATHCHAR}+\}	{	/* new-style path reference */
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			yytext[yyleng-1] = '\0';
 			DPRINT("Ref: %s\n", yytext+2);
@@ -158,7 +158,7 @@ static int dts_version; /* = 0 */
 		}
 
 <INITIAL>"&/"{PATHCHAR}+ {	/* old-style path reference */
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("Ref: %s\n", yytext+1);
 			yylval.labelref = strdup(yytext+1);
@@ -166,7 +166,7 @@ static int dts_version; /* = 0 */
 		}
 
 <BYTESTRING>[0-9a-fA-F]{2} {
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			yylval.byte = strtol(yytext, NULL, 16);
 			DPRINT("Byte: %02x\n", (int)yylval.byte);
@@ -174,7 +174,7 @@ static int dts_version; /* = 0 */
 		}
 
 <BYTESTRING>"]"	{
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("/BYTESTRING\n");
 			BEGIN_DEFAULT();
@@ -182,7 +182,7 @@ static int dts_version; /* = 0 */
 		}
 
 <PROPNODENAME>{PROPNODECHAR}+ {
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("PropNodeName: %s\n", yytext);
 			yylval.propnodename = strdup(yytext);
@@ -190,11 +190,10 @@ static int dts_version; /* = 0 */
 			return DT_PROPNODENAME;
 		}
 
-
 <*>[[:space:]]+	/* eat whitespace */
 
 <*>"/*"([^*]|\*+[^*/])*\*+"/"	{
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("Comment: %s\n", yytext);
 			/* eat comments */
@@ -203,7 +202,7 @@ static int dts_version; /* = 0 */
 <*>"//".*\n	/* eat line comments */
 
 <*>.		{
-			yylloc.filenum = srcpos_filenum;
+			yylloc.file = srcpos_file;
 			yylloc.first_line = yylineno;
 			DPRINT("Char: %c (\\x%02x)\n", yytext[0],
 				(unsigned)yytext[0]);
@@ -227,8 +226,7 @@ static int dts_version; /* = 0 */
  */
 
 struct incl_file {
-	int filenum;
-	FILE *file;
+	struct dtc_file *file;
 	YY_BUFFER_STATE yy_prev_buf;
 	int yy_prev_lineno;
 	struct incl_file *prev;
@@ -247,8 +245,9 @@ static int incl_depth = 0;
 
 int push_input_file(const char *filename)
 {
-	FILE *f;
 	struct incl_file *incl_file;
+	struct dtc_file *newfile;
+	struct search_path search, *searchptr = NULL;
 
 	if (!filename) {
 		yyerror("No include file name given.");
@@ -260,7 +259,19 @@ int push_input_file(const char *filename)
 		return 0;
 	}
 
-	f = dtc_open_file(filename);
+	if (srcpos_file) {
+		search.dir = srcpos_file->dir;
+		search.next = NULL;
+		search.prev = NULL;
+		searchptr = &search;
+	}
+
+	newfile = dtc_open_file(filename, searchptr);
+	if (!newfile) {
+		yyerrorf("Couldn't open \"%s\": %s",
+		         filename, strerror(errno));
+		exit(1);
+	}
 
 	incl_file = malloc(sizeof(struct incl_file));
 	if (!incl_file) {
@@ -273,8 +284,7 @@ int push_input_file(const char *filename)
 	 */
 	incl_file->yy_prev_buf = YY_CURRENT_BUFFER;
 	incl_file->yy_prev_lineno = yylineno;
-	incl_file->filenum = srcpos_filenum;
-	incl_file->file = yyin;
+	incl_file->file = srcpos_file;
 	incl_file->prev = incl_file_stack;
 
 	incl_file_stack = incl_file;
@@ -282,9 +292,9 @@ int push_input_file(const char *filename)
 	/*
 	 * Establish new context.
 	 */
-	srcpos_filenum = lookup_file_name(filename, 0);
+	srcpos_file = newfile;
 	yylineno = 1;
-	yyin = f;
+	yyin = newfile->file;
 	yy_switch_to_buffer(yy_create_buffer(yyin, YY_BUF_SIZE));
 
 	return 1;
@@ -298,7 +308,7 @@ int pop_input_file(void)
 	if (incl_file_stack == 0)
 		return 0;
 
-	fclose(yyin);
+	dtc_close_file(srcpos_file);
 
 	/*
 	 * Pop.
@@ -313,8 +323,8 @@ int pop_input_file(void)
 	yy_delete_buffer(YY_CURRENT_BUFFER);
 	yy_switch_to_buffer(incl_file->yy_prev_buf);
 	yylineno = incl_file->yy_prev_lineno;
-	srcpos_filenum = incl_file->filenum;
-	yyin = incl_file->file;
+	srcpos_file = incl_file->file;
+	yyin = incl_file->file ? incl_file->file->file : NULL;
 
 	/*
 	 * Free old state.
diff --git a/dtc-parser.y b/dtc-parser.y
index ddb7f27..8ed58e8 100644
--- a/dtc-parser.y
+++ b/dtc-parser.y
@@ -309,7 +309,7 @@ label:
 
 void yyerrorf(char const *s, ...)
 {
-	const char *fname = srcpos_filename_for_num(yylloc.filenum);
+	const char *fname = srcpos_file ? srcpos_file->name : "<no-file>";
 	va_list va;
 	va_start(va, s);
 
diff --git a/dtc.c b/dtc.c
index 6295b39..fb716f3 100644
--- a/dtc.c
+++ b/dtc.c
@@ -118,7 +118,7 @@ int main(int argc, char *argv[])
 	int force = 0, check = 0;
 	const char *arg;
 	int opt;
-	FILE *inf = NULL;
+	struct dtc_file *inf = NULL;
 	FILE *outf = NULL;
 	int outversion = DEFAULT_FDT_VERSION;
 	int boot_cpuid_phys = 0xfeedbeef;
@@ -192,14 +192,18 @@ int main(int argc, char *argv[])
 	} else if (streq(inform, "fs")) {
 		bi = dt_from_fs(arg);
 	} else if(streq(inform, "dtb")) {
-		inf = dtc_open_file(arg);
-		bi = dt_from_blob(inf);
+		inf = dtc_open_file(arg, NULL);
+		if (!inf)
+			die("Couldn't open \"%s\": %s\n", arg,
+			    strerror(errno));
+
+		bi = dt_from_blob(inf->file);
 	} else {
 		die("Unknown input format \"%s\"\n", inform);
 	}
 
-	if (inf && (inf != stdin))
-		fclose(inf);
+	if (inf && inf->file != stdin)
+		fclose(inf->file);
 
 	if (! bi || ! bi->dt)
 		die("Couldn't read input tree\n");
diff --git a/srcpos.c b/srcpos.c
index 352b0fe..7340c33 100644
--- a/srcpos.c
+++ b/srcpos.c
@@ -20,86 +20,94 @@
 #include "dtc.h"
 #include "srcpos.h"
 
-
-/*
- * Record the complete unique set of opened file names.
- * Primarily used to cache source position file names.
- */
-#define MAX_N_FILE_NAMES	(100)
-
-const char *file_names[MAX_N_FILE_NAMES];
-static int n_file_names = 0;
-
 /*
  * Like yylineno, this is the current open file pos.
  */
 
-int srcpos_filenum = -1;
-
+struct dtc_file *srcpos_file;
 
-
-FILE *dtc_open_file(const char *fname)
+static int dtc_open_one(struct dtc_file *file,
+                        const char *search,
+                        const char *fname)
 {
-	FILE *f;
-
-	if (lookup_file_name(fname, 1) < 0)
-		die("Too many files opened\n");
-
-	if (streq(fname, "-"))
-		f = stdin;
-	else
-		f = fopen(fname, "r");
+	char *fullname;
+
+	if (search) {
+		fullname = malloc(strlen(search) + strlen(fname) + 2);
+		if (!fullname)
+			die("Out of memory\n");
+
+		strcpy(fullname, search);
+		strcat(fullname, "/");
+		strcat(fullname, fname);
+	} else {
+		fullname = strdup(fname);
+	}
 
-	if (! f)
-		die("Couldn't open \"%s\": %s\n", fname, strerror(errno));
+	file->file = fopen(fullname, "r");
+	if (!file->file) {
+		free(fullname);
+		return 0;
+	}
 
-	return f;
+	file->name = fullname;
+	return 1;
 }
 
 
-
-/*
- * Locate and optionally add filename fname in the file_names[] array.
- *
- * If the filename is currently not in the array and the boolean
- * add_it is non-zero, an attempt to add the filename will be made.
- *
- * Returns;
- *    Index [0..MAX_N_FILE_NAMES) where the filename is kept
- *    -1 if the name can not be recorded
- */
-
-int lookup_file_name(const char *fname, int add_it)
+struct dtc_file *dtc_open_file(const char *fname,
+                               const struct search_path *search)
 {
-	int i;
-
-	for (i = 0; i < n_file_names; i++) {
-		if (strcmp(file_names[i], fname) == 0)
-			return i;
+	static const struct search_path default_search = { NULL, NULL, NULL };
+
+	struct dtc_file *file;
+	const char *slash;
+
+	file = malloc(sizeof(struct dtc_file));
+	if (!file)
+		die("Out of memory\n");
+
+	slash = strrchr(fname, '/');
+	if (slash) {
+		char *dir = malloc(slash - fname + 1);
+		if (!dir)
+			die("Out of memory\n");
+
+		memcpy(dir, fname, slash - fname);
+		dir[slash - fname] = 0;
+		file->dir = dir;
+	} else {
+		file->dir = NULL;
 	}
 
-	if (add_it) {
-		if (n_file_names < MAX_N_FILE_NAMES) {
-			file_names[n_file_names] = strdup(fname);
-			return n_file_names++;
-		}
+	if (streq(fname, "-")) {
+		file->name = "stdin";
+		file->file = stdin;
+		return file;
 	}
 
-	return -1;
-}
+	if (!search)
+		search = &default_search;
 
+	while (search) {
+		if (dtc_open_one(file, search->dir, fname))
+			return file;
 
-const char *srcpos_filename_for_num(int filenum)
-{
-	if (0 <= filenum && filenum < n_file_names) {
-		return file_names[filenum];
+		if (errno != ENOENT)
+			goto out;
+
+		search = search->next;
 	}
 
-	return 0;
+out:
+	free(file);
+	return NULL;
 }
 
-
-const char *srcpos_get_filename(void)
+void dtc_close_file(struct dtc_file *file)
 {
-	return srcpos_filename_for_num(srcpos_filenum);
+	if (fclose(file->file))
+		die("Error closing \"%s\": %s\n", file->name, strerror(errno));
+
+	free(file);
 }
diff --git a/srcpos.h b/srcpos.h
index e59c788..8108539 100644
--- a/srcpos.h
+++ b/srcpos.h
@@ -22,13 +22,21 @@
  * array of all opened filenames.
  */
 
+#include <stdio.h>
+
+struct dtc_file {
+	const char *dir;
+	const char *name;
+	FILE *file;
+};
+
 #if ! defined(YYLTYPE) && ! defined(YYLTYPE_IS_DECLARED)
 typedef struct YYLTYPE {
     int first_line;
     int first_column;
     int last_line;
     int last_column;
-    int filenum;
+    struct dtc_file *file;
 } YYLTYPE;
 
 #define YYLTYPE_IS_DECLARED	1
@@ -48,7 +56,7 @@ typedef struct YYLTYPE {
 	  (Current).first_column = YYRHSLOC (Rhs, 1).first_column;	\
 	  (Current).last_line    = YYRHSLOC (Rhs, N).last_line;		\
 	  (Current).last_column  = YYRHSLOC (Rhs, N).last_column;	\
-	  (Current).filenum      = YYRHSLOC (Rhs, N).filenum;		\
+	  (Current).file         = YYRHSLOC (Rhs, N).file;		\
 	}								\
       else								\
 	{								\
@@ -56,7 +64,7 @@ typedef struct YYLTYPE {
 	    YYRHSLOC (Rhs, 0).last_line;				\
 	  (Current).first_column = (Current).last_column =		\
 	    YYRHSLOC (Rhs, 0).last_column;				\
-	  (Current).filenum      = YYRHSLOC (Rhs, 0).filenum;		\
+	  (Current).file         = YYRHSLOC (Rhs, 0).file;		\
 	}								\
     while (YYID (0))
 
@@ -65,12 +73,16 @@ typedef struct YYLTYPE {
 extern void yyerror(char const *);
 extern void yyerrorf(char const *, ...) __attribute__((format(printf, 1, 2)));
 
-extern int srcpos_filenum;
+extern struct dtc_file *srcpos_file;
 
 extern int push_input_file(const char *filename);
 extern int pop_input_file(void);
 
-extern FILE *dtc_open_file(const char *fname);
-extern int lookup_file_name(const char *fname, int add_it);
-extern const char *srcpos_filename_for_num(int filenum);
-const char *srcpos_get_filename(void);
+struct search_path {
+	const char *dir; /* NULL for current directory */
+	struct search_path *prev, *next;
+};
+
+extern struct dtc_file *dtc_open_file(const char *fname,
+                                      const struct search_path *search);
+extern void dtc_close_file(struct dtc_file *file);
-- 
1.5.3

^ permalink raw reply related

* Re: [PATCH 1/3] Add yyerrorf() for formatted error messages.
From: Scott Wood @ 2008-01-03 23:45 UTC (permalink / raw)
  To: jdl; +Cc: linuxppc-dev
In-Reply-To: <20080103234329.GA8441@ld0162-tx32.am.freescale.net>

Scott Wood wrote:
> Signed-off-by: Scott Wood <scottwood@freescale.com>
> ---
>  dtc-parser.y |   16 +++++++++++++---
>  srcpos.h     |    1 +
>  treesource.c |    1 -
>  3 files changed, 14 insertions(+), 4 deletions(-)

I forgot to tag them as such, but these are of course dtc patches and 
not Linux patches.

-Scott

^ permalink raw reply


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox