Merge branch 'v4l_for_2.6.35' of git://git.kernel.org/pub/scm/linux/kernel/git/mcheha...
authorLinus Torvalds <torvalds@linux-foundation.org>
Wed, 4 Aug 2010 17:38:08 +0000 (10:38 -0700)
committerLinus Torvalds <torvalds@linux-foundation.org>
Wed, 4 Aug 2010 17:38:08 +0000 (10:38 -0700)
* 'v4l_for_2.6.35' of git://git.kernel.org/pub/scm/linux/kernel/git/mchehab/linux-2.6: (243 commits)
  V4L/DVB: sms: Convert IR support to use the Remote Controller core
  V4L/DVB: sms: properly initialize IR phys and IR name
  V4L/DVB: standardize names at rc-dib0700 tables
  V4L/DVB: smsusb: enable IR port for Hauppauge WinTV MiniStick
  V4L/DVB: dib0700: Fix RC protocol logic to properly handle NEC/NECx and RC-5
  V4L/DVB: dib0700: properly implement IR change_protocol
  V4L/DVB: dib0700: break keytable into NEC and RC-5 variants
  V4L/DVB: dib0700: avoid bad repeat
  V4L/DVB: Port dib0700 to rc-core
  V4L/DVB: Add a keymap file with dib0700 table
  V4L/DVB: dvb-usb: add support for rc-core mode
  V4L/DVB: dvb-usb: prepare drivers for using rc-core
  V4L/DVB: dvb-usb: get rid of struct dvb_usb_rc_key
  V4L/DVB: rj54n1cb0c: fix a comment in the driver
  V4L/DVB: V4L2: sh_vou: VOU does support the full PAL resolution too
  V4L/DVB: V4L2: sh_mobile_camera_ceu: add support for CSI2
  V4L/DVB: V4L2: soc-camera: add a MIPI CSI-2 driver for SH-Mobile platforms
  V4L/DVB: V4L2: soc-camera: export soc-camera bus type for notifications
  V4L/DVB: V4L2: mediabus: add 12-bit Bayer and YUV420 pixel formats
  V4L/DVB: mediabus: fix ambiguous pixel code names
  ...

751 files changed:
Documentation/apparmor.txt [new file with mode: 0644]
Documentation/arm/memory.txt
Documentation/arm/tcm.txt
Documentation/filesystems/xfs.txt
Documentation/kernel-parameters.txt
Documentation/tomoyo.txt
MAINTAINERS
arch/arm/Kconfig
arch/arm/Makefile
arch/arm/boot/Makefile
arch/arm/boot/compressed/Makefile
arch/arm/boot/compressed/Makefile.debug [deleted file]
arch/arm/boot/compressed/head-l7200.S [deleted file]
arch/arm/boot/compressed/head.S
arch/arm/boot/compressed/misc.c
arch/arm/common/gic.c
arch/arm/common/sa1111.c
arch/arm/configs/kirkwood_defconfig
arch/arm/configs/lusl7200_defconfig [deleted file]
arch/arm/include/asm/elf.h
arch/arm/include/asm/hwcap.h
arch/arm/include/asm/irq.h
arch/arm/include/asm/kexec.h
arch/arm/include/asm/mach/arch.h
arch/arm/include/asm/mach/irq.h
arch/arm/include/asm/mach/map.h
arch/arm/include/asm/mach/pci.h
arch/arm/include/asm/memblock.h [new file with mode: 0644]
arch/arm/include/asm/memory.h
arch/arm/include/asm/mmzone.h [deleted file]
arch/arm/include/asm/ptrace.h
arch/arm/include/asm/setup.h
arch/arm/include/asm/stackprotector.h [new file with mode: 0644]
arch/arm/include/asm/system.h
arch/arm/include/asm/tls.h [new file with mode: 0644]
arch/arm/include/asm/vfpmacros.h
arch/arm/kernel/Makefile
arch/arm/kernel/asm-offsets.c
arch/arm/kernel/compat.c
arch/arm/kernel/compat.h
arch/arm/kernel/crash_dump.c [new file with mode: 0644]
arch/arm/kernel/entry-armv.S
arch/arm/kernel/irq.c
arch/arm/kernel/machine_kexec.c
arch/arm/kernel/process.c
arch/arm/kernel/ptrace.c
arch/arm/kernel/relocate_kernel.S
arch/arm/kernel/setup.c
arch/arm/kernel/smp.c
arch/arm/kernel/smp_twd.c
arch/arm/kernel/tcm.c
arch/arm/kernel/traps.c
arch/arm/lib/Makefile
arch/arm/mach-aaec2000/include/mach/memory.h
arch/arm/mach-at91/Kconfig
arch/arm/mach-at91/Makefile
arch/arm/mach-at91/at91sam9g45.c
arch/arm/mach-at91/board-sam9g20ek-2slot-mmc.c
arch/arm/mach-at91/board-sam9g20ek.c
arch/arm/mach-at91/board-snapper9260.c [new file with mode: 0644]
arch/arm/mach-at91/include/mach/at91cap9.h
arch/arm/mach-at91/include/mach/at91cap9_ddrsdr.h
arch/arm/mach-at91/include/mach/at91sam9260.h
arch/arm/mach-at91/include/mach/at91sam9261.h
arch/arm/mach-at91/include/mach/at91sam9_ddrsdr.h [new file with mode: 0644]
arch/arm/mach-at91/include/mach/at91sam9_sdramc.h
arch/arm/mach-at91/include/mach/at91sam9rl.h
arch/arm/mach-at91/include/mach/board.h
arch/arm/mach-at91/include/mach/cpu.h
arch/arm/mach-at91/include/mach/gpio.h
arch/arm/mach-at91/pm.h
arch/arm/mach-at91/pm_slowclock.S
arch/arm/mach-bcmring/core.c
arch/arm/mach-clps711x/Kconfig
arch/arm/mach-clps711x/clep7312.c
arch/arm/mach-clps711x/edb7211-arch.c
arch/arm/mach-clps711x/fortunet.c
arch/arm/mach-clps711x/include/mach/memory.h
arch/arm/mach-cns3xxx/Makefile
arch/arm/mach-cns3xxx/cns3420vb.c
arch/arm/mach-cns3xxx/devices.c [new file with mode: 0644]
arch/arm/mach-cns3xxx/devices.h [new file with mode: 0644]
arch/arm/mach-cns3xxx/include/mach/cns3xxx.h
arch/arm/mach-cns3xxx/pcie.c [new file with mode: 0644]
arch/arm/mach-cns3xxx/pm.c
arch/arm/mach-davinci/include/mach/memory.h
arch/arm/mach-dove/common.c
arch/arm/mach-dove/common.h
arch/arm/mach-dove/dove-db-setup.c
arch/arm/mach-ep93xx/adssphere.c
arch/arm/mach-ep93xx/clock.c
arch/arm/mach-ep93xx/core.c
arch/arm/mach-ep93xx/edb93xx.c
arch/arm/mach-ep93xx/gesbc9312.c
arch/arm/mach-ep93xx/include/mach/platform.h
arch/arm/mach-ep93xx/micro9.c
arch/arm/mach-ep93xx/simone.c
arch/arm/mach-ep93xx/ts72xx.c
arch/arm/mach-imx/Kconfig [moved from arch/arm/mach-mx2/Kconfig with 57% similarity]
arch/arm/mach-imx/Makefile [moved from arch/arm/mach-mx2/Makefile with 55% similarity]
arch/arm/mach-imx/Makefile.boot [moved from arch/arm/mach-mx2/Makefile.boot with 67% similarity]
arch/arm/mach-imx/clock-imx1.c [moved from arch/arm/mach-mx1/clock.c with 90% similarity]
arch/arm/mach-imx/clock-imx21.c [moved from arch/arm/mach-mx2/clock_imx21.c with 100% similarity]
arch/arm/mach-imx/clock-imx27.c [moved from arch/arm/mach-mx2/clock_imx27.c with 99% similarity]
arch/arm/mach-imx/cpu-imx27.c [moved from arch/arm/mach-mx2/cpu_imx27.c with 100% similarity]
arch/arm/mach-imx/devices-imx1.h [new file with mode: 0644]
arch/arm/mach-imx/devices-imx21.h [new file with mode: 0644]
arch/arm/mach-imx/devices-imx27.h [new file with mode: 0644]
arch/arm/mach-imx/devices.c [moved from arch/arm/mach-mx2/devices.c with 67% similarity]
arch/arm/mach-imx/devices.h [moved from arch/arm/mach-mx2/devices.h with 54% similarity]
arch/arm/mach-imx/dma-v1.c [moved from arch/arm/plat-mxc/dma-mx1-mx2.c with 99% similarity]
arch/arm/mach-imx/eukrea_mbimx27-baseboard.c [moved from arch/arm/mach-mx2/eukrea_mbimx27-baseboard.c with 52% similarity]
arch/arm/mach-imx/include/mach/dma-mx1-mx2.h [new file with mode: 0644]
arch/arm/mach-imx/include/mach/dma-v1.h [moved from arch/arm/plat-mxc/include/mach/dma-mx1-mx2.h with 93% similarity]
arch/arm/mach-imx/mach-cpuimx27.c [moved from arch/arm/mach-mx2/mach-cpuimx27.c with 66% similarity]
arch/arm/mach-imx/mach-imx27lite.c [moved from arch/arm/mach-mx2/mach-imx27lite.c with 86% similarity]
arch/arm/mach-imx/mach-mx1ads.c [moved from arch/arm/mach-mx1/mach-mx1ads.c with 81% similarity]
arch/arm/mach-imx/mach-mx21ads.c [moved from arch/arm/mach-mx2/mach-mx21ads.c with 77% similarity]
arch/arm/mach-imx/mach-mx27_3ds.c [moved from arch/arm/mach-mx2/mach-mx27_3ds.c with 74% similarity]
arch/arm/mach-imx/mach-mx27ads.c [moved from arch/arm/mach-mx2/mach-mx27ads.c with 82% similarity]
arch/arm/mach-imx/mach-mxt_td60.c [moved from arch/arm/mach-mx2/mach-mxt_td60.c with 86% similarity]
arch/arm/mach-imx/mach-pca100.c [moved from arch/arm/mach-mx2/mach-pca100.c with 80% similarity]
arch/arm/mach-imx/mach-pcm038.c [moved from arch/arm/mach-mx2/mach-pcm038.c with 91% similarity]
arch/arm/mach-imx/mach-scb9328.c [moved from arch/arm/mach-mx1/mach-scb9328.c with 89% similarity]
arch/arm/mach-imx/mm-imx1.c [moved from arch/arm/mach-mx1/generic.c with 68% similarity]
arch/arm/mach-imx/mm-imx21.c [moved from arch/arm/mach-mx2/mm-imx21.c with 95% similarity]
arch/arm/mach-imx/mm-imx27.c [moved from arch/arm/mach-mx2/mm-imx27.c with 95% similarity]
arch/arm/mach-imx/mx1-camera-fiq-ksym.c [moved from arch/arm/mach-mx1/ksym_mx1.c with 100% similarity]
arch/arm/mach-imx/mx1-camera-fiq.S [moved from arch/arm/mach-mx1/mx1_camera_fiq.S with 100% similarity]
arch/arm/mach-imx/pcm970-baseboard.c [moved from arch/arm/mach-mx2/pcm970-baseboard.c with 100% similarity]
arch/arm/mach-imx/pm-imx27.c [new file with mode: 0644]
arch/arm/mach-integrator/common.h [new file with mode: 0644]
arch/arm/mach-integrator/core.c
arch/arm/mach-integrator/integrator_ap.c
arch/arm/mach-integrator/integrator_cp.c
arch/arm/mach-integrator/pci_v3.c
arch/arm/mach-iop13xx/include/mach/memory.h
arch/arm/mach-iop13xx/pci.c
arch/arm/mach-ixp2000/pci.c
arch/arm/mach-ixp23xx/pci.c
arch/arm/mach-ixp4xx/common-pci.c
arch/arm/mach-ixp4xx/include/mach/memory.h
arch/arm/mach-kirkwood/Kconfig
arch/arm/mach-kirkwood/Makefile
arch/arm/mach-kirkwood/addr-map.c
arch/arm/mach-kirkwood/common.c
arch/arm/mach-kirkwood/common.h
arch/arm/mach-kirkwood/db88f6281-bp-setup.c
arch/arm/mach-kirkwood/include/mach/bridge-regs.h
arch/arm/mach-kirkwood/include/mach/irqs.h
arch/arm/mach-kirkwood/include/mach/kirkwood.h
arch/arm/mach-kirkwood/include/mach/leds-ns2.h [new file with mode: 0644]
arch/arm/mach-kirkwood/mpp.c
arch/arm/mach-kirkwood/mpp.h
arch/arm/mach-kirkwood/mv88f6281gtw_ge-setup.c
arch/arm/mach-kirkwood/netspace_v2-setup.c
arch/arm/mach-kirkwood/netxbig_v2-setup.c
arch/arm/mach-kirkwood/openrd-setup.c
arch/arm/mach-kirkwood/pcie.c
arch/arm/mach-kirkwood/rd88f6192-nas-setup.c
arch/arm/mach-kirkwood/rd88f6281-setup.c
arch/arm/mach-kirkwood/t5325-setup.c [new file with mode: 0644]
arch/arm/mach-kirkwood/ts219-setup.c
arch/arm/mach-kirkwood/ts41x-setup.c
arch/arm/mach-ks8695/pci.c
arch/arm/mach-l7200/Makefile [deleted file]
arch/arm/mach-l7200/Makefile.boot [deleted file]
arch/arm/mach-l7200/core.c [deleted file]
arch/arm/mach-l7200/include/mach/aux_reg.h [deleted file]
arch/arm/mach-l7200/include/mach/debug-macro.S [deleted file]
arch/arm/mach-l7200/include/mach/entry-macro.S [deleted file]
arch/arm/mach-l7200/include/mach/gp_timers.h [deleted file]
arch/arm/mach-l7200/include/mach/gpio.h [deleted file]
arch/arm/mach-l7200/include/mach/hardware.h [deleted file]
arch/arm/mach-l7200/include/mach/io.h [deleted file]
arch/arm/mach-l7200/include/mach/irqs.h [deleted file]
arch/arm/mach-l7200/include/mach/memory.h [deleted file]
arch/arm/mach-l7200/include/mach/pmpcon.h [deleted file]
arch/arm/mach-l7200/include/mach/pmu.h [deleted file]
arch/arm/mach-l7200/include/mach/serial.h [deleted file]
arch/arm/mach-l7200/include/mach/serial_l7200.h [deleted file]
arch/arm/mach-l7200/include/mach/sib.h [deleted file]
arch/arm/mach-l7200/include/mach/sys-clock.h [deleted file]
arch/arm/mach-l7200/include/mach/system.h [deleted file]
arch/arm/mach-l7200/include/mach/time.h [deleted file]
arch/arm/mach-l7200/include/mach/timex.h [deleted file]
arch/arm/mach-l7200/include/mach/uncompress.h [deleted file]
arch/arm/mach-l7200/include/mach/vmalloc.h [deleted file]
arch/arm/mach-lh7a40x/include/mach/memory.h
arch/arm/mach-lpc32xx/Kconfig [new file with mode: 0644]
arch/arm/mach-lpc32xx/Makefile [new file with mode: 0644]
arch/arm/mach-lpc32xx/Makefile.boot [new file with mode: 0644]
arch/arm/mach-lpc32xx/clock.c [new file with mode: 0644]
arch/arm/mach-lpc32xx/clock.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/common.c [new file with mode: 0644]
arch/arm/mach-lpc32xx/common.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/gpiolib.c [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/clkdev.h [moved from arch/arm/plat-mxc/include/mach/board-pcm043.h with 57% similarity]
arch/arm/mach-lpc32xx/include/mach/debug-macro.S [moved from arch/arm/plat-mxc/include/mach/board-mx35pdk.h with 55% similarity]
arch/arm/mach-lpc32xx/include/mach/entry-macro.S [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/gpio.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/hardware.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/i2c.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/io.h [moved from arch/arm/plat-mxc/include/mach/board-pcm037.h with 57% similarity]
arch/arm/mach-lpc32xx/include/mach/irqs.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/memory.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/platform.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/system.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/timex.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/uncompress.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/include/mach/vmalloc.h [new file with mode: 0644]
arch/arm/mach-lpc32xx/irq.c [new file with mode: 0644]
arch/arm/mach-lpc32xx/phy3250.c [new file with mode: 0644]
arch/arm/mach-lpc32xx/pm.c [new file with mode: 0644]
arch/arm/mach-lpc32xx/serial.c [new file with mode: 0644]
arch/arm/mach-lpc32xx/suspend.S [new file with mode: 0644]
arch/arm/mach-lpc32xx/timer.c [new file with mode: 0644]
arch/arm/mach-msm/Makefile
arch/arm/mach-msm/board-trout-gpio.c [new file with mode: 0644]
arch/arm/mach-msm/board-trout.c
arch/arm/mach-msm/board-trout.h
arch/arm/mach-msm/include/mach/gpio.h
arch/arm/mach-mx1/Kconfig [deleted file]
arch/arm/mach-mx1/Makefile [deleted file]
arch/arm/mach-mx1/Makefile.boot [deleted file]
arch/arm/mach-mx1/crm_regs.h [deleted file]
arch/arm/mach-mx1/devices.c [deleted file]
arch/arm/mach-mx1/devices.h [deleted file]
arch/arm/mach-mx2/serial.c [deleted file]
arch/arm/mach-mx25/Kconfig
arch/arm/mach-mx25/Makefile
arch/arm/mach-mx25/clock.c
arch/arm/mach-mx25/devices-imx25.h [new file with mode: 0644]
arch/arm/mach-mx25/devices.c
arch/arm/mach-mx25/devices.h
arch/arm/mach-mx25/eukrea_mbimxsd-baseboard.c [new file with mode: 0644]
arch/arm/mach-mx25/mach-cpuimx25.c [new file with mode: 0644]
arch/arm/mach-mx25/mach-mx25_3ds.c [moved from arch/arm/mach-mx25/mach-mx25pdk.c with 76% similarity]
arch/arm/mach-mx25/mm.c
arch/arm/mach-mx3/Kconfig
arch/arm/mach-mx3/Makefile
arch/arm/mach-mx3/clock-imx35.c
arch/arm/mach-mx3/devices-imx31.h [new file with mode: 0644]
arch/arm/mach-mx3/devices-imx35.h [new file with mode: 0644]
arch/arm/mach-mx3/devices.c
arch/arm/mach-mx3/devices.h
arch/arm/mach-mx3/eukrea_mbimxsd-baseboard.c [new file with mode: 0644]
arch/arm/mach-mx3/mach-armadillo5x0.c
arch/arm/mach-mx3/mach-cpuimx35.c [new file with mode: 0644]
arch/arm/mach-mx3/mach-kzm_arm11_01.c
arch/arm/mach-mx3/mach-mx31_3ds.c
arch/arm/mach-mx3/mach-mx31ads.c
arch/arm/mach-mx3/mach-mx31lilly.c
arch/arm/mach-mx3/mach-mx31lite.c
arch/arm/mach-mx3/mach-mx31moboard.c
arch/arm/mach-mx3/mach-mx35_3ds.c [moved from arch/arm/mach-mx3/mach-mx35pdk.c with 89% similarity]
arch/arm/mach-mx3/mach-pcm037.c
arch/arm/mach-mx3/mach-pcm037_eet.c
arch/arm/mach-mx3/mach-pcm043.c
arch/arm/mach-mx3/mach-qong.c
arch/arm/mach-mx3/mm.c
arch/arm/mach-mx3/mx31lilly-db.c
arch/arm/mach-mx3/mx31lite-db.c
arch/arm/mach-mx3/mx31moboard-devboard.c
arch/arm/mach-mx3/mx31moboard-marxbot.c
arch/arm/mach-mx3/mx31moboard-smartbot.c
arch/arm/mach-mx5/Kconfig
arch/arm/mach-mx5/Makefile
arch/arm/mach-mx5/board-cpuimx51.c [new file with mode: 0644]
arch/arm/mach-mx5/board-mx51_3ds.c [new file with mode: 0644]
arch/arm/mach-mx5/board-mx51_babbage.c
arch/arm/mach-mx5/clock-mx51.c
arch/arm/mach-mx5/devices.c
arch/arm/mach-mx5/devices.h
arch/arm/mach-mx5/eukrea_mbimx51-baseboard.c [new file with mode: 0644]
arch/arm/mach-mx5/mm.c
arch/arm/mach-mxc91231/crm_regs.h
arch/arm/mach-mxc91231/devices.c
arch/arm/mach-mxc91231/mm.c
arch/arm/mach-nomadik/clock.c
arch/arm/mach-omap1/board-ams-delta.c
arch/arm/mach-omap1/board-fsample.c
arch/arm/mach-omap1/board-generic.c
arch/arm/mach-omap1/board-h2.c
arch/arm/mach-omap1/board-h3.c
arch/arm/mach-omap1/board-htcherald.c
arch/arm/mach-omap1/board-innovator.c
arch/arm/mach-omap1/board-nokia770.c
arch/arm/mach-omap1/board-osk.c
arch/arm/mach-omap1/board-palmte.c
arch/arm/mach-omap1/board-palmtt.c
arch/arm/mach-omap1/board-palmz71.c
arch/arm/mach-omap1/board-perseus2.c
arch/arm/mach-omap1/board-sx1.c
arch/arm/mach-omap1/board-voiceblue.c
arch/arm/mach-omap1/io.c
arch/arm/mach-omap2/board-2430sdp.c
arch/arm/mach-omap2/board-3430sdp.c
arch/arm/mach-omap2/board-3630sdp.c
arch/arm/mach-omap2/board-4430sdp.c
arch/arm/mach-omap2/board-am3517evm.c
arch/arm/mach-omap2/board-apollon.c
arch/arm/mach-omap2/board-cm-t35.c
arch/arm/mach-omap2/board-devkit8000.c
arch/arm/mach-omap2/board-generic.c
arch/arm/mach-omap2/board-h4.c
arch/arm/mach-omap2/board-igep0020.c
arch/arm/mach-omap2/board-ldp.c
arch/arm/mach-omap2/board-n8x0.c
arch/arm/mach-omap2/board-omap3beagle.c
arch/arm/mach-omap2/board-omap3evm.c
arch/arm/mach-omap2/board-omap3pandora.c
arch/arm/mach-omap2/board-omap3touchbook.c
arch/arm/mach-omap2/board-overo.c
arch/arm/mach-omap2/board-rx51.c
arch/arm/mach-omap2/board-zoom2.c
arch/arm/mach-omap2/board-zoom3.c
arch/arm/mach-omap2/clock3xxx_data.c
arch/arm/mach-omap2/io.c
arch/arm/mach-orion5x/Kconfig
arch/arm/mach-orion5x/dns323-setup.c
arch/arm/mach-orion5x/include/mach/system.h
arch/arm/mach-pxa/cm-x2xx-pci.c
arch/arm/mach-pxa/corgi.c
arch/arm/mach-pxa/eseries.c
arch/arm/mach-pxa/generic.h
arch/arm/mach-pxa/include/mach/memory.h
arch/arm/mach-pxa/palmt5.c
arch/arm/mach-pxa/palmtreo.c
arch/arm/mach-pxa/poodle.c
arch/arm/mach-pxa/spitz.c
arch/arm/mach-pxa/tosa.c
arch/arm/mach-realview/core.c
arch/arm/mach-realview/include/mach/board-pb1176.h
arch/arm/mach-realview/include/mach/irqs-pb1176.h
arch/arm/mach-realview/include/mach/memory.h
arch/arm/mach-realview/realview_eb.c
arch/arm/mach-realview/realview_pb1176.c
arch/arm/mach-realview/realview_pb11mp.c
arch/arm/mach-realview/realview_pba8.c
arch/arm/mach-realview/realview_pbx.c
arch/arm/mach-s3c2410/mach-h1940.c
arch/arm/mach-s3c2412/mach-smdk2413.c
arch/arm/mach-s3c2412/mach-vstms.c
arch/arm/mach-s3c2440/mach-rx1950.c
arch/arm/mach-s3c2440/mach-rx3715.c
arch/arm/mach-sa1100/generic.h
arch/arm/mach-sa1100/include/mach/memory.h
arch/arm/mach-shark/include/mach/memory.h
arch/arm/mach-shmobile/Kconfig
arch/arm/mach-shmobile/include/mach/irqs.h
arch/arm/mach-spear3xx/clock.c
arch/arm/mach-spear6xx/clock.c
arch/arm/mach-u300/clock.c
arch/arm/mach-u300/include/mach/memory.h
arch/arm/mach-u300/u300.c
arch/arm/mach-ux500/board-mop500.c
arch/arm/mach-ux500/clock.c
arch/arm/mach-ux500/devices-db8500.c
arch/arm/mach-ux500/include/mach/irqs-board-mop500.h [new file with mode: 0644]
arch/arm/mach-ux500/include/mach/irqs-db5500.h [new file with mode: 0644]
arch/arm/mach-ux500/include/mach/irqs-db8500.h [new file with mode: 0644]
arch/arm/mach-ux500/include/mach/irqs.h
arch/arm/mach-ux500/pins-db8500.h [new file with mode: 0644]
arch/arm/mach-versatile/core.c
arch/arm/mach-versatile/pci.c
arch/arm/mach-vexpress/ct-ca9x4.c
arch/arm/mach-vexpress/include/mach/ct-ca9x4.h
arch/arm/mach-vexpress/v2m.c
arch/arm/mach-w90x900/dev.c
arch/arm/mach-w90x900/include/mach/regs-gcr.h [new file with mode: 0644]
arch/arm/mach-w90x900/mach-nuc950evb.c
arch/arm/mach-w90x900/nuc910.c
arch/arm/mach-w90x900/nuc950.c
arch/arm/mm/Kconfig
arch/arm/mm/Makefile
arch/arm/mm/alignment.c
arch/arm/mm/discontig.c [deleted file]
arch/arm/mm/dma-mapping.c
arch/arm/mm/fault.c
arch/arm/mm/init.c
arch/arm/mm/ioremap.c
arch/arm/mm/mm.h
arch/arm/mm/mmap.c
arch/arm/mm/mmu.c
arch/arm/mm/nommu.c
arch/arm/mm/proc-arm1020.S
arch/arm/mm/proc-arm1020e.S
arch/arm/mm/proc-arm1022.S
arch/arm/mm/proc-arm1026.S
arch/arm/mm/proc-arm6_7.S
arch/arm/mm/proc-arm720.S
arch/arm/mm/proc-arm740.S
arch/arm/mm/proc-arm7tdmi.S
arch/arm/mm/proc-arm920.S
arch/arm/mm/proc-arm922.S
arch/arm/mm/proc-arm925.S
arch/arm/mm/proc-arm926.S
arch/arm/mm/proc-arm940.S
arch/arm/mm/proc-arm946.S
arch/arm/mm/proc-arm9tdmi.S
arch/arm/mm/proc-fa526.S
arch/arm/mm/proc-feroceon.S
arch/arm/mm/proc-mohawk.S
arch/arm/mm/proc-sa110.S
arch/arm/mm/proc-sa1100.S
arch/arm/mm/proc-v6.S
arch/arm/mm/proc-v7.S
arch/arm/mm/proc-xsc3.S
arch/arm/mm/proc-xscale.S
arch/arm/mm/vmregion.c
arch/arm/mm/vmregion.h
arch/arm/plat-iop/pci.c
arch/arm/plat-iop/time.c
arch/arm/plat-mxc/3ds_debugboard.c [new file with mode: 0644]
arch/arm/plat-mxc/Kconfig
arch/arm/plat-mxc/Makefile
arch/arm/plat-mxc/audmux-v1.c
arch/arm/plat-mxc/audmux-v2.c
arch/arm/plat-mxc/clock.c
arch/arm/plat-mxc/devices.c
arch/arm/plat-mxc/devices/Kconfig [new file with mode: 0644]
arch/arm/plat-mxc/devices/Makefile [new file with mode: 0644]
arch/arm/plat-mxc/devices/platform-flexcan.c [new file with mode: 0644]
arch/arm/plat-mxc/devices/platform-imx-i2c.c [new file with mode: 0644]
arch/arm/plat-mxc/devices/platform-imx-uart.c [new file with mode: 0644]
arch/arm/plat-mxc/devices/platform-mxc_nand.c [new file with mode: 0644]
arch/arm/plat-mxc/devices/platform-spi_imx.c [new file with mode: 0644]
arch/arm/plat-mxc/ehci.c
arch/arm/plat-mxc/gpio.c
arch/arm/plat-mxc/include/mach/3ds_debugboard.h [new file with mode: 0644]
arch/arm/plat-mxc/include/mach/board-armadillo5x0.h [deleted file]
arch/arm/plat-mxc/include/mach/board-kzmarm11.h [deleted file]
arch/arm/plat-mxc/include/mach/board-mx21ads.h [deleted file]
arch/arm/plat-mxc/include/mach/board-mx27ads.h [deleted file]
arch/arm/plat-mxc/include/mach/board-mx27lite.h [deleted file]
arch/arm/plat-mxc/include/mach/board-mx27pdk.h [deleted file]
arch/arm/plat-mxc/include/mach/board-mx31_3ds.h [deleted file]
arch/arm/plat-mxc/include/mach/board-mx31ads.h [deleted file]
arch/arm/plat-mxc/include/mach/board-mx31lilly.h
arch/arm/plat-mxc/include/mach/board-mx31lite.h
arch/arm/plat-mxc/include/mach/board-mx31moboard.h
arch/arm/plat-mxc/include/mach/board-pcm038.h
arch/arm/plat-mxc/include/mach/board-qong.h [deleted file]
arch/arm/plat-mxc/include/mach/debug-macro.S
arch/arm/plat-mxc/include/mach/devices-common.h [new file with mode: 0644]
arch/arm/plat-mxc/include/mach/eukrea-baseboards.h [moved from arch/arm/plat-mxc/include/mach/board-eukrea_cpuimx27.h with 64% similarity]
arch/arm/plat-mxc/include/mach/gpio.h
arch/arm/plat-mxc/include/mach/iomux-mx25.h
arch/arm/plat-mxc/include/mach/iomux-mx51.h
arch/arm/plat-mxc/include/mach/iomux-mxc91231.h
arch/arm/plat-mxc/include/mach/iomux-v3.h
arch/arm/plat-mxc/include/mach/memory.h
arch/arm/plat-mxc/include/mach/mmc.h
arch/arm/plat-mxc/include/mach/mx1.h
arch/arm/plat-mxc/include/mach/mx25.h
arch/arm/plat-mxc/include/mach/mx27.h
arch/arm/plat-mxc/include/mach/mx2_cam.h [new file with mode: 0644]
arch/arm/plat-mxc/include/mach/mx31.h
arch/arm/plat-mxc/include/mach/mx35.h
arch/arm/plat-mxc/include/mach/mx3_camera.h
arch/arm/plat-mxc/include/mach/mxc91231.h
arch/arm/plat-mxc/include/mach/mxc_nand.h
arch/arm/plat-mxc/include/mach/system.h
arch/arm/plat-mxc/include/mach/timex.h
arch/arm/plat-mxc/include/mach/uncompress.h
arch/arm/plat-mxc/include/mach/vmalloc.h
arch/arm/plat-mxc/irq.c
arch/arm/plat-mxc/system.c
arch/arm/plat-mxc/tzic.c
arch/arm/plat-nomadik/gpio.c
arch/arm/plat-nomadik/include/plat/gpio.h
arch/arm/plat-nomadik/include/plat/mtu.h
arch/arm/plat-nomadik/include/plat/pincfg.h [new file with mode: 0644]
arch/arm/plat-nomadik/timer.c
arch/arm/plat-omap/common.c
arch/arm/plat-omap/fb.c
arch/arm/plat-omap/include/plat/common.h
arch/arm/plat-omap/include/plat/vram.h
arch/arm/plat-orion/pcie.c
arch/arm/plat-spear/time.c
arch/arm/plat-versatile/Makefile
arch/arm/plat-versatile/leds.c [new file with mode: 0644]
arch/arm/vfp/vfpmodule.c
drivers/amba/bus.c
drivers/gpio/pl061.c
drivers/leds/Kconfig
drivers/leds/Makefile
drivers/leds/leds-ns2.c [new file with mode: 0644]
drivers/media/video/Kconfig
drivers/media/video/Makefile
drivers/media/video/mx2_camera.c [new file with mode: 0644]
drivers/misc/Kconfig
drivers/misc/Makefile
drivers/misc/arm-charlcd.c [new file with mode: 0644]
drivers/mmc/host/mmci.c
drivers/mmc/host/mmci.h
drivers/mmc/host/mxcmmc.c
drivers/mtd/nand/mxc_nand.c
drivers/mtd/ubi/build.c
drivers/mtd/ubi/eba.c
drivers/mtd/ubi/io.c
drivers/mtd/ubi/scan.c
drivers/mtd/ubi/scan.h
drivers/mtd/ubi/ubi.h
drivers/net/phy/marvell.c
drivers/parisc/led.c
drivers/rtc/rtc-pl031.c
drivers/serial/amba-pl010.c
drivers/serial/amba-pl011.c
drivers/usb/gadget/at91_udc.c
drivers/usb/gadget/at91_udc.h
drivers/usb/gadget/fsl_mxc_udc.c
drivers/usb/host/ehci-mxc.c
drivers/video/imxfb.c
drivers/video/omap2/vram.c
fs/9p/Makefile
fs/9p/fid.c
fs/9p/v9fs.c
fs/9p/v9fs.h
fs/9p/v9fs_vfs.h
fs/9p/vfs_dir.c
fs/9p/vfs_file.c
fs/9p/vfs_inode.c
fs/9p/vfs_super.c
fs/9p/xattr.c [new file with mode: 0644]
fs/9p/xattr.h [new file with mode: 0644]
fs/9p/xattr_user.c [new file with mode: 0644]
fs/cifs/Kconfig
fs/cifs/Makefile
fs/cifs/cache.c [new file with mode: 0644]
fs/cifs/cifs_dfs_ref.c
fs/cifs/cifs_fs_sb.h
fs/cifs/cifs_spnego.c
fs/cifs/cifsfs.c
fs/cifs/cifsfs.h
fs/cifs/cifsglob.h
fs/cifs/cifsproto.h
fs/cifs/connect.c
fs/cifs/dir.c
fs/cifs/dns_resolve.c
fs/cifs/file.c
fs/cifs/fscache.c [new file with mode: 0644]
fs/cifs/fscache.h [new file with mode: 0644]
fs/cifs/inode.c
fs/cifs/ioctl.c
fs/cifs/netmisc.c
fs/cifs/readdir.c
fs/cifs/smberr.h
fs/direct-io.c
fs/ext4/inode.c
fs/fuse/dir.c
fs/gfs2/aops.c
fs/gfs2/bmap.c
fs/gfs2/bmap.h
fs/gfs2/dir.c
fs/gfs2/file.c
fs/gfs2/glock.c
fs/gfs2/incore.h
fs/gfs2/ops_fstype.c
fs/gfs2/quota.c
fs/gfs2/super.c
fs/gfs2/sys.c
fs/namei.c
fs/nfs/dir.c
fs/ocfs2/aops.c
fs/open.c
fs/ubifs/lpt.c
fs/ubifs/lpt_commit.c
fs/ubifs/recovery.c
fs/ubifs/super.c
fs/xfs/Makefile
fs/xfs/linux-2.6/xfs_acl.c
fs/xfs/linux-2.6/xfs_aops.c
fs/xfs/linux-2.6/xfs_aops.h
fs/xfs/linux-2.6/xfs_buf.c
fs/xfs/linux-2.6/xfs_buf.h
fs/xfs/linux-2.6/xfs_dmapi_priv.h [deleted file]
fs/xfs/linux-2.6/xfs_export.c
fs/xfs/linux-2.6/xfs_file.c
fs/xfs/linux-2.6/xfs_fs_subr.c
fs/xfs/linux-2.6/xfs_fs_subr.h [deleted file]
fs/xfs/linux-2.6/xfs_ioctl.c
fs/xfs/linux-2.6/xfs_ioctl32.c
fs/xfs/linux-2.6/xfs_iops.c
fs/xfs/linux-2.6/xfs_linux.h
fs/xfs/linux-2.6/xfs_quotaops.c
fs/xfs/linux-2.6/xfs_super.c
fs/xfs/linux-2.6/xfs_super.h
fs/xfs/linux-2.6/xfs_sync.c
fs/xfs/linux-2.6/xfs_sync.h
fs/xfs/linux-2.6/xfs_trace.c
fs/xfs/linux-2.6/xfs_trace.h
fs/xfs/quota/xfs_dquot.c
fs/xfs/quota/xfs_dquot_item.c
fs/xfs/quota/xfs_qm.c
fs/xfs/quota/xfs_qm_bhv.c
fs/xfs/quota/xfs_qm_stats.c
fs/xfs/quota/xfs_qm_syscalls.c
fs/xfs/quota/xfs_trans_dquot.c
fs/xfs/support/debug.c
fs/xfs/xfs_alloc.c
fs/xfs/xfs_alloc.h
fs/xfs/xfs_alloc_btree.c
fs/xfs/xfs_attr.c
fs/xfs/xfs_attr_leaf.c
fs/xfs/xfs_bmap.c
fs/xfs/xfs_bmap.h
fs/xfs/xfs_bmap_btree.c
fs/xfs/xfs_btree.c
fs/xfs/xfs_buf_item.c
fs/xfs/xfs_buf_item.h
fs/xfs/xfs_da_btree.c
fs/xfs/xfs_dfrag.c
fs/xfs/xfs_dir2.c
fs/xfs/xfs_dir2_block.c
fs/xfs/xfs_dir2_data.c
fs/xfs/xfs_dir2_leaf.c
fs/xfs/xfs_dir2_node.c
fs/xfs/xfs_dir2_sf.c
fs/xfs/xfs_dmapi.h [deleted file]
fs/xfs/xfs_dmops.c [deleted file]
fs/xfs/xfs_error.c
fs/xfs/xfs_extfree_item.c
fs/xfs/xfs_filestream.c
fs/xfs/xfs_filestream.h
fs/xfs/xfs_fsops.c
fs/xfs/xfs_ialloc.c
fs/xfs/xfs_ialloc_btree.c
fs/xfs/xfs_iget.c
fs/xfs/xfs_inode.c
fs/xfs/xfs_inode.h
fs/xfs/xfs_inode_item.c
fs/xfs/xfs_inode_item.h
fs/xfs/xfs_iomap.c
fs/xfs/xfs_iomap.h
fs/xfs/xfs_itable.c
fs/xfs/xfs_log.c
fs/xfs/xfs_log.h
fs/xfs/xfs_log_cil.c
fs/xfs/xfs_log_recover.c
fs/xfs/xfs_mount.c
fs/xfs/xfs_mount.h
fs/xfs/xfs_rename.c
fs/xfs/xfs_rtalloc.c
fs/xfs/xfs_rw.c
fs/xfs/xfs_trans.c
fs/xfs/xfs_trans.h
fs/xfs/xfs_trans_ail.c
fs/xfs/xfs_trans_buf.c
fs/xfs/xfs_trans_extfree.c
fs/xfs/xfs_trans_inode.c
fs/xfs/xfs_trans_item.c [deleted file]
fs/xfs/xfs_trans_priv.h
fs/xfs/xfs_utils.c
fs/xfs/xfs_utils.h
fs/xfs/xfs_vnodeops.c
include/linux/amba/bus.h
include/linux/amba/mmci.h
include/linux/amba/serial.h
include/linux/capability.h
include/linux/fs.h
include/linux/lsm_audit.h
include/linux/marvell_phy.h [new file with mode: 0644]
include/linux/omapfb.h
include/linux/security.h
include/linux/swiotlb.h
include/linux/virtio_9p.h
include/linux/xattr.h
include/net/9p/9p.h
include/net/9p/client.h
lib/atomic64_test.c
lib/swiotlb.c
net/9p/client.c
net/9p/protocol.c
net/9p/trans_fd.c
security/Kconfig
security/Makefile
security/apparmor/.gitignore [new file with mode: 0644]
security/apparmor/Kconfig [new file with mode: 0644]
security/apparmor/Makefile [new file with mode: 0644]
security/apparmor/apparmorfs.c [new file with mode: 0644]
security/apparmor/audit.c [new file with mode: 0644]
security/apparmor/capability.c [new file with mode: 0644]
security/apparmor/context.c [new file with mode: 0644]
security/apparmor/domain.c [new file with mode: 0644]
security/apparmor/file.c [new file with mode: 0644]
security/apparmor/include/apparmor.h [new file with mode: 0644]
security/apparmor/include/apparmorfs.h [new file with mode: 0644]
security/apparmor/include/audit.h [new file with mode: 0644]
security/apparmor/include/capability.h [new file with mode: 0644]
security/apparmor/include/context.h [new file with mode: 0644]
security/apparmor/include/domain.h [new file with mode: 0644]
security/apparmor/include/file.h [new file with mode: 0644]
security/apparmor/include/ipc.h [new file with mode: 0644]
security/apparmor/include/match.h [new file with mode: 0644]
security/apparmor/include/path.h [new file with mode: 0644]
security/apparmor/include/policy.h [new file with mode: 0644]
security/apparmor/include/policy_unpack.h [new file with mode: 0644]
security/apparmor/include/procattr.h [new file with mode: 0644]
security/apparmor/include/resource.h [new file with mode: 0644]
security/apparmor/include/sid.h [new file with mode: 0644]
security/apparmor/ipc.c [new file with mode: 0644]
security/apparmor/lib.c [new file with mode: 0644]
security/apparmor/lsm.c [new file with mode: 0644]
security/apparmor/match.c [new file with mode: 0644]
security/apparmor/path.c [new file with mode: 0644]
security/apparmor/policy.c [new file with mode: 0644]
security/apparmor/policy_unpack.c [new file with mode: 0644]
security/apparmor/procattr.c [new file with mode: 0644]
security/apparmor/resource.c [new file with mode: 0644]
security/apparmor/sid.c [new file with mode: 0644]
security/capability.c
security/inode.c
security/integrity/ima/ima_fs.c
security/keys/internal.h
security/keys/keyctl.c
security/keys/proc.c
security/keys/process_keys.c
security/keys/request_key.c
security/security.c
security/selinux/avc.c
security/selinux/hooks.c
security/selinux/include/classmap.h
security/selinux/netnode.c
security/selinux/selinuxfs.c
security/selinux/ss/avtab.c
security/selinux/ss/conditional.c
security/selinux/ss/policydb.c
security/selinux/ss/policydb.h
security/selinux/ss/services.c
security/selinux/ss/symtab.c
security/smack/smack.h
security/smack/smack_lsm.c
security/tomoyo/Makefile
security/tomoyo/common.c
security/tomoyo/common.h
security/tomoyo/domain.c
security/tomoyo/file.c
security/tomoyo/gc.c
security/tomoyo/group.c [new file with mode: 0644]
security/tomoyo/load_policy.c [new file with mode: 0644]
security/tomoyo/memory.c [new file with mode: 0644]
security/tomoyo/mount.c [new file with mode: 0644]
security/tomoyo/path_group.c [deleted file]
security/tomoyo/realpath.c
security/tomoyo/securityfs_if.c [new file with mode: 0644]
security/tomoyo/tomoyo.c
security/tomoyo/util.c [new file with mode: 0644]
tools/perf/arch/arm/Makefile [new file with mode: 0644]
tools/perf/arch/arm/util/dwarf-regs.c [new file with mode: 0644]

diff --git a/Documentation/apparmor.txt b/Documentation/apparmor.txt
new file mode 100644 (file)
index 0000000..93c1fd7
--- /dev/null
@@ -0,0 +1,39 @@
+--- What is AppArmor? ---
+
+AppArmor is MAC style security extension for the Linux kernel.  It implements
+a task centered policy, with task "profiles" being created and loaded
+from user space.  Tasks on the system that do not have a profile defined for
+them run in an unconfined state which is equivalent to standard Linux DAC
+permissions.
+
+--- How to enable/disable ---
+
+set CONFIG_SECURITY_APPARMOR=y
+
+If AppArmor should be selected as the default security module then
+   set CONFIG_DEFAULT_SECURITY="apparmor"
+   and CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE=1
+
+Build the kernel
+
+If AppArmor is not the default security module it can be enabled by passing
+security=apparmor on the kernel's command line.
+
+If AppArmor is the default security module it can be disabled by passing
+apparmor=0, security=XXXX (where XXX is valid security module), on the
+kernel's command line
+
+For AppArmor to enforce any restrictions beyond standard Linux DAC permissions
+policy must be loaded into the kernel from user space (see the Documentation
+and tools links).
+
+--- Documentation ---
+
+Documentation can be found on the wiki.
+
+--- Links ---
+
+Mailing List - apparmor@lists.ubuntu.com
+Wiki - http://apparmor.wiki.kernel.org/
+User space tools - https://launchpad.net/apparmor
+Kernel module - git://git.kernel.org/pub/scm/linux/kernel/git/jj/apparmor-dev.git
index eb0fae18ffb12a805bb81eb2c5005a773d499d2b..771d48d3b335a1419f1ec363d540c77ad6d75fbc 100644 (file)
@@ -33,7 +33,13 @@ ffff0000     ffff0fff        CPU vector page.
 
 fffe0000       fffeffff        XScale cache flush area.  This is used
                                in proc-xscale.S to flush the whole data
-                               cache.  Free for other usage on non-XScale.
+                               cache. (XScale does not have TCM.)
+
+fffe8000       fffeffff        DTCM mapping area for platforms with
+                               DTCM mounted inside the CPU.
+
+fffe0000       fffe7fff        ITCM mapping area for platforms with
+                               ITCM mounted inside the CPU.
 
 fff00000       fffdffff        Fixmap mapping region.  Addresses provided
                                by fix_to_virt() will be located here.
index 77fd9376e6d73b4cc47d39afb8d7b01ad4b00120..7c15871c1885df512a87493c8fbfc3c1df6cc610 100644 (file)
@@ -19,8 +19,8 @@ defines a CPUID_TCM register that you can read out from the
 system control coprocessor. Documentation from ARM can be found
 at http://infocenter.arm.com, search for "TCM Status Register"
 to see documents for all CPUs. Reading this register you can
-determine if ITCM (bit 0) and/or DTCM (bit 16) is present in the
-machine.
+determine if ITCM (bits 1-0) and/or DTCM (bit 17-16) is present
+in the machine.
 
 There is further a TCM region register (search for "TCM Region
 Registers" at the ARM site) that can report and modify the location
@@ -35,7 +35,15 @@ The TCM memory can then be remapped to another address again using
 the MMU, but notice that the TCM if often used in situations where
 the MMU is turned off. To avoid confusion the current Linux
 implementation will map the TCM 1 to 1 from physical to virtual
-memory in the location specified by the machine.
+memory in the location specified by the kernel. Currently Linux
+will map ITCM to 0xfffe0000 and on, and DTCM to 0xfffe8000 and
+on, supporting a maximum of 32KiB of ITCM and 32KiB of DTCM.
+
+Newer versions of the region registers also support dividing these
+TCMs in two separate banks, so for example an 8KiB ITCM is divided
+into two 4KiB banks with its own control registers. The idea is to
+be able to lock and hide one of the banks for use by the secure
+world (TrustZone).
 
 TCM is used for a few things:
 
@@ -65,18 +73,18 @@ in <asm/tcm.h>. Using this interface it is possible to:
   memory. Such a heap is great for things like saving
   device state when shutting off device power domains.
 
-A machine that has TCM memory shall select HAVE_TCM in
-arch/arm/Kconfig for itself, and then the
-rest of the functionality will depend on the physical
-location and size of ITCM and DTCM to be defined in
-mach/memory.h for the machine. Code that needs to use
-TCM shall #include <asm/tcm.h> If the TCM is not located
-at the place given in memory.h it will be moved using
-the TCM Region registers.
+A machine that has TCM memory shall select HAVE_TCM from
+arch/arm/Kconfig for itself. Code that needs to use TCM shall
+#include <asm/tcm.h>
 
 Functions to go into itcm can be tagged like this:
 int __tcmfunc foo(int bar);
 
+Since these are marked to become long_calls and you may want
+to have functions called locally inside the TCM without
+wasting space, there is also the __tcmlocalfunc prefix that
+will make the call relative.
+
 Variables to go into dtcm can be tagged like this:
 int __tcmdata foo;
 
index 9878f50d6ed6d37b3241eb558a58d08681898927..7bff3e4f35df84a9def7507badb42ccdeffef419 100644 (file)
@@ -131,17 +131,6 @@ When mounting an XFS filesystem, the following options are accepted.
        Don't check for double mounted file systems using the file system uuid.
        This is useful to mount LVM snapshot volumes.
 
-  osyncisosync
-       Make O_SYNC writes implement true O_SYNC.  WITHOUT this option,
-       Linux XFS behaves as if an "osyncisdsync" option is used,
-       which will make writes to files opened with the O_SYNC flag set
-       behave as if the O_DSYNC flag had been used instead.
-       This can result in better performance without compromising
-       data safety.
-       However if this option is not in effect, timestamp updates from
-       O_SYNC writes can be lost if the system crashes.
-       If timestamp updates are critical, use the osyncisosync option.
-
   uquota/usrquota/uqnoenforce/quota
        User disk quota accounting enabled, and limits (optionally)
        enforced.  Refer to xfs_quota(8) for further details.
index 2b2407d9a6d025a8451605b104a35daa7da59b47..b61f89fa01c193def3bc453f2422c4cc40ac06bb 100644 (file)
@@ -93,6 +93,7 @@ parameter is applicable:
                        Documentation/scsi/.
        SECURITY Different security models are enabled.
        SELINUX SELinux support is enabled.
+       APPARMOR AppArmor support is enabled.
        SERIAL  Serial support is enabled.
        SH      SuperH architecture is enabled.
        SMP     The kernel is an SMP kernel.
@@ -2312,6 +2313,13 @@ and is between 256 and 4096 characters. It is defined in the file
                        If enabled at boot time, /selinux/disable can be used
                        later to disable prior to initial policy load.
 
+       apparmor=       [APPARMOR] Disable or enable AppArmor at boot time
+                       Format: { "0" | "1" }
+                       See security/apparmor/Kconfig help text
+                       0 -- disable.
+                       1 -- enable.
+                       Default value is set via kernel config option.
+
        serialnumber    [BUGS=X86-32]
 
        shapers=        [NET]
index b3a232cae7f8d2bf41683cc32f15840b87467335..200a2d37cbc8970e08ac3f2c2323ba066c4f3bdb 100644 (file)
@@ -3,8 +3,8 @@
 TOMOYO is a name-based MAC extension (LSM module) for the Linux kernel.
 
 LiveCD-based tutorials are available at
-http://tomoyo.sourceforge.jp/en/1.6.x/1st-step/ubuntu8.04-live/
-http://tomoyo.sourceforge.jp/en/1.6.x/1st-step/centos5-live/ .
+http://tomoyo.sourceforge.jp/1.7/1st-step/ubuntu10.04-live/
+http://tomoyo.sourceforge.jp/1.7/1st-step/centos5-live/ .
 Though these tutorials use non-LSM version of TOMOYO, they are useful for you
 to know what TOMOYO is.
 
@@ -13,12 +13,12 @@ to know what TOMOYO is.
 Build the kernel with CONFIG_SECURITY_TOMOYO=y and pass "security=tomoyo" on
 kernel's command line.
 
-Please see http://tomoyo.sourceforge.jp/en/2.2.x/ for details.
+Please see http://tomoyo.sourceforge.jp/2.3/ for details.
 
 --- Where is documentation? ---
 
 User <-> Kernel interface documentation is available at
-http://tomoyo.sourceforge.jp/en/2.2.x/policy-reference.html .
+http://tomoyo.sourceforge.jp/2.3/policy-reference.html .
 
 Materials we prepared for seminars and symposiums are available at
 http://sourceforge.jp/projects/tomoyo/docs/?category_id=532&language_id=1 .
@@ -50,6 +50,6 @@ multiple LSM modules at the same time. We feel sorry that you have to give up
 SELinux/SMACK/AppArmor etc. when you want to use TOMOYO.
 
 We hope that LSM becomes stackable in future. Meanwhile, you can use non-LSM
-version of TOMOYO, available at http://tomoyo.sourceforge.jp/en/1.6.x/ .
+version of TOMOYO, available at http://tomoyo.sourceforge.jp/1.7/ .
 LSM version of TOMOYO is a subset of non-LSM version of TOMOYO. We are planning
 to port non-LSM version's functionalities to LSM versions.
index 02f75fccac20915ae4c7aad6b333ed0061f90e44..33606bb91f1f77e27906475a7725c0f9df02e2ac 100644 (file)
@@ -5061,6 +5061,14 @@ S:       Supported
 F:     include/linux/selinux*
 F:     security/selinux/
 
+APPARMOR SECURITY MODULE
+M:     John Johansen <john.johansen@canonical.com>
+L:     apparmor@lists.ubuntu.com (subscribers-only, general discussion)
+W:     apparmor.wiki.kernel.org
+T:     git git://git.kernel.org/pub/scm/linux/kernel/git/jj/apparmor-dev.git
+S:     Supported
+F:     security/apparmor/
+
 SENSABLE PHANTOM
 M:     Jiri Slaby <jirislaby@gmail.com>
 S:     Maintained
@@ -5605,7 +5613,7 @@ L:        tomoyo-users-en@lists.sourceforge.jp (subscribers-only, for developers and us
 L:     tomoyo-dev@lists.sourceforge.jp (subscribers-only, for developers in Japanese)
 L:     tomoyo-users@lists.sourceforge.jp (subscribers-only, for users in Japanese)
 W:     http://tomoyo.sourceforge.jp/
-T:     quilt http://svn.sourceforge.jp/svnroot/tomoyo/trunk/2.2.x/tomoyo-lsm/patches/
+T:     quilt http://svn.sourceforge.jp/svnroot/tomoyo/trunk/2.3.x/tomoyo-lsm/patches/
 S:     Maintained
 F:     security/tomoyo/
 
index 98922f7d2d1236dd7fd29fa404447b46189c0222..e39caa8b0c93e323c9c1e2feda7bb90fd1a3a4a1 100644 (file)
@@ -10,6 +10,7 @@ config ARM
        default y
        select HAVE_AOUT
        select HAVE_IDE
+       select HAVE_MEMBLOCK
        select RTC_LIB
        select SYS_SUPPORTS_APM_EMULATION
        select GENERIC_ATOMIC64 if (!CPU_32v6K)
@@ -24,6 +25,7 @@ config ARM
        select HAVE_KERNEL_LZMA
        select HAVE_PERF_EVENTS
        select PERF_USE_VMALLOC
+       select HAVE_REGS_AND_STACK_ACCESS_API
        help
          The ARM series is a line of low-power-consumption RISC chip designs
          licensed by ARM Ltd and targeted at embedded applications and
@@ -55,7 +57,7 @@ config GENERIC_CLOCKEVENTS
 config GENERIC_CLOCKEVENTS_BROADCAST
        bool
        depends on GENERIC_CLOCKEVENTS
-       default y if SMP && !LOCAL_TIMERS
+       default y if SMP
 
 config HAVE_TCM
        bool
@@ -301,6 +303,7 @@ config ARCH_CNS3XXX
        select CPU_V6
        select GENERIC_CLOCKEVENTS
        select ARM_GIC
+       select PCI_DOMAINS if PCI
        help
          Support for Cavium Networks CNS3XXX platform.
 
@@ -439,21 +442,6 @@ config ARCH_IXP4XX
        help
          Support for Intel's IXP4XX (XScale) family of processors.
 
-config ARCH_L7200
-       bool "LinkUp-L7200"
-       select CPU_ARM720T
-       select FIQ
-       select ARCH_USES_GETTIMEOFFSET
-       help
-         Say Y here if you intend to run this kernel on a LinkUp Systems
-         L7200 Software Development Board which uses an ARM720T processor.
-         Information on this board can be obtained at:
-
-         <http://www.linkupsys.com/>
-
-         If you have any questions or comments about the Linux kernel port
-         to this board, send e-mail to <sjhill@cotw.com>.
-
 config ARCH_DOVE
        bool "Marvell Dove"
        select PCI
@@ -482,6 +470,19 @@ config ARCH_LOKI
        help
          Support for the Marvell Loki (88RC8480) SoC.
 
+config ARCH_LPC32XX
+       bool "NXP LPC32XX"
+       select CPU_ARM926T
+       select ARCH_REQUIRE_GPIOLIB
+       select HAVE_IDE
+       select ARM_AMBA
+       select USB_ARCH_HAS_OHCI
+       select COMMON_CLKDEV
+       select GENERIC_TIME
+       select GENERIC_CLOCKEVENTS
+       help
+         Support for the NXP LPC32XX family of processors
+
 config ARCH_MV78XX0
        bool "Marvell MV78xx0"
        select CPU_FEROCEON
@@ -586,6 +587,7 @@ config ARCH_MSM
        bool "Qualcomm MSM"
        select HAVE_CLK
        select GENERIC_CLOCKEVENTS
+       select ARCH_REQUIRE_GPIOLIB
        help
          Support for Qualcomm MSM/QSD based systems.  This runs on the
          apps processor of the MSM/QSD and depends on a shared memory
@@ -719,7 +721,6 @@ config ARCH_SHARK
 config ARCH_LH7A40X
        bool "Sharp LH7A40X"
        select CPU_ARM922T
-       select ARCH_DISCONTIGMEM_ENABLE if !LH7A40X_CONTIGMEM
        select ARCH_SPARSEMEM_ENABLE if !LH7A40X_CONTIGMEM
        select ARCH_USES_GETTIMEOFFSET
        help
@@ -845,6 +846,8 @@ source "arch/arm/mach-lh7a40x/Kconfig"
 
 source "arch/arm/mach-loki/Kconfig"
 
+source "arch/arm/mach-lpc32xx/Kconfig"
+
 source "arch/arm/mach-msm/Kconfig"
 
 source "arch/arm/mach-mv78xx0/Kconfig"
@@ -1031,11 +1034,6 @@ endmenu
 
 source "arch/arm/common/Kconfig"
 
-config FORCE_MAX_ZONEORDER
-       int
-       depends on SA1111
-       default "9"
-
 menu "Bus support"
 
 config ARM_AMBA
@@ -1060,7 +1058,7 @@ config ISA_DMA_API
        bool
 
 config PCI
-       bool "PCI support" if ARCH_INTEGRATOR_AP || ARCH_VERSATILE_PB || ARCH_IXP4XX || ARCH_KS8695 || MACH_ARMCORE
+       bool "PCI support" if ARCH_INTEGRATOR_AP || ARCH_VERSATILE_PB || ARCH_IXP4XX || ARCH_KS8695 || MACH_ARMCORE || ARCH_CNS3XXX
        help
          Find out whether you have a PCI motherboard. PCI is the name of a
          bus system, i.e. the way the CPU talks to the other stuff inside
@@ -1172,9 +1170,10 @@ config HOTPLUG_CPU
 config LOCAL_TIMERS
        bool "Use local timer interrupts"
        depends on SMP && (REALVIEW_EB_ARM11MP || MACH_REALVIEW_PB11MP || \
-               REALVIEW_EB_A9MP || MACH_REALVIEW_PBX || ARCH_OMAP4 || ARCH_U8500)
+               REALVIEW_EB_A9MP || MACH_REALVIEW_PBX || ARCH_OMAP4 || \
+               ARCH_U8500 || ARCH_VEXPRESS_CA9X4)
        default y
-       select HAVE_ARM_TWD if (ARCH_REALVIEW || ARCH_OMAP4 || ARCH_U8500)
+       select HAVE_ARM_TWD if (ARCH_REALVIEW || ARCH_VEXPRESS || ARCH_OMAP4 || ARCH_U8500)
        help
          Enable support for local timers on SMP platforms, rather then the
          legacy IPI broadcast method.  Local timers allows the system
@@ -1185,10 +1184,10 @@ source kernel/Kconfig.preempt
 
 config HZ
        int
-       default 128 if ARCH_L7200
        default 200 if ARCH_EBSA110 || ARCH_S3C2410 || ARCH_S5P6440 || ARCH_S5P6442 || ARCH_S5PV210
        default OMAP_32K_TIMER_HZ if ARCH_OMAP && OMAP_32K_TIMER
        default AT91_TIMER_HZ if ARCH_AT91
+       default SHMOBILE_TIMER_HZ if ARCH_SHMOBILE
        default 100
 
 config THUMB2_KERNEL
@@ -1241,10 +1240,6 @@ config OABI_COMPAT
 config ARCH_HAS_HOLES_MEMORYMODEL
        bool
 
-# Discontigmem is deprecated
-config ARCH_DISCONTIGMEM_ENABLE
-       bool
-
 config ARCH_SPARSEMEM_ENABLE
        bool
 
@@ -1252,13 +1247,7 @@ config ARCH_SPARSEMEM_DEFAULT
        def_bool ARCH_SPARSEMEM_ENABLE
 
 config ARCH_SELECT_MEMORY_MODEL
-       def_bool ARCH_DISCONTIGMEM_ENABLE && ARCH_SPARSEMEM_ENABLE
-
-config NODES_SHIFT
-       int
-       default "4" if ARCH_LH7A40X
-       default "2"
-       depends on NEED_MULTIPLE_NODES
+       def_bool ARCH_SPARSEMEM_ENABLE
 
 config HIGHMEM
        bool "High Memory Support (EXPERIMENTAL)"
@@ -1290,8 +1279,33 @@ config HW_PERF_EVENTS
          Enable hardware performance counter support for perf events. If
          disabled, perf events will use software events only.
 
+config SPARSE_IRQ
+       def_bool n
+       help
+         This enables support for sparse irqs. This is useful in general
+         as most CPUs have a fairly sparse array of IRQ vectors, which
+         the irq_desc then maps directly on to. Systems with a high
+         number of off-chip IRQs will want to treat this as
+         experimental until they have been independently verified.
+
 source "mm/Kconfig"
 
+config FORCE_MAX_ZONEORDER
+       int "Maximum zone order" if ARCH_SHMOBILE
+       range 11 64 if ARCH_SHMOBILE
+       default "9" if SA1111
+       default "11"
+       help
+         The kernel memory allocator divides physically contiguous memory
+         blocks into "zones", where each zone is a power of two number of
+         pages.  This option selects the largest power of two that the kernel
+         keeps in the memory allocator.  If you need to allocate very large
+         blocks of physically contiguous memory, then you may need to
+         increase this value.
+
+         This config option is actually maximum order plus one. For example,
+         a value of 11 means that the largest free memory block is 2^10 pages.
+
 config LEDS
        bool "Timer and CPU usage LEDs"
        depends on ARCH_CDB89712 || ARCH_EBSA110 || \
@@ -1375,6 +1389,24 @@ config UACCESS_WITH_MEMCPY
          However, if the CPU data cache is using a write-allocate mode,
          this option is unlikely to provide any performance gain.
 
+config CC_STACKPROTECTOR
+       bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
+       help
+         This option turns on the -fstack-protector GCC feature. This
+         feature puts, at the beginning of functions, a canary value on
+         the stack just before the return address, and validates
+         the value just before actually returning.  Stack based buffer
+         overflows (that need to overwrite this return address) now also
+         overwrite the canary, which gets detected and the attack is then
+         neutralized via a kernel panic.
+         This feature requires gcc version 4.2 or above.
+
+config DEPRECATED_PARAM_STRUCT
+       bool "Provide old way to pass kernel parameters"
+       help
+         This was deprecated in 2001 and announced to live on for 5 years.
+         Some old boot loaders still use this way.
+
 endmenu
 
 menu "Boot options"
@@ -1485,6 +1517,105 @@ config ATAGS_PROC
          Should the atags used to boot the kernel be exported in an "atags"
          file in procfs. Useful with kexec.
 
+config AUTO_ZRELADDR
+       bool "Auto calculation of the decompressed kernel image address"
+       depends on !ZBOOT_ROM && !ARCH_U300
+       help
+         ZRELADDR is the physical address where the decompressed kernel
+         image will be placed. If AUTO_ZRELADDR is selected, the address
+         will be determined at run-time by masking the current IP with
+         0xf8000000. This assumes the zImage being placed in the first 128MB
+         from start of memory.
+
+config ZRELADDR
+       hex "Physical address of the decompressed kernel image"
+       depends on !AUTO_ZRELADDR
+       default 0x00008000 if ARCH_BCMRING ||\
+               ARCH_CNS3XXX ||\
+               ARCH_DOVE ||\
+               ARCH_EBSA110 ||\
+               ARCH_FOOTBRIDGE ||\
+               ARCH_INTEGRATOR ||\
+               ARCH_IOP13XX ||\
+               ARCH_IOP33X ||\
+               ARCH_IXP2000 ||\
+               ARCH_IXP23XX ||\
+               ARCH_IXP4XX ||\
+               ARCH_KIRKWOOD ||\
+               ARCH_KS8695 ||\
+               ARCH_LOKI ||\
+               ARCH_MMP ||\
+               ARCH_MV78XX0 ||\
+               ARCH_NOMADIK ||\
+               ARCH_NUC93X ||\
+               ARCH_NS9XXX ||\
+               ARCH_ORION5X ||\
+               ARCH_SPEAR3XX ||\
+               ARCH_SPEAR6XX ||\
+               ARCH_U8500 ||\
+               ARCH_VERSATILE ||\
+               ARCH_W90X900
+       default 0x08008000 if ARCH_MX1 ||\
+               ARCH_SHARK
+       default 0x10008000 if ARCH_MSM ||\
+               ARCH_OMAP1 ||\
+               ARCH_RPC
+       default 0x20008000 if ARCH_S5P6440 ||\
+               ARCH_S5P6442 ||\
+               ARCH_S5PC100 ||\
+               ARCH_S5PV210
+       default 0x30008000 if ARCH_S3C2410 ||\
+               ARCH_S3C2400 ||\
+               ARCH_S3C2412 ||\
+               ARCH_S3C2416 ||\
+               ARCH_S3C2440 ||\
+               ARCH_S3C2443
+       default 0x40008000 if ARCH_STMP378X ||\
+               ARCH_STMP37XX ||\
+               ARCH_SH7372 ||\
+               ARCH_SH7377
+       default 0x50008000 if ARCH_S3C64XX ||\
+               ARCH_SH7367
+       default 0x60008000 if ARCH_VEXPRESS
+       default 0x80008000 if ARCH_MX25 ||\
+               ARCH_MX3 ||\
+               ARCH_NETX ||\
+               ARCH_OMAP2PLUS ||\
+               ARCH_PNX4008
+       default 0x90008000 if ARCH_MX5 ||\
+               ARCH_MX91231
+       default 0xa0008000 if ARCH_IOP32X ||\
+               ARCH_PXA ||\
+               MACH_MX27
+       default 0xc0008000 if ARCH_LH7A40X ||\
+               MACH_MX21
+       default 0xf0008000 if ARCH_AAEC2000 ||\
+               ARCH_L7200
+       default 0xc0028000 if ARCH_CLPS711X
+       default 0x70008000 if ARCH_AT91 && (ARCH_AT91CAP9 || ARCH_AT91SAM9G45)
+       default 0x20008000 if ARCH_AT91 && !(ARCH_AT91CAP9 || ARCH_AT91SAM9G45)
+       default 0xc0008000 if ARCH_DAVINCI && ARCH_DAVINCI_DA8XX
+       default 0x80008000 if ARCH_DAVINCI && !ARCH_DAVINCI_DA8XX
+       default 0x00008000 if ARCH_EP93XX && EP93XX_SDCE3_SYNC_PHYS_OFFSET
+       default 0xc0008000 if ARCH_EP93XX && EP93XX_SDCE0_PHYS_OFFSET
+       default 0xd0008000 if ARCH_EP93XX && EP93XX_SDCE1_PHYS_OFFSET
+       default 0xe0008000 if ARCH_EP93XX && EP93XX_SDCE2_PHYS_OFFSET
+       default 0xf0008000 if ARCH_EP93XX && EP93XX_SDCE3_ASYNC_PHYS_OFFSET
+       default 0x00008000 if ARCH_GEMINI && GEMINI_MEM_SWAP
+       default 0x10008000 if ARCH_GEMINI && !GEMINI_MEM_SWAP
+       default 0x70008000 if ARCH_REALVIEW && REALVIEW_HIGH_PHYS_OFFSET
+       default 0x00008000 if ARCH_REALVIEW && !REALVIEW_HIGH_PHYS_OFFSET
+       default 0xc0208000 if ARCH_SA1100 && SA1111
+       default 0xc0008000 if ARCH_SA1100 && !SA1111
+       default 0x30108000 if ARCH_S3C2410 && PM_H1940
+       default 0x28E08000 if ARCH_U300 && MACH_U300_SINGLE_RAM
+       default 0x48008000 if ARCH_U300 && !MACH_U300_SINGLE_RAM
+       help
+         ZRELADDR is the physical address where the decompressed kernel
+         image will be placed. ZRELADDR has to be specified when the
+         assumption of AUTO_ZRELADDR is not valid, or when ZBOOT_ROM is
+         selected.
+
 endmenu
 
 menu "CPU Power Management"
index 64ba313724d2377fda7e439e130d7ad69dd1a83c..63d998e8c672ef4488eb72df2cfdcce2f7ae502f 100644 (file)
@@ -34,6 +34,10 @@ ifeq ($(CONFIG_FRAME_POINTER),y)
 KBUILD_CFLAGS  +=-fno-omit-frame-pointer -mapcs -mno-sched-prolog
 endif
 
+ifeq ($(CONFIG_CC_STACKPROTECTOR),y)
+KBUILD_CFLAGS  +=-fstack-protector
+endif
+
 ifeq ($(CONFIG_CPU_BIG_ENDIAN),y)
 KBUILD_CPPFLAGS        += -mbig-endian
 AS             += -EB
@@ -139,14 +143,14 @@ machine-$(CONFIG_ARCH_IXP23XX)            := ixp23xx
 machine-$(CONFIG_ARCH_IXP4XX)          := ixp4xx
 machine-$(CONFIG_ARCH_KIRKWOOD)                := kirkwood
 machine-$(CONFIG_ARCH_KS8695)          := ks8695
-machine-$(CONFIG_ARCH_L7200)           := l7200
 machine-$(CONFIG_ARCH_LH7A40X)         := lh7a40x
 machine-$(CONFIG_ARCH_LOKI)            := loki
+machine-$(CONFIG_ARCH_LPC32XX)         := lpc32xx
 machine-$(CONFIG_ARCH_MMP)             := mmp
 machine-$(CONFIG_ARCH_MSM)             := msm
 machine-$(CONFIG_ARCH_MV78XX0)         := mv78xx0
-machine-$(CONFIG_ARCH_MX1)             := mx1
-machine-$(CONFIG_ARCH_MX2)             := mx2
+machine-$(CONFIG_ARCH_MX1)             := imx
+machine-$(CONFIG_ARCH_MX2)             := imx
 machine-$(CONFIG_ARCH_MX25)            := mx25
 machine-$(CONFIG_ARCH_MX3)             := mx3
 machine-$(CONFIG_ARCH_MX5)             := mx5
index 4a590f4113e2af044ea1764aeb0681ad7f50a74c..f705213caa881af9c07e181c0d2a3a1a26a5d98a 100644 (file)
 MKIMAGE         := $(srctree)/scripts/mkuboot.sh
 
 ifneq ($(MACHINE),)
-include $(srctree)/$(MACHINE)/Makefile.boot
+-include $(srctree)/$(MACHINE)/Makefile.boot
 endif
 
 # Note: the following conditions must always be true:
-#   ZRELADDR == virt_to_phys(PAGE_OFFSET + TEXT_OFFSET)
 #   PARAMS_PHYS must be within 4MB of ZRELADDR
 #   INITRD_PHYS must be in RAM
-ZRELADDR    := $(zreladdr-y)
 PARAMS_PHYS := $(params_phys-y)
 INITRD_PHYS := $(initrd_phys-y)
 
-export ZRELADDR INITRD_PHYS PARAMS_PHYS
+export INITRD_PHYS PARAMS_PHYS
 
 targets := Image zImage xipImage bootpImage uImage
 
@@ -67,7 +65,7 @@ quiet_cmd_uimage = UIMAGE  $@
 ifeq ($(CONFIG_ZBOOT_ROM),y)
 $(obj)/uImage: LOADADDR=$(CONFIG_ZBOOT_ROM_TEXT)
 else
-$(obj)/uImage: LOADADDR=$(ZRELADDR)
+$(obj)/uImage: LOADADDR=$(CONFIG_ZRELADDR)
 endif
 
 ifeq ($(CONFIG_THUMB2_KERNEL),y)
index 864a002137fed0bbc42efe7b4f2dc787a06ba48a..7636c9b3f9a7899f9209d9a82fa78de8a6dc9b17 100644 (file)
@@ -4,6 +4,7 @@
 # create a compressed vmlinuz image from the original vmlinux
 #
 
+AFLAGS_head.o += -DTEXT_OFFSET=$(TEXT_OFFSET)
 HEAD   = head.o
 OBJS   = misc.o decompress.o
 FONTC  = $(srctree)/drivers/video/console/font_acorn_8x8.c
@@ -19,10 +20,6 @@ ifeq ($(CONFIG_ARCH_SHARK),y)
 OBJS           += head-shark.o ofw-shark.o
 endif
 
-ifeq ($(CONFIG_ARCH_L7200),y)
-OBJS           += head-l7200.o
-endif
-
 ifeq ($(CONFIG_ARCH_P720T),y)
 # Borrow this code from SA1100
 OBJS           += head-sa1100.o
@@ -82,19 +79,9 @@ endif
 EXTRA_CFLAGS  := -fpic -fno-builtin
 EXTRA_AFLAGS  := -Wa,-march=all
 
-# Supply ZRELADDR, INITRD_PHYS and PARAMS_PHYS to the decompressor via
-# linker symbols.  We only define initrd_phys and params_phys if the
-# machine class defined the corresponding makefile variable.
-LDFLAGS_vmlinux := --defsym zreladdr=$(ZRELADDR)
 ifeq ($(CONFIG_CPU_ENDIAN_BE8),y)
 LDFLAGS_vmlinux += --be8
 endif
-ifneq ($(INITRD_PHYS),)
-LDFLAGS_vmlinux += --defsym initrd_phys=$(INITRD_PHYS)
-endif
-ifneq ($(PARAMS_PHYS),)
-LDFLAGS_vmlinux += --defsym params_phys=$(PARAMS_PHYS)
-endif
 # ?
 LDFLAGS_vmlinux += -p
 # Report unresolved symbol references
diff --git a/arch/arm/boot/compressed/Makefile.debug b/arch/arm/boot/compressed/Makefile.debug
deleted file mode 100644 (file)
index 491a037..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-#
-# linux/arch/arm/boot/compressed/Makefile
-#
-# create a compressed vmlinux image from the original vmlinux
-#
-
-COMPRESSED_EXTRA=../../lib/ll_char_wr.o
-OBJECTS=misc-debug.o ll_char_wr.aout.o
-
-CFLAGS=-D__KERNEL__ -O2 -DSTDC_HEADERS -DSTANDALONE_DEBUG -Wall -I../../../../include -c
-
-test-gzip: piggy.aout.o $(OBJECTS)
-       $(CC) -o $@ $(OBJECTS) piggy.aout.o
-
-misc-debug.o: misc.c
-       $(CC) $(CFLAGS) -o $@ misc.c
-
-piggy.aout.o: piggy.o
-       arm-linuxelf-objcopy --change-leading-char -I elf32-arm -O arm-aout32-linux piggy.o piggy.aout.o
-
-ll_char_wr.aout.o: $(COMPRESSED_EXTRA)
-       arm-linuxelf-objcopy --change-leading-char -I elf32-arm -O arm-aout32-linux $(COMPRESSED_EXTRA) ll_char_wr.aout.o
-
diff --git a/arch/arm/boot/compressed/head-l7200.S b/arch/arm/boot/compressed/head-l7200.S
deleted file mode 100644 (file)
index d0e3b20..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/* 
- * linux/arch/arm/boot/compressed/head-l7200.S
- * 
- * Copyright (C) 2000 Steve Hill <sjhill@cotw.com>
- * 
- * Some code borrowed from Nicolas Pitre's 'head-sa1100.S' file. This
- * is merged with head.S by the linker.
- */
-
-#include <asm/mach-types.h>
-
-#ifndef CONFIG_ARCH_L7200
-#error What am I doing here...
-#endif
-
-               .section        ".start", "ax"
-
-__L7200_start:
-               mov     r0, #0x00100000         @ FLASH address of initrd
-               mov     r2, #0xf1000000         @ RAM address of initrd
-               add     r3, r2, #0x00700000     @ Size of initrd 
-1:
-               ldmia   r0!, {r4, r5, r6, r7}
-               stmia   r2!, {r4, r5, r6, r7}
-               cmp     r2, r3
-               ble     1b
-
-               mov     r8, #0                  @ Zero it out
-               mov     r7, #MACH_TYPE_L7200    @ Set architecture ID
index c5191b1532e8284cbeac17cef819522863a90743..abf4d65acf6243de88d3a0df342afabce87436e2 100644 (file)
@@ -170,9 +170,16 @@ not_angel:
 
                .text
                adr     r0, LC0
- ARM(          ldmia   r0, {r1, r2, r3, r4, r5, r6, r11, ip, sp})
- THUMB(                ldmia   r0, {r1, r2, r3, r4, r5, r6, r11, ip}   )
+ ARM(          ldmia   r0, {r1, r2, r3, r5, r6, r11, ip, sp})
+ THUMB(                ldmia   r0, {r1, r2, r3, r5, r6, r11, ip}       )
  THUMB(                ldr     sp, [r0, #32]                           )
+#ifdef CONFIG_AUTO_ZRELADDR
+               @ determine final kernel image address
+               and     r4, pc, #0xf8000000
+               add     r4, r4, #TEXT_OFFSET
+#else
+               ldr     r4, =CONFIG_ZRELADDR
+#endif
                subs    r0, r0, r1              @ calculate the delta offset
 
                                                @ if delta is zero, we are
@@ -310,18 +317,17 @@ wont_overwrite:   mov     r0, r4
 LC0:           .word   LC0                     @ r1
                .word   __bss_start             @ r2
                .word   _end                    @ r3
-               .word   zreladdr                @ r4
                .word   _start                  @ r5
                .word   _image_size             @ r6
                .word   _got_start              @ r11
                .word   _got_end                @ ip
-               .word   user_stack+4096         @ sp
+               .word   user_stack_end          @ sp
 LC1:           .word   reloc_end - reloc_start
                .size   LC0, . - LC0
 
 #ifdef CONFIG_ARCH_RPC
                .globl  params
-params:                ldr     r0, =params_phys
+params:                ldr     r0, =0x10000100         @ params_phys for RPC
                mov     pc, lr
                .ltorg
                .align
@@ -339,9 +345,8 @@ params:             ldr     r0, =params_phys
  *  r4 = kernel execution address
  *  r7 = architecture number
  *  r8 = atags pointer
- *  r9 = run-time address of "start"  (???)
  * On exit,
- *  r1, r2, r3, r9, r10, r12 corrupted
+ *  r0, r1, r2, r3, r9, r10, r12 corrupted
  * This routine must preserve:
  *  r4, r5, r6, r7, r8
  */
@@ -396,12 +401,18 @@ __armv3_mpu_cache_on:
 
                mov     r0, #0
                mcr     p15, 0, r0, c7, c0, 0   @ invalidate whole cache v3
+               /*
+                * ?? ARMv3 MMU does not allow reading the control register,
+                * does this really work on ARMv3 MPU?
+                */
                mrc     p15, 0, r0, c1, c0, 0   @ read control reg
                                                @ .... .... .... WC.M
                orr     r0, r0, #0x000d         @ .... .... .... 11.1
+               /* ?? this overwrites the value constructed above? */
                mov     r0, #0
                mcr     p15, 0, r0, c1, c0, 0   @ write control reg
 
+               /* ?? invalidate for the second time? */
                mcr     p15, 0, r0, c7, c0, 0   @ invalidate whole cache v3
                mov     pc, lr
 
@@ -771,8 +782,10 @@ proc_types:
  * Turn off the Cache and MMU.  ARMv3 does not support
  * reading the control register, but ARMv4 does.
  *
- * On exit, r0, r1, r2, r3, r9, r12 corrupted
- * This routine must preserve: r4, r6, r7
+ * On exit,
+ *  r0, r1, r2, r3, r9, r12 corrupted
+ * This routine must preserve:
+ *  r4, r6, r7
  */
                .align  5
 cache_off:     mov     r3, #12                 @ cache_off function
@@ -845,7 +858,7 @@ __armv3_mmu_cache_off:
  * Clean and flush the cache to maintain consistency.
  *
  * On exit,
- *  r1, r2, r3, r9, r11, r12 corrupted
+ *  r1, r2, r3, r9, r10, r11, r12 corrupted
  * This routine must preserve:
  *  r0, r4, r5, r6, r7
  */
@@ -988,7 +1001,7 @@ no_cache_id:
 __armv3_mmu_cache_flush:
 __armv3_mpu_cache_flush:
                mov     r1, #0
-               mcr     p15, 0, r0, c7, c0, 0   @ invalidate whole cache v3
+               mcr     p15, 0, r1, c7, c0, 0   @ invalidate whole cache v3
                mov     pc, lr
 
 /*
@@ -1001,6 +1014,7 @@ __armv3_mpu_cache_flush:
 phexbuf:       .space  12
                .size   phexbuf, . - phexbuf
 
+@ phex corrupts {r0, r1, r2, r3}
 phex:          adr     r3, phexbuf
                mov     r2, #0
                strb    r2, [r3, r1]
@@ -1015,6 +1029,7 @@ phex:             adr     r3, phexbuf
                strb    r2, [r3, r1]
                b       1b
 
+@ puts corrupts {r0, r1, r2, r3}
 puts:          loadsp  r3, r1
 1:             ldrb    r2, [r0], #1
                teq     r2, #0
@@ -1029,12 +1044,14 @@ puts:           loadsp  r3, r1
                teq     r0, #0
                bne     1b
                mov     pc, lr
+@ putc corrupts {r0, r1, r2, r3}
 putc:
                mov     r2, r0
                mov     r0, #0
                loadsp  r3, r1
                b       2b
 
+@ memdump corrupts {r0, r1, r2, r3, r10, r11, r12, lr}
 memdump:       mov     r12, r0
                mov     r10, lr
                mov     r11, #0
@@ -1070,3 +1087,4 @@ reloc_end:
                .align
                .section ".stack", "w"
 user_stack:    .space  4096
+user_stack_end:
index d2b2ef41cd4ff7ac32bf91e4e947cc57993cbb2d..e653a6d3c8d90dae62ee3da745bfce67c34d27fb 100644 (file)
@@ -28,9 +28,6 @@ unsigned int __machine_arch_type;
 
 #include <asm/unaligned.h>
 
-#ifdef STANDALONE_DEBUG
-#define putstr printf
-#else
 
 static void putstr(const char *ptr);
 extern void error(char *x);
@@ -116,7 +113,6 @@ static void putstr(const char *ptr)
        flush();
 }
 
-#endif
 
 void *memcpy(void *__dest, __const void *__src, size_t __n)
 {
@@ -186,7 +182,6 @@ asmlinkage void __div0(void)
 
 extern void do_decompress(u8 *input, int len, u8 *output, void (*error)(char *x));
 
-#ifndef STANDALONE_DEBUG
 
 unsigned long
 decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
@@ -211,18 +206,3 @@ decompress_kernel(unsigned long output_start, unsigned long free_mem_ptr_p,
        putstr(" done, booting the kernel.\n");
        return output_ptr;
 }
-#else
-
-char output_buffer[1500*1024];
-
-int main()
-{
-       output_data = output_buffer;
-
-       putstr("Uncompressing Linux...");
-       decompress(input_data, input_data_end - input_data,
-                       NULL, NULL, output_data, NULL, error);
-       putstr("done.\n");
-       return 0;
-}
-#endif
index 337741f734ac08d7f438e5d6240293adf3c5c366..7dfa9a85bc0c875b11567025f68e92bd768d7419 100644 (file)
@@ -108,6 +108,51 @@ static void gic_unmask_irq(unsigned int irq)
        spin_unlock(&irq_controller_lock);
 }
 
+static int gic_set_type(unsigned int irq, unsigned int type)
+{
+       void __iomem *base = gic_dist_base(irq);
+       unsigned int gicirq = gic_irq(irq);
+       u32 enablemask = 1 << (gicirq % 32);
+       u32 enableoff = (gicirq / 32) * 4;
+       u32 confmask = 0x2 << ((gicirq % 16) * 2);
+       u32 confoff = (gicirq / 16) * 4;
+       bool enabled = false;
+       u32 val;
+
+       /* Interrupt configuration for SGIs can't be changed */
+       if (gicirq < 16)
+               return -EINVAL;
+
+       if (type != IRQ_TYPE_LEVEL_HIGH && type != IRQ_TYPE_EDGE_RISING)
+               return -EINVAL;
+
+       spin_lock(&irq_controller_lock);
+
+       val = readl(base + GIC_DIST_CONFIG + confoff);
+       if (type == IRQ_TYPE_LEVEL_HIGH)
+               val &= ~confmask;
+       else if (type == IRQ_TYPE_EDGE_RISING)
+               val |= confmask;
+
+       /*
+        * As recommended by the spec, disable the interrupt before changing
+        * the configuration
+        */
+       if (readl(base + GIC_DIST_ENABLE_SET + enableoff) & enablemask) {
+               writel(enablemask, base + GIC_DIST_ENABLE_CLEAR + enableoff);
+               enabled = true;
+       }
+
+       writel(val, base + GIC_DIST_CONFIG + confoff);
+
+       if (enabled)
+               writel(enablemask, base + GIC_DIST_ENABLE_SET + enableoff);
+
+       spin_unlock(&irq_controller_lock);
+
+       return 0;
+}
+
 #ifdef CONFIG_SMP
 static int gic_set_cpu(unsigned int irq, const struct cpumask *mask_val)
 {
@@ -161,6 +206,7 @@ static struct irq_chip gic_chip = {
        .ack            = gic_ack_irq,
        .mask           = gic_mask_irq,
        .unmask         = gic_unmask_irq,
+       .set_type       = gic_set_type,
 #ifdef CONFIG_SMP
        .set_affinity   = gic_set_cpu,
 #endif
index 9eaf65f43642e6886b3ab4bae43e7821aad285b6..517d50ddbeb3153d102e426fc915405bae76012b 100644 (file)
@@ -185,13 +185,10 @@ static struct sa1111_dev_info sa1111_devices[] = {
        },
 };
 
-void __init sa1111_adjust_zones(int node, unsigned long *size, unsigned long *holes)
+void __init sa1111_adjust_zones(unsigned long *size, unsigned long *holes)
 {
        unsigned int sz = SZ_1M >> PAGE_SHIFT;
 
-       if (node != 0)
-               sz = 0;
-
        size[1] = size[0] - sz;
        size[0] = sz;
 }
index f2e3a9088df6d43880779071e30dff09f695f37d..ccc9c9959b82baf75d0faa04769a85e79ac23d51 100644 (file)
@@ -13,11 +13,19 @@ CONFIG_MACH_RD88F6192_NAS=y
 CONFIG_MACH_RD88F6281=y
 CONFIG_MACH_MV88F6281GTW_GE=y
 CONFIG_MACH_SHEEVAPLUG=y
+CONFIG_MACH_ESATA_SHEEVAPLUG=y
+CONFIG_MACH_GURUPLUG=y
 CONFIG_MACH_TS219=y
 CONFIG_MACH_TS41X=y
 CONFIG_MACH_OPENRD_BASE=y
 CONFIG_MACH_OPENRD_CLIENT=y
+CONFIG_MACH_OPENRD_ULTIMATE=y
 CONFIG_MACH_NETSPACE_V2=y
+CONFIG_MACH_INETSPACE_V2=y
+CONFIG_MACH_NETSPACE_MAX_V2=y
+CONFIG_MACH_NET2BIG_V2=y
+CONFIG_MACH_NET5BIG_V2=y
+CONFIG_MACH_T5325=y
 # CONFIG_CPU_FEROCEON_OLD_ID is not set
 CONFIG_NO_HZ=y
 CONFIG_HIGH_RES_TIMERS=y
diff --git a/arch/arm/configs/lusl7200_defconfig b/arch/arm/configs/lusl7200_defconfig
deleted file mode 100644 (file)
index 816fc42..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-CONFIG_EXPERIMENTAL=y
-CONFIG_SYSVIPC=y
-CONFIG_BSD_PROCESS_ACCT=y
-CONFIG_LOG_BUF_SHIFT=14
-CONFIG_BLK_DEV_INITRD=y
-CONFIG_EMBEDDED=y
-# CONFIG_HOTPLUG is not set
-CONFIG_MODULES=y
-CONFIG_ARCH_L7200=y
-# CONFIG_ARM_THUMB is not set
-CONFIG_ZBOOT_ROM_TEXT=0x00010000
-CONFIG_ZBOOT_ROM_BSS=0xf03e0000
-CONFIG_ZBOOT_ROM=y
-CONFIG_CMDLINE="console=tty0 console=ttyLU1,115200 root=/dev/ram initrd=0xf1000000,0x005dac7b mem=32M"
-CONFIG_BINFMT_AOUT=y
-CONFIG_BLK_DEV_RAM=y
-# CONFIG_INPUT is not set
-# CONFIG_SERIO_SERPORT is not set
-# CONFIG_VT is not set
-CONFIG_SERIAL_NONSTANDARD=y
-CONFIG_EXT2_FS=y
-CONFIG_DEBUG_USER=y
-# CONFIG_CRC32 is not set
index 51662feb9f1dd03b8e1c8a3f7d208c063208aa89..6750b8e45a4914a59f6ef6cbbcb0cc84efe0ead0 100644 (file)
@@ -121,4 +121,8 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
 extern void elf_set_personality(const struct elf32_hdr *);
 #define SET_PERSONALITY(ex)    elf_set_personality(&(ex))
 
+struct mm_struct;
+extern unsigned long arch_randomize_brk(struct mm_struct *mm);
+#define arch_randomize_brk arch_randomize_brk
+
 #endif
index f7bd52b1c3654430351a5b7c5f2665e527979908..c1062c317103f706b9b2209fe8a5146c9ea4e7bf 100644 (file)
@@ -19,6 +19,7 @@
 #define HWCAP_NEON     4096
 #define HWCAP_VFPv3    8192
 #define HWCAP_VFPv3D16 16384
+#define HWCAP_TLS      32768
 
 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
 /*
index 237282f7c762f3056b2ce76ab1a0e18d75a1499c..2721a5814cb93b56e0583722df184440c9497532 100644 (file)
@@ -7,6 +7,8 @@
 #define irq_canonicalize(i)    (i)
 #endif
 
+#define NR_IRQS_LEGACY 16
+
 /*
  * Use this value to indicate lack of interrupt
  * capability
index df15a0dc228e23da027667d3a992658daadf2305..8ec9ef5c3c7be25a2705451e8aab0a8205a47e67 100644 (file)
 
 #ifndef __ASSEMBLY__
 
-struct kimage;
-/* Provide a dummy definition to avoid build failures. */
+/**
+ * crash_setup_regs() - save registers for the panic kernel
+ * @newregs: registers are saved here
+ * @oldregs: registers to be saved (may be %NULL)
+ *
+ * Function copies machine registers from @oldregs to @newregs. If @oldregs is
+ * %NULL then current registers are stored there.
+ */
 static inline void crash_setup_regs(struct pt_regs *newregs,
-                                        struct pt_regs *oldregs) { }
+                                   struct pt_regs *oldregs)
+{
+       if (oldregs) {
+               memcpy(newregs, oldregs, sizeof(*newregs));
+       } else {
+               __asm__ __volatile__ ("stmia %0, {r0 - r15}"
+                                     : : "r" (&newregs->ARM_r0));
+               __asm__ __volatile__ ("mrs %0, cpsr"
+                                     : "=r" (newregs->ARM_cpsr));
+       }
+}
 
 #endif /* __ASSEMBLY__ */
 
index c59842dc7cb8d8f2b3a3e140d3a17d8da575efe0..8a0dd18ba6427301ed4b802739a390dec64d12c2 100644 (file)
@@ -20,6 +20,7 @@ struct machine_desc {
         * by assembler code in head.S, head-common.S
         */
        unsigned int            nr;             /* architecture number  */
+       unsigned int            nr_irqs;        /* number of IRQs */
        unsigned int            phys_io;        /* start of physical io */
        unsigned int            io_pg_offst;    /* byte offset for io 
                                                 * page tabe entry      */
@@ -37,6 +38,7 @@ struct machine_desc {
        void                    (*fixup)(struct machine_desc *,
                                         struct tag *, char **,
                                         struct meminfo *);
+       void                    (*reserve)(void);/* reserve mem blocks  */
        void                    (*map_io)(void);/* IO mapping function  */
        void                    (*init_irq)(void);
        struct sys_timer        *timer;         /* system tick timer    */
index 8920b2d6e3b850634c501abe7f1512c6eea4a46f..ce3eee9fe26cbb055cbea6ab0d5567af4964b29a 100644 (file)
@@ -17,6 +17,7 @@ struct seq_file;
 /*
  * This is internal.  Do not use it.
  */
+extern unsigned int arch_nr_irqs;
 extern void (*init_arch_irq)(void);
 extern void init_FIQ(void);
 extern int show_fiq_list(struct seq_file *, void *);
index 742c2aaeb02031d4d4e77dbf11e653910887343b..d2fedb5aeb1f381d74dbdfd29516fbbfd0ea4e13 100644 (file)
@@ -27,6 +27,8 @@ struct map_desc {
 #define MT_MEMORY              9
 #define MT_ROM                 10
 #define MT_MEMORY_NONCACHED    11
+#define MT_MEMORY_DTCM         12
+#define MT_MEMORY_ITCM         13
 
 #ifdef CONFIG_MMU
 extern void iotable_init(struct map_desc *, int);
index 52f0da1e97df28765c3dfe8a618a896727d5ec1b..16330bd0657cb172f5ff2d736ceb78c22dbdc23b 100644 (file)
@@ -46,6 +46,7 @@ struct pci_sys_data {
                                        /* IRQ mapping                          */
        int             (*map_irq)(struct pci_dev *, u8, u8);
        struct hw_pci   *hw;
+       void            *private_data;  /* platform controller private data     */
 };
 
 /*
diff --git a/arch/arm/include/asm/memblock.h b/arch/arm/include/asm/memblock.h
new file mode 100644 (file)
index 0000000..fdbc43b
--- /dev/null
@@ -0,0 +1,16 @@
+#ifndef _ASM_ARM_MEMBLOCK_H
+#define _ASM_ARM_MEMBLOCK_H
+
+#ifdef CONFIG_MMU
+extern phys_addr_t lowmem_end_addr;
+#define MEMBLOCK_REAL_LIMIT    lowmem_end_addr
+#else
+#define MEMBLOCK_REAL_LIMIT    0
+#endif
+
+struct meminfo;
+struct machine_desc;
+
+extern void arm_memblock_init(struct meminfo *, struct machine_desc *);
+
+#endif
index 4312ee5e3d0b6d97b83f0655435c7514d43da671..23c2e8e5c0faaa09d81910456d4de63a96a513da 100644 (file)
 
 #endif /* !CONFIG_MMU */
 
+/*
+ * We fix the TCM memories max 32 KiB ITCM resp DTCM at these
+ * locations
+ */
+#ifdef CONFIG_HAVE_TCM
+#define ITCM_OFFSET    UL(0xfffe0000)
+#define DTCM_OFFSET    UL(0xfffe8000)
+#endif
+
 /*
  * Physical vs virtual RAM address space conversion.  These are
  * private definitions which should NOT be used outside memory.h
 #endif
 
 #ifndef arch_adjust_zones
-#define arch_adjust_zones(node,size,holes) do { } while (0)
+#define arch_adjust_zones(size,holes) do { } while (0)
 #elif !defined(CONFIG_ZONE_DMA)
 #error "custom arch_adjust_zones() requires CONFIG_ZONE_DMA"
 #endif
@@ -234,76 +243,11 @@ static inline __deprecated void *bus_to_virt(unsigned long x)
  *  virt_to_page(k)    convert a _valid_ virtual address to struct page *
  *  virt_addr_valid(k) indicates whether a virtual address is valid
  */
-#ifndef CONFIG_DISCONTIGMEM
-
 #define ARCH_PFN_OFFSET                PHYS_PFN_OFFSET
 
 #define virt_to_page(kaddr)    pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
 #define virt_addr_valid(kaddr) ((unsigned long)(kaddr) >= PAGE_OFFSET && (unsigned long)(kaddr) < (unsigned long)high_memory)
 
-#define PHYS_TO_NID(addr)      (0)
-
-#else /* CONFIG_DISCONTIGMEM */
-
-/*
- * This is more complex.  We have a set of mem_map arrays spread
- * around in memory.
- */
-#include <linux/numa.h>
-
-#define arch_pfn_to_nid(pfn)   PFN_TO_NID(pfn)
-#define arch_local_page_offset(pfn, nid) LOCAL_MAP_NR((pfn) << PAGE_SHIFT)
-
-#define virt_to_page(kaddr)                                    \
-       (ADDR_TO_MAPBASE(kaddr) + LOCAL_MAP_NR(kaddr))
-
-#define virt_addr_valid(kaddr) (KVADDR_TO_NID(kaddr) < MAX_NUMNODES)
-
-/*
- * Common discontigmem stuff.
- *  PHYS_TO_NID is used by the ARM kernel/setup.c
- */
-#define PHYS_TO_NID(addr)      PFN_TO_NID((addr) >> PAGE_SHIFT)
-
-/*
- * Given a kaddr, ADDR_TO_MAPBASE finds the owning node of the memory
- * and returns the mem_map of that node.
- */
-#define ADDR_TO_MAPBASE(kaddr) NODE_MEM_MAP(KVADDR_TO_NID(kaddr))
-
-/*
- * Given a page frame number, find the owning node of the memory
- * and returns the mem_map of that node.
- */
-#define PFN_TO_MAPBASE(pfn)    NODE_MEM_MAP(PFN_TO_NID(pfn))
-
-#ifdef NODE_MEM_SIZE_BITS
-#define NODE_MEM_SIZE_MASK     ((1 << NODE_MEM_SIZE_BITS) - 1)
-
-/*
- * Given a kernel address, find the home node of the underlying memory.
- */
-#define KVADDR_TO_NID(addr) \
-       (((unsigned long)(addr) - PAGE_OFFSET) >> NODE_MEM_SIZE_BITS)
-
-/*
- * Given a page frame number, convert it to a node id.
- */
-#define PFN_TO_NID(pfn) \
-       (((pfn) - PHYS_PFN_OFFSET) >> (NODE_MEM_SIZE_BITS - PAGE_SHIFT))
-
-/*
- * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory
- * and returns the index corresponding to the appropriate page in the
- * node's mem_map.
- */
-#define LOCAL_MAP_NR(addr) \
-       (((unsigned long)(addr) & NODE_MEM_SIZE_MASK) >> PAGE_SHIFT)
-
-#endif /* NODE_MEM_SIZE_BITS */
-
-#endif /* !CONFIG_DISCONTIGMEM */
-
 /*
  * Optional coherency support.  Currently used only by selected
  * Intel XSC3-based systems.
diff --git a/arch/arm/include/asm/mmzone.h b/arch/arm/include/asm/mmzone.h
deleted file mode 100644 (file)
index ae63a4f..0000000
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *  arch/arm/include/asm/mmzone.h
- *
- *  1999-12-29 Nicolas Pitre           Created
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#ifndef __ASM_MMZONE_H
-#define __ASM_MMZONE_H
-
-/*
- * Currently defined in arch/arm/mm/discontig.c
- */
-extern pg_data_t discontig_node_data[];
-
-/*
- * Return a pointer to the node data for node n.
- */
-#define NODE_DATA(nid)         (&discontig_node_data[nid])
-
-/*
- * NODE_MEM_MAP gives the kaddr for the mem_map of the node.
- */
-#define NODE_MEM_MAP(nid)      (NODE_DATA(nid)->node_mem_map)
-
-#include <mach/memory.h>
-
-#endif
index 9dcb11e590268f8bef4230557f477edb656588f3..c974be8913a76dda0a25e8c8f5ad1e7f3a03610d 100644 (file)
@@ -184,6 +184,42 @@ extern unsigned long profile_pc(struct pt_regs *regs);
 #define predicate(x)           ((x) & 0xf0000000)
 #define PREDICATE_ALWAYS       0xe0000000
 
+/*
+ * kprobe-based event tracer support
+ */
+#include <linux/stddef.h>
+#include <linux/types.h>
+#define MAX_REG_OFFSET (offsetof(struct pt_regs, ARM_ORIG_r0))
+
+extern int regs_query_register_offset(const char *name);
+extern const char *regs_query_register_name(unsigned int offset);
+extern bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr);
+extern unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs,
+                                              unsigned int n);
+
+/**
+ * regs_get_register() - get register value from its offset
+ * @regs:         pt_regs from which register value is gotten
+ * @offset:    offset number of the register.
+ *
+ * regs_get_register returns the value of a register whose offset from @regs.
+ * The @offset is the offset of the register in struct pt_regs.
+ * If @offset is bigger than MAX_REG_OFFSET, this returns 0.
+ */
+static inline unsigned long regs_get_register(struct pt_regs *regs,
+                                             unsigned int offset)
+{
+       if (unlikely(offset > MAX_REG_OFFSET))
+               return 0;
+       return *(unsigned long *)((unsigned long)regs + offset);
+}
+
+/* Valid only for Kernel mode traps. */
+static inline unsigned long kernel_stack_pointer(struct pt_regs *regs)
+{
+       return regs->ARM_sp;
+}
+
 #endif /* __KERNEL__ */
 
 #endif /* __ASSEMBLY__ */
index f392fb4437afbd86b35807f16a152ab773df17f4..f1e5a9bca2491d982bda9fda1d40aa7b63b0cfd8 100644 (file)
@@ -201,8 +201,7 @@ static struct tagtable __tagtable_##fn __tag = { tag, fn }
 struct membank {
        unsigned long start;
        unsigned long size;
-       unsigned short node;
-       unsigned short highmem;
+       unsigned int highmem;
 };
 
 struct meminfo {
@@ -212,9 +211,8 @@ struct meminfo {
 
 extern struct meminfo meminfo;
 
-#define for_each_nodebank(iter,mi,no)                  \
-       for (iter = 0; iter < (mi)->nr_banks; iter++)   \
-               if ((mi)->bank[iter].node == no)
+#define for_each_bank(iter,mi)                         \
+       for (iter = 0; iter < (mi)->nr_banks; iter++)
 
 #define bank_pfn_start(bank)   __phys_to_pfn((bank)->start)
 #define bank_pfn_end(bank)     __phys_to_pfn((bank)->start + (bank)->size)
diff --git a/arch/arm/include/asm/stackprotector.h b/arch/arm/include/asm/stackprotector.h
new file mode 100644 (file)
index 0000000..de00332
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * GCC stack protector support.
+ *
+ * Stack protector works by putting predefined pattern at the start of
+ * the stack frame and verifying that it hasn't been overwritten when
+ * returning from the function.  The pattern is called stack canary
+ * and gcc expects it to be defined by a global variable called
+ * "__stack_chk_guard" on ARM.  This unfortunately means that on SMP
+ * we cannot have a different canary value per task.
+ */
+
+#ifndef _ASM_STACKPROTECTOR_H
+#define _ASM_STACKPROTECTOR_H 1
+
+#include <linux/random.h>
+#include <linux/version.h>
+
+extern unsigned long __stack_chk_guard;
+
+/*
+ * Initialize the stackprotector canary value.
+ *
+ * NOTE: this must only be called from functions that never return,
+ * and it must always be inlined.
+ */
+static __always_inline void boot_init_stack_canary(void)
+{
+       unsigned long canary;
+
+       /* Try to get a semi random initial value. */
+       get_random_bytes(&canary, sizeof(canary));
+       canary ^= LINUX_VERSION_CODE;
+
+       current->stack_canary = canary;
+       __stack_chk_guard = current->stack_canary;
+}
+
+#endif /* _ASM_STACKPROTECTOR_H */
index 5f4f48002734c2aa173ed8b8c0cd2294b64a8250..8ba1ccf82a0200283367db344ed79259f8d57c05 100644 (file)
@@ -83,7 +83,7 @@ void arm_notify_die(const char *str, struct pt_regs *regs, struct siginfo *info,
 
 void hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int,
                                       struct pt_regs *),
-                    int sig, const char *name);
+                    int sig, int code, const char *name);
 
 #define xchg(ptr,x) \
        ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
diff --git a/arch/arm/include/asm/tls.h b/arch/arm/include/asm/tls.h
new file mode 100644 (file)
index 0000000..e71d6ff
--- /dev/null
@@ -0,0 +1,46 @@
+#ifndef __ASMARM_TLS_H
+#define __ASMARM_TLS_H
+
+#ifdef __ASSEMBLY__
+       .macro set_tls_none, tp, tmp1, tmp2
+       .endm
+
+       .macro set_tls_v6k, tp, tmp1, tmp2
+       mcr     p15, 0, \tp, c13, c0, 3         @ set TLS register
+       .endm
+
+       .macro set_tls_v6, tp, tmp1, tmp2
+       ldr     \tmp1, =elf_hwcap
+       ldr     \tmp1, [\tmp1, #0]
+       mov     \tmp2, #0xffff0fff
+       tst     \tmp1, #HWCAP_TLS               @ hardware TLS available?
+       mcrne   p15, 0, \tp, c13, c0, 3         @ yes, set TLS register
+       streq   \tp, [\tmp2, #-15]              @ set TLS value at 0xffff0ff0
+       .endm
+
+       .macro set_tls_software, tp, tmp1, tmp2
+       mov     \tmp1, #0xffff0fff
+       str     \tp, [\tmp1, #-15]              @ set TLS value at 0xffff0ff0
+       .endm
+#endif
+
+#ifdef CONFIG_TLS_REG_EMUL
+#define tls_emu                1
+#define has_tls_reg            1
+#define set_tls                set_tls_none
+#elif __LINUX_ARM_ARCH__ >= 7 ||                                       \
+       (__LINUX_ARM_ARCH__ == 6 && defined(CONFIG_CPU_32v6K))
+#define tls_emu                0
+#define has_tls_reg            1
+#define set_tls                set_tls_v6k
+#elif __LINUX_ARM_ARCH__ == 6
+#define tls_emu                0
+#define has_tls_reg            (elf_hwcap & HWCAP_TLS)
+#define set_tls                set_tls_v6
+#else
+#define tls_emu                0
+#define has_tls_reg            0
+#define set_tls                set_tls_software
+#endif
+
+#endif /* __ASMARM_TLS_H */
index 422f3cc204a27310f99d9b25adebb9f49d16e3d0..3d5fc41ae8d38a7743b3bee9c55490135c19dcea 100644 (file)
@@ -3,6 +3,8 @@
  *
  * Assembler-only file containing VFP macros and register definitions.
  */
+#include <asm/hwcap.h>
+
 #include "vfp.h"
 
 @ Macros to allow building with old toolkits (with no VFP support)
        LDC     p11, cr0, [\base],#32*4             @ FLDMIAD \base!, {d0-d15}
 #endif
 #ifdef CONFIG_VFPv3
+#if __LINUX_ARM_ARCH__ <= 6
+       ldr     \tmp, =elf_hwcap                    @ may not have MVFR regs
+       ldr     \tmp, [\tmp, #0]
+       tst     \tmp, #HWCAP_VFPv3D16
+       ldceq   p11, cr0, [\base],#32*4             @ FLDMIAD \base!, {d16-d31}
+       addne   \base, \base, #32*4                 @ step over unused register space
+#else
        VFPFMRX \tmp, MVFR0                         @ Media and VFP Feature Register 0
        and     \tmp, \tmp, #MVFR0_A_SIMD_MASK      @ A_SIMD field
        cmp     \tmp, #2                            @ 32 x 64bit registers?
        ldceql  p11, cr0, [\base],#32*4             @ FLDMIAD \base!, {d16-d31}
        addne   \base, \base, #32*4                 @ step over unused register space
+#endif
 #endif
        .endm
 
        STC     p11, cr0, [\base],#32*4             @ FSTMIAD \base!, {d0-d15}
 #endif
 #ifdef CONFIG_VFPv3
+#if __LINUX_ARM_ARCH__ <= 6
+       ldr     \tmp, =elf_hwcap                    @ may not have MVFR regs
+       ldr     \tmp, [\tmp, #0]
+       tst     \tmp, #HWCAP_VFPv3D16
+       stceq   p11, cr0, [\base],#32*4             @ FSTMIAD \base!, {d16-d31}
+       addne   \base, \base, #32*4                 @ step over unused register space
+#else
        VFPFMRX \tmp, MVFR0                         @ Media and VFP Feature Register 0
        and     \tmp, \tmp, #MVFR0_A_SIMD_MASK      @ A_SIMD field
        cmp     \tmp, #2                            @ 32 x 64bit registers?
        stceql  p11, cr0, [\base],#32*4             @ FSTMIAD \base!, {d16-d31}
        addne   \base, \base, #32*4                 @ step over unused register space
+#endif
 #endif
        .endm
index 26d302c28e1318b4aa5db81a491fcd6a82b0e6fa..980b78e31328156925f361cf5f6a2deac14c1500 100644 (file)
@@ -13,10 +13,12 @@ CFLAGS_REMOVE_return_address.o = -pg
 
 # Object file lists.
 
-obj-y          := compat.o elf.o entry-armv.o entry-common.o irq.o \
+obj-y          := elf.o entry-armv.o entry-common.o irq.o \
                   process.o ptrace.o return_address.o setup.o signal.o \
                   sys_arm.o stacktrace.o time.o traps.o
 
+obj-$(CONFIG_DEPRECATED_PARAM_STRUCT) += compat.o
+
 obj-$(CONFIG_LEDS)             += leds.o
 obj-$(CONFIG_OC_ETM)           += etm.o
 
@@ -39,6 +41,7 @@ obj-$(CONFIG_ARM_THUMBEE)     += thumbee.o
 obj-$(CONFIG_KGDB)             += kgdb.o
 obj-$(CONFIG_ARM_UNWIND)       += unwind.o
 obj-$(CONFIG_HAVE_TCM)         += tcm.o
+obj-$(CONFIG_CRASH_DUMP)       += crash_dump.o
 
 obj-$(CONFIG_CRUNCH)           += crunch.o crunch-bits.o
 AFLAGS_crunch-bits.o           := -Wa,-mcpu=ep9312
index 883511522fca9e83be970c2611fd2ce5a1a75a41..85f2a019f77bc93b17e0c55bf60693d18a8e2ffa 100644 (file)
@@ -40,6 +40,9 @@
 int main(void)
 {
   DEFINE(TSK_ACTIVE_MM,                offsetof(struct task_struct, active_mm));
+#ifdef CONFIG_CC_STACKPROTECTOR
+  DEFINE(TSK_STACK_CANARY,     offsetof(struct task_struct, stack_canary));
+#endif
   BLANK();
   DEFINE(TI_FLAGS,             offsetof(struct thread_info, flags));
   DEFINE(TI_PREEMPT,           offsetof(struct thread_info, preempt_count));
index 0a1385442f4344548bf20c5c0b28090f743e12b3..925652318b8b5df4cb7dce4383b99cee2640285b 100644 (file)
@@ -217,10 +217,3 @@ void __init convert_to_tag_list(struct tag *tags)
        struct param_struct *params = (struct param_struct *)tags;
        build_tag_list(params, &params->u2);
 }
-
-void __init squash_mem_tags(struct tag *tag)
-{
-       for (; tag->hdr.size; tag = tag_next(tag))
-               if (tag->hdr.tag == ATAG_MEM)
-                       tag->hdr.tag = ATAG_NONE;
-}
index 27e61a68bd1c5693909a4ac0dbbdb00c6663b684..39264ab1b9c640cd81447f4a54ec1f19c118fede 100644 (file)
@@ -9,5 +9,3 @@
 */
 
 extern void convert_to_tag_list(struct tag *tags);
-
-extern void squash_mem_tags(struct tag *tag);
diff --git a/arch/arm/kernel/crash_dump.c b/arch/arm/kernel/crash_dump.c
new file mode 100644 (file)
index 0000000..cd3b853
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * arch/arm/kernel/crash_dump.c
+ *
+ * Copyright (C) 2010 Nokia Corporation.
+ * Author: Mika Westerberg
+ *
+ * This code is taken from arch/x86/kernel/crash_dump_64.c
+ *   Created by: Hariprasad Nellitheertha (hari@in.ibm.com)
+ *   Copyright (C) IBM Corporation, 2004. All rights reserved
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/errno.h>
+#include <linux/crash_dump.h>
+#include <linux/uaccess.h>
+#include <linux/io.h>
+
+/* stores the physical address of elf header of crash image */
+unsigned long long elfcorehdr_addr = ELFCORE_ADDR_MAX;
+
+/**
+ * copy_oldmem_page() - copy one page from old kernel memory
+ * @pfn: page frame number to be copied
+ * @buf: buffer where the copied page is placed
+ * @csize: number of bytes to copy
+ * @offset: offset in bytes into the page
+ * @userbuf: if set, @buf is int he user address space
+ *
+ * This function copies one page from old kernel memory into buffer pointed by
+ * @buf. If @buf is in userspace, set @userbuf to %1. Returns number of bytes
+ * copied or negative error in case of failure.
+ */
+ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
+                        size_t csize, unsigned long offset,
+                        int userbuf)
+{
+       void *vaddr;
+
+       if (!csize)
+               return 0;
+
+       vaddr = ioremap(pfn << PAGE_SHIFT, PAGE_SIZE);
+       if (!vaddr)
+               return -ENOMEM;
+
+       if (userbuf) {
+               if (copy_to_user(buf, vaddr + offset, csize)) {
+                       iounmap(vaddr);
+                       return -EFAULT;
+               }
+       } else {
+               memcpy(buf, vaddr + offset, csize);
+       }
+
+       iounmap(vaddr);
+       return csize;
+}
index 3fd7861de4d16c508ee424e52281de0dc39a4db7..bb8e93a76407241042345c51273690f6cdc35578 100644 (file)
@@ -22,6 +22,7 @@
 #include <asm/thread_notify.h>
 #include <asm/unwind.h>
 #include <asm/unistd.h>
+#include <asm/tls.h>
 
 #include "entry-header.S"
 
@@ -735,11 +736,11 @@ ENTRY(__switch_to)
 #ifdef CONFIG_MMU
        ldr     r6, [r2, #TI_CPU_DOMAIN]
 #endif
-#if defined(CONFIG_HAS_TLS_REG)
-       mcr     p15, 0, r3, c13, c0, 3          @ set TLS register
-#elif !defined(CONFIG_TLS_REG_EMUL)
-       mov     r4, #0xffff0fff
-       str     r3, [r4, #-15]                  @ TLS val at 0xffff0ff0
+       set_tls r3, r4, r5
+#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
+       ldr     r7, [r2, #TI_TASK]
+       ldr     r8, =__stack_chk_guard
+       ldr     r7, [r7, #TSK_STACK_CANARY]
 #endif
 #ifdef CONFIG_MMU
        mcr     p15, 0, r6, c3, c0, 0           @ Set domain register
@@ -749,6 +750,9 @@ ENTRY(__switch_to)
        ldr     r0, =thread_notify_head
        mov     r1, #THREAD_NOTIFY_SWITCH
        bl      atomic_notifier_call_chain
+#if defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_SMP)
+       str     r7, [r8]
+#endif
  THUMB(        mov     ip, r4                     )
        mov     r0, r5
  ARM(  ldmia   r4, {r4 - sl, fp, sp, pc}  )    @ Load all regs saved previously
@@ -1005,17 +1009,12 @@ kuser_cmpxchg_fixup:
  */
 
 __kuser_get_tls:                               @ 0xffff0fe0
-
-#if !defined(CONFIG_HAS_TLS_REG) && !defined(CONFIG_TLS_REG_EMUL)
-       ldr     r0, [pc, #(16 - 8)]             @ TLS stored at 0xffff0ff0
-#else
-       mrc     p15, 0, r0, c13, c0, 3          @ read TLS register
-#endif
+       ldr     r0, [pc, #(16 - 8)]     @ read TLS, set in kuser_get_tls_init
        usr_ret lr
-
-       .rep    5
-       .word   0                       @ pad up to __kuser_helper_version
-       .endr
+       mrc     p15, 0, r0, c13, c0, 3  @ 0xffff0fe8 hardware TLS code
+       .rep    4
+       .word   0                       @ 0xffff0ff0 software TLS value, then
+       .endr                           @ pad up to __kuser_helper_version
 
 /*
  * Reference declaration:
index 3b3d2c80509c0bb4c3499f944414a11425f6e5e6..c0d5c3b3a760fa79624657ebc495b1d7b81b8c66 100644 (file)
 #define irq_finish(irq) do { } while (0)
 #endif
 
+unsigned int arch_nr_irqs;
 void (*init_arch_irq)(void) __initdata = NULL;
 unsigned long irq_err_count;
 
 int show_interrupts(struct seq_file *p, void *v)
 {
        int i = *(loff_t *) v, cpu;
+       struct irq_desc *desc;
        struct irqaction * action;
        unsigned long flags;
 
@@ -67,24 +69,25 @@ int show_interrupts(struct seq_file *p, void *v)
                seq_putc(p, '\n');
        }
 
-       if (i < NR_IRQS) {
-               raw_spin_lock_irqsave(&irq_desc[i].lock, flags);
-               action = irq_desc[i].action;
+       if (i < nr_irqs) {
+               desc = irq_to_desc(i);
+               raw_spin_lock_irqsave(&desc->lock, flags);
+               action = desc->action;
                if (!action)
                        goto unlock;
 
                seq_printf(p, "%3d: ", i);
                for_each_present_cpu(cpu)
                        seq_printf(p, "%10u ", kstat_irqs_cpu(i, cpu));
-               seq_printf(p, " %10s", irq_desc[i].chip->name ? : "-");
+               seq_printf(p, " %10s", desc->chip->name ? : "-");
                seq_printf(p, "  %s", action->name);
                for (action = action->next; action; action = action->next)
                        seq_printf(p, ", %s", action->name);
 
                seq_putc(p, '\n');
 unlock:
-               raw_spin_unlock_irqrestore(&irq_desc[i].lock, flags);
-       } else if (i == NR_IRQS) {
+               raw_spin_unlock_irqrestore(&desc->lock, flags);
+       } else if (i == nr_irqs) {
 #ifdef CONFIG_FIQ
                show_fiq_list(p, v);
 #endif
@@ -112,7 +115,7 @@ asmlinkage void __exception asm_do_IRQ(unsigned int irq, struct pt_regs *regs)
         * Some hardware gives randomly wrong interrupts.  Rather
         * than crashing, do something sensible.
         */
-       if (unlikely(irq >= NR_IRQS)) {
+       if (unlikely(irq >= nr_irqs)) {
                if (printk_ratelimit())
                        printk(KERN_WARNING "Bad IRQ%u\n", irq);
                ack_bad_irq(irq);
@@ -132,12 +135,12 @@ void set_irq_flags(unsigned int irq, unsigned int iflags)
        struct irq_desc *desc;
        unsigned long flags;
 
-       if (irq >= NR_IRQS) {
+       if (irq >= nr_irqs) {
                printk(KERN_ERR "Trying to set irq flags for IRQ%d\n", irq);
                return;
        }
 
-       desc = irq_desc + irq;
+       desc = irq_to_desc(irq);
        raw_spin_lock_irqsave(&desc->lock, flags);
        desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE | IRQ_NOAUTOEN;
        if (iflags & IRQF_VALID)
@@ -151,14 +154,25 @@ void set_irq_flags(unsigned int irq, unsigned int iflags)
 
 void __init init_IRQ(void)
 {
+       struct irq_desc *desc;
        int irq;
 
-       for (irq = 0; irq < NR_IRQS; irq++)
-               irq_desc[irq].status |= IRQ_NOREQUEST | IRQ_NOPROBE;
+       for (irq = 0; irq < nr_irqs; irq++) {
+               desc = irq_to_desc_alloc_node(irq, 0);
+               desc->status |= IRQ_NOREQUEST | IRQ_NOPROBE;
+       }
 
        init_arch_irq();
 }
 
+#ifdef CONFIG_SPARSE_IRQ
+int __init arch_probe_nr_irqs(void)
+{
+       nr_irqs = arch_nr_irqs ? arch_nr_irqs : NR_IRQS;
+       return 0;
+}
+#endif
+
 #ifdef CONFIG_HOTPLUG_CPU
 
 static void route_irq(struct irq_desc *desc, unsigned int irq, unsigned int cpu)
@@ -178,10 +192,9 @@ static void route_irq(struct irq_desc *desc, unsigned int irq, unsigned int cpu)
 void migrate_irqs(void)
 {
        unsigned int i, cpu = smp_processor_id();
+       struct irq_desc *desc;
 
-       for (i = 0; i < NR_IRQS; i++) {
-               struct irq_desc *desc = irq_desc + i;
-
+       for_each_irq_desc(i, desc) {
                if (desc->node == cpu) {
                        unsigned int newcpu = cpumask_any_and(desc->affinity,
                                                              cpu_online_mask);
index 598ca61e7bca8496a853128a433dc7d1dfba0edf..1fc74cbd1a193ee4dcd2fd50afdd279804d9e5fd 100644 (file)
@@ -37,12 +37,12 @@ void machine_kexec_cleanup(struct kimage *image)
 {
 }
 
-void machine_shutdown(void)
-{
-}
-
 void machine_crash_shutdown(struct pt_regs *regs)
 {
+       local_irq_disable();
+       crash_save_cpu(regs, smp_processor_id());
+
+       printk(KERN_INFO "Loading crashdump kernel...\n");
 }
 
 void machine_kexec(struct kimage *image)
@@ -74,7 +74,11 @@ void machine_kexec(struct kimage *image)
                           (unsigned long) reboot_code_buffer + KEXEC_CONTROL_PAGE_SIZE);
        printk(KERN_INFO "Bye!\n");
 
-       cpu_proc_fin();
+       local_irq_disable();
+       local_fiq_disable();
        setup_mm_for_reboot(0); /* mode is not used, so just pass 0*/
+       flush_cache_all();
+       cpu_proc_fin();
+       flush_cache_all();
        cpu_reset(reboot_code_buffer_phys);
 }
index a4a9cc88bec73a525a9edd4bdc7db94cea370ce9..401e38be1f787c16e7b36d6429406a05229d83da 100644 (file)
@@ -28,7 +28,9 @@
 #include <linux/tick.h>
 #include <linux/utsname.h>
 #include <linux/uaccess.h>
+#include <linux/random.h>
 
+#include <asm/cacheflush.h>
 #include <asm/leds.h>
 #include <asm/processor.h>
 #include <asm/system.h>
 #include <asm/stacktrace.h>
 #include <asm/mach/time.h>
 
+#ifdef CONFIG_CC_STACKPROTECTOR
+#include <linux/stackprotector.h>
+unsigned long __stack_chk_guard __read_mostly;
+EXPORT_SYMBOL(__stack_chk_guard);
+#endif
+
 static const char *processor_modes[] = {
   "USER_26", "FIQ_26" , "IRQ_26" , "SVC_26" , "UK4_26" , "UK5_26" , "UK6_26" , "UK7_26" ,
   "UK8_26" , "UK9_26" , "UK10_26", "UK11_26", "UK12_26", "UK13_26", "UK14_26", "UK15_26",
@@ -84,10 +92,9 @@ __setup("hlt", hlt_setup);
 
 void arm_machine_restart(char mode, const char *cmd)
 {
-       /*
-        * Clean and disable cache, and turn off interrupts
-        */
-       cpu_proc_fin();
+       /* Disable interrupts first */
+       local_irq_disable();
+       local_fiq_disable();
 
        /*
         * Tell the mm system that we are going to reboot -
@@ -96,6 +103,15 @@ void arm_machine_restart(char mode, const char *cmd)
         */
        setup_mm_for_reboot(mode);
 
+       /* Clean and invalidate caches */
+       flush_cache_all();
+
+       /* Turn off caching */
+       cpu_proc_fin();
+
+       /* Push out any further dirty data, and ensure cache is empty */
+       flush_cache_all();
+
        /*
         * Now call the architecture specific reboot code.
         */
@@ -189,19 +205,29 @@ int __init reboot_setup(char *str)
 
 __setup("reboot=", reboot_setup);
 
-void machine_halt(void)
+void machine_shutdown(void)
 {
+#ifdef CONFIG_SMP
+       smp_send_stop();
+#endif
 }
 
+void machine_halt(void)
+{
+       machine_shutdown();
+       while (1);
+}
 
 void machine_power_off(void)
 {
+       machine_shutdown();
        if (pm_power_off)
                pm_power_off();
 }
 
 void machine_restart(char *cmd)
 {
+       machine_shutdown();
        arm_pm_restart(reboot_mode, cmd);
 }
 
@@ -426,3 +452,9 @@ unsigned long get_wchan(struct task_struct *p)
        } while (count ++ < 16);
        return 0;
 }
+
+unsigned long arch_randomize_brk(struct mm_struct *mm)
+{
+       unsigned long range_end = mm->brk + 0x02000000;
+       return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
+}
index 3f562a7c0a99445f3747ec0d0198d4f53a4d83fd..f99d489822d50fb23e46f4e7760411b766e040e7 100644 (file)
 #define BREAKINST_THUMB        0xde01
 #endif
 
+struct pt_regs_offset {
+       const char *name;
+       int offset;
+};
+
+#define REG_OFFSET_NAME(r) \
+       {.name = #r, .offset = offsetof(struct pt_regs, ARM_##r)}
+#define REG_OFFSET_END {.name = NULL, .offset = 0}
+
+static const struct pt_regs_offset regoffset_table[] = {
+       REG_OFFSET_NAME(r0),
+       REG_OFFSET_NAME(r1),
+       REG_OFFSET_NAME(r2),
+       REG_OFFSET_NAME(r3),
+       REG_OFFSET_NAME(r4),
+       REG_OFFSET_NAME(r5),
+       REG_OFFSET_NAME(r6),
+       REG_OFFSET_NAME(r7),
+       REG_OFFSET_NAME(r8),
+       REG_OFFSET_NAME(r9),
+       REG_OFFSET_NAME(r10),
+       REG_OFFSET_NAME(fp),
+       REG_OFFSET_NAME(ip),
+       REG_OFFSET_NAME(sp),
+       REG_OFFSET_NAME(lr),
+       REG_OFFSET_NAME(pc),
+       REG_OFFSET_NAME(cpsr),
+       REG_OFFSET_NAME(ORIG_r0),
+       REG_OFFSET_END,
+};
+
+/**
+ * regs_query_register_offset() - query register offset from its name
+ * @name:      the name of a register
+ *
+ * regs_query_register_offset() returns the offset of a register in struct
+ * pt_regs from its name. If the name is invalid, this returns -EINVAL;
+ */
+int regs_query_register_offset(const char *name)
+{
+       const struct pt_regs_offset *roff;
+       for (roff = regoffset_table; roff->name != NULL; roff++)
+               if (!strcmp(roff->name, name))
+                       return roff->offset;
+       return -EINVAL;
+}
+
+/**
+ * regs_query_register_name() - query register name from its offset
+ * @offset:    the offset of a register in struct pt_regs.
+ *
+ * regs_query_register_name() returns the name of a register from its
+ * offset in struct pt_regs. If the @offset is invalid, this returns NULL;
+ */
+const char *regs_query_register_name(unsigned int offset)
+{
+       const struct pt_regs_offset *roff;
+       for (roff = regoffset_table; roff->name != NULL; roff++)
+               if (roff->offset == offset)
+                       return roff->name;
+       return NULL;
+}
+
+/**
+ * regs_within_kernel_stack() - check the address in the stack
+ * @regs:      pt_regs which contains kernel stack pointer.
+ * @addr:      address which is checked.
+ *
+ * regs_within_kernel_stack() checks @addr is within the kernel stack page(s).
+ * If @addr is within the kernel stack, it returns true. If not, returns false.
+ */
+bool regs_within_kernel_stack(struct pt_regs *regs, unsigned long addr)
+{
+       return ((addr & ~(THREAD_SIZE - 1))  ==
+               (kernel_stack_pointer(regs) & ~(THREAD_SIZE - 1)));
+}
+
+/**
+ * regs_get_kernel_stack_nth() - get Nth entry of the stack
+ * @regs:      pt_regs which contains kernel stack pointer.
+ * @n:         stack entry number.
+ *
+ * regs_get_kernel_stack_nth() returns @n th entry of the kernel stack which
+ * is specified by @regs. If the @n th entry is NOT in the kernel stack,
+ * this returns 0.
+ */
+unsigned long regs_get_kernel_stack_nth(struct pt_regs *regs, unsigned int n)
+{
+       unsigned long *addr = (unsigned long *)kernel_stack_pointer(regs);
+       addr += n;
+       if (regs_within_kernel_stack(regs, (unsigned long)addr))
+               return *addr;
+       else
+               return 0;
+}
+
 /*
  * this routine will get a word off of the processes privileged stack.
  * the offset is how far from the base addr as stored in the THREAD.
index 61930eb0902941030e3e180aca40f6f82697e39e..fd26f8d65151a949e6ecff394f0146258882b9d6 100644 (file)
@@ -10,6 +10,12 @@ relocate_new_kernel:
        ldr     r0,kexec_indirection_page
        ldr     r1,kexec_start_address
 
+       /*
+        * If there is no indirection page (we are doing crashdumps)
+        * skip any relocation.
+        */
+       cmp     r0, #0
+       beq     2f
 
 0:     /* top, read another word for the indirection page */
        ldr     r3, [r0],#4
index 122d999bdc7ca0c8f690355a101f59f1ea8152f8..d5231ae7355aa286bf5503e0180954f84e4f6022 100644 (file)
 #include <linux/seq_file.h>
 #include <linux/screen_info.h>
 #include <linux/init.h>
+#include <linux/kexec.h>
+#include <linux/crash_dump.h>
 #include <linux/root_dev.h>
 #include <linux/cpu.h>
 #include <linux/interrupt.h>
 #include <linux/smp.h>
 #include <linux/fs.h>
 #include <linux/proc_fs.h>
+#include <linux/memblock.h>
 
 #include <asm/unified.h>
 #include <asm/cpu.h>
@@ -44,7 +47,9 @@
 #include <asm/traps.h>
 #include <asm/unwind.h>
 
+#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
 #include "compat.h"
+#endif
 #include "atags.h"
 #include "tcm.h"
 
@@ -269,6 +274,21 @@ static void __init cacheid_init(void)
 extern struct proc_info_list *lookup_processor_type(unsigned int);
 extern struct machine_desc *lookup_machine_type(unsigned int);
 
+static void __init feat_v6_fixup(void)
+{
+       int id = read_cpuid_id();
+
+       if ((id & 0xff0f0000) != 0x41070000)
+               return;
+
+       /*
+        * HWCAP_TLS is available only on 1136 r1p0 and later,
+        * see also kuser_get_tls_init.
+        */
+       if ((((id >> 4) & 0xfff) == 0xb36) && (((id >> 20) & 3) == 0))
+               elf_hwcap &= ~HWCAP_TLS;
+}
+
 static void __init setup_processor(void)
 {
        struct proc_info_list *list;
@@ -311,6 +331,8 @@ static void __init setup_processor(void)
        elf_hwcap &= ~HWCAP_THUMB;
 #endif
 
+       feat_v6_fixup();
+
        cacheid_init();
        cpu_proc_init();
 }
@@ -402,13 +424,12 @@ static int __init arm_add_memory(unsigned long start, unsigned long size)
        size -= start & ~PAGE_MASK;
        bank->start = PAGE_ALIGN(start);
        bank->size  = size & PAGE_MASK;
-       bank->node  = PHYS_TO_NID(start);
 
        /*
         * Check whether this memory region has non-zero size or
         * invalid node number.
         */
-       if (bank->size == 0 || bank->node >= MAX_NUMNODES)
+       if (bank->size == 0)
                return -EINVAL;
 
        meminfo.nr_banks++;
@@ -663,6 +684,86 @@ static int __init customize_machine(void)
 }
 arch_initcall(customize_machine);
 
+#ifdef CONFIG_KEXEC
+static inline unsigned long long get_total_mem(void)
+{
+       unsigned long total;
+
+       total = max_low_pfn - min_low_pfn;
+       return total << PAGE_SHIFT;
+}
+
+/**
+ * reserve_crashkernel() - reserves memory are for crash kernel
+ *
+ * This function reserves memory area given in "crashkernel=" kernel command
+ * line parameter. The memory reserved is used by a dump capture kernel when
+ * primary kernel is crashing.
+ */
+static void __init reserve_crashkernel(void)
+{
+       unsigned long long crash_size, crash_base;
+       unsigned long long total_mem;
+       int ret;
+
+       total_mem = get_total_mem();
+       ret = parse_crashkernel(boot_command_line, total_mem,
+                               &crash_size, &crash_base);
+       if (ret)
+               return;
+
+       ret = reserve_bootmem(crash_base, crash_size, BOOTMEM_EXCLUSIVE);
+       if (ret < 0) {
+               printk(KERN_WARNING "crashkernel reservation failed - "
+                      "memory is in use (0x%lx)\n", (unsigned long)crash_base);
+               return;
+       }
+
+       printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
+              "for crashkernel (System RAM: %ldMB)\n",
+              (unsigned long)(crash_size >> 20),
+              (unsigned long)(crash_base >> 20),
+              (unsigned long)(total_mem >> 20));
+
+       crashk_res.start = crash_base;
+       crashk_res.end = crash_base + crash_size - 1;
+       insert_resource(&iomem_resource, &crashk_res);
+}
+#else
+static inline void reserve_crashkernel(void) {}
+#endif /* CONFIG_KEXEC */
+
+/*
+ * Note: elfcorehdr_addr is not just limited to vmcore. It is also used by
+ * is_kdump_kernel() to determine if we are booting after a panic. Hence
+ * ifdef it under CONFIG_CRASH_DUMP and not CONFIG_PROC_VMCORE.
+ */
+
+#ifdef CONFIG_CRASH_DUMP
+/*
+ * elfcorehdr= specifies the location of elf core header stored by the crashed
+ * kernel. This option will be passed by kexec loader to the capture kernel.
+ */
+static int __init setup_elfcorehdr(char *arg)
+{
+       char *end;
+
+       if (!arg)
+               return -EINVAL;
+
+       elfcorehdr_addr = memparse(arg, &end);
+       return end > arg ? 0 : -EINVAL;
+}
+early_param("elfcorehdr", setup_elfcorehdr);
+#endif /* CONFIG_CRASH_DUMP */
+
+static void __init squash_mem_tags(struct tag *tag)
+{
+       for (; tag->hdr.size; tag = tag_next(tag))
+               if (tag->hdr.tag == ATAG_MEM)
+                       tag->hdr.tag = ATAG_NONE;
+}
+
 void __init setup_arch(char **cmdline_p)
 {
        struct tag *tags = (struct tag *)&init_tags;
@@ -683,12 +784,14 @@ void __init setup_arch(char **cmdline_p)
        else if (mdesc->boot_params)
                tags = phys_to_virt(mdesc->boot_params);
 
+#if defined(CONFIG_DEPRECATED_PARAM_STRUCT)
        /*
         * If we have the old style parameters, convert them to
         * a tag list.
         */
        if (tags->hdr.tag != ATAG_CORE)
                convert_to_tag_list(tags);
+#endif
        if (tags->hdr.tag != ATAG_CORE)
                tags = (struct tag *)&init_tags;
 
@@ -716,12 +819,15 @@ void __init setup_arch(char **cmdline_p)
 
        parse_early_param();
 
+       arm_memblock_init(&meminfo, mdesc);
+
        paging_init(mdesc);
        request_standard_resources(&meminfo, mdesc);
 
 #ifdef CONFIG_SMP
        smp_init_cpus();
 #endif
+       reserve_crashkernel();
 
        cpu_init();
        tcm_init();
@@ -729,6 +835,7 @@ void __init setup_arch(char **cmdline_p)
        /*
         * Set up various architecture-specific pointers
         */
+       arch_nr_irqs = mdesc->nr_irqs;
        init_arch_irq = mdesc->init_irq;
        system_timer = mdesc->timer;
        init_machine = mdesc->init_machine;
index b8c3d0f689d9560cc33a7e8ec06958ad216e7ef1..40dc74f2b27f3362f8739f5e9898963dd27a221b 100644 (file)
@@ -429,7 +429,11 @@ static void smp_timer_broadcast(const struct cpumask *mask)
 {
        send_ipi_message(mask, IPI_TIMER);
 }
+#else
+#define smp_timer_broadcast    NULL
+#endif
 
+#ifndef CONFIG_LOCAL_TIMERS
 static void broadcast_timer_set_mode(enum clock_event_mode mode,
        struct clock_event_device *evt)
 {
@@ -444,7 +448,6 @@ static void local_timer_setup(struct clock_event_device *evt)
        evt->rating     = 400;
        evt->mult       = 1;
        evt->set_mode   = broadcast_timer_set_mode;
-       evt->broadcast  = smp_timer_broadcast;
 
        clockevents_register_device(evt);
 }
@@ -456,6 +459,7 @@ void __cpuinit percpu_timer_setup(void)
        struct clock_event_device *evt = &per_cpu(percpu_clockevent, cpu);
 
        evt->cpumask = cpumask_of(cpu);
+       evt->broadcast = smp_timer_broadcast;
 
        local_timer_setup(evt);
 }
@@ -467,10 +471,13 @@ static DEFINE_SPINLOCK(stop_lock);
  */
 static void ipi_cpu_stop(unsigned int cpu)
 {
-       spin_lock(&stop_lock);
-       printk(KERN_CRIT "CPU%u: stopping\n", cpu);
-       dump_stack();
-       spin_unlock(&stop_lock);
+       if (system_state == SYSTEM_BOOTING ||
+           system_state == SYSTEM_RUNNING) {
+               spin_lock(&stop_lock);
+               printk(KERN_CRIT "CPU%u: stopping\n", cpu);
+               dump_stack();
+               spin_unlock(&stop_lock);
+       }
 
        set_cpu_online(cpu, false);
 
index 7c5f0c024db7e468aba3a185bded3bf3fde7073a..35882fbf37f90063723d3247352a3c05af480f99 100644 (file)
@@ -132,7 +132,8 @@ void __cpuinit twd_timer_setup(struct clock_event_device *clk)
        twd_calibrate_rate();
 
        clk->name = "local_timer";
-       clk->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT;
+       clk->features = CLOCK_EVT_FEAT_PERIODIC | CLOCK_EVT_FEAT_ONESHOT |
+                       CLOCK_EVT_FEAT_C3STOP;
        clk->rating = 350;
        clk->set_mode = twd_set_mode;
        clk->set_next_event = twd_set_next_event;
index e50303868f1b62dd3853667d4a1445629eb4999c..26685c2f7a49d11b16421f5cad55c3c5109a27ea 100644 (file)
 #include <linux/ioport.h>
 #include <linux/genalloc.h>
 #include <linux/string.h> /* memcpy */
-#include <asm/page.h> /* PAGE_SHIFT */
 #include <asm/cputype.h>
 #include <asm/mach/map.h>
 #include <mach/memory.h>
 #include "tcm.h"
 
-/* Scream and warn about misuse */
-#if !defined(ITCM_OFFSET) || !defined(ITCM_END) || \
-    !defined(DTCM_OFFSET) || !defined(DTCM_END)
-#error "TCM support selected but offsets not defined!"
-#endif
-
 static struct gen_pool *tcm_pool;
 
 /* TCM section definitions from the linker */
 extern char __itcm_start, __sitcm_text, __eitcm_text;
 extern char __dtcm_start, __sdtcm_data, __edtcm_data;
 
+/* These will be increased as we run */
+u32 dtcm_end = DTCM_OFFSET;
+u32 itcm_end = ITCM_OFFSET;
+
 /*
  * TCM memory resources
  */
 static struct resource dtcm_res = {
        .name = "DTCM RAM",
        .start = DTCM_OFFSET,
-       .end = DTCM_END,
+       .end = DTCM_OFFSET,
        .flags = IORESOURCE_MEM
 };
 
 static struct resource itcm_res = {
        .name = "ITCM RAM",
        .start = ITCM_OFFSET,
-       .end = ITCM_END,
+       .end = ITCM_OFFSET,
        .flags = IORESOURCE_MEM
 };
 
@@ -52,8 +49,8 @@ static struct map_desc dtcm_iomap[] __initdata = {
        {
                .virtual        = DTCM_OFFSET,
                .pfn            = __phys_to_pfn(DTCM_OFFSET),
-               .length         = (DTCM_END - DTCM_OFFSET + 1),
-               .type           = MT_UNCACHED
+               .length         = 0,
+               .type           = MT_MEMORY_DTCM
        }
 };
 
@@ -61,8 +58,8 @@ static struct map_desc itcm_iomap[] __initdata = {
        {
                .virtual        = ITCM_OFFSET,
                .pfn            = __phys_to_pfn(ITCM_OFFSET),
-               .length         = (ITCM_END - ITCM_OFFSET + 1),
-               .type           = MT_UNCACHED
+               .length         = 0,
+               .type           = MT_MEMORY_ITCM
        }
 };
 
@@ -93,14 +90,24 @@ void tcm_free(void *addr, size_t len)
 }
 EXPORT_SYMBOL(tcm_free);
 
-
-static void __init setup_tcm_bank(u8 type, u32 offset, u32 expected_size)
+static int __init setup_tcm_bank(u8 type, u8 bank, u8 banks,
+                                 u32 *offset)
 {
        const int tcm_sizes[16] = { 0, -1, -1, 4, 8, 16, 32, 64, 128,
                                    256, 512, 1024, -1, -1, -1, -1 };
        u32 tcm_region;
        int tcm_size;
 
+       /*
+        * If there are more than one TCM bank of this type,
+        * select the TCM bank to operate on in the TCM selection
+        * register.
+        */
+       if (banks > 1)
+               asm("mcr        p15, 0, %0, c9, c2, 0"
+                   : /* No output operands */
+                   : "r" (bank));
+
        /* Read the special TCM region register c9, 0 */
        if (!type)
                asm("mrc        p15, 0, %0, c9, c1, 0"
@@ -111,26 +118,24 @@ static void __init setup_tcm_bank(u8 type, u32 offset, u32 expected_size)
 
        tcm_size = tcm_sizes[(tcm_region >> 2) & 0x0f];
        if (tcm_size < 0) {
-               pr_err("CPU: %sTCM of unknown size!\n",
-                       type ? "I" : "D");
+               pr_err("CPU: %sTCM%d of unknown size\n",
+                      type ? "I" : "D", bank);
+               return -EINVAL;
+       } else if (tcm_size > 32) {
+               pr_err("CPU: %sTCM%d larger than 32k found\n",
+                      type ? "I" : "D", bank);
+               return -EINVAL;
        } else {
-               pr_info("CPU: found %sTCM %dk @ %08x, %senabled\n",
+               pr_info("CPU: found %sTCM%d %dk @ %08x, %senabled\n",
                        type ? "I" : "D",
+                       bank,
                        tcm_size,
                        (tcm_region & 0xfffff000U),
                        (tcm_region & 1) ? "" : "not ");
        }
 
-       if (tcm_size != expected_size) {
-               pr_crit("CPU: %sTCM was detected %dk but expected %dk!\n",
-                      type ? "I" : "D",
-                      tcm_size,
-                      expected_size);
-               /* Adjust to the expected size? what can we do... */
-       }
-
        /* Force move the TCM bank to where we want it, enable */
-       tcm_region = offset | (tcm_region & 0x00000ffeU) | 1;
+       tcm_region = *offset | (tcm_region & 0x00000ffeU) | 1;
 
        if (!type)
                asm("mcr        p15, 0, %0, c9, c1, 0"
@@ -141,10 +146,15 @@ static void __init setup_tcm_bank(u8 type, u32 offset, u32 expected_size)
                    : /* No output operands */
                    : "r" (tcm_region));
 
-       pr_debug("CPU: moved %sTCM %dk to %08x, enabled\n",
-                type ? "I" : "D",
-                tcm_size,
-                (tcm_region & 0xfffff000U));
+       /* Increase offset */
+       *offset += (tcm_size << 10);
+
+       pr_info("CPU: moved %sTCM%d %dk to %08x, enabled\n",
+               type ? "I" : "D",
+               bank,
+               tcm_size,
+               (tcm_region & 0xfffff000U));
+       return 0;
 }
 
 /*
@@ -153,34 +163,52 @@ static void __init setup_tcm_bank(u8 type, u32 offset, u32 expected_size)
 void __init tcm_init(void)
 {
        u32 tcm_status = read_cpuid_tcmstatus();
+       u8 dtcm_banks = (tcm_status >> 16) & 0x03;
+       u8 itcm_banks = (tcm_status & 0x03);
        char *start;
        char *end;
        char *ram;
+       int ret;
+       int i;
 
        /* Setup DTCM if present */
-       if (tcm_status & (1 << 16)) {
-               setup_tcm_bank(0, DTCM_OFFSET,
-                              (DTCM_END - DTCM_OFFSET + 1) >> 10);
+       if (dtcm_banks > 0) {
+               for (i = 0; i < dtcm_banks; i++) {
+                       ret = setup_tcm_bank(0, i, dtcm_banks, &dtcm_end);
+                       if (ret)
+                               return;
+               }
+               dtcm_res.end = dtcm_end - 1;
                request_resource(&iomem_resource, &dtcm_res);
+               dtcm_iomap[0].length = dtcm_end - DTCM_OFFSET;
                iotable_init(dtcm_iomap, 1);
                /* Copy data from RAM to DTCM */
                start = &__sdtcm_data;
                end   = &__edtcm_data;
                ram   = &__dtcm_start;
+               /* This means you compiled more code than fits into DTCM */
+               BUG_ON((end - start) > (dtcm_end - DTCM_OFFSET));
                memcpy(start, ram, (end-start));
                pr_debug("CPU DTCM: copied data from %p - %p\n", start, end);
        }
 
        /* Setup ITCM if present */
-       if (tcm_status & 1) {
-               setup_tcm_bank(1, ITCM_OFFSET,
-                              (ITCM_END - ITCM_OFFSET + 1) >> 10);
+       if (itcm_banks > 0) {
+               for (i = 0; i < itcm_banks; i++) {
+                       ret = setup_tcm_bank(1, i, itcm_banks, &itcm_end);
+                       if (ret)
+                               return;
+               }
+               itcm_res.end = itcm_end - 1;
                request_resource(&iomem_resource, &itcm_res);
+               itcm_iomap[0].length = itcm_end - ITCM_OFFSET;
                iotable_init(itcm_iomap, 1);
                /* Copy code from RAM to ITCM */
                start = &__sitcm_text;
                end   = &__eitcm_text;
                ram   = &__itcm_start;
+               /* This means you compiled more code than fits into ITCM */
+               BUG_ON((end - start) > (itcm_end - ITCM_OFFSET));
                memcpy(start, ram, (end-start));
                pr_debug("CPU ITCM: copied code from %p - %p\n", start, end);
        }
@@ -208,10 +236,10 @@ static int __init setup_tcm_pool(void)
        pr_debug("Setting up TCM memory pool\n");
 
        /* Add the rest of DTCM to the TCM pool */
-       if (tcm_status & (1 << 16)) {
-               if (dtcm_pool_start < DTCM_END) {
+       if (tcm_status & (0x03 << 16)) {
+               if (dtcm_pool_start < dtcm_end) {
                        ret = gen_pool_add(tcm_pool, dtcm_pool_start,
-                                          DTCM_END - dtcm_pool_start + 1, -1);
+                                          dtcm_end - dtcm_pool_start, -1);
                        if (ret) {
                                pr_err("CPU DTCM: could not add DTCM " \
                                       "remainder to pool!\n");
@@ -219,16 +247,16 @@ static int __init setup_tcm_pool(void)
                        }
                        pr_debug("CPU DTCM: Added %08x bytes @ %08x to " \
                                 "the TCM memory pool\n",
-                                DTCM_END - dtcm_pool_start + 1,
+                                dtcm_end - dtcm_pool_start,
                                 dtcm_pool_start);
                }
        }
 
        /* Add the rest of ITCM to the TCM pool */
-       if (tcm_status & 1) {
-               if (itcm_pool_start < ITCM_END) {
+       if (tcm_status & 0x03) {
+               if (itcm_pool_start < itcm_end) {
                        ret = gen_pool_add(tcm_pool, itcm_pool_start,
-                                          ITCM_END - itcm_pool_start + 1, -1);
+                                          itcm_end - itcm_pool_start, -1);
                        if (ret) {
                                pr_err("CPU ITCM: could not add ITCM " \
                                       "remainder to pool!\n");
@@ -236,7 +264,7 @@ static int __init setup_tcm_pool(void)
                        }
                        pr_debug("CPU ITCM: Added %08x bytes @ %08x to " \
                                 "the TCM memory pool\n",
-                                ITCM_END - itcm_pool_start + 1,
+                                itcm_end - itcm_pool_start,
                                 itcm_pool_start);
                }
        }
index 1621e5327b2a72a6c9197e95615928e749aa5f41..cda78d59aa31b2971ed897b9db78afd6bfb0f36e 100644 (file)
@@ -30,6 +30,7 @@
 #include <asm/unistd.h>
 #include <asm/traps.h>
 #include <asm/unwind.h>
+#include <asm/tls.h>
 
 #include "ptrace.h"
 #include "signal.h"
@@ -518,17 +519,20 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
 
        case NR(set_tls):
                thread->tp_value = regs->ARM_r0;
-#if defined(CONFIG_HAS_TLS_REG)
-               asm ("mcr p15, 0, %0, c13, c0, 3" : : "r" (regs->ARM_r0) );
-#elif !defined(CONFIG_TLS_REG_EMUL)
-               /*
-                * User space must never try to access this directly.
-                * Expect your app to break eventually if you do so.
-                * The user helper at 0xffff0fe0 must be used instead.
-                * (see entry-armv.S for details)
-                */
-               *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
-#endif
+               if (tls_emu)
+                       return 0;
+               if (has_tls_reg) {
+                       asm ("mcr p15, 0, %0, c13, c0, 3"
+                               : : "r" (regs->ARM_r0));
+               } else {
+                       /*
+                        * User space must never try to access this directly.
+                        * Expect your app to break eventually if you do so.
+                        * The user helper at 0xffff0fe0 must be used instead.
+                        * (see entry-armv.S for details)
+                        */
+                       *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
+               }
                return 0;
 
 #ifdef CONFIG_NEEDS_SYSCALL_FOR_CMPXCHG
@@ -743,6 +747,16 @@ void __init trap_init(void)
        return;
 }
 
+static void __init kuser_get_tls_init(unsigned long vectors)
+{
+       /*
+        * vectors + 0xfe0 = __kuser_get_tls
+        * vectors + 0xfe8 = hardware TLS instruction at 0xffff0fe8
+        */
+       if (tls_emu || has_tls_reg)
+               memcpy((void *)vectors + 0xfe0, (void *)vectors + 0xfe8, 4);
+}
+
 void __init early_trap_init(void)
 {
        unsigned long vectors = CONFIG_VECTORS_BASE;
@@ -760,6 +774,11 @@ void __init early_trap_init(void)
        memcpy((void *)vectors + 0x200, __stubs_start, __stubs_end - __stubs_start);
        memcpy((void *)vectors + 0x1000 - kuser_sz, __kuser_helper_start, kuser_sz);
 
+       /*
+        * Do processor specific fixups for the kuser helpers
+        */
+       kuser_get_tls_init(vectors);
+
        /*
         * Copy signal return handlers into the vector page, and
         * set sigreturn to be a pointer to these.
index 030ba7219f482bfd9873b196d1a8634d5fc2eacb..59ff42ddf0aed656f3def2c44859f0eec414b1d3 100644 (file)
@@ -41,7 +41,6 @@ else
 endif
 
 lib-$(CONFIG_ARCH_RPC)         += ecard.o io-acorn.o floppydma.o
-lib-$(CONFIG_ARCH_L7200)       += io-acorn.o
 lib-$(CONFIG_ARCH_SHARK)       += io-shark.o
 
 $(obj)/csumpartialcopy.o:      $(obj)/csumpartialcopygeneric.S
index c00822543d9f78a307c4a7c7f3c576db75c2efb4..4f93c567a35a3acb8969d5ae7951bfc2e8f008e4 100644 (file)
 
 #define PHYS_OFFSET    UL(0xf0000000)
 
-/*
- * The nodes are the followings:
- *
- *   node 0: 0xf000.0000 - 0xf3ff.ffff
- *   node 1: 0xf400.0000 - 0xf7ff.ffff
- *   node 2: 0xf800.0000 - 0xfbff.ffff
- *   node 3: 0xfc00.0000 - 0xffff.ffff
- */
-#define NODE_MEM_SIZE_BITS     26
-
 #endif /* __ASM_ARCH_MEMORY_H */
index 841eaf8f27e221dfa600178e4d20ac0d56ddeaad..939bccd70569846987c6ddb304cd22c7de730bf7 100644 (file)
@@ -366,6 +366,17 @@ config MACH_STAMP9G20
 
 endif
 
+if (ARCH_AT91SAM9260 || ARCH_AT91SAM9G20)
+comment "AT91SAM9260/AT91SAM9G20 boards"
+
+config MACH_SNAPPER_9260
+        bool "Bluewater Systems Snapper 9260/9G20 module"
+        help
+          Select this if you are using the Bluewater Systems Snapper 9260 or
+          Snapper 9G20 modules.
+          <http://www.bluewatersys.com/>
+endif
+
 # ----------------------------------------------------------
 
 if ARCH_AT91SAM9G45
index c1f821e58222b77257e875c3ce5a72ea2be6429d..ca2ac003f41f5666fb8da8c1e23b34ab3e363ea6 100644 (file)
@@ -66,6 +66,9 @@ obj-$(CONFIG_MACH_CPU9G20)    += board-cpu9krea.o
 obj-$(CONFIG_MACH_STAMP9G20)   += board-stamp9g20.o
 obj-$(CONFIG_MACH_PORTUXG20)   += board-stamp9g20.o
 
+# AT91SAM9260/AT91SAM9G20 board-specific support
+obj-$(CONFIG_MACH_SNAPPER_9260)        += board-snapper9260.o
+
 # AT91SAM9G45 board-specific support
 obj-$(CONFIG_MACH_AT91SAM9G45EKES) += board-sam9m10g45ek.o
 
index 85166b7e69a18235969336742526c2961c486d66..753c0d31a3d3f0b407cfe20b68f5ba66189cd1a7 100644 (file)
@@ -20,6 +20,7 @@
 #include <mach/at91_pmc.h>
 #include <mach/at91_rstc.h>
 #include <mach/at91_shdwc.h>
+#include <mach/cpu.h>
 
 #include "generic.h"
 #include "clock.h"
@@ -176,6 +177,13 @@ static struct clk mmc1_clk = {
        .type           = CLK_TYPE_PERIPHERAL,
 };
 
+/* Video decoder clock - Only for sam9m10/sam9m11 */
+static struct clk vdec_clk = {
+       .name           = "vdec_clk",
+       .pmc_mask       = 1 << AT91SAM9G45_ID_VDEC,
+       .type           = CLK_TYPE_PERIPHERAL,
+};
+
 /* One additional fake clock for ohci */
 static struct clk ohci_clk = {
        .name           = "ohci_clk",
@@ -239,6 +247,9 @@ static void __init at91sam9g45_register_clocks(void)
        for (i = 0; i < ARRAY_SIZE(periph_clocks); i++)
                clk_register(periph_clocks[i]);
 
+       if (cpu_is_at91sam9m10() || cpu_is_at91sam9m11())
+               clk_register(&vdec_clk);
+
        clk_register(&pck0);
        clk_register(&pck1);
 }
index a4102d72cc9b1c8e9d323f432fb5873b2144cc44..c49f5c003ee10d9fbad7a6f076f0e1dc58b0d653 100644 (file)
@@ -26,6 +26,9 @@
 #include <linux/spi/spi.h>
 #include <linux/spi/at73c213.h>
 #include <linux/clk.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/fixed.h>
+#include <linux/regulator/consumer.h>
 
 #include <mach/hardware.h>
 #include <asm/setup.h>
@@ -235,6 +238,46 @@ static struct gpio_led ek_leds[] = {
        }
 };
 
+#if defined(CONFIG_REGULATOR_FIXED_VOLTAGE) || defined(CONFIG_REGULATOR_FIXED_VOLTAGE_MODULE)
+static struct regulator_consumer_supply ek_audio_consumer_supplies[] = {
+       REGULATOR_SUPPLY("AVDD", "0-001b"),
+       REGULATOR_SUPPLY("HPVDD", "0-001b"),
+       REGULATOR_SUPPLY("DBVDD", "0-001b"),
+       REGULATOR_SUPPLY("DCVDD", "0-001b"),
+};
+
+static struct regulator_init_data ek_avdd_reg_init_data = {
+       .constraints    = {
+               .name   = "3V3",
+               .valid_ops_mask = REGULATOR_CHANGE_STATUS,
+       },
+       .consumer_supplies = ek_audio_consumer_supplies,
+       .num_consumer_supplies = ARRAY_SIZE(ek_audio_consumer_supplies),
+};
+
+static struct fixed_voltage_config ek_vdd_pdata = {
+       .supply_name    = "board-3V3",
+       .microvolts     = 3300000,
+       .gpio           = -EINVAL,
+       .enabled_at_boot = 0,
+       .init_data      = &ek_avdd_reg_init_data,
+};
+static struct platform_device ek_voltage_regulator = {
+       .name           = "reg-fixed-voltage",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &ek_vdd_pdata,
+       },
+};
+static void __init ek_add_regulators(void)
+{
+       platform_device_register(&ek_voltage_regulator);
+}
+#else
+static void __init ek_add_regulators(void) {}
+#endif
+
 static struct i2c_board_info __initdata ek_i2c_devices[] = {
        {
                I2C_BOARD_INFO("24c512", 0x50),
@@ -256,6 +299,8 @@ static void __init ek_board_init(void)
        ek_add_device_nand();
        /* Ethernet */
        at91_add_device_eth(&ek_macb_data);
+       /* Regulators */
+       ek_add_regulators();
        /* MMC */
 #if defined(CONFIG_MMC_ATMELMCI) || defined(CONFIG_MMC_ATMELMCI_MODULE)
        at91_add_device_mci(0, &ek_mmc_data);
index c11fd47aec5d464a9f228f19a9ac79097ebcaf46..6ea9808b8868d53a0c7cefd1926f921eadd82633 100644 (file)
@@ -27,6 +27,9 @@
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
 #include <linux/clk.h>
+#include <linux/regulator/machine.h>
+#include <linux/regulator/fixed.h>
+#include <linux/regulator/consumer.h>
 
 #include <mach/hardware.h>
 #include <asm/setup.h>
@@ -269,6 +272,46 @@ static void __init ek_add_device_buttons(void)
 static void __init ek_add_device_buttons(void) {}
 #endif
 
+#if defined(CONFIG_REGULATOR_FIXED_VOLTAGE) || defined(CONFIG_REGULATOR_FIXED_VOLTAGE_MODULE)
+static struct regulator_consumer_supply ek_audio_consumer_supplies[] = {
+       REGULATOR_SUPPLY("AVDD", "0-001b"),
+       REGULATOR_SUPPLY("HPVDD", "0-001b"),
+       REGULATOR_SUPPLY("DBVDD", "0-001b"),
+       REGULATOR_SUPPLY("DCVDD", "0-001b"),
+};
+
+static struct regulator_init_data ek_avdd_reg_init_data = {
+       .constraints    = {
+               .name   = "3V3",
+               .valid_ops_mask = REGULATOR_CHANGE_STATUS,
+       },
+       .consumer_supplies = ek_audio_consumer_supplies,
+       .num_consumer_supplies = ARRAY_SIZE(ek_audio_consumer_supplies),
+};
+
+static struct fixed_voltage_config ek_vdd_pdata = {
+       .supply_name    = "board-3V3",
+       .microvolts     = 3300000,
+       .gpio           = -EINVAL,
+       .enabled_at_boot = 0,
+       .init_data      = &ek_avdd_reg_init_data,
+};
+static struct platform_device ek_voltage_regulator = {
+       .name           = "reg-fixed-voltage",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &ek_vdd_pdata,
+       },
+};
+static void __init ek_add_regulators(void)
+{
+       platform_device_register(&ek_voltage_regulator);
+}
+#else
+static void __init ek_add_regulators(void) {}
+#endif
+
 
 static struct i2c_board_info __initdata ek_i2c_devices[] = {
         {
@@ -294,6 +337,8 @@ static void __init ek_board_init(void)
        ek_add_device_nand();
        /* Ethernet */
        at91_add_device_eth(&ek_macb_data);
+       /* Regulators */
+       ek_add_regulators();
        /* MMC */
        at91_add_device_mmc(0, &ek_mmc_data);
        /* I2C */
diff --git a/arch/arm/mach-at91/board-snapper9260.c b/arch/arm/mach-at91/board-snapper9260.c
new file mode 100644 (file)
index 0000000..2c08ae4
--- /dev/null
@@ -0,0 +1,189 @@
+/*
+ * linux/arch/arm/mach-at91/board-snapper9260.c
+ *
+ *  Copyright (C) 2010 Bluewater System Ltd
+ *
+ * Author: Andre Renaud <andre@bluewatersys.com>
+ * Author: Ryan Mallon  <ryan@bluewatersys.com>
+ *
+ * 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
+ *
+ */
+
+#include <linux/init.h>
+#include <linux/gpio.h>
+#include <linux/platform_device.h>
+#include <linux/spi/spi.h>
+#include <linux/i2c/pca953x.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+
+#include <mach/hardware.h>
+#include <mach/board.h>
+#include <mach/at91sam9_smc.h>
+
+#include "sam9_smc.h"
+#include "generic.h"
+
+#define SNAPPER9260_IO_EXP_GPIO(x)     (NR_BUILTIN_GPIO + (x))
+
+static void __init snapper9260_map_io(void)
+{
+       at91sam9260_initialize(18432000);
+
+       /* Debug on ttyS0 */
+       at91_register_uart(0, 0, 0);
+       at91_set_serial_console(0);
+
+       at91_register_uart(AT91SAM9260_ID_US0, 1,
+                          ATMEL_UART_CTS | ATMEL_UART_RTS);
+       at91_register_uart(AT91SAM9260_ID_US1, 2,
+                          ATMEL_UART_CTS | ATMEL_UART_RTS);
+       at91_register_uart(AT91SAM9260_ID_US2, 3, 0);
+}
+
+static void __init snapper9260_init_irq(void)
+{
+       at91sam9260_init_interrupts(NULL);
+}
+
+static struct at91_usbh_data __initdata snapper9260_usbh_data = {
+       .ports          = 2,
+};
+
+static struct at91_udc_data __initdata snapper9260_udc_data = {
+       .vbus_pin               = SNAPPER9260_IO_EXP_GPIO(5),
+       .vbus_active_low        = 1,
+       .vbus_polled            = 1,
+};
+
+static struct at91_eth_data snapper9260_macb_data = {
+       .is_rmii        = 1,
+};
+
+static struct mtd_partition __initdata snapper9260_nand_partitions[] = {
+       {
+               .name   = "Preboot",
+               .offset = 0,
+               .size   = SZ_128K,
+       },
+       {
+               .name   = "Bootloader",
+               .offset = MTDPART_OFS_APPEND,
+               .size   = SZ_256K,
+       },
+       {
+               .name   = "Environment",
+               .offset = MTDPART_OFS_APPEND,
+               .size   = SZ_128K,
+       },
+       {
+               .name   = "Kernel",
+               .offset = MTDPART_OFS_APPEND,
+               .size   = SZ_4M,
+       },
+       {
+               .name   = "Filesystem",
+               .offset = MTDPART_OFS_APPEND,
+               .size   = MTDPART_SIZ_FULL,
+       },
+};
+
+static struct mtd_partition * __init
+snapper9260_nand_partition_info(int size, int *num_partitions)
+{
+       *num_partitions = ARRAY_SIZE(snapper9260_nand_partitions);
+       return snapper9260_nand_partitions;
+}
+
+static struct atmel_nand_data __initdata snapper9260_nand_data = {
+       .ale            = 21,
+       .cle            = 22,
+       .rdy_pin        = AT91_PIN_PC13,
+       .partition_info = snapper9260_nand_partition_info,
+       .bus_width_16   = 0,
+};
+
+static struct sam9_smc_config __initdata snapper9260_nand_smc_config = {
+       .ncs_read_setup         = 0,
+       .nrd_setup              = 0,
+       .ncs_write_setup        = 0,
+       .nwe_setup              = 0,
+
+       .ncs_read_pulse         = 5,
+       .nrd_pulse              = 2,
+       .ncs_write_pulse        = 5,
+       .nwe_pulse              = 2,
+
+       .read_cycle             = 7,
+       .write_cycle            = 7,
+
+       .mode                   = (AT91_SMC_READMODE | AT91_SMC_WRITEMODE |
+                                  AT91_SMC_EXNWMODE_DISABLE),
+       .tdf_cycles             = 1,
+};
+
+static struct pca953x_platform_data snapper9260_io_expander_data = {
+       .gpio_base              = SNAPPER9260_IO_EXP_GPIO(0),
+};
+
+static struct i2c_board_info __initdata snapper9260_i2c_devices[] = {
+       {
+               /* IO expander */
+               I2C_BOARD_INFO("max7312", 0x28),
+               .platform_data = &snapper9260_io_expander_data,
+       },
+       {
+               /* Audio codec */
+               I2C_BOARD_INFO("tlv320aic23", 0x1a),
+       },
+       {
+               /* RTC */
+               I2C_BOARD_INFO("isl1208", 0x6f),
+       },
+};
+
+static void __init snapper9260_add_device_nand(void)
+{
+       at91_set_A_periph(AT91_PIN_PC14, 0);
+       sam9_smc_configure(3, &snapper9260_nand_smc_config);
+       at91_add_device_nand(&snapper9260_nand_data);
+}
+
+static void __init snapper9260_board_init(void)
+{
+       at91_add_device_i2c(snapper9260_i2c_devices,
+                           ARRAY_SIZE(snapper9260_i2c_devices));
+       at91_add_device_serial();
+       at91_add_device_usbh(&snapper9260_usbh_data);
+       at91_add_device_udc(&snapper9260_udc_data);
+       at91_add_device_eth(&snapper9260_macb_data);
+       at91_add_device_ssc(AT91SAM9260_ID_SSC, (ATMEL_SSC_TF | ATMEL_SSC_TK |
+                                                ATMEL_SSC_TD | ATMEL_SSC_RD));
+       snapper9260_add_device_nand();
+}
+
+MACHINE_START(SNAPPER_9260, "Bluewater Systems Snapper 9260/9G20 module")
+       .phys_io        = AT91_BASE_SYS,
+       .io_pg_offst    = (AT91_VA_BASE_SYS >> 18) & 0xfffc,
+       .boot_params    = AT91_SDRAM_BASE + 0x100,
+       .timer          = &at91sam926x_timer,
+       .map_io         = snapper9260_map_io,
+       .init_irq       = snapper9260_init_irq,
+       .init_machine   = snapper9260_board_init,
+MACHINE_END
+
+
index d8c1ededaa75aea4ab8835ade94c2dda544068f7..9c6af97374851a72d2481a0fc4b03ba64781eff8 100644 (file)
@@ -84,7 +84,7 @@
  */
 #define AT91_ECC       (0xffffe200 - AT91_BASE_SYS)
 #define AT91_BCRAMC    (0xffffe400 - AT91_BASE_SYS)
-#define AT91_DDRSDRC   (0xffffe600 - AT91_BASE_SYS)
+#define AT91_DDRSDRC0  (0xffffe600 - AT91_BASE_SYS)
 #define AT91_SMC       (0xffffe800 - AT91_BASE_SYS)
 #define AT91_MATRIX    (0xffffea00 - AT91_BASE_SYS)
 #define AT91_CCFG      (0xffffeb10 - AT91_BASE_SYS)
index 1499b1cbffddbe6c3f0ff3d70617d2314d574ab4..976f4a6c33532e85e6a8053df737cf638c820827 100644 (file)
@@ -15,7 +15,7 @@
 #ifndef AT91CAP9_DDRSDR_H
 #define AT91CAP9_DDRSDR_H
 
-#define AT91_DDRSDRC_MR                (AT91_DDRSDRC + 0x00)   /* Mode Register */
+#define AT91_DDRSDRC_MR                0x00    /* Mode Register */
 #define                AT91_DDRSDRC_MODE       (0xf << 0)              /* Command Mode */
 #define                        AT91_DDRSDRC_MODE_NORMAL                0
 #define                        AT91_DDRSDRC_MODE_NOP           1
 #define                        AT91_DDRSDRC_MODE_EXT_LMR       5
 #define                        AT91_DDRSDRC_MODE_DEEP          6
 
-#define AT91_DDRSDRC_RTR       (AT91_DDRSDRC + 0x04)   /* Refresh Timer Register */
+#define AT91_DDRSDRC_RTR       0x04    /* Refresh Timer Register */
 #define                AT91_DDRSDRC_COUNT      (0xfff << 0)            /* Refresh Timer Counter */
 
-#define AT91_DDRSDRC_CR                (AT91_DDRSDRC + 0x08)   /* Configuration Register */
+#define AT91_DDRSDRC_CR                0x08    /* Configuration Register */
 #define                AT91_DDRSDRC_NC         (3 << 0)                /* Number of Column Bits */
 #define                        AT91_DDRSDRC_NC_SDR8    (0 << 0)
 #define                        AT91_DDRSDRC_NC_SDR9    (1 << 0)
@@ -49,7 +49,7 @@
 #define                AT91_DDRSDRC_DLL        (1 << 7)                /* Reset DLL */
 #define                AT91_DDRSDRC_DICDS      (1 << 8)                /* Output impedance control */
 
-#define AT91_DDRSDRC_T0PR      (AT91_DDRSDRC + 0x0C)   /* Timing 0 Register */
+#define AT91_DDRSDRC_T0PR      0x0C    /* Timing 0 Register */
 #define                AT91_DDRSDRC_TRAS       (0xf <<  0)             /* Active to Precharge delay */
 #define                AT91_DDRSDRC_TRCD       (0xf <<  4)             /* Row to Column delay */
 #define                AT91_DDRSDRC_TWR        (0xf <<  8)             /* Write recovery delay */
 #define                AT91_DDRSDRC_TWTR       (1   << 24)             /* Internal Write to Read delay */
 #define                AT91_DDRSDRC_TMRD       (0xf << 28)             /* Load mode to active/refresh delay */
 
-#define AT91_DDRSDRC_T1PR      (AT91_DDRSDRC + 0x10)   /* Timing 1 Register */
+#define AT91_DDRSDRC_T1PR      0x10    /* Timing 1 Register */
 #define                AT91_DDRSDRC_TRFC       (0x1f << 0)             /* Row Cycle Delay */
 #define                AT91_DDRSDRC_TXSNR      (0xff << 8)             /* Exit self-refresh to non-read */
 #define                AT91_DDRSDRC_TXSRD      (0xff << 16)            /* Exit self-refresh to read */
 #define                AT91_DDRSDRC_TXP        (0xf  << 24)            /* Exit power-down delay */
 
-#define AT91_DDRSDRC_LPR       (AT91_DDRSDRC + 0x18)   /* Low Power Register */
+#define AT91_DDRSDRC_LPR       0x18    /* Low Power Register */
 #define                AT91_DDRSDRC_LPCB               (3 << 0)        /* Low-power Configurations */
 #define                        AT91_DDRSDRC_LPCB_DISABLE               0
 #define                        AT91_DDRSDRC_LPCB_SELF_REFRESH          1
 #define                        AT91_DDRSDRC_TIMEOUT_64_CLK_CYCLES      (1 << 12)
 #define                        AT91_DDRSDRC_TIMEOUT_128_CLK_CYCLES     (2 << 12)
 
-#define AT91_DDRSDRC_MDR       (AT91_DDRSDRC + 0x1C)   /* Memory Device Register */
+#define AT91_DDRSDRC_MDR       0x1C    /* Memory Device Register */
 #define                AT91_DDRSDRC_MD         (3 << 0)                /* Memory Device Type */
 #define                        AT91_DDRSDRC_MD_SDR             0
 #define                        AT91_DDRSDRC_MD_LOW_POWER_SDR   1
 #define                        AT91_DDRSDRC_MD_DDR             2
 #define                        AT91_DDRSDRC_MD_LOW_POWER_DDR   3
 
-#define AT91_DDRSDRC_DLLR      (AT91_DDRSDRC + 0x20)   /* DLL Information Register */
+#define AT91_DDRSDRC_DLLR      0x20    /* DLL Information Register */
 #define                AT91_DDRSDRC_MDINC      (1 << 0)                /* Master Delay increment */
 #define                AT91_DDRSDRC_MDDEC      (1 << 1)                /* Master Delay decrement */
 #define                AT91_DDRSDRC_MDOVF      (1 << 2)                /* Master Delay Overflow */
 #define                AT91_DDRSDRC_SDVAL      (0xff << 16)            /* Slave Delay value */
 #define                AT91_DDRSDRC_SDCVAL     (0xff << 24)            /* Slave Delay Correction value */
 
+/* Register access macros */
+#define at91_ramc_read(num, reg) \
+       at91_sys_read(AT91_DDRSDRC##num + reg)
+#define at91_ramc_write(num, reg, value) \
+       at91_sys_write(AT91_DDRSDRC##num + reg, value)
+
 
 #endif
index 43c396b9b4cb8cc1ceedf44bf24fe62ff225c880..4e79036d3b801849ea8f547e6dd6fdf8b16d894e 100644 (file)
@@ -84,7 +84,7 @@
  * System Peripherals (offset from AT91_BASE_SYS)
  */
 #define AT91_ECC       (0xffffe800 - AT91_BASE_SYS)
-#define AT91_SDRAMC    (0xffffea00 - AT91_BASE_SYS)
+#define AT91_SDRAMC0   (0xffffea00 - AT91_BASE_SYS)
 #define AT91_SMC       (0xffffec00 - AT91_BASE_SYS)
 #define AT91_MATRIX    (0xffffee00 - AT91_BASE_SYS)
 #define AT91_CCFG      (0xffffef10 - AT91_BASE_SYS)
index 87de8be17484be6966c7ee02bcf4a94620932e63..2b561851812952fe60e8b44fa1d44641fcdd81bc 100644 (file)
@@ -68,7 +68,7 @@
 /*
  * System Peripherals (offset from AT91_BASE_SYS)
  */
-#define AT91_SDRAMC    (0xffffea00 - AT91_BASE_SYS)
+#define AT91_SDRAMC0   (0xffffea00 - AT91_BASE_SYS)
 #define AT91_SMC       (0xffffec00 - AT91_BASE_SYS)
 #define AT91_MATRIX    (0xffffee00 - AT91_BASE_SYS)
 #define AT91_AIC       (0xfffff000 - AT91_BASE_SYS)
diff --git a/arch/arm/mach-at91/include/mach/at91sam9_ddrsdr.h b/arch/arm/mach-at91/include/mach/at91sam9_ddrsdr.h
new file mode 100644 (file)
index 0000000..d27b15b
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * Header file for the Atmel DDR/SDR SDRAM Controller
+ *
+ * Copyright (C) 2010 Atmel Corporation
+ *     Nicolas Ferre <nicolas.ferre@atmel.com>
+ *
+ * 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.
+ */
+#ifndef AT91SAM9_DDRSDR_H
+#define AT91SAM9_DDRSDR_H
+
+#define AT91_DDRSDRC_MR                0x00    /* Mode Register */
+#define                AT91_DDRSDRC_MODE       (0x7 << 0)              /* Command Mode */
+#define                        AT91_DDRSDRC_MODE_NORMAL        0
+#define                        AT91_DDRSDRC_MODE_NOP           1
+#define                        AT91_DDRSDRC_MODE_PRECHARGE     2
+#define                        AT91_DDRSDRC_MODE_LMR           3
+#define                        AT91_DDRSDRC_MODE_REFRESH       4
+#define                        AT91_DDRSDRC_MODE_EXT_LMR       5
+#define                        AT91_DDRSDRC_MODE_DEEP          6
+
+#define AT91_DDRSDRC_RTR       0x04    /* Refresh Timer Register */
+#define                AT91_DDRSDRC_COUNT      (0xfff << 0)            /* Refresh Timer Counter */
+
+#define AT91_DDRSDRC_CR                0x08    /* Configuration Register */
+#define                AT91_DDRSDRC_NC         (3 << 0)                /* Number of Column Bits */
+#define                        AT91_DDRSDRC_NC_SDR8    (0 << 0)
+#define                        AT91_DDRSDRC_NC_SDR9    (1 << 0)
+#define                        AT91_DDRSDRC_NC_SDR10   (2 << 0)
+#define                        AT91_DDRSDRC_NC_SDR11   (3 << 0)
+#define                        AT91_DDRSDRC_NC_DDR9    (0 << 0)
+#define                        AT91_DDRSDRC_NC_DDR10   (1 << 0)
+#define                        AT91_DDRSDRC_NC_DDR11   (2 << 0)
+#define                        AT91_DDRSDRC_NC_DDR12   (3 << 0)
+#define                AT91_DDRSDRC_NR         (3 << 2)                /* Number of Row Bits */
+#define                        AT91_DDRSDRC_NR_11      (0 << 2)
+#define                        AT91_DDRSDRC_NR_12      (1 << 2)
+#define                        AT91_DDRSDRC_NR_13      (2 << 2)
+#define                        AT91_DDRSDRC_NR_14      (3 << 2)
+#define                AT91_DDRSDRC_CAS        (7 << 4)                /* CAS Latency */
+#define                        AT91_DDRSDRC_CAS_2      (2 << 4)
+#define                        AT91_DDRSDRC_CAS_3      (3 << 4)
+#define                        AT91_DDRSDRC_CAS_25     (6 << 4)
+#define                AT91_DDRSDRC_RST_DLL    (1 << 7)                /* Reset DLL */
+#define                AT91_DDRSDRC_DICDS      (1 << 8)                /* Output impedance control */
+#define                AT91_DDRSDRC_DIS_DLL    (1 << 9)                /* Disable DLL */
+#define                AT91_DDRSDRC_OCD        (1 << 12)               /* Off-Chip Driver */
+#define                AT91_DDRSDRC_DQMS       (1 << 16)               /* Mask Data is Shared */
+#define                AT91_DDRSDRC_ACTBST     (1 << 18)               /* Active Bank X to Burst Stop Read Access Bank Y */
+
+#define AT91_DDRSDRC_T0PR      0x0C    /* Timing 0 Register */
+#define                AT91_DDRSDRC_TRAS       (0xf <<  0)             /* Active to Precharge delay */
+#define                AT91_DDRSDRC_TRCD       (0xf <<  4)             /* Row to Column delay */
+#define                AT91_DDRSDRC_TWR        (0xf <<  8)             /* Write recovery delay */
+#define                AT91_DDRSDRC_TRC        (0xf << 12)             /* Row cycle delay */
+#define                AT91_DDRSDRC_TRP        (0xf << 16)             /* Row precharge delay */
+#define                AT91_DDRSDRC_TRRD       (0xf << 20)             /* Active BankA to BankB */
+#define                AT91_DDRSDRC_TWTR       (0x7 << 24)             /* Internal Write to Read delay */
+#define                AT91_DDRSDRC_RED_WRRD   (0x1 << 27)             /* Reduce Write to Read Delay */
+#define                AT91_DDRSDRC_TMRD       (0xf << 28)             /* Load mode to active/refresh delay */
+
+#define AT91_DDRSDRC_T1PR      0x10    /* Timing 1 Register */
+#define                AT91_DDRSDRC_TRFC       (0x1f << 0)             /* Row Cycle Delay */
+#define                AT91_DDRSDRC_TXSNR      (0xff << 8)             /* Exit self-refresh to non-read */
+#define                AT91_DDRSDRC_TXSRD      (0xff << 16)            /* Exit self-refresh to read */
+#define                AT91_DDRSDRC_TXP        (0xf  << 24)            /* Exit power-down delay */
+
+#define AT91_DDRSDRC_T2PR      0x14    /* Timing 2 Register */
+#define                AT91_DDRSDRC_TXARD      (0xf  << 0)             /* Exit active power down delay to read command in mode "Fast Exit" */
+#define                AT91_DDRSDRC_TXARDS     (0xf  << 4)             /* Exit active power down delay to read command in mode "Slow Exit" */
+#define                AT91_DDRSDRC_TRPA       (0xf  << 8)             /* Row Precharge All delay */
+#define                AT91_DDRSDRC_TRTP       (0x7  << 12)            /* Read to Precharge delay */
+
+#define AT91_DDRSDRC_LPR       0x1C    /* Low Power Register */
+#define                AT91_DDRSDRC_LPCB       (3 << 0)                /* Low-power Configurations */
+#define                        AT91_DDRSDRC_LPCB_DISABLE               0
+#define                        AT91_DDRSDRC_LPCB_SELF_REFRESH          1
+#define                        AT91_DDRSDRC_LPCB_POWER_DOWN            2
+#define                        AT91_DDRSDRC_LPCB_DEEP_POWER_DOWN       3
+#define                AT91_DDRSDRC_CLKFR      (1 << 2)        /* Clock Frozen */
+#define                AT91_DDRSDRC_PASR       (7 << 4)        /* Partial Array Self Refresh */
+#define                AT91_DDRSDRC_TCSR       (3 << 8)        /* Temperature Compensated Self Refresh */
+#define                AT91_DDRSDRC_DS         (3 << 10)       /* Drive Strength */
+#define                AT91_DDRSDRC_TIMEOUT    (3 << 12)       /* Time to define when Low Power Mode is enabled */
+#define                        AT91_DDRSDRC_TIMEOUT_0_CLK_CYCLES       (0 << 12)
+#define                        AT91_DDRSDRC_TIMEOUT_64_CLK_CYCLES      (1 << 12)
+#define                        AT91_DDRSDRC_TIMEOUT_128_CLK_CYCLES     (2 << 12)
+#define                AT91_DDRSDRC_APDE       (1 << 16)        /* Active power down exit time */
+#define                AT91_DDRSDRC_UPD_MR     (3 << 20)        /* Update load mode register and extended mode register */
+
+#define AT91_DDRSDRC_MDR       0x20    /* Memory Device Register */
+#define                AT91_DDRSDRC_MD         (3 << 0)                /* Memory Device Type */
+#define                        AT91_DDRSDRC_MD_SDR             0
+#define                        AT91_DDRSDRC_MD_LOW_POWER_SDR   1
+#define                        AT91_DDRSDRC_MD_LOW_POWER_DDR   3
+#define                        AT91_DDRSDRC_MD_DDR2            6
+#define                AT91_DDRSDRC_DBW        (1 << 4)                /* Data Bus Width */
+#define                        AT91_DDRSDRC_DBW_32BITS         (0 <<  4)
+#define                        AT91_DDRSDRC_DBW_16BITS         (1 <<  4)
+
+#define AT91_DDRSDRC_DLL       0x24    /* DLL Information Register */
+#define                AT91_DDRSDRC_MDINC      (1 << 0)                /* Master Delay increment */
+#define                AT91_DDRSDRC_MDDEC      (1 << 1)                /* Master Delay decrement */
+#define                AT91_DDRSDRC_MDOVF      (1 << 2)                /* Master Delay Overflow */
+#define                AT91_DDRSDRC_MDVAL      (0xff <<  8)            /* Master Delay value */
+
+#define AT91_DDRSDRC_HS                0x2C    /* High Speed Register */
+#define                AT91_DDRSDRC_DIS_ATCP_RD        (1 << 2)        /* Anticip read access is disabled */
+
+#define AT91_DDRSDRC_DELAY(n)  (0x30 + (0x4 * (n)))    /* Delay I/O Register n */
+
+#define AT91_DDRSDRC_WPMR      0xE4    /* Write Protect Mode Register */
+#define                AT91_DDRSDRC_WP         (1 << 0)                /* Write protect enable */
+#define                AT91_DDRSDRC_WPKEY      (0xffffff << 8)         /* Write protect key */
+#define                AT91_DDRSDRC_KEY        (0x444452 << 8)         /* Write protect key = "DDR" */
+
+#define AT91_DDRSDRC_WPSR      0xE8    /* Write Protect Status Register */
+#define                AT91_DDRSDRC_WPVS       (1 << 0)                /* Write protect violation status */
+#define                AT91_DDRSDRC_WPVSRC     (0xffff << 8)           /* Write protect violation source */
+
+/* Register access macros */
+#define at91_ramc_read(num, reg) \
+       at91_sys_read(AT91_DDRSDRC##num + reg)
+#define at91_ramc_write(num, reg, value) \
+       at91_sys_write(AT91_DDRSDRC##num + reg, value)
+
+#endif
index b7260389f7cac2a51937143c10e55e3e75ee8aa9..100f5a592926356db536780996a7796ff6856e91 100644 (file)
@@ -17,7 +17,7 @@
 #define AT91SAM9_SDRAMC_H
 
 /* SDRAM Controller (SDRAMC) registers */
-#define AT91_SDRAMC_MR         (AT91_SDRAMC + 0x00)    /* SDRAM Controller Mode Register */
+#define AT91_SDRAMC_MR         0x00    /* SDRAM Controller Mode Register */
 #define                AT91_SDRAMC_MODE        (0xf << 0)              /* Command Mode */
 #define                        AT91_SDRAMC_MODE_NORMAL         0
 #define                        AT91_SDRAMC_MODE_NOP            1
 #define                        AT91_SDRAMC_MODE_EXT_LMR        5
 #define                        AT91_SDRAMC_MODE_DEEP           6
 
-#define AT91_SDRAMC_TR         (AT91_SDRAMC + 0x04)    /* SDRAM Controller Refresh Timer Register */
+#define AT91_SDRAMC_TR         0x04    /* SDRAM Controller Refresh Timer Register */
 #define                AT91_SDRAMC_COUNT       (0xfff << 0)            /* Refresh Timer Counter */
 
-#define AT91_SDRAMC_CR         (AT91_SDRAMC + 0x08)    /* SDRAM Controller Configuration Register */
+#define AT91_SDRAMC_CR         0x08    /* SDRAM Controller Configuration Register */
 #define                AT91_SDRAMC_NC          (3 << 0)                /* Number of Column Bits */
 #define                        AT91_SDRAMC_NC_8        (0 << 0)
 #define                        AT91_SDRAMC_NC_9        (1 << 0)
@@ -57,7 +57,7 @@
 #define                AT91_SDRAMC_TRAS        (0xf << 24)             /* Active to Precharge Delay */
 #define                AT91_SDRAMC_TXSR        (0xf << 28)             /* Exit Self Refresh to Active Delay */
 
-#define AT91_SDRAMC_LPR                (AT91_SDRAMC + 0x10)    /* SDRAM Controller Low Power Register */
+#define AT91_SDRAMC_LPR                0x10    /* SDRAM Controller Low Power Register */
 #define                AT91_SDRAMC_LPCB                (3 << 0)        /* Low-power Configurations */
 #define                        AT91_SDRAMC_LPCB_DISABLE                0
 #define                        AT91_SDRAMC_LPCB_SELF_REFRESH           1
 #define                        AT91_SDRAMC_TIMEOUT_64_CLK_CYCLES       (1 << 12)
 #define                        AT91_SDRAMC_TIMEOUT_128_CLK_CYCLES      (2 << 12)
 
-#define AT91_SDRAMC_IER                (AT91_SDRAMC + 0x14)    /* SDRAM Controller Interrupt Enable Register */
-#define AT91_SDRAMC_IDR                (AT91_SDRAMC + 0x18)    /* SDRAM Controller Interrupt Disable Register */
-#define AT91_SDRAMC_IMR                (AT91_SDRAMC + 0x1C)    /* SDRAM Controller Interrupt Mask Register */
-#define AT91_SDRAMC_ISR                (AT91_SDRAMC + 0x20)    /* SDRAM Controller Interrupt Status Register */
+#define AT91_SDRAMC_IER                0x14    /* SDRAM Controller Interrupt Enable Register */
+#define AT91_SDRAMC_IDR                0x18    /* SDRAM Controller Interrupt Disable Register */
+#define AT91_SDRAMC_IMR                0x1C    /* SDRAM Controller Interrupt Mask Register */
+#define AT91_SDRAMC_ISR                0x20    /* SDRAM Controller Interrupt Status Register */
 #define                AT91_SDRAMC_RES         (1 << 0)                /* Refresh Error Status */
 
-#define AT91_SDRAMC_MDR                (AT91_SDRAMC + 0x24)    /* SDRAM Memory Device Register */
+#define AT91_SDRAMC_MDR                0x24    /* SDRAM Memory Device Register */
 #define                AT91_SDRAMC_MD          (3 << 0)                /* Memory Device Type */
 #define                        AT91_SDRAMC_MD_SDRAM            0
 #define                        AT91_SDRAMC_MD_LOW_POWER_SDRAM  1
 
+/* Register access macros */
+#define at91_ramc_read(num, reg) \
+       at91_sys_read(AT91_SDRAMC##num + reg)
+#define at91_ramc_write(num, reg, value) \
+       at91_sys_write(AT91_SDRAMC##num + reg, value)
 
 #endif
index fc2de6c09c86a67c21073e405144ad17d94f8f64..87ba8517ad98291a12749853cfc7379e021c4997 100644 (file)
@@ -74,7 +74,7 @@
  */
 #define AT91_DMA       (0xffffe600 - AT91_BASE_SYS)
 #define AT91_ECC       (0xffffe800 - AT91_BASE_SYS)
-#define AT91_SDRAMC    (0xffffea00 - AT91_BASE_SYS)
+#define AT91_SDRAMC0   (0xffffea00 - AT91_BASE_SYS)
 #define AT91_SMC       (0xffffec00 - AT91_BASE_SYS)
 #define AT91_MATRIX    (0xffffee00 - AT91_BASE_SYS)
 #define AT91_CCFG      (0xffffef10 - AT91_BASE_SYS)
index df2ed848c9f89b0e9f2e0bb3ee6a7c8d0fd631d5..58528aa9c8a86ddea8286cfb9ebdac7e26ed6942 100644 (file)
@@ -44,6 +44,8 @@
  /* USB Device */
 struct at91_udc_data {
        u8      vbus_pin;               /* high == host powering us */
+       u8      vbus_active_low;        /* vbus polarity */
+       u8      vbus_polled;            /* Use polling, not interrupt */
        u8      pullup_pin;             /* active == D+ pulled up */
        u8      pullup_active_low;      /* true == pullup_pin is active low */
 };
index 833659d1200ac057faff56ccd567de4ad718e09b..3bef931d0b1c915b5de540ee860dcf37cf27cba6 100644 (file)
@@ -52,6 +52,7 @@ static inline unsigned long at91_cpu_fully_identify(void)
 
 #define ARCH_EXID_AT91SAM9M11  0x00000001
 #define ARCH_EXID_AT91SAM9M10  0x00000002
+#define ARCH_EXID_AT91SAM9G46  0x00000003
 #define ARCH_EXID_AT91SAM9G45  0x00000004
 
 static inline unsigned long at91_exid_identify(void)
@@ -128,9 +129,18 @@ static inline unsigned long at91cap9_rev_identify(void)
 #ifdef CONFIG_ARCH_AT91SAM9G45
 #define cpu_is_at91sam9g45()   (at91_cpu_identify() == ARCH_ID_AT91SAM9G45)
 #define cpu_is_at91sam9g45es() (at91_cpu_fully_identify() == ARCH_ID_AT91SAM9G45ES)
+#define cpu_is_at91sam9m10()    (cpu_is_at91sam9g45() && \
+                                (at91_exid_identify() == ARCH_EXID_AT91SAM9M10))
+#define cpu_is_at91sam9m46()    (cpu_is_at91sam9g45() && \
+                                (at91_exid_identify() == ARCH_EXID_AT91SAM9G46))
+#define cpu_is_at91sam9m11()    (cpu_is_at91sam9g45() && \
+                                (at91_exid_identify() == ARCH_EXID_AT91SAM9M11))
 #else
 #define cpu_is_at91sam9g45()   (0)
 #define cpu_is_at91sam9g45es() (0)
+#define cpu_is_at91sam9m10()   (0)
+#define cpu_is_at91sam9g46()   (0)
+#define cpu_is_at91sam9m11()   (0)
 #endif
 
 #ifdef CONFIG_ARCH_AT91CAP9
index 04c91e31c9c5be8a7c20ca5a31b6ebef99963f89..bfdd8ab26dc8a2399a379058df2e9a04f41c2888 100644 (file)
@@ -19,6 +19,7 @@
 #define PIN_BASE               NR_AIC_IRQS
 
 #define MAX_GPIO_BANKS         5
+#define NR_BUILTIN_GPIO                (PIN_BASE + (MAX_GPIO_BANKS * 32))
 
 /* these pin numbers double as IRQ numbers, like AT91xxx_ID_* values */
 
index 08322c44df1a98d287c0247321158de4d41bb99c..8c87d0c1b8f8b9b9dc0383bff155798454a6460f 100644 (file)
@@ -30,14 +30,50 @@ static inline u32 sdram_selfrefresh_enable(void)
 {
        u32 saved_lpr, lpr;
 
-       saved_lpr = at91_sys_read(AT91_DDRSDRC_LPR);
+       saved_lpr = at91_ramc_read(0, AT91_DDRSDRC_LPR);
 
        lpr = saved_lpr & ~AT91_DDRSDRC_LPCB;
-       at91_sys_write(AT91_DDRSDRC_LPR, lpr | AT91_DDRSDRC_LPCB_SELF_REFRESH);
+       at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr | AT91_DDRSDRC_LPCB_SELF_REFRESH);
        return saved_lpr;
 }
 
-#define sdram_selfrefresh_disable(saved_lpr)   at91_sys_write(AT91_DDRSDRC_LPR, saved_lpr)
+#define sdram_selfrefresh_disable(saved_lpr)   at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr)
+
+#elif defined(CONFIG_ARCH_AT91SAM9G45)
+#include <mach/at91sam9_ddrsdr.h>
+
+/* We manage both DDRAM/SDRAM controllers, we need more than one value to
+ * remember.
+ */
+static u32 saved_lpr1;
+
+static inline u32 sdram_selfrefresh_enable(void)
+{
+       /* Those tow values allow us to delay self-refresh activation
+        * to the maximum. */
+       u32 lpr0, lpr1;
+       u32 saved_lpr0;
+
+       saved_lpr1 = at91_ramc_read(1, AT91_DDRSDRC_LPR);
+       lpr1 = saved_lpr1 & ~AT91_DDRSDRC_LPCB;
+       lpr1 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
+
+       saved_lpr0 = at91_ramc_read(0, AT91_DDRSDRC_LPR);
+       lpr0 = saved_lpr0 & ~AT91_DDRSDRC_LPCB;
+       lpr0 |= AT91_DDRSDRC_LPCB_SELF_REFRESH;
+
+       /* self-refresh mode now */
+       at91_ramc_write(0, AT91_DDRSDRC_LPR, lpr0);
+       at91_ramc_write(1, AT91_DDRSDRC_LPR, lpr1);
+
+       return saved_lpr0;
+}
+
+#define sdram_selfrefresh_disable(saved_lpr0)  \
+       do { \
+               at91_ramc_write(0, AT91_DDRSDRC_LPR, saved_lpr0); \
+               at91_ramc_write(1, AT91_DDRSDRC_LPR, saved_lpr1); \
+       } while (0)
 
 #else
 #include <mach/at91sam9_sdramc.h>
@@ -47,7 +83,6 @@ static inline u32 sdram_selfrefresh_enable(void)
  * FIXME either or both the SDRAM controllers (EB0, EB1) might be in use;
  * handle those cases both here and in the Suspend-To-RAM support.
  */
-#define        AT91_SDRAMC     AT91_SDRAMC0
 #warning Assuming EB1 SDRAM controller is *NOT* used
 #endif
 
@@ -55,13 +90,13 @@ static inline u32 sdram_selfrefresh_enable(void)
 {
        u32 saved_lpr, lpr;
 
-       saved_lpr = at91_sys_read(AT91_SDRAMC_LPR);
+       saved_lpr = at91_ramc_read(0, AT91_SDRAMC_LPR);
 
        lpr = saved_lpr & ~AT91_SDRAMC_LPCB;
-       at91_sys_write(AT91_SDRAMC_LPR, lpr | AT91_SDRAMC_LPCB_SELF_REFRESH);
+       at91_ramc_write(0, AT91_SDRAMC_LPR, lpr | AT91_SDRAMC_LPCB_SELF_REFRESH);
        return saved_lpr;
 }
 
-#define sdram_selfrefresh_disable(saved_lpr)   at91_sys_write(AT91_SDRAMC_LPR, saved_lpr)
+#define sdram_selfrefresh_disable(saved_lpr)   at91_ramc_write(0, AT91_SDRAMC_LPR, saved_lpr)
 
 #endif
index 9c5b48e68a71343e26f2f17c4856886fc0509373..b6b00a1f612546eb463036214455336381560e37 100644 (file)
 #include <mach/hardware.h>
 #include <mach/at91_pmc.h>
 
-#ifdef CONFIG_ARCH_AT91RM9200
+#if defined(CONFIG_ARCH_AT91RM9200)
 #include <mach/at91rm9200_mc.h>
 #elif defined(CONFIG_ARCH_AT91CAP9)
 #include <mach/at91cap9_ddrsdr.h>
+#elif defined(CONFIG_ARCH_AT91SAM9G45)
+#include <mach/at91sam9_ddrsdr.h>
 #else
 #include <mach/at91sam9_sdramc.h>
 #endif
@@ -30,7 +32,6 @@
  * FIXME either or both the SDRAM controllers (EB0, EB1) might be in use;
  * handle those cases both here and in the Suspend-To-RAM support.
  */
-#define AT91_SDRAMC    AT91_SDRAMC0
 #warning Assuming EB1 SDRAM controller is *NOT* used
 #endif
 
@@ -113,12 +114,14 @@ ENTRY(at91_slow_clock)
        /*
         * Register usage:
         *  R1 = Base address of AT91_PMC
-        *  R2 = Base address of AT91_SDRAMC (or AT91_SYS on AT91RM9200)
+        *  R2 = Base address of RAM Controller (SDRAM, DDRSDR, or AT91_SYS)
         *  R3 = temporary register
         *  R4 = temporary register
+        *  R5 = Base address of second RAM Controller or 0 if not present
         */
        ldr     r1, .at91_va_base_pmc
        ldr     r2, .at91_va_base_sdramc
+       ldr     r5, .at91_va_base_ramc1
 
        /* Drain write buffer */
        mcr     p15, 0, r0, c7, c10, 4
@@ -127,20 +130,33 @@ ENTRY(at91_slow_clock)
        /* Put SDRAM in self-refresh mode */
        mov     r3, #1
        str     r3, [r2, #AT91_SDRAMC_SRR]
-#elif defined(CONFIG_ARCH_AT91CAP9)
-       /* Enable SDRAM self-refresh mode */
-       ldr     r3, [r2, #AT91_DDRSDRC_LPR - AT91_DDRSDRC]
-       str     r3, .saved_sam9_lpr
+#elif defined(CONFIG_ARCH_AT91CAP9) \
+       || defined(CONFIG_ARCH_AT91SAM9G45)
 
-       mov     r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
-       str     r3, [r2, #AT91_DDRSDRC_LPR - AT91_DDRSDRC]
+       /* prepare for DDRAM self-refresh mode */
+       ldr     r3, [r2, #AT91_DDRSDRC_LPR]
+       str     r3, .saved_sam9_lpr
+       bic     r3, #AT91_DDRSDRC_LPCB
+       orr     r3, #AT91_DDRSDRC_LPCB_SELF_REFRESH
+
+       /* figure out if we use the second ram controller */
+       cmp     r5, #0
+       ldrne   r4, [r5, #AT91_DDRSDRC_LPR]
+       strne   r4, .saved_sam9_lpr1
+       bicne   r4, #AT91_DDRSDRC_LPCB
+       orrne   r4, #AT91_DDRSDRC_LPCB_SELF_REFRESH
+
+       /* Enable DDRAM self-refresh mode */
+       str     r3, [r2, #AT91_DDRSDRC_LPR]
+       strne   r4, [r5, #AT91_DDRSDRC_LPR]
 #else
        /* Enable SDRAM self-refresh mode */
-       ldr     r3, [r2, #AT91_SDRAMC_LPR - AT91_SDRAMC]
+       ldr     r3, [r2, #AT91_SDRAMC_LPR]
        str     r3, .saved_sam9_lpr
 
-       mov     r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
-       str     r3, [r2, #AT91_SDRAMC_LPR - AT91_SDRAMC]
+       bic     r3, #AT91_SDRAMC_LPCB
+       orr     r3, #AT91_SDRAMC_LPCB_SELF_REFRESH
+       str     r3, [r2, #AT91_SDRAMC_LPR]
 #endif
 
        /* Save Master clock setting */
@@ -247,14 +263,21 @@ ENTRY(at91_slow_clock)
 
 #ifdef CONFIG_ARCH_AT91RM9200
        /* Do nothing - self-refresh is automatically disabled. */
-#elif defined(CONFIG_ARCH_AT91CAP9)
-       /* Restore LPR on AT91CAP9 */
+#elif defined(CONFIG_ARCH_AT91CAP9) \
+       || defined(CONFIG_ARCH_AT91SAM9G45)
+       /* Restore LPR on AT91 with DDRAM */
        ldr     r3, .saved_sam9_lpr
-       str     r3, [r2, #AT91_DDRSDRC_LPR - AT91_DDRSDRC]
+       str     r3, [r2, #AT91_DDRSDRC_LPR]
+
+       /* if we use the second ram controller */
+       cmp     r5, #0
+       ldrne   r4, .saved_sam9_lpr1
+       strne   r4, [r5, #AT91_DDRSDRC_LPR]
+
 #else
-       /* Restore LPR on AT91SAM9 */
+       /* Restore LPR on AT91 with SDRAM */
        ldr     r3, .saved_sam9_lpr
-       str     r3, [r2, #AT91_SDRAMC_LPR - AT91_SDRAMC]
+       str     r3, [r2, #AT91_SDRAMC_LPR]
 #endif
 
        /* Restore registers, and return */
@@ -273,18 +296,29 @@ ENTRY(at91_slow_clock)
 .saved_sam9_lpr:
        .word 0
 
+.saved_sam9_lpr1:
+       .word 0
+
 .at91_va_base_pmc:
        .word AT91_VA_BASE_SYS + AT91_PMC
 
 #ifdef CONFIG_ARCH_AT91RM9200
 .at91_va_base_sdramc:
        .word AT91_VA_BASE_SYS
-#elif defined(CONFIG_ARCH_AT91CAP9)
+#elif defined(CONFIG_ARCH_AT91CAP9) \
+       || defined(CONFIG_ARCH_AT91SAM9G45)
 .at91_va_base_sdramc:
-       .word AT91_VA_BASE_SYS + AT91_DDRSDRC
+       .word AT91_VA_BASE_SYS + AT91_DDRSDRC0
 #else
 .at91_va_base_sdramc:
-       .word AT91_VA_BASE_SYS + AT91_SDRAMC
+       .word AT91_VA_BASE_SYS + AT91_SDRAMC0
+#endif
+
+.at91_va_base_ramc1:
+#if defined(CONFIG_ARCH_AT91SAM9G45)
+       .word AT91_VA_BASE_SYS + AT91_DDRSDRC1
+#else
+       .word 0
 #endif
 
 ENTRY(at91_slow_clock_sz)
index 72e405df0fb07dd4b363153f149742875725f7ad..d3f959e92b2dd2ef15e129a3bd79e52801811efe 100644 (file)
@@ -91,14 +91,23 @@ static struct clk uart_clk = {
        .parent = &pll1_clk,
 };
 
+static struct clk dummy_apb_pclk = {
+       .name = "BUSCLK",
+       .type = CLK_TYPE_PRIMARY,
+       .mode = CLK_MODE_XTAL,
+};
+
 static struct clk_lookup lookups[] = {
-       {                       /* UART0 */
-        .dev_id = "uarta",
-        .clk = &uart_clk,
-        }, {                   /* UART1 */
-            .dev_id = "uartb",
-            .clk = &uart_clk,
-            }
+       {                       /* Bus clock */
+               .con_id = "apb_pclk",
+               .clk = &dummy_apb_pclk,
+       }, {                    /* UART0 */
+               .dev_id = "uarta",
+               .clk = &uart_clk,
+       }, {                    /* UART1 */
+               .dev_id = "uartb",
+               .clk = &uart_clk,
+       }
 };
 
 static struct amba_device *amba_devs[] __initdata = {
index dbaae5f746a1ced107faf56439c7f2bf71bc845c..eb34bd1251d491224f95216ca882070baa5933ce 100644 (file)
@@ -30,7 +30,6 @@ config ARCH_CLEP7312
 config ARCH_EDB7211
        bool "EDB7211"
        select ISA
-       select ARCH_DISCONTIGMEM_ENABLE
        select ARCH_SPARSEMEM_ENABLE
        select ARCH_SELECT_MEMORY_MODEL
        help
index 09fb57e452130d0766f4fe3eab0219138572ea13..3c3bf45039ff05f44c122adbc3bb1cceded613ab 100644 (file)
@@ -32,7 +32,6 @@ fixup_clep7312(struct machine_desc *desc, struct tag *tags,
        mi->nr_banks=1;
        mi->bank[0].start = 0xc0000000;
        mi->bank[0].size = 0x01000000;
-       mi->bank[0].node = 0;
 }
 
 
index dc81cc68595de96edd2f9e2679d1cd855bace03f..4a7a2322979a17c3dcb833bf44122f8af51bba8a 100644 (file)
@@ -18,6 +18,7 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include <linux/init.h>
+#include <linux/memblock.h>
 #include <linux/types.h>
 #include <linux/string.h>
 
 
 extern void edb7211_map_io(void);
 
+/* Reserve screen memory region at the start of main system memory. */
+static void __init edb7211_reserve(void)
+{
+       memblock_reserve(PHYS_OFFSET, 0x00020000);
+}
+
 static void __init
 fixup_edb7211(struct machine_desc *desc, struct tag *tags,
              char **cmdline, struct meminfo *mi)
@@ -43,10 +50,8 @@ fixup_edb7211(struct machine_desc *desc, struct tag *tags,
         */
        mi->bank[0].start = 0xc0000000;
        mi->bank[0].size = 8*1024*1024;
-       mi->bank[0].node = 0;
        mi->bank[1].start = 0xc1000000;
        mi->bank[1].size = 8*1024*1024;
-       mi->bank[1].node = 1;
        mi->nr_banks = 2;
 }
 
@@ -57,6 +62,7 @@ MACHINE_START(EDB7211, "CL-EDB7211 (EP7211 eval board)")
        .boot_params    = 0xc0020100,   /* 0xc0000000 - 0xc001ffff can be video RAM */
        .fixup          = fixup_edb7211,
        .map_io         = edb7211_map_io,
+       .reserve        = edb7211_reserve,
        .init_irq       = clps711x_init_irq,
        .timer          = &clps711x_timer,
 MACHINE_END
index 7430e4049d87b1ca789b372f2641c4088547c31c..a696099aa4f8f22ddd32e836b4bbb124acdc4ea0 100644 (file)
@@ -39,7 +39,6 @@ struct meminfo memmap = {
                {
                        .start  = 0xC0000000,
                        .size   = 0x01000000,
-                       .node   = 0
                },
        },
 };
index f70d52be48a2a61c88b7276a830b7b3abf17aee5..f45c8e892cb5a0ae9cdf0c9cd2c78c2dfa61bb07 100644 (file)
@@ -20,7 +20,6 @@
 #ifndef __ASM_ARCH_MEMORY_H
 #define __ASM_ARCH_MEMORY_H
 
-
 /*
  * Physical DRAM offset.
  */
@@ -72,7 +71,6 @@
  *     node 2:  0xd0000000 - 0xd7ffffff
  *     node 3:  0xd8000000 - 0xdfffffff
  */
-#define NODE_MEM_SIZE_BITS     24
 #define SECTION_SIZE_BITS      24
 #define MAX_PHYSMEM_BITS       32
 
index 427507a2d696255449456da00763562056bd731e..11033f1c2e23b82b52d96569fb4932be6a1a11c0 100644 (file)
@@ -1,2 +1,3 @@
-obj-$(CONFIG_ARCH_CNS3XXX)             += core.o pm.o
+obj-$(CONFIG_ARCH_CNS3XXX)             += core.o pm.o devices.o
+obj-$(CONFIG_PCI)                      += pcie.o
 obj-$(CONFIG_MACH_CNS3420VB)           += cns3420vb.o
index 2e30c8288740b2a24752cdfe565a7e2bef5e77ca..9df8391fd78ac9ebfbb33425261ff9c631db79b1 100644 (file)
@@ -32,6 +32,7 @@
 #include <mach/cns3xxx.h>
 #include <mach/irqs.h>
 #include "core.h"
+#include "devices.h"
 
 /*
  * NOR Flash
@@ -117,6 +118,9 @@ static void __init cns3420_init(void)
 {
        platform_add_devices(cns3420_pdevs, ARRAY_SIZE(cns3420_pdevs));
 
+       cns3xxx_ahci_init();
+       cns3xxx_sdhci_init();
+
        pm_power_off = cns3xxx_power_off;
 }
 
diff --git a/arch/arm/mach-cns3xxx/devices.c b/arch/arm/mach-cns3xxx/devices.c
new file mode 100644 (file)
index 0000000..50b4d31
--- /dev/null
@@ -0,0 +1,111 @@
+/*
+ * CNS3xxx common devices
+ *
+ * Copyright 2008 Cavium Networks
+ *               Scott Shu
+ * Copyright 2010 MontaVista Software, LLC.
+ *               Anton Vorontsov <avorontsov@mvista.com>
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/io.h>
+#include <linux/init.h>
+#include <linux/compiler.h>
+#include <linux/dma-mapping.h>
+#include <linux/platform_device.h>
+#include <mach/cns3xxx.h>
+#include <mach/irqs.h>
+#include "core.h"
+#include "devices.h"
+
+/*
+ * AHCI
+ */
+static struct resource cns3xxx_ahci_resource[] = {
+       [0] = {
+               .start  = CNS3XXX_SATA2_BASE,
+               .end    = CNS3XXX_SATA2_BASE + CNS3XXX_SATA2_SIZE - 1,
+               .flags  = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start  = IRQ_CNS3XXX_SATA,
+               .end    = IRQ_CNS3XXX_SATA,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static u64 cns3xxx_ahci_dmamask = DMA_BIT_MASK(32);
+
+static struct platform_device cns3xxx_ahci_pdev = {
+       .name           = "ahci",
+       .id             = 0,
+       .resource       = cns3xxx_ahci_resource,
+       .num_resources  = ARRAY_SIZE(cns3xxx_ahci_resource),
+       .dev            = {
+               .dma_mask               = &cns3xxx_ahci_dmamask,
+               .coherent_dma_mask      = DMA_BIT_MASK(32),
+       },
+};
+
+void __init cns3xxx_ahci_init(void)
+{
+       u32 tmp;
+
+       tmp = __raw_readl(MISC_SATA_POWER_MODE);
+       tmp |= 0x1 << 16; /* Disable SATA PHY 0 from SLUMBER Mode */
+       tmp |= 0x1 << 17; /* Disable SATA PHY 1 from SLUMBER Mode */
+       __raw_writel(tmp, MISC_SATA_POWER_MODE);
+
+       /* Enable SATA PHY */
+       cns3xxx_pwr_power_up(0x1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_SATA_PHY0);
+       cns3xxx_pwr_power_up(0x1 << PM_PLL_HM_PD_CTRL_REG_OFFSET_SATA_PHY1);
+
+       /* Enable SATA Clock */
+       cns3xxx_pwr_clk_en(0x1 << PM_CLK_GATE_REG_OFFSET_SATA);
+
+       /* De-Asscer SATA Reset */
+       cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SATA));
+
+       platform_device_register(&cns3xxx_ahci_pdev);
+}
+
+/*
+ * SDHCI
+ */
+static struct resource cns3xxx_sdhci_resources[] = {
+       [0] = {
+               .start = CNS3XXX_SDIO_BASE,
+               .end   = CNS3XXX_SDIO_BASE + SZ_4K - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       [1] = {
+               .start = IRQ_CNS3XXX_SDIO,
+               .end   = IRQ_CNS3XXX_SDIO,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device cns3xxx_sdhci_pdev = {
+       .name           = "sdhci-cns3xxx",
+       .id             = 0,
+       .num_resources  = ARRAY_SIZE(cns3xxx_sdhci_resources),
+       .resource       = cns3xxx_sdhci_resources,
+};
+
+void __init cns3xxx_sdhci_init(void)
+{
+       u32 __iomem *gpioa = __io(CNS3XXX_MISC_BASE_VIRT + 0x0014);
+       u32 gpioa_pins = __raw_readl(gpioa);
+
+       /* MMC/SD pins share with GPIOA */
+       gpioa_pins |= 0x1fff0004;
+       __raw_writel(gpioa_pins, gpioa);
+
+       cns3xxx_pwr_clk_en(CNS3XXX_PWR_CLK_EN(SDIO));
+       cns3xxx_pwr_soft_rst(CNS3XXX_PWR_SOFTWARE_RST(SDIO));
+
+       platform_device_register(&cns3xxx_sdhci_pdev);
+}
diff --git a/arch/arm/mach-cns3xxx/devices.h b/arch/arm/mach-cns3xxx/devices.h
new file mode 100644 (file)
index 0000000..27e15a1
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * CNS3xxx common devices
+ *
+ * Copyright 2008 Cavium Networks
+ *               Scott Shu
+ * Copyright 2010 MontaVista Software, LLC.
+ *               Anton Vorontsov <avorontsov@mvista.com>
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#ifndef __CNS3XXX_DEVICES_H_
+#define __CNS3XXX_DEVICES_H_
+
+void __init cns3xxx_ahci_init(void);
+void __init cns3xxx_sdhci_init(void);
+
+#endif /* __CNS3XXX_DEVICES_H_ */
index 8a2f5a21d4ee3ab63843b6311606d55aaa298352..6dbce13771ca49c83c89dde5b4f0b6f734e20c1f 100644 (file)
  * Misc block
  */
 #define MISC_MEM_MAP(offs) (void __iomem *)(CNS3XXX_MISC_BASE_VIRT + (offs))
-#define MISC_MEM_MAP_VALUE(offset) (*((volatile unsigned int *)(CNS3XXX_MISC_BASE_VIRT + (offset))))
-
-#define MISC_MEMORY_REMAP_REG                  MISC_MEM_MAP_VALUE(0x00)
-#define MISC_CHIP_CONFIG_REG                   MISC_MEM_MAP_VALUE(0x04)
-#define MISC_DEBUG_PROBE_DATA_REG              MISC_MEM_MAP_VALUE(0x08)
-#define MISC_DEBUG_PROBE_SELECTION_REG         MISC_MEM_MAP_VALUE(0x0C)
-#define MISC_IO_PIN_FUNC_SELECTION_REG         MISC_MEM_MAP_VALUE(0x10)
-#define MISC_GPIOA_PIN_ENABLE_REG              MISC_MEM_MAP_VALUE(0x14)
-#define MISC_GPIOB_PIN_ENABLE_REG              MISC_MEM_MAP_VALUE(0x18)
-#define MISC_IO_PAD_DRIVE_STRENGTH_CTRL_A      MISC_MEM_MAP_VALUE(0x1C)
-#define MISC_IO_PAD_DRIVE_STRENGTH_CTRL_B      MISC_MEM_MAP_VALUE(0x20)
-#define MISC_GPIOA_15_0_PULL_CTRL_REG          MISC_MEM_MAP_VALUE(0x24)
-#define MISC_GPIOA_16_31_PULL_CTRL_REG         MISC_MEM_MAP_VALUE(0x28)
-#define MISC_GPIOB_15_0_PULL_CTRL_REG          MISC_MEM_MAP_VALUE(0x2C)
-#define MISC_GPIOB_16_31_PULL_CTRL_REG         MISC_MEM_MAP_VALUE(0x30)
-#define MISC_IO_PULL_CTRL_REG                  MISC_MEM_MAP_VALUE(0x34)
-#define MISC_E_FUSE_31_0_REG                   MISC_MEM_MAP_VALUE(0x40)
-#define MISC_E_FUSE_63_32_REG                  MISC_MEM_MAP_VALUE(0x44)
-#define MISC_E_FUSE_95_64_REG                  MISC_MEM_MAP_VALUE(0x48)
-#define MISC_E_FUSE_127_96_REG                 MISC_MEM_MAP_VALUE(0x4C)
-#define MISC_SOFTWARE_TEST_1_REG               MISC_MEM_MAP_VALUE(0x50)
-#define MISC_SOFTWARE_TEST_2_REG               MISC_MEM_MAP_VALUE(0x54)
-
-#define MISC_SATA_POWER_MODE                   MISC_MEM_MAP_VALUE(0x310)
-
-#define MISC_USB_CFG_REG                       MISC_MEM_MAP_VALUE(0x800)
-#define MISC_USB_STS_REG                       MISC_MEM_MAP_VALUE(0x804)
-#define MISC_USBPHY00_CFG_REG                  MISC_MEM_MAP_VALUE(0x808)
-#define MISC_USBPHY01_CFG_REG                  MISC_MEM_MAP_VALUE(0x80c)
-#define MISC_USBPHY10_CFG_REG                  MISC_MEM_MAP_VALUE(0x810)
-#define MISC_USBPHY11_CFG_REG                  MISC_MEM_MAP_VALUE(0x814)
+
+#define MISC_MEMORY_REMAP_REG                  MISC_MEM_MAP(0x00)
+#define MISC_CHIP_CONFIG_REG                   MISC_MEM_MAP(0x04)
+#define MISC_DEBUG_PROBE_DATA_REG              MISC_MEM_MAP(0x08)
+#define MISC_DEBUG_PROBE_SELECTION_REG         MISC_MEM_MAP(0x0C)
+#define MISC_IO_PIN_FUNC_SELECTION_REG         MISC_MEM_MAP(0x10)
+#define MISC_GPIOA_PIN_ENABLE_REG              MISC_MEM_MAP(0x14)
+#define MISC_GPIOB_PIN_ENABLE_REG              MISC_MEM_MAP(0x18)
+#define MISC_IO_PAD_DRIVE_STRENGTH_CTRL_A      MISC_MEM_MAP(0x1C)
+#define MISC_IO_PAD_DRIVE_STRENGTH_CTRL_B      MISC_MEM_MAP(0x20)
+#define MISC_GPIOA_15_0_PULL_CTRL_REG          MISC_MEM_MAP(0x24)
+#define MISC_GPIOA_16_31_PULL_CTRL_REG         MISC_MEM_MAP(0x28)
+#define MISC_GPIOB_15_0_PULL_CTRL_REG          MISC_MEM_MAP(0x2C)
+#define MISC_GPIOB_16_31_PULL_CTRL_REG         MISC_MEM_MAP(0x30)
+#define MISC_IO_PULL_CTRL_REG                  MISC_MEM_MAP(0x34)
+#define MISC_E_FUSE_31_0_REG                   MISC_MEM_MAP(0x40)
+#define MISC_E_FUSE_63_32_REG                  MISC_MEM_MAP(0x44)
+#define MISC_E_FUSE_95_64_REG                  MISC_MEM_MAP(0x48)
+#define MISC_E_FUSE_127_96_REG                 MISC_MEM_MAP(0x4C)
+#define MISC_SOFTWARE_TEST_1_REG               MISC_MEM_MAP(0x50)
+#define MISC_SOFTWARE_TEST_2_REG               MISC_MEM_MAP(0x54)
+
+#define MISC_SATA_POWER_MODE                   MISC_MEM_MAP(0x310)
+
+#define MISC_USB_CFG_REG                       MISC_MEM_MAP(0x800)
+#define MISC_USB_STS_REG                       MISC_MEM_MAP(0x804)
+#define MISC_USBPHY00_CFG_REG                  MISC_MEM_MAP(0x808)
+#define MISC_USBPHY01_CFG_REG                  MISC_MEM_MAP(0x80c)
+#define MISC_USBPHY10_CFG_REG                  MISC_MEM_MAP(0x810)
+#define MISC_USBPHY11_CFG_REG                  MISC_MEM_MAP(0x814)
 
 #define MISC_PCIEPHY_CMCTL(x)                  MISC_MEM_MAP(0x900 + (x) * 0x004)
 #define MISC_PCIEPHY_CTL(x)                    MISC_MEM_MAP(0x940 + (x) * 0x100)
 /*
  * Power management and clock control
  */
-#define PMU_REG_VALUE(offset) (*((volatile unsigned int *)(CNS3XXX_PM_BASE_VIRT + (offset))))
-
-#define PM_CLK_GATE_REG                                        PMU_REG_VALUE(0x000)
-#define PM_SOFT_RST_REG                                        PMU_REG_VALUE(0x004)
-#define PM_HS_CFG_REG                                  PMU_REG_VALUE(0x008)
-#define PM_CACTIVE_STA_REG                             PMU_REG_VALUE(0x00C)
-#define PM_PWR_STA_REG                                 PMU_REG_VALUE(0x010)
-#define PM_CLK_CTRL_REG                                        PMU_REG_VALUE(0x014)
-#define PM_PLL_LCD_I2S_CTRL_REG                                PMU_REG_VALUE(0x018)
-#define PM_PLL_HM_PD_CTRL_REG                          PMU_REG_VALUE(0x01C)
-#define PM_REGULAT_CTRL_REG                            PMU_REG_VALUE(0x020)
-#define PM_WDT_CTRL_REG                                        PMU_REG_VALUE(0x024)
-#define PM_WU_CTRL0_REG                                        PMU_REG_VALUE(0x028)
-#define PM_WU_CTRL1_REG                                        PMU_REG_VALUE(0x02C)
-#define PM_CSR_REG                                     PMU_REG_VALUE(0x030)
+#define PMU_MEM_MAP(offs) (void __iomem *)(CNS3XXX_PM_BASE_VIRT + (offs))
+
+#define PM_CLK_GATE_REG                                        PMU_MEM_MAP(0x000)
+#define PM_SOFT_RST_REG                                        PMU_MEM_MAP(0x004)
+#define PM_HS_CFG_REG                                  PMU_MEM_MAP(0x008)
+#define PM_CACTIVE_STA_REG                             PMU_MEM_MAP(0x00C)
+#define PM_PWR_STA_REG                                 PMU_MEM_MAP(0x010)
+#define PM_CLK_CTRL_REG                                        PMU_MEM_MAP(0x014)
+#define PM_PLL_LCD_I2S_CTRL_REG                                PMU_MEM_MAP(0x018)
+#define PM_PLL_HM_PD_CTRL_REG                          PMU_MEM_MAP(0x01C)
+#define PM_REGULAT_CTRL_REG                            PMU_MEM_MAP(0x020)
+#define PM_WDT_CTRL_REG                                        PMU_MEM_MAP(0x024)
+#define PM_WU_CTRL0_REG                                        PMU_MEM_MAP(0x028)
+#define PM_WU_CTRL1_REG                                        PMU_MEM_MAP(0x02C)
+#define PM_CSR_REG                                     PMU_MEM_MAP(0x030)
 
 /* PM_CLK_GATE_REG */
 #define PM_CLK_GATE_REG_OFFSET_SDIO                    (25)
diff --git a/arch/arm/mach-cns3xxx/pcie.c b/arch/arm/mach-cns3xxx/pcie.c
new file mode 100644 (file)
index 0000000..38088c3
--- /dev/null
@@ -0,0 +1,389 @@
+/*
+ * PCI-E support for CNS3xxx
+ *
+ * Copyright 2008 Cavium Networks
+ *               Richard Liu <richard.liu@caviumnetworks.com>
+ * Copyright 2010 MontaVista Software, LLC.
+ *               Anton Vorontsov <avorontsov@mvista.com>
+ *
+ * This file is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License, Version 2, as
+ * published by the Free Software Foundation.
+ */
+
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/bug.h>
+#include <linux/pci.h>
+#include <linux/io.h>
+#include <linux/ioport.h>
+#include <linux/interrupt.h>
+#include <linux/ptrace.h>
+#include <asm/mach/map.h>
+#include <mach/cns3xxx.h>
+#include "core.h"
+
+enum cns3xxx_access_type {
+       CNS3XXX_HOST_TYPE = 0,
+       CNS3XXX_CFG0_TYPE,
+       CNS3XXX_CFG1_TYPE,
+       CNS3XXX_NUM_ACCESS_TYPES,
+};
+
+struct cns3xxx_pcie {
+       struct map_desc cfg_bases[CNS3XXX_NUM_ACCESS_TYPES];
+       unsigned int irqs[2];
+       struct resource res_io;
+       struct resource res_mem;
+       struct hw_pci hw_pci;
+
+       bool linked;
+};
+
+static struct cns3xxx_pcie cns3xxx_pcie[]; /* forward decl. */
+
+static struct cns3xxx_pcie *sysdata_to_cnspci(void *sysdata)
+{
+       struct pci_sys_data *root = sysdata;
+
+       return &cns3xxx_pcie[root->domain];
+}
+
+static struct cns3xxx_pcie *pdev_to_cnspci(struct pci_dev *dev)
+{
+       return sysdata_to_cnspci(dev->sysdata);
+}
+
+static struct cns3xxx_pcie *pbus_to_cnspci(struct pci_bus *bus)
+{
+       return sysdata_to_cnspci(bus->sysdata);
+}
+
+static void __iomem *cns3xxx_pci_cfg_base(struct pci_bus *bus,
+                                 unsigned int devfn, int where)
+{
+       struct cns3xxx_pcie *cnspci = pbus_to_cnspci(bus);
+       int busno = bus->number;
+       int slot = PCI_SLOT(devfn);
+       int offset;
+       enum cns3xxx_access_type type;
+       void __iomem *base;
+
+       /* If there is no link, just show the CNS PCI bridge. */
+       if (!cnspci->linked && (busno > 0 || slot > 0))
+               return NULL;
+
+       /*
+        * The CNS PCI bridge doesn't fit into the PCI hierarchy, though
+        * we still want to access it. For this to work, we must place
+        * the first device on the same bus as the CNS PCI bridge.
+        */
+       if (busno == 0) {
+               if (slot > 1)
+                       return NULL;
+               type = slot;
+       } else {
+               type = CNS3XXX_CFG1_TYPE;
+       }
+
+       base = (void __iomem *)cnspci->cfg_bases[type].virtual;
+       offset = ((busno & 0xf) << 20) | (devfn << 12) | (where & 0xffc);
+
+       return base + offset;
+}
+
+static int cns3xxx_pci_read_config(struct pci_bus *bus, unsigned int devfn,
+                                  int where, int size, u32 *val)
+{
+       u32 v;
+       void __iomem *base;
+       u32 mask = (0x1ull << (size * 8)) - 1;
+       int shift = (where % 4) * 8;
+
+       base = cns3xxx_pci_cfg_base(bus, devfn, where);
+       if (!base) {
+               *val = 0xffffffff;
+               return PCIBIOS_SUCCESSFUL;
+       }
+
+       v = __raw_readl(base);
+
+       if (bus->number == 0 && devfn == 0 &&
+                       (where & 0xffc) == PCI_CLASS_REVISION) {
+               /*
+                * RC's class is 0xb, but Linux PCI driver needs 0x604
+                * for a PCIe bridge. So we must fixup the class code
+                * to 0x604 here.
+                */
+               v &= 0xff;
+               v |= 0x604 << 16;
+       }
+
+       *val = (v >> shift) & mask;
+
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int cns3xxx_pci_write_config(struct pci_bus *bus, unsigned int devfn,
+                                   int where, int size, u32 val)
+{
+       u32 v;
+       void __iomem *base;
+       u32 mask = (0x1ull << (size * 8)) - 1;
+       int shift = (where % 4) * 8;
+
+       base = cns3xxx_pci_cfg_base(bus, devfn, where);
+       if (!base)
+               return PCIBIOS_SUCCESSFUL;
+
+       v = __raw_readl(base);
+
+       v &= ~(mask << shift);
+       v |= (val & mask) << shift;
+
+       __raw_writel(v, base);
+
+       return PCIBIOS_SUCCESSFUL;
+}
+
+static int cns3xxx_pci_setup(int nr, struct pci_sys_data *sys)
+{
+       struct cns3xxx_pcie *cnspci = sysdata_to_cnspci(sys);
+       struct resource *res_io = &cnspci->res_io;
+       struct resource *res_mem = &cnspci->res_mem;
+       struct resource **sysres = sys->resource;
+
+       BUG_ON(request_resource(&iomem_resource, res_io) ||
+              request_resource(&iomem_resource, res_mem));
+
+       sysres[0] = res_io;
+       sysres[1] = res_mem;
+
+       return 1;
+}
+
+static struct pci_ops cns3xxx_pcie_ops = {
+       .read = cns3xxx_pci_read_config,
+       .write = cns3xxx_pci_write_config,
+};
+
+static struct pci_bus *cns3xxx_pci_scan_bus(int nr, struct pci_sys_data *sys)
+{
+       return pci_scan_bus(sys->busnr, &cns3xxx_pcie_ops, sys);
+}
+
+static int cns3xxx_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
+{
+       struct cns3xxx_pcie *cnspci = pdev_to_cnspci(dev);
+       int irq = cnspci->irqs[slot];
+
+       pr_info("PCIe map irq: %04d:%02x:%02x.%02x slot %d, pin %d, irq: %d\n",
+               pci_domain_nr(dev->bus), dev->bus->number, PCI_SLOT(dev->devfn),
+               PCI_FUNC(dev->devfn), slot, pin, irq);
+
+       return irq;
+}
+
+static struct cns3xxx_pcie cns3xxx_pcie[] = {
+       [0] = {
+               .cfg_bases = {
+                       [CNS3XXX_HOST_TYPE] = {
+                               .virtual = CNS3XXX_PCIE0_HOST_BASE_VIRT,
+                               .pfn = __phys_to_pfn(CNS3XXX_PCIE0_HOST_BASE),
+                               .length = SZ_16M,
+                               .type = MT_DEVICE,
+                       },
+                       [CNS3XXX_CFG0_TYPE] = {
+                               .virtual = CNS3XXX_PCIE0_CFG0_BASE_VIRT,
+                               .pfn = __phys_to_pfn(CNS3XXX_PCIE0_CFG0_BASE),
+                               .length = SZ_16M,
+                               .type = MT_DEVICE,
+                       },
+                       [CNS3XXX_CFG1_TYPE] = {
+                               .virtual = CNS3XXX_PCIE0_CFG1_BASE_VIRT,
+                               .pfn = __phys_to_pfn(CNS3XXX_PCIE0_CFG1_BASE),
+                               .length = SZ_16M,
+                               .type = MT_DEVICE,
+                       },
+               },
+               .res_io = {
+                       .name = "PCIe0 I/O space",
+                       .start = CNS3XXX_PCIE0_IO_BASE,
+                       .end = CNS3XXX_PCIE0_IO_BASE + SZ_16M - 1,
+                       .flags = IORESOURCE_IO,
+               },
+               .res_mem = {
+                       .name = "PCIe0 non-prefetchable",
+                       .start = CNS3XXX_PCIE0_MEM_BASE,
+                       .end = CNS3XXX_PCIE0_MEM_BASE + SZ_16M - 1,
+                       .flags = IORESOURCE_MEM,
+               },
+               .irqs = { IRQ_CNS3XXX_PCIE0_RC, IRQ_CNS3XXX_PCIE0_DEVICE, },
+               .hw_pci = {
+                       .domain = 0,
+                       .swizzle = pci_std_swizzle,
+                       .nr_controllers = 1,
+                       .setup = cns3xxx_pci_setup,
+                       .scan = cns3xxx_pci_scan_bus,
+                       .map_irq = cns3xxx_pcie_map_irq,
+               },
+       },
+       [1] = {
+               .cfg_bases = {
+                       [CNS3XXX_HOST_TYPE] = {
+                               .virtual = CNS3XXX_PCIE1_HOST_BASE_VIRT,
+                               .pfn = __phys_to_pfn(CNS3XXX_PCIE1_HOST_BASE),
+                               .length = SZ_16M,
+                               .type = MT_DEVICE,
+                       },
+                       [CNS3XXX_CFG0_TYPE] = {
+                               .virtual = CNS3XXX_PCIE1_CFG0_BASE_VIRT,
+                               .pfn = __phys_to_pfn(CNS3XXX_PCIE1_CFG0_BASE),
+                               .length = SZ_16M,
+                               .type = MT_DEVICE,
+                       },
+                       [CNS3XXX_CFG1_TYPE] = {
+                               .virtual = CNS3XXX_PCIE1_CFG1_BASE_VIRT,
+                               .pfn = __phys_to_pfn(CNS3XXX_PCIE1_CFG1_BASE),
+                               .length = SZ_16M,
+                               .type = MT_DEVICE,
+                       },
+               },
+               .res_io = {
+                       .name = "PCIe1 I/O space",
+                       .start = CNS3XXX_PCIE1_IO_BASE,
+                       .end = CNS3XXX_PCIE1_IO_BASE + SZ_16M - 1,
+                       .flags = IORESOURCE_IO,
+               },
+               .res_mem = {
+                       .name = "PCIe1 non-prefetchable",
+                       .start = CNS3XXX_PCIE1_MEM_BASE,
+                       .end = CNS3XXX_PCIE1_MEM_BASE + SZ_16M - 1,
+                       .flags = IORESOURCE_MEM,
+               },
+               .irqs = { IRQ_CNS3XXX_PCIE1_RC, IRQ_CNS3XXX_PCIE1_DEVICE, },
+               .hw_pci = {
+                       .domain = 1,
+                       .swizzle = pci_std_swizzle,
+                       .nr_controllers = 1,
+                       .setup = cns3xxx_pci_setup,
+                       .scan = cns3xxx_pci_scan_bus,
+                       .map_irq = cns3xxx_pcie_map_irq,
+               },
+       },
+};
+
+static void __init cns3xxx_pcie_check_link(struct cns3xxx_pcie *cnspci)
+{
+       int port = cnspci->hw_pci.domain;
+       u32 reg;
+       unsigned long time;
+
+       reg = __raw_readl(MISC_PCIE_CTRL(port));
+       /*
+        * Enable Application Request to 1, it will exit L1 automatically,
+        * but when chip back, it will use another clock, still can use 0x1.
+        */
+       reg |= 0x3;
+       __raw_writel(reg, MISC_PCIE_CTRL(port));
+
+       pr_info("PCIe: Port[%d] Enable PCIe LTSSM\n", port);
+       pr_info("PCIe: Port[%d] Check data link layer...", port);
+
+       time = jiffies;
+       while (1) {
+               reg = __raw_readl(MISC_PCIE_PM_DEBUG(port));
+               if (reg & 0x1) {
+                       pr_info("Link up.\n");
+                       cnspci->linked = 1;
+                       break;
+               } else if (time_after(jiffies, time + 50)) {
+                       pr_info("Device not found.\n");
+                       break;
+               }
+       }
+}
+
+static void __init cns3xxx_pcie_hw_init(struct cns3xxx_pcie *cnspci)
+{
+       int port = cnspci->hw_pci.domain;
+       struct pci_sys_data sd = {
+               .domain = port,
+       };
+       struct pci_bus bus = {
+               .number = 0,
+               .ops = &cns3xxx_pcie_ops,
+               .sysdata = &sd,
+       };
+       u32 io_base = cnspci->res_io.start >> 16;
+       u32 mem_base = cnspci->res_mem.start >> 16;
+       u32 host_base = cnspci->cfg_bases[CNS3XXX_HOST_TYPE].pfn;
+       u32 cfg0_base = cnspci->cfg_bases[CNS3XXX_CFG0_TYPE].pfn;
+       u32 devfn = 0;
+       u8 tmp8;
+       u16 pos;
+       u16 dc;
+
+       host_base = (__pfn_to_phys(host_base) - 1) >> 16;
+       cfg0_base = (__pfn_to_phys(cfg0_base) - 1) >> 16;
+
+       pci_bus_write_config_byte(&bus, devfn, PCI_PRIMARY_BUS, 0);
+       pci_bus_write_config_byte(&bus, devfn, PCI_SECONDARY_BUS, 1);
+       pci_bus_write_config_byte(&bus, devfn, PCI_SUBORDINATE_BUS, 1);
+
+       pci_bus_read_config_byte(&bus, devfn, PCI_PRIMARY_BUS, &tmp8);
+       pci_bus_read_config_byte(&bus, devfn, PCI_SECONDARY_BUS, &tmp8);
+       pci_bus_read_config_byte(&bus, devfn, PCI_SUBORDINATE_BUS, &tmp8);
+
+       pci_bus_write_config_word(&bus, devfn, PCI_MEMORY_BASE, mem_base);
+       pci_bus_write_config_word(&bus, devfn, PCI_MEMORY_LIMIT, host_base);
+       pci_bus_write_config_word(&bus, devfn, PCI_IO_BASE_UPPER16, io_base);
+       pci_bus_write_config_word(&bus, devfn, PCI_IO_LIMIT_UPPER16, cfg0_base);
+
+       if (!cnspci->linked)
+               return;
+
+       /* Set Device Max_Read_Request_Size to 128 byte */
+       devfn = PCI_DEVFN(1, 0);
+       pos = pci_bus_find_capability(&bus, devfn, PCI_CAP_ID_EXP);
+       pci_bus_read_config_word(&bus, devfn, pos + PCI_EXP_DEVCTL, &dc);
+       dc &= ~(0x3 << 12);     /* Clear Device Control Register [14:12] */
+       pci_bus_write_config_word(&bus, devfn, pos + PCI_EXP_DEVCTL, dc);
+       pci_bus_read_config_word(&bus, devfn, pos + PCI_EXP_DEVCTL, &dc);
+       if (!(dc & (0x3 << 12)))
+               pr_info("PCIe: Set Device Max_Read_Request_Size to 128 byte\n");
+
+       /* Disable PCIe0 Interrupt Mask INTA to INTD */
+       __raw_writel(~0x3FFF, MISC_PCIE_INT_MASK(port));
+}
+
+static int cns3xxx_pcie_abort_handler(unsigned long addr, unsigned int fsr,
+                                     struct pt_regs *regs)
+{
+       if (fsr & (1 << 10))
+               regs->ARM_pc += 4;
+       return 0;
+}
+
+static int __init cns3xxx_pcie_init(void)
+{
+       int i;
+
+       hook_fault_code(16 + 6, cns3xxx_pcie_abort_handler, SIGBUS,
+                       "imprecise external abort");
+
+       for (i = 0; i < ARRAY_SIZE(cns3xxx_pcie); i++) {
+               iotable_init(cns3xxx_pcie[i].cfg_bases,
+                            ARRAY_SIZE(cns3xxx_pcie[i].cfg_bases));
+               cns3xxx_pwr_clk_en(0x1 << PM_CLK_GATE_REG_OFFSET_PCIE(i));
+               cns3xxx_pwr_soft_rst(0x1 << PM_SOFT_RST_REG_OFFST_PCIE(i));
+               cns3xxx_pcie_check_link(&cns3xxx_pcie[i]);
+               cns3xxx_pcie_hw_init(&cns3xxx_pcie[i]);
+               pci_common_init(&cns3xxx_pcie[i].hw_pci);
+       }
+
+       pci_assign_unassigned_resources();
+
+       return 0;
+}
+device_initcall(cns3xxx_pcie_init);
index 725e1a4fc23103ecd01df12eea9483d3f81a42f3..38e44706feabf43a69a9a3429f3a6753b51d34a0 100644 (file)
@@ -6,18 +6,25 @@
  * published by the Free Software Foundation.
  */
 
+#include <linux/io.h>
 #include <linux/delay.h>
 #include <mach/system.h>
 #include <mach/cns3xxx.h>
 
 void cns3xxx_pwr_clk_en(unsigned int block)
 {
-       PM_CLK_GATE_REG |= (block & PM_CLK_GATE_REG_MASK);
+       u32 reg = __raw_readl(PM_CLK_GATE_REG);
+
+       reg |= (block & PM_CLK_GATE_REG_MASK);
+       __raw_writel(reg, PM_CLK_GATE_REG);
 }
 
 void cns3xxx_pwr_power_up(unsigned int block)
 {
-       PM_PLL_HM_PD_CTRL_REG &= ~(block & CNS3XXX_PWR_PLL_ALL);
+       u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
+
+       reg &= ~(block & CNS3XXX_PWR_PLL_ALL);
+       __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
 
        /* Wait for 300us for the PLL output clock locked. */
        udelay(300);
@@ -25,22 +32,29 @@ void cns3xxx_pwr_power_up(unsigned int block)
 
 void cns3xxx_pwr_power_down(unsigned int block)
 {
+       u32 reg = __raw_readl(PM_PLL_HM_PD_CTRL_REG);
+
        /* write '1' to power down */
-       PM_PLL_HM_PD_CTRL_REG |= (block & CNS3XXX_PWR_PLL_ALL);
+       reg |= (block & CNS3XXX_PWR_PLL_ALL);
+       __raw_writel(reg, PM_PLL_HM_PD_CTRL_REG);
 };
 
 static void cns3xxx_pwr_soft_rst_force(unsigned int block)
 {
+       u32 reg = __raw_readl(PM_SOFT_RST_REG);
+
        /*
         * bit 0, 28, 29 => program low to reset,
         * the other else program low and then high
         */
        if (block & 0x30000001) {
-               PM_SOFT_RST_REG &= ~(block & PM_SOFT_RST_REG_MASK);
+               reg &= ~(block & PM_SOFT_RST_REG_MASK);
        } else {
-               PM_SOFT_RST_REG &= ~(block & PM_SOFT_RST_REG_MASK);
-               PM_SOFT_RST_REG |= (block & PM_SOFT_RST_REG_MASK);
+               reg &= ~(block & PM_SOFT_RST_REG_MASK);
+               reg |= (block & PM_SOFT_RST_REG_MASK);
        }
+
+       __raw_writel(reg, PM_SOFT_RST_REG);
 }
 
 void cns3xxx_pwr_soft_rst(unsigned int block)
@@ -73,12 +87,13 @@ void arch_reset(char mode, const char *cmd)
  */
 int cns3xxx_cpu_clock(void)
 {
+       u32 reg = __raw_readl(PM_CLK_CTRL_REG);
        int cpu;
        int cpu_sel;
        int div_sel;
 
-       cpu_sel = (PM_CLK_CTRL_REG >> PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL) & 0xf;
-       div_sel = (PM_CLK_CTRL_REG >> PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV) & 0x3;
+       cpu_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_PLL_CPU_SEL) & 0xf;
+       div_sel = (reg >> PM_CLK_CTRL_REG_OFFSET_CPU_CLK_DIV) & 0x3;
 
        cpu = (300 + ((cpu_sel / 3) * 100) + ((cpu_sel % 3) * 33)) >> div_sel;
 
index a91edfb8beeac3109542989c957256436fd5a5c8..22eb97c1c30b48c89e6e2f397f73ee5727f5240a 100644 (file)
  * below 128M
  */
 static inline void
-__arch_adjust_zones(int node, unsigned long *size, unsigned long *holes)
+__arch_adjust_zones(unsigned long *size, unsigned long *holes)
 {
        unsigned int sz = (128<<20) >> PAGE_SHIFT;
 
-       if (node != 0)
-               sz = 0;
-
        size[1] = size[0] - sz;
        size[0] = sz;
 }
 
-#define arch_adjust_zones(node, zone_size, holes) \
-        if ((meminfo.bank[0].size >> 20) > 128) __arch_adjust_zones(node, zone_size, holes)
+#define arch_adjust_zones(zone_size, holes) \
+        if ((meminfo.bank[0].size >> 20) > 128) __arch_adjust_zones(zone_size, holes)
 
 #define ISA_DMA_THRESHOLD      (PHYS_OFFSET + (128<<20) - 1)
 #define MAX_DMA_ADDRESS                (PAGE_OFFSET + (128<<20))
index 5da2cf402c81d9773ce979ead618381e0efcd3e2..f7a12586a1f5eaf9c1b0316b6efc2b914a63fa30 100644 (file)
@@ -752,6 +752,67 @@ void __init dove_xor1_init(void)
        platform_device_register(&dove_xor11_channel);
 }
 
+/*****************************************************************************
+ * SDIO
+ ****************************************************************************/
+static u64 sdio_dmamask = DMA_BIT_MASK(32);
+
+static struct resource dove_sdio0_resources[] = {
+       {
+               .start  = DOVE_SDIO0_PHYS_BASE,
+               .end    = DOVE_SDIO0_PHYS_BASE + 0xff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = IRQ_DOVE_SDIO0,
+               .end    = IRQ_DOVE_SDIO0,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device dove_sdio0 = {
+       .name           = "sdhci-mv",
+       .id             = 0,
+       .dev            = {
+               .dma_mask               = &sdio_dmamask,
+               .coherent_dma_mask      = DMA_BIT_MASK(32),
+       },
+       .resource       = dove_sdio0_resources,
+       .num_resources  = ARRAY_SIZE(dove_sdio0_resources),
+};
+
+void __init dove_sdio0_init(void)
+{
+       platform_device_register(&dove_sdio0);
+}
+
+static struct resource dove_sdio1_resources[] = {
+       {
+               .start  = DOVE_SDIO1_PHYS_BASE,
+               .end    = DOVE_SDIO1_PHYS_BASE + 0xff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = IRQ_DOVE_SDIO1,
+               .end    = IRQ_DOVE_SDIO1,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device dove_sdio1 = {
+       .name           = "sdhci-mv",
+       .id             = 1,
+       .dev            = {
+               .dma_mask               = &sdio_dmamask,
+               .coherent_dma_mask      = DMA_BIT_MASK(32),
+       },
+       .resource       = dove_sdio1_resources,
+       .num_resources  = ARRAY_SIZE(dove_sdio1_resources),
+};
+
+void __init dove_sdio1_init(void)
+{
+       platform_device_register(&dove_sdio1);
+}
+
 void __init dove_init(void)
 {
        int tclk;
index b29e8937de4fd0acf9148bb0880dcc1c1ccafc94..a51517c3fe7654b629f4772ae2ef16cc63280f5f 100644 (file)
@@ -36,5 +36,7 @@ void dove_uart3_init(void);
 void dove_spi0_init(void);
 void dove_spi1_init(void);
 void dove_i2c_init(void);
+void dove_sdio0_init(void);
+void dove_sdio1_init(void);
 
 #endif
index f2971b7452242132a7ddc07552af66a5c330c911..bef70460fbc669353907355d3b9ca04f0a8308f3 100644 (file)
@@ -82,6 +82,8 @@ static void __init dove_db_init(void)
        dove_ehci0_init();
        dove_ehci1_init();
        dove_sata_init(&dove_db_sata_data);
+       dove_sdio0_init();
+       dove_sdio1_init();
        dove_spi0_init();
        dove_spi1_init();
        dove_uart0_init();
index 3a1a855bfdcace3e35591a50ede18edb6f2a1ec3..f744f676783f3024c0d18be2bff733432b260d9c 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/mtd/physmap.h>
 
 #include <mach/hardware.h>
 
 #include <asm/mach/arch.h>
 
 
-static struct physmap_flash_data adssphere_flash_data = {
-       .width          = 4,
-};
-
-static struct resource adssphere_flash_resource = {
-       .start          = EP93XX_CS6_PHYS_BASE,
-       .end            = EP93XX_CS6_PHYS_BASE + SZ_32M - 1,
-       .flags          = IORESOURCE_MEM,
-};
-
-static struct platform_device adssphere_flash = {
-       .name           = "physmap-flash",
-       .id             = 0,
-       .dev            = {
-               .platform_data  = &adssphere_flash_data,
-       },
-       .num_resources  = 1,
-       .resource       = &adssphere_flash_resource,
-};
-
 static struct ep93xx_eth_data __initdata adssphere_eth_data = {
        .phy_id         = 1,
 };
@@ -48,8 +27,7 @@ static struct ep93xx_eth_data __initdata adssphere_eth_data = {
 static void __init adssphere_init_machine(void)
 {
        ep93xx_init_devices();
-       platform_device_register(&adssphere_flash);
-
+       ep93xx_register_flash(4, EP93XX_CS6_PHYS_BASE, SZ_32M);
        ep93xx_register_eth(&adssphere_eth_data, 1);
 }
 
index e29bdef9b2e201ea345c4139487e4895dffad94d..7f3039761d91aecf0c0c46c84424f5ad4c1bf743 100644 (file)
@@ -185,7 +185,7 @@ static struct clk_lookup clocks[] = {
        INIT_CK(NULL,                   "pll1",         &clk_pll1),
        INIT_CK(NULL,                   "fclk",         &clk_f),
        INIT_CK(NULL,                   "hclk",         &clk_h),
-       INIT_CK(NULL,                   "pclk",         &clk_p),
+       INIT_CK(NULL,                   "apb_pclk",     &clk_p),
        INIT_CK(NULL,                   "pll2",         &clk_pll2),
        INIT_CK("ep93xx-ohci",          NULL,           &clk_usb_host),
        INIT_CK("ep93xx-keypad",        NULL,           &clk_keypad),
index 9092677f63eb739a529d137b5b1be891b11f53da..8e37a045188cbcf4bc334d521186b8d4a2871d5d 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/termios.h>
 #include <linux/amba/bus.h>
 #include <linux/amba/serial.h>
+#include <linux/mtd/physmap.h>
 #include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
 #include <linux/spi/spi.h>
@@ -215,8 +216,8 @@ void ep93xx_devcfg_set_clear(unsigned int set_bits, unsigned int clear_bits)
        spin_lock_irqsave(&syscon_swlock, flags);
 
        val = __raw_readl(EP93XX_SYSCON_DEVCFG);
-       val |= set_bits;
        val &= ~clear_bits;
+       val |= set_bits;
        __raw_writel(0xaa, EP93XX_SYSCON_SWLOCK);
        __raw_writel(val, EP93XX_SYSCON_DEVCFG);
 
@@ -347,6 +348,43 @@ static struct platform_device ep93xx_ohci_device = {
 };
 
 
+/*************************************************************************
+ * EP93xx physmap'ed flash
+ *************************************************************************/
+static struct physmap_flash_data ep93xx_flash_data;
+
+static struct resource ep93xx_flash_resource = {
+       .flags          = IORESOURCE_MEM,
+};
+
+static struct platform_device ep93xx_flash = {
+       .name           = "physmap-flash",
+       .id             = 0,
+       .dev            = {
+               .platform_data  = &ep93xx_flash_data,
+       },
+       .num_resources  = 1,
+       .resource       = &ep93xx_flash_resource,
+};
+
+/**
+ * ep93xx_register_flash() - Register the external flash device.
+ * @width:     bank width in octets
+ * @start:     resource start address
+ * @size:      resource size
+ */
+void __init ep93xx_register_flash(unsigned int width,
+                                 resource_size_t start, resource_size_t size)
+{
+       ep93xx_flash_data.width         = width;
+
+       ep93xx_flash_resource.start     = start;
+       ep93xx_flash_resource.end       = start + size - 1;
+
+       platform_device_register(&ep93xx_flash);
+}
+
+
 /*************************************************************************
  * EP93xx ethernet peripheral handling
  *************************************************************************/
@@ -620,6 +658,11 @@ static struct platform_device ep93xx_fb_device = {
        .resource               = ep93xx_fb_resource,
 };
 
+static struct platform_device ep93xx_bl_device = {
+       .name           = "ep93xx-bl",
+       .id             = -1,
+};
+
 /**
  * ep93xx_register_fb - Register the framebuffer platform device.
  * @data:      platform specific framebuffer configuration (__initdata)
@@ -628,6 +671,7 @@ void __init ep93xx_register_fb(struct ep93xxfb_mach_info *data)
 {
        ep93xxfb_data = *data;
        platform_device_register(&ep93xx_fb_device);
+       platform_device_register(&ep93xx_bl_device);
 }
 
 
index 3884182cd3623e8799b00323115d097f1894e4e9..c2ce9034ba87f5b856cb6e1cae89fb69060b8ffe 100644 (file)
@@ -27,7 +27,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/mtd/physmap.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
 #include <asm/mach/arch.h>
 
 
-static struct physmap_flash_data edb93xx_flash_data;
-
-static struct resource edb93xx_flash_resource = {
-       .flags          = IORESOURCE_MEM,
-};
-
-static struct platform_device edb93xx_flash = {
-       .name           = "physmap-flash",
-       .id             = 0,
-       .dev            = {
-               .platform_data  = &edb93xx_flash_data,
-       },
-       .num_resources  = 1,
-       .resource       = &edb93xx_flash_resource,
-};
-
-static void __init __edb93xx_register_flash(unsigned int width,
-                       resource_size_t start, resource_size_t size)
-{
-       edb93xx_flash_data.width        = width;
-       edb93xx_flash_resource.start    = start;
-       edb93xx_flash_resource.end      = start + size - 1;
-
-       platform_device_register(&edb93xx_flash);
-}
-
 static void __init edb93xx_register_flash(void)
 {
        if (machine_is_edb9307() || machine_is_edb9312() ||
            machine_is_edb9315()) {
-               __edb93xx_register_flash(4, EP93XX_CS6_PHYS_BASE, SZ_32M);
+               ep93xx_register_flash(4, EP93XX_CS6_PHYS_BASE, SZ_32M);
        } else {
-               __edb93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_16M);
+               ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_16M);
        }
 }
 
index a809618e9f059043b706bf25e57ffcf070dd3ff4..d97168c0ba336fa22179328b9dc72316807c13bb 100644 (file)
@@ -13,7 +13,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/mtd/physmap.h>
 
 #include <mach/hardware.h>
 
 #include <asm/mach/arch.h>
 
 
-static struct physmap_flash_data gesbc9312_flash_data = {
-       .width          = 4,
-};
-
-static struct resource gesbc9312_flash_resource = {
-       .start          = EP93XX_CS6_PHYS_BASE,
-       .end            = EP93XX_CS6_PHYS_BASE + SZ_8M - 1,
-       .flags          = IORESOURCE_MEM,
-};
-
-static struct platform_device gesbc9312_flash = {
-       .name           = "physmap-flash",
-       .id             = 0,
-       .dev            = {
-               .platform_data  = &gesbc9312_flash_data,
-       },
-       .num_resources  = 1,
-       .resource       = &gesbc9312_flash_resource,
-};
-
 static struct ep93xx_eth_data __initdata gesbc9312_eth_data = {
        .phy_id         = 1,
 };
@@ -48,8 +27,7 @@ static struct ep93xx_eth_data __initdata gesbc9312_eth_data = {
 static void __init gesbc9312_init_machine(void)
 {
        ep93xx_init_devices();
-       platform_device_register(&gesbc9312_flash);
-
+       ep93xx_register_flash(4, EP93XX_CS6_PHYS_BASE, SZ_8M);
        ep93xx_register_eth(&gesbc9312_eth_data, 0);
 }
 
index 9a4413dd44bb6e1cd2ac6cbc291cfd87b7220d6f..a6c09176334ce1a7028705feeddfc38ddadf235e 100644 (file)
@@ -43,6 +43,9 @@ static inline void ep93xx_devcfg_clear_bits(unsigned int bits)
 
 unsigned int ep93xx_chip_revision(void);
 
+void ep93xx_register_flash(unsigned int width,
+                          resource_size_t start, resource_size_t size);
+
 void ep93xx_register_eth(struct ep93xx_eth_data *data, int copy_addr);
 void ep93xx_register_i2c(struct i2c_gpio_platform_data *data,
                         struct i2c_board_info *devices, int num);
index 1cc911b4efa659dbfbc7e35aee6f80236e81e800..2ba776320a8282e978d989eea0377d6511dc3ab7 100644 (file)
@@ -14,7 +14,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/mtd/physmap.h>
 #include <linux/io.h>
 
 #include <mach/hardware.h>
  * Micro9-Lite uses a separate MTD map driver for flash support
  * Micro9-Slim has up to 64MB of either 32-bit or 16-bit flash on CS1
  *************************************************************************/
-static struct physmap_flash_data micro9_flash_data;
-
-static struct resource micro9_flash_resource = {
-       .start          = EP93XX_CS1_PHYS_BASE,
-       .end            = EP93XX_CS1_PHYS_BASE + SZ_64M - 1,
-       .flags          = IORESOURCE_MEM,
-};
-
-static struct platform_device micro9_flash = {
-       .name           = "physmap-flash",
-       .id             = 0,
-       .dev            = {
-               .platform_data  = &micro9_flash_data,
-       },
-       .num_resources  = 1,
-       .resource       = &micro9_flash_resource,
-};
-
-static void __init __micro9_register_flash(unsigned int width)
-{
-       micro9_flash_data.width = width;
-
-       platform_device_register(&micro9_flash);
-}
-
 static unsigned int __init micro9_detect_bootwidth(void)
 {
        u32 v;
@@ -70,10 +44,17 @@ static unsigned int __init micro9_detect_bootwidth(void)
 
 static void __init micro9_register_flash(void)
 {
+       unsigned int width;
+
        if (machine_is_micro9())
-               __micro9_register_flash(4);
+               width = 4;
        else if (machine_is_micro9m() || machine_is_micro9s())
-               __micro9_register_flash(micro9_detect_bootwidth());
+               width = micro9_detect_bootwidth();
+       else
+               width = 0;
+
+       if (width)
+               ep93xx_register_flash(width, EP93XX_CS1_PHYS_BASE, SZ_64M);
 }
 
 
index 388aec95f60e39fb304ac48c655c413f33129c45..5dded5884133f89e27898567a61163c583fa8f3d 100644 (file)
@@ -18,7 +18,6 @@
 #include <linux/kernel.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/mtd/physmap.h>
 #include <linux/gpio.h>
 #include <linux/i2c.h>
 #include <linux/i2c-gpio.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 
-static struct physmap_flash_data simone_flash_data = {
-       .width          = 2,
-};
-
-static struct resource simone_flash_resource = {
-       .start          = EP93XX_CS6_PHYS_BASE,
-       .end            = EP93XX_CS6_PHYS_BASE + SZ_8M - 1,
-       .flags          = IORESOURCE_MEM,
-};
-
-static struct platform_device simone_flash = {
-       .name           = "physmap-flash",
-       .id             = 0,
-       .num_resources  = 1,
-       .resource       = &simone_flash_resource,
-       .dev = {
-               .platform_data  = &simone_flash_data,
-       },
-};
-
 static struct ep93xx_eth_data __initdata simone_eth_data = {
        .phy_id         = 1,
 };
@@ -77,8 +56,7 @@ static struct i2c_board_info __initdata simone_i2c_board_info[] = {
 static void __init simone_init_machine(void)
 {
        ep93xx_init_devices();
-
-       platform_device_register(&simone_flash);
+       ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_8M);
        ep93xx_register_eth(&simone_eth_data, 1);
        ep93xx_register_fb(&simone_fb_info);
        ep93xx_register_i2c(&simone_i2c_gpio_data, simone_i2c_board_info,
index ae7319e588c7e59ca570173d47d1e95a0fe06d0f..93aeab8af705e8dd3dde989b1658e81e6ed60062 100644 (file)
@@ -17,7 +17,6 @@
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <linux/m48t86.h>
-#include <linux/mtd/physmap.h>
 #include <linux/mtd/nand.h>
 #include <linux/mtd/partitions.h>
 
@@ -173,31 +172,13 @@ static struct platform_device ts72xx_nand_flash = {
 };
 
 
-/*************************************************************************
- * NOR flash (TS-7200 only)
- *************************************************************************/
-static struct physmap_flash_data ts72xx_nor_data = {
-       .width          = 2,
-};
-
-static struct resource ts72xx_nor_resource = {
-       .start          = EP93XX_CS6_PHYS_BASE,
-       .end            = EP93XX_CS6_PHYS_BASE + SZ_16M - 1,
-       .flags          = IORESOURCE_MEM,
-};
-
-static struct platform_device ts72xx_nor_flash = {
-       .name                   = "physmap-flash",
-       .id                     = 0,
-       .dev.platform_data      = &ts72xx_nor_data,
-       .resource               = &ts72xx_nor_resource,
-       .num_resources          = 1,
-};
-
 static void __init ts72xx_register_flash(void)
 {
+       /*
+        * TS7200 has NOR flash all other TS72xx board have NAND flash.
+        */
        if (board_is_ts7200()) {
-               platform_device_register(&ts72xx_nor_flash);
+               ep93xx_register_flash(2, EP93XX_CS6_PHYS_BASE, SZ_16M);
        } else {
                resource_size_t start;
 
similarity index 57%
rename from arch/arm/mach-mx2/Kconfig
rename to arch/arm/mach-imx/Kconfig
index 742fd4e6dcb928486d299eec335f95b7cba6a431..c5c0369bb481dff32f4bbb8c214f4859a16787ac 100644 (file)
+config IMX_HAVE_DMA_V1
+       bool
+
+if ARCH_MX1
+
+config SOC_IMX1
+       select CPU_ARM920T
+       select IMX_HAVE_DMA_V1
+       select IMX_HAVE_IOMUX_V1
+       bool
+
+comment "MX1 platforms:"
+config MACH_MXLADS
+       bool
+
+config ARCH_MX1ADS
+       bool "MX1ADS platform"
+       select MACH_MXLADS
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       help
+         Say Y here if you are using Motorola MX1ADS/MXLADS boards
+
+config MACH_SCB9328
+       bool "Synertronixx scb9328"
+       select IMX_HAVE_PLATFORM_IMX_UART
+       help
+         Say Y here if you are using a Synertronixx scb9328 board
+
+endif
+
 if ARCH_MX2
 
+config SOC_IMX21
+       select CPU_ARM926T
+       select ARCH_MXC_AUDMUX_V1
+       select IMX_HAVE_DMA_V1
+       select IMX_HAVE_IOMUX_V1
+       bool
+
+config SOC_IMX27
+       select CPU_ARM926T
+       select ARCH_MXC_AUDMUX_V1
+       select IMX_HAVE_DMA_V1
+       select IMX_HAVE_IOMUX_V1
+       bool
+
 choice
        prompt "CPUs:"
        default MACH_MX21
 
 config MACH_MX21
        bool "i.MX21 support"
-       select ARCH_MXC_AUDMUX_V1
+       select SOC_IMX21
        help
          This enables support for Freescale's MX2 based i.MX21 processor.
 
 config MACH_MX27
        bool "i.MX27 support"
-       select ARCH_MXC_AUDMUX_V1
+       select SOC_IMX27
        help
          This enables support for Freescale's MX2 based i.MX27 processor.
 
 endchoice
 
-comment "MX2 platforms:"
+endif
+
+if MACH_MX21
+
+comment "MX21 platforms:"
 
 config MACH_MX21ADS
        bool "MX21ADS platform"
-       depends on MACH_MX21
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
        help
          Include support for MX21ADS platform. This includes specific
          configurations for the board and its peripherals.
 
+endif
+
+if MACH_MX27
+
+comment "MX27 platforms:"
+
 config MACH_MX27ADS
        bool "MX27ADS platform"
-       depends on MACH_MX27
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
        help
          Include support for MX27ADS platform. This includes specific
          configurations for the board and its peripherals.
 
 config MACH_PCM038
        bool "Phytec phyCORE-i.MX27 CPU module (pcm038)"
-       depends on MACH_MX27
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
+       select IMX_HAVE_PLATFORM_SPI_IMX
        select MXC_ULPI if USB_ULPI
        help
          Include support for phyCORE-i.MX27 (aka pcm038) platform. This
@@ -58,7 +119,9 @@ endchoice
 
 config MACH_CPUIMX27
        bool "Eukrea CPUIMX27 module"
-       depends on MACH_MX27
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
        help
          Include support for Eukrea CPUIMX27 platform. This includes
          specific configurations for the module and its peripherals.
@@ -67,9 +130,16 @@ config MACH_EUKREA_CPUIMX27_USESDHC2
        bool "CPUIMX27 integrates SDHC2 module"
        depends on MACH_CPUIMX27
        help
-         This adds support for the internal SDHC2 used on CPUIMX27 used
+         This adds support for the internal SDHC2 used on CPUIMX27
          for wifi or eMMC.
 
+config MACH_EUKREA_CPUIMX27_USEUART4
+       bool "CPUIMX27 integrates UART4 module"
+       depends on MACH_CPUIMX27
+       help
+         This adds support for the internal UART4 used on CPUIMX27
+         for bluetooth.
+
 choice
        prompt "Baseboard"
        depends on MACH_CPUIMX27
@@ -78,6 +148,8 @@ choice
 config MACH_EUKREA_MBIMX27_BASEBOARD
        prompt "Eukrea MBIMX27 development board"
        bool
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_SPI_IMX
        help
          This adds board specific devices that can be found on Eukrea's
          MBIMX27 evaluation board.
@@ -86,21 +158,24 @@ endchoice
 
 config MACH_MX27_3DS
        bool "MX27PDK platform"
-       depends on MACH_MX27
+       select IMX_HAVE_PLATFORM_IMX_UART
        help
          Include support for MX27PDK platform. This includes specific
          configurations for the board and its peripherals.
 
 config MACH_IMX27LITE
        bool "LogicPD MX27 LITEKIT platform"
-       depends on MACH_MX27
+       select IMX_HAVE_PLATFORM_IMX_UART
        help
          Include support for MX27 LITEKIT platform. This includes specific
          configurations for the board and its peripherals.
 
 config MACH_PCA100
        bool "Phytec phyCARD-s (pca100)"
-       depends on MACH_MX27
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
+       select IMX_HAVE_PLATFORM_SPI_IMX
        select MXC_ULPI if USB_ULPI
        help
          Include support for phyCARD-s (aka pca100) platform. This
@@ -108,7 +183,9 @@ config MACH_PCA100
 
 config MACH_MXT_TD60
        bool "Maxtrack i-MXT TD60"
-       depends on MACH_MX27
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
        help
          Include support for i-MXT (aka td60) platform. This
          includes specific configurations for the module and its peripherals.
similarity index 55%
rename from arch/arm/mach-mx2/Makefile
rename to arch/arm/mach-imx/Makefile
index e3254faac8289655f2997afe2f0d24d1fff8cfbb..46a9fdfbbd157101e22fbd19e1edb6d2c2d893af 100644 (file)
@@ -4,14 +4,24 @@
 
 # Object file lists.
 
-obj-y  :=  devices.o serial.o
+obj-y  :=  devices.o
 
-obj-$(CONFIG_MACH_MX21) += clock_imx21.o mm-imx21.o
+obj-$(CONFIG_IMX_HAVE_DMA_V1) += dma-v1.o
 
-obj-$(CONFIG_MACH_MX27) += cpu_imx27.o
-obj-$(CONFIG_MACH_MX27) += clock_imx27.o mm-imx27.o
+obj-$(CONFIG_ARCH_MX1) += clock-imx1.o mm-imx1.o
+obj-$(CONFIG_MACH_MX21) += clock-imx21.o mm-imx21.o
+
+obj-$(CONFIG_MACH_MX27) += cpu-imx27.o pm-imx27.o
+obj-$(CONFIG_MACH_MX27) += clock-imx27.o mm-imx27.o
+
+# Support for CMOS sensor interface
+obj-$(CONFIG_MX1_VIDEO)        += mx1-camera-fiq.o mx1-camera-fiq-ksym.o
+
+obj-$(CONFIG_ARCH_MX1ADS) += mach-mx1ads.o
+obj-$(CONFIG_MACH_SCB9328) += mach-scb9328.o
 
 obj-$(CONFIG_MACH_MX21ADS) += mach-mx21ads.o
+
 obj-$(CONFIG_MACH_MX27ADS) += mach-mx27ads.o
 obj-$(CONFIG_MACH_PCM038) += mach-pcm038.o
 obj-$(CONFIG_MACH_PCM970_BASEBOARD) += pcm970-baseboard.o
similarity index 67%
rename from arch/arm/mach-mx2/Makefile.boot
rename to arch/arm/mach-imx/Makefile.boot
index e867398a8fdbb5304493c40104635e1e40a3f778..7988a85cf07db0453ec39715c38a70067a2ef1d0 100644 (file)
@@ -1,3 +1,7 @@
+zreladdr-$(CONFIG_ARCH_MX1)    := 0x08008000
+params_phys-$(CONFIG_ARCH_MX1) := 0x08000100
+initrd_phys-$(CONFIG_ARCH_MX1) := 0x08800000
+
 zreladdr-$(CONFIG_MACH_MX21)   := 0xC0008000
 params_phys-$(CONFIG_MACH_MX21)        := 0xC0000100
 initrd_phys-$(CONFIG_MACH_MX21)        := 0xC0800000
similarity index 90%
rename from arch/arm/mach-mx1/clock.c
rename to arch/arm/mach-imx/clock-imx1.c
index 6cf2d4a7511dc441561c80fe80ca432cf886d3b5..c05096c38301038292e9b9f6e0bb10990c31433e 100644 (file)
@@ -2,18 +2,17 @@
  *  Copyright (C) 2008 Sascha Hauer <s.hauer@pengutronix.de>, Pengutronix
  *
  * 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.
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
  *
  * 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
+ * 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.,
+ * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #include <linux/kernel.h>
 #include <mach/clock.h>
 #include <mach/hardware.h>
 #include <mach/common.h>
-#include "crm_regs.h"
+
+#define IO_ADDR_CCM(off)       (MX1_IO_ADDRESS(MX1_CCM_BASE_ADDR + (off)))
+
+/* CCM register addresses */
+#define CCM_CSCR       IO_ADDR_CCM(0x0)
+#define CCM_MPCTL0     IO_ADDR_CCM(0x4)
+#define CCM_SPCTL0     IO_ADDR_CCM(0xc)
+#define CCM_PCDR       IO_ADDR_CCM(0x20)
+
+#define CCM_CSCR_CLKO_OFFSET   29
+#define CCM_CSCR_CLKO_MASK     (0x7 << 29)
+#define CCM_CSCR_USB_OFFSET    26
+#define CCM_CSCR_USB_MASK      (0x7 << 26)
+#define CCM_CSCR_OSC_EN_SHIFT  17
+#define CCM_CSCR_SYSTEM_SEL    (1 << 16)
+#define CCM_CSCR_BCLK_OFFSET   10
+#define CCM_CSCR_BCLK_MASK     (0xf << 10)
+#define CCM_CSCR_PRESC         (1 << 15)
+
+#define CCM_PCDR_PCLK3_OFFSET  16
+#define CCM_PCDR_PCLK3_MASK    (0x7f << 16)
+#define CCM_PCDR_PCLK2_OFFSET  4
+#define CCM_PCDR_PCLK2_MASK    (0xf << 4)
+#define CCM_PCDR_PCLK1_OFFSET  0
+#define CCM_PCDR_PCLK1_MASK    0xf
+
+#define IO_ADDR_SCM(off)       (MX1_IO_ADDRESS(MX1_SCM_BASE_ADDR + (off)))
+
+/* SCM register addresses */
+#define SCM_GCCR       IO_ADDR_SCM(0xc)
+
+#define SCM_GCCR_DMA_CLK_EN_OFFSET     3
+#define SCM_GCCR_CSI_CLK_EN_OFFSET     2
+#define SCM_GCCR_MMA_CLK_EN_OFFSET     1
+#define SCM_GCCR_USBD_CLK_EN_OFFSET    0
 
 static int _clk_enable(struct clk *clk)
 {
@@ -596,7 +629,8 @@ int __init mx1_clocks_init(unsigned long fref)
        clk_enable(&hclk);
        clk_enable(&fclk);
 
-       mxc_timer_init(&gpt_clk, IO_ADDRESS(TIM1_BASE_ADDR), TIM1_INT);
+       mxc_timer_init(&gpt_clk, MX1_IO_ADDRESS(MX1_TIM1_BASE_ADDR),
+                       MX1_TIM1_INT);
 
        return 0;
 }
similarity index 99%
rename from arch/arm/mach-mx2/clock_imx27.c
rename to arch/arm/mach-imx/clock-imx27.c
index 0f0823c8b1707e9d8f86bbc77fb0320aa25395b8..5a1aa15c8a16140f17e75ea451b5441c9c413d10 100644 (file)
@@ -644,7 +644,7 @@ static struct clk_lookup lookups[] = {
        _REGISTER_CLOCK("spi_imx.1", NULL, cspi2_clk)
        _REGISTER_CLOCK("spi_imx.2", NULL, cspi3_clk)
        _REGISTER_CLOCK("imx-fb.0", NULL, lcdc_clk)
-       _REGISTER_CLOCK(NULL, "csi", csi_clk)
+       _REGISTER_CLOCK("mx2-camera.0", NULL, csi_clk)
        _REGISTER_CLOCK("fsl-usb2-udc", "usb", usb_clk)
        _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", usb_clk1)
        _REGISTER_CLOCK("mxc-ehci.0", "usb", usb_clk)
diff --git a/arch/arm/mach-imx/devices-imx1.h b/arch/arm/mach-imx/devices-imx1.h
new file mode 100644 (file)
index 0000000..a8d94f0
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright (C) 2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <mach/mx1.h>
+#include <mach/devices-common.h>
+
+#define imx1_add_i2c_imx(pdata)                \
+       imx_add_imx_i2c(0, MX1_I2C_BASE_ADDR, SZ_4K, MX1_INT_I2C, pdata)
+
+#define imx1_add_imx_uart0(pdata)      \
+       imx_add_imx_uart_3irq(0, MX1_UART1_BASE_ADDR, 0xd0, MX1_INT_UART1RX, MX1_INT_UART1TX, MX1_INT_UART1RTS, pdata)
+#define imx1_add_imx_uart1(pdata)      \
+       imx_add_imx_uart_3irq(0, MX1_UART2_BASE_ADDR, 0xd0, MX1_INT_UART2RX, MX1_INT_UART2TX, MX1_INT_UART2RTS, pdata)
diff --git a/arch/arm/mach-imx/devices-imx21.h b/arch/arm/mach-imx/devices-imx21.h
new file mode 100644 (file)
index 0000000..42788e9
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <mach/mx21.h>
+#include <mach/devices-common.h>
+
+#define imx21_add_i2c_imx(pdata)       \
+       imx_add_imx_i2c(0, MX2x_I2C_BASE_ADDR, SZ_4K, MX2x_INT_I2C, pdata)
+
+#define imx21_add_imx_uart0(pdata)     \
+       imx_add_imx_uart_1irq(0, MX21_UART1_BASE_ADDR, SZ_4K, MX21_INT_UART1, pdata)
+#define imx21_add_imx_uart1(pdata)     \
+       imx_add_imx_uart_1irq(1, MX21_UART2_BASE_ADDR, SZ_4K, MX21_INT_UART2, pdata)
+#define imx21_add_imx_uart2(pdata)     \
+       imx_add_imx_uart_1irq(2, MX21_UART3_BASE_ADDR, SZ_4K, MX21_INT_UART3, pdata)
+#define imx21_add_imx_uart3(pdata)     \
+       imx_add_imx_uart_1irq(3, MX21_UART4_BASE_ADDR, SZ_4K, MX21_INT_UART4, pdata)
+
+#define imx21_add_mxc_nand(pdata)      \
+       imx_add_mxc_nand_v1(MX21_NFC_BASE_ADDR, MX21_INT_NANDFC, pdata)
+
+#define imx21_add_spi_imx0(pdata)      \
+       imx_add_spi_imx(0, MX21_CSPI1_BASE_ADDR, SZ_4K, MX21_INT_CSPI1, pdata)
+#define imx21_add_spi_imx1(pdata)      \
+       imx_add_spi_imx(1, MX21_CSPI2_BASE_ADDR, SZ_4K, MX21_INT_CSPI2, pdata)
diff --git a/arch/arm/mach-imx/devices-imx27.h b/arch/arm/mach-imx/devices-imx27.h
new file mode 100644 (file)
index 0000000..65e7bb7
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <mach/mx27.h>
+#include <mach/devices-common.h>
+
+#define imx27_add_i2c_imx0(pdata)      \
+       imx_add_imx_i2c(0, MX27_I2C1_BASE_ADDR, SZ_4K, MX27_INT_I2C1, pdata)
+#define imx27_add_i2c_imx1(pdata)      \
+       imx_add_imx_i2c(1, MX27_I2C2_BASE_ADDR, SZ_4K, MX27_INT_I2C2, pdata)
+
+#define imx27_add_imx_uart0(pdata)     \
+       imx_add_imx_uart_1irq(0, MX27_UART1_BASE_ADDR, SZ_4K, MX27_INT_UART1, pdata)
+#define imx27_add_imx_uart1(pdata)     \
+       imx_add_imx_uart_1irq(1, MX27_UART2_BASE_ADDR, SZ_4K, MX27_INT_UART2, pdata)
+#define imx27_add_imx_uart2(pdata)     \
+       imx_add_imx_uart_1irq(2, MX27_UART3_BASE_ADDR, SZ_4K, MX27_INT_UART3, pdata)
+#define imx27_add_imx_uart3(pdata)     \
+       imx_add_imx_uart_1irq(3, MX27_UART4_BASE_ADDR, SZ_4K, MX27_INT_UART4, pdata)
+#define imx27_add_imx_uart4(pdata)     \
+       imx_add_imx_uart_1irq(4, MX27_UART5_BASE_ADDR, SZ_4K, MX27_INT_UART5, pdata)
+#define imx27_add_imx_uart5(pdata)     \
+       imx_add_imx_uart_1irq(5, MX27_UART6_BASE_ADDR, SZ_4K, MX27_INT_UART6, pdata)
+
+#define imx27_add_mxc_nand(pdata)      \
+       imx_add_mxc_nand_v1(MX27_NFC_BASE_ADDR, MX27_INT_NANDFC, pdata)
+
+#define imx27_add_spi_imx0(pdata)      \
+       imx_add_spi_imx(0, MX27_CSPI1_BASE_ADDR, SZ_4K, MX27_INT_CSPI1, pdata)
+#define imx27_add_spi_imx1(pdata)      \
+       imx_add_spi_imx(1, MX27_CSPI2_BASE_ADDR, SZ_4K, MX27_INT_CSPI2, pdata)
+#define imx27_add_spi_imx2(pdata)      \
+       imx_add_spi_imx(2, MX27_CSPI3_BASE_ADDR, SZ_4K, MX27_INT_CSPI3, pdata)
similarity index 67%
rename from arch/arm/mach-mx2/devices.c
rename to arch/arm/mach-imx/devices.c
index a0aeb8a4adc19ef419a0a045ad3b882131597106..9c271a752b84da4e0380bf9fed2c86a5658a9640 100644 (file)
@@ -11,6 +11,9 @@
  *
  * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
  * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
+ * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
+ * Copyright (c) 2008 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
+ * Copyright (c) 2008 Darius Augulis <darius.augulis@teltonika.lt>
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -32,6 +35,7 @@
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
 #include <linux/dma-mapping.h>
+#include <linux/serial.h>
 
 #include <mach/irqs.h>
 #include <mach/hardware.h>
 
 #include "devices.h"
 
-/*
- * SPI master controller
- *
- * - i.MX1: 2 channel (slighly different register setting)
- * - i.MX21: 2 channel
- * - i.MX27: 3 channel
- */
-#define DEFINE_IMX_SPI_DEVICE(n, baseaddr, irq)                                        \
-       static struct resource mxc_spi_resources ## n[] = {                     \
-               {                                                               \
-                       .start = baseaddr,                                      \
-                       .end = baseaddr + SZ_4K - 1,                            \
-                       .flags = IORESOURCE_MEM,                                \
-               }, {                                                            \
-                       .start = irq,                                           \
-                       .end = irq,                                             \
-                       .flags = IORESOURCE_IRQ,                                \
-               },                                                              \
-       };                                                                      \
-                                                                               \
-       struct platform_device mxc_spi_device ## n = {                          \
-               .name = "spi_imx",                                              \
-               .id = n,                                                        \
-               .num_resources = ARRAY_SIZE(mxc_spi_resources ## n),            \
-               .resource = mxc_spi_resources ## n,                             \
+#if defined(CONFIG_ARCH_MX1)
+static struct resource imx1_camera_resources[] = {
+       {
+               .start  = 0x00224000,
+               .end    = 0x00224010,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = MX1_CSI_INT,
+               .end    = MX1_CSI_INT,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static u64 imx1_camera_dmamask = DMA_BIT_MASK(32);
+
+struct platform_device imx1_camera_device = {
+       .name           = "mx1-camera",
+       .id             = 0, /* This is used to put cameras on this interface */
+       .dev            = {
+               .dma_mask = &imx1_camera_dmamask,
+               .coherent_dma_mask = DMA_BIT_MASK(32),
+       },
+       .resource       = imx1_camera_resources,
+       .num_resources  = ARRAY_SIZE(imx1_camera_resources),
+};
+
+static struct resource imx_rtc_resources[] = {
+       {
+               .start  = 0x00204000,
+               .end    = 0x00204024,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = MX1_RTC_INT,
+               .end    = MX1_RTC_INT,
+               .flags  = IORESOURCE_IRQ,
+       }, {
+               .start  = MX1_RTC_SAMINT,
+               .end    = MX1_RTC_SAMINT,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device imx_rtc_device = {
+       .name           = "rtc-imx",
+       .id             = 0,
+       .resource       = imx_rtc_resources,
+       .num_resources  = ARRAY_SIZE(imx_rtc_resources),
+};
+
+static struct resource imx_wdt_resources[] = {
+       {
+               .start  = 0x00201000,
+               .end    = 0x00201008,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = MX1_WDT_INT,
+               .end    = MX1_WDT_INT,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device imx_wdt_device = {
+       .name           = "imx-wdt",
+       .id             = 0,
+       .resource       = imx_wdt_resources,
+       .num_resources  = ARRAY_SIZE(imx_wdt_resources),
+};
+
+static struct resource imx_usb_resources[] = {
+       {
+               .start  = 0x00212000,
+               .end    = 0x00212148,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = MX1_USBD_INT0,
+               .end    = MX1_USBD_INT0,
+               .flags  = IORESOURCE_IRQ,
+       }, {
+               .start  = MX1_USBD_INT1,
+               .end    = MX1_USBD_INT1,
+               .flags  = IORESOURCE_IRQ,
+       }, {
+               .start  = MX1_USBD_INT2,
+               .end    = MX1_USBD_INT2,
+               .flags  = IORESOURCE_IRQ,
+       }, {
+               .start  = MX1_USBD_INT3,
+               .end    = MX1_USBD_INT3,
+               .flags  = IORESOURCE_IRQ,
+       }, {
+               .start  = MX1_USBD_INT4,
+               .end    = MX1_USBD_INT4,
+               .flags  = IORESOURCE_IRQ,
+       }, {
+               .start  = MX1_USBD_INT5,
+               .end    = MX1_USBD_INT5,
+               .flags  = IORESOURCE_IRQ,
+       }, {
+               .start  = MX1_USBD_INT6,
+               .end    = MX1_USBD_INT6,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device imx_usb_device = {
+       .name           = "imx_udc",
+       .id             = 0,
+       .num_resources  = ARRAY_SIZE(imx_usb_resources),
+       .resource       = imx_usb_resources,
+};
+
+/* GPIO port description */
+static struct mxc_gpio_port imx_gpio_ports[] = {
+       {
+               .chip.label = "gpio-0",
+               .base = (void __iomem *)MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR),
+               .irq = MX1_GPIO_INT_PORTA,
+               .virtual_irq_start = MXC_GPIO_IRQ_START,
+       }, {
+               .chip.label = "gpio-1",
+               .base = (void __iomem *)MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x100),
+               .irq = MX1_GPIO_INT_PORTB,
+               .virtual_irq_start = MXC_GPIO_IRQ_START + 32,
+       }, {
+               .chip.label = "gpio-2",
+               .base = (void __iomem *)MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x200),
+               .irq = MX1_GPIO_INT_PORTC,
+               .virtual_irq_start = MXC_GPIO_IRQ_START + 64,
+       }, {
+               .chip.label = "gpio-3",
+               .base = (void __iomem *)MX1_IO_ADDRESS(MX1_GPIO_BASE_ADDR + 0x300),
+               .irq = MX1_GPIO_INT_PORTD,
+               .virtual_irq_start = MXC_GPIO_IRQ_START + 96,
        }
+};
+
+int __init imx1_register_gpios(void)
+{
+       return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
+}
+#endif
 
-DEFINE_IMX_SPI_DEVICE(0, MX2x_CSPI1_BASE_ADDR, MX2x_INT_CSPI1);
-DEFINE_IMX_SPI_DEVICE(1, MX2x_CSPI2_BASE_ADDR, MX2x_INT_CSPI2);
+#if defined(CONFIG_MACH_MX21) || defined(CONFIG_MACH_MX27)
 
 #ifdef CONFIG_MACH_MX27
-DEFINE_IMX_SPI_DEVICE(2, MX27_CSPI3_BASE_ADDR, MX27_INT_CSPI3);
+static struct resource mx27_camera_resources[] = {
+       {
+              .start = MX27_CSI_BASE_ADDR,
+              .end = MX27_CSI_BASE_ADDR + 0x1f,
+              .flags = IORESOURCE_MEM,
+       }, {
+              .start = MX27_EMMA_PRP_BASE_ADDR,
+              .end = MX27_EMMA_PRP_BASE_ADDR + 0x1f,
+              .flags = IORESOURCE_MEM,
+       }, {
+              .start = MX27_INT_CSI,
+              .end = MX27_INT_CSI,
+              .flags = IORESOURCE_IRQ,
+       },{
+              .start = MX27_INT_EMMAPRP,
+              .end = MX27_INT_EMMAPRP,
+              .flags = IORESOURCE_IRQ,
+       },
+};
+struct platform_device mx27_camera_device = {
+       .name = "mx2-camera",
+       .id = 0,
+       .num_resources = ARRAY_SIZE(mx27_camera_resources),
+       .resource = mx27_camera_resources,
+       .dev = {
+               .coherent_dma_mask = 0xffffffff,
+       },
+};
 #endif
 
 /*
@@ -140,34 +285,6 @@ struct platform_device mxc_w1_master_device = {
        .resource = mxc_w1_master_resources,
 };
 
-#define DEFINE_MXC_NAND_DEVICE(pfx, baseaddr, irq)                     \
-       static struct resource pfx ## _nand_resources[] = {             \
-               {                                                       \
-                       .start = baseaddr,                              \
-                       .end = baseaddr + SZ_4K - 1,                    \
-                       .flags = IORESOURCE_MEM,                        \
-               }, {                                                    \
-                       .start = irq,                                   \
-                       .end = irq,                                     \
-                       .flags = IORESOURCE_IRQ,                        \
-               },                                                      \
-       };                                                              \
-                                                                       \
-       struct platform_device pfx ## _nand_device = {                  \
-               .name = "mxc_nand",                                     \
-               .id = 0,                                                \
-               .num_resources = ARRAY_SIZE(pfx ## _nand_resources),    \
-               .resource = pfx ## _nand_resources,                     \
-       }
-
-#ifdef CONFIG_MACH_MX21
-DEFINE_MXC_NAND_DEVICE(imx21, MX21_NFC_BASE_ADDR, MX21_INT_NANDFC);
-#endif
-
-#ifdef CONFIG_MACH_MX27
-DEFINE_MXC_NAND_DEVICE(imx27, MX27_NFC_BASE_ADDR, MX27_INT_NANDFC);
-#endif
-
 /*
  * lcdc:
  * - i.MX1: the basic controller
@@ -218,32 +335,6 @@ struct platform_device mxc_fec_device = {
 };
 #endif
 
-#define DEFINE_IMX_I2C_DEVICE(n, baseaddr, irq)                                \
-       static struct resource mxc_i2c_resources ## n[] = {             \
-               {                                                       \
-                       .start = baseaddr,                              \
-                       .end = baseaddr + SZ_4K - 1,                    \
-                       .flags = IORESOURCE_MEM,                        \
-               }, {                                                    \
-                       .start = irq,                                   \
-                       .end = irq,                                     \
-                       .flags = IORESOURCE_IRQ,                        \
-               }                                                       \
-       };                                                              \
-                                                                       \
-       struct platform_device mxc_i2c_device ## n = {                  \
-               .name = "imx-i2c",                                      \
-               .id = n,                                                \
-               .num_resources = ARRAY_SIZE(mxc_i2c_resources ## n),    \
-               .resource = mxc_i2c_resources ## n,                     \
-       }
-
-DEFINE_IMX_I2C_DEVICE(0, MX2x_I2C_BASE_ADDR, MX2x_INT_I2C);
-
-#ifdef CONFIG_MACH_MX27
-DEFINE_IMX_I2C_DEVICE(1, MX27_I2C2_BASE_ADDR, MX27_INT_I2C2);
-#endif
-
 static struct resource mxc_pwm_resources[] = {
        {
                .start = MX2x_PWM_BASE_ADDR,
@@ -454,26 +545,21 @@ DEFINE_IMX_SSI_DEVICE(1, 2, MX2x_SSI1_BASE_ADDR, MX2x_INT_SSI1);
 
 #ifdef CONFIG_MACH_MX21
 DEFINE_MXC_GPIO_PORTS(MX21, imx21);
+
+int __init imx21_register_gpios(void)
+{
+       return mxc_gpio_init(imx21_gpio_ports, ARRAY_SIZE(imx21_gpio_ports));
+}
 #endif
 
 #ifdef CONFIG_MACH_MX27
 DEFINE_MXC_GPIO_PORTS(MX27, imx27);
-#endif
 
-int __init mxc_register_gpios(void)
+int __init imx27_register_gpios(void)
 {
-#ifdef CONFIG_MACH_MX21
-       if (cpu_is_mx21())
-               return mxc_gpio_init(imx21_gpio_ports, ARRAY_SIZE(imx21_gpio_ports));
-       else
-#endif
-#ifdef CONFIG_MACH_MX27
-       if (cpu_is_mx27())
-               return mxc_gpio_init(imx27_gpio_ports, ARRAY_SIZE(imx27_gpio_ports));
-       else
-#endif
-               return 0;
+       return mxc_gpio_init(imx27_gpio_ports, ARRAY_SIZE(imx27_gpio_ports));
 }
+#endif
 
 #ifdef CONFIG_MACH_MX21
 static struct resource mx21_usbhc_resources[] = {
@@ -501,3 +587,23 @@ struct platform_device mx21_usbhc_device = {
 };
 #endif
 
+static struct resource imx_kpp_resources[] = {
+       {
+               .start  = MX2x_KPP_BASE_ADDR,
+               .end    = MX2x_KPP_BASE_ADDR + 0xf,
+               .flags  = IORESOURCE_MEM
+       }, {
+               .start  = MX2x_INT_KPP,
+               .end    = MX2x_INT_KPP,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device imx_kpp_device = {
+       .name = "imx-keypad",
+       .id = -1,
+       .num_resources = ARRAY_SIZE(imx_kpp_resources),
+       .resource = imx_kpp_resources,
+};
+
+#endif
similarity index 54%
rename from arch/arm/mach-mx2/devices.h
rename to arch/arm/mach-imx/devices.h
index 84ed51380174ebd6cadaef60f19245ede9df7782..efd4527506a5e661da74c95e9d756c0674ca3d33 100644 (file)
@@ -1,3 +1,11 @@
+#ifdef CONFIG_ARCH_MX1
+extern struct platform_device imx1_camera_device;
+extern struct platform_device imx_rtc_device;
+extern struct platform_device imx_wdt_device;
+extern struct platform_device imx_usb_device;
+#endif
+
+#if defined(CONFIG_MACH_MX21) || defined(CONFIG_MACH_MX27)
 extern struct platform_device mxc_gpt1;
 extern struct platform_device mxc_gpt2;
 #ifdef CONFIG_MACH_MX27
@@ -6,37 +14,19 @@ extern struct platform_device mxc_gpt4;
 extern struct platform_device mxc_gpt5;
 #endif
 extern struct platform_device mxc_wdt;
-extern struct platform_device mxc_uart_device0;
-extern struct platform_device mxc_uart_device1;
-extern struct platform_device mxc_uart_device2;
-extern struct platform_device mxc_uart_device3;
-extern struct platform_device mxc_uart_device4;
-extern struct platform_device mxc_uart_device5;
 extern struct platform_device mxc_w1_master_device;
-#ifdef CONFIG_MACH_MX21
-extern struct platform_device imx21_nand_device;
-#endif
-#ifdef CONFIG_MACH_MX27
-extern struct platform_device imx27_nand_device;
-#endif
 extern struct platform_device mxc_fb_device;
 extern struct platform_device mxc_fec_device;
 extern struct platform_device mxc_pwm_device;
-extern struct platform_device mxc_i2c_device0;
-#ifdef CONFIG_MACH_MX27
-extern struct platform_device mxc_i2c_device1;
-#endif
 extern struct platform_device mxc_sdhc_device0;
 extern struct platform_device mxc_sdhc_device1;
 extern struct platform_device mxc_otg_udc_device;
+extern struct platform_device mx27_camera_device;
 extern struct platform_device mxc_otg_host;
 extern struct platform_device mxc_usbh1;
 extern struct platform_device mxc_usbh2;
-extern struct platform_device mxc_spi_device0;
-extern struct platform_device mxc_spi_device1;
-#ifdef CONFIG_MACH_MX27
-extern struct platform_device mxc_spi_device2;
-#endif
 extern struct platform_device mx21_usbhc_device;
 extern struct platform_device imx_ssi_device0;
 extern struct platform_device imx_ssi_device1;
+extern struct platform_device imx_kpp_device;
+#endif
similarity index 99%
rename from arch/arm/plat-mxc/dma-mx1-mx2.c
rename to arch/arm/mach-imx/dma-v1.c
index e16014b0d13c817fe56e66fcb71a588ee0abf72e..fd1d9197d06ef66f9b5e5a3d95d3a825510f47a5 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  linux/arch/arm/plat-mxc/dma-mx1-mx2.c
+ *  linux/arch/arm/plat-mxc/dma-v1.c
  *
  *  i.MX DMA registration and IRQ dispatching
  *
@@ -34,7 +34,7 @@
 #include <asm/system.h>
 #include <asm/irq.h>
 #include <mach/hardware.h>
-#include <mach/dma-mx1-mx2.h>
+#include <mach/dma-v1.h>
 
 #define DMA_DCR     0x00               /* Control Register */
 #define DMA_DISR    0x04               /* Interrupt status Register */
similarity index 52%
rename from arch/arm/mach-mx2/eukrea_mbimx27-baseboard.c
rename to arch/arm/mach-imx/eukrea_mbimx27-baseboard.c
index f3b169d5245fcdf7f751c896ad693073bba31087..4edc5f43920109011d6e8f8fd64234e3fe3cb992 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Eric Benard - eric@eukrea.com
+ * Copyright (C) 2009-2010 Eric Benard - eric@eukrea.com
  *
  * Based on pcm970-baseboard.c which is :
  * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
@@ -24,6 +24,9 @@
 #include <linux/platform_device.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/ads7846.h>
+#include <linux/backlight.h>
+#include <video/platform_lcd.h>
+#include <linux/input/matrix_keypad.h>
 
 #include <asm/mach/arch.h>
 
 #include <mach/imxfb.h>
 #include <mach/hardware.h>
 #include <mach/mmc.h>
-#include <mach/imx-uart.h>
+#include <mach/spi.h>
+#include <mach/ssi.h>
+#include <mach/audmux.h>
 
+#include "devices-imx27.h"
 #include "devices.h"
 
 static int eukrea_mbimx27_pins[] = {
@@ -48,10 +54,12 @@ static int eukrea_mbimx27_pins[] = {
        PE10_PF_UART3_CTS,
        PE11_PF_UART3_RTS,
        /* UART4 */
+#if !defined(MACH_EUKREA_CPUIMX27_USEUART4)
        PB26_AF_UART4_RTS,
        PB28_AF_UART4_TXD,
        PB29_AF_UART4_CTS,
        PB31_AF_UART4_RXD,
+#endif
        /* SDHC1*/
        PE18_PF_SD1_D0,
        PE19_PF_SD1_D1,
@@ -84,10 +92,29 @@ static int eukrea_mbimx27_pins[] = {
        PA30_PF_CONTRAST,
        PA31_PF_OE_ACD,
        /* SPI1 */
-       PD28_PF_CSPI1_SS0,
        PD29_PF_CSPI1_SCLK,
        PD30_PF_CSPI1_MISO,
        PD31_PF_CSPI1_MOSI,
+       /* SSI4 */
+#if defined(CONFIG_SND_SOC_EUKREA_TLV320) \
+       || defined(CONFIG_SND_SOC_EUKREA_TLV320_MODULE)
+       PC16_PF_SSI4_FS,
+       PC17_PF_SSI4_RXD | GPIO_PUEN,
+       PC18_PF_SSI4_TXD | GPIO_PUEN,
+       PC19_PF_SSI4_CLK,
+#endif
+};
+
+static const uint32_t eukrea_mbimx27_keymap[] = {
+       KEY(0, 0, KEY_UP),
+       KEY(0, 1, KEY_DOWN),
+       KEY(1, 0, KEY_RIGHT),
+       KEY(1, 1, KEY_LEFT),
+};
+
+static struct matrix_keymap_data eukrea_mbimx27_keymap_data = {
+       .keymap         = eukrea_mbimx27_keymap,
+       .keymap_size    = ARRAY_SIZE(eukrea_mbimx27_keymap),
 };
 
 static struct gpio_led gpio_leds[] = {
@@ -103,12 +130,6 @@ static struct gpio_led gpio_leds[] = {
                .active_low             = 1,
                .gpio                   = GPIO_PORTF | 19,
        },
-       {
-               .name                   = "backlight",
-               .default_trigger        = "backlight",
-               .active_low             = 0,
-               .gpio                   = GPIO_PORTE | 5,
-       },
 };
 
 static struct gpio_led_platform_data gpio_led_info = {
@@ -127,7 +148,7 @@ static struct platform_device leds_gpio = {
 static struct imx_fb_videomode eukrea_mbimx27_modes[] = {
        {
                .mode = {
-                       .name           = "CMO-QGVA",
+                       .name           = "CMO-QVGA",
                        .refresh        = 60,
                        .xres           = 320,
                        .yres           = 240,
@@ -141,6 +162,38 @@ static struct imx_fb_videomode eukrea_mbimx27_modes[] = {
                },
                .pcr            = 0xFAD08B80,
                .bpp            = 16,
+       }, {
+               .mode = {
+                       .name           = "DVI-VGA",
+                       .refresh        = 60,
+                       .xres           = 640,
+                       .yres           = 480,
+                       .pixclock       = 32000,
+                       .hsync_len      = 1,
+                       .left_margin    = 35,
+                       .right_margin   = 0,
+                       .vsync_len      = 1,
+                       .upper_margin   = 7,
+                       .lower_margin   = 0,
+               },
+               .pcr            = 0xFA208B80,
+               .bpp            = 16,
+       }, {
+               .mode = {
+                       .name           = "DVI-SVGA",
+                       .refresh        = 60,
+                       .xres           = 800,
+                       .yres           = 600,
+                       .pixclock       = 25000,
+                       .hsync_len      = 1,
+                       .left_margin    = 35,
+                       .right_margin   = 0,
+                       .vsync_len      = 1,
+                       .upper_margin   = 7,
+                       .lower_margin   = 0,
+               },
+               .pcr            = 0xFA208B80,
+               .bpp            = 16,
        },
 };
 
@@ -153,16 +206,52 @@ static struct imx_fb_platform_data eukrea_mbimx27_fb_data = {
        .dmacr          = 0x00040060,
 };
 
-static struct imxuart_platform_data uart_pdata[] = {
-       {
-               .flags = IMXUART_HAVE_RTSCTS,
-       },
-       {
-               .flags = IMXUART_HAVE_RTSCTS,
+static void eukrea_mbimx27_bl_set_intensity(int intensity)
+{
+       if (intensity)
+               gpio_direction_output(GPIO_PORTE | 5, 1);
+       else
+               gpio_direction_output(GPIO_PORTE | 5, 0);
+}
+
+static struct generic_bl_info eukrea_mbimx27_bl_info = {
+       .name                   = "eukrea_mbimx27-bl",
+       .max_intensity          = 0xff,
+       .default_intensity      = 0xff,
+       .set_bl_intensity       = eukrea_mbimx27_bl_set_intensity,
+};
+
+static struct platform_device eukrea_mbimx27_bl_dev = {
+       .name                   = "generic-bl",
+       .id                     = 1,
+       .dev = {
+               .platform_data  = &eukrea_mbimx27_bl_info,
        },
 };
 
-#if defined(CONFIG_TOUCHSCREEN_ADS7846)
+static void eukrea_mbimx27_lcd_power_set(struct plat_lcd_data *pd,
+                                  unsigned int power)
+{
+       if (power)
+               gpio_direction_output(GPIO_PORTA | 25, 1);
+       else
+               gpio_direction_output(GPIO_PORTA | 25, 0);
+}
+
+static struct plat_lcd_data eukrea_mbimx27_lcd_power_data = {
+       .set_power              = eukrea_mbimx27_lcd_power_set,
+};
+
+static struct platform_device eukrea_mbimx27_lcd_powerdev = {
+       .name                   = "platform-lcd",
+       .dev.platform_data      = &eukrea_mbimx27_lcd_power_data,
+};
+
+static const struct imxuart_platform_data uart_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
+};
+
+#if defined(CONFIG_TOUCHSCREEN_ADS7846) \
        || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
 
 #define ADS7846_PENDOWN (GPIO_PORTD | 25)
@@ -173,7 +262,6 @@ static void ads7846_dev_init(void)
                printk(KERN_ERR "can't get ads746 pen down GPIO\n");
                return;
        }
-
        gpio_direction_input(ADS7846_PENDOWN);
 }
 
@@ -186,7 +274,9 @@ static struct ads7846_platform_data ads7846_config __initdata = {
        .get_pendown_state      = ads7846_get_pendown_state,
        .keep_vref_on           = 1,
 };
+#endif
 
+#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
 static struct spi_board_info eukrea_mbimx27_spi_board_info[] __initdata = {
        [0] = {
                .modalias       = "ads7846",
@@ -201,16 +291,30 @@ static struct spi_board_info eukrea_mbimx27_spi_board_info[] __initdata = {
 
 static int eukrea_mbimx27_spi_cs[] = {GPIO_PORTD | 28};
 
-static struct spi_imx_master eukrea_mbimx27_spi_0_data = {
+static const struct spi_imx_master eukrea_mbimx27_spi0_data __initconst = {
        .chipselect     = eukrea_mbimx27_spi_cs,
        .num_chipselect = ARRAY_SIZE(eukrea_mbimx27_spi_cs),
 };
 #endif
 
+static struct i2c_board_info eukrea_mbimx27_i2c_devices[] = {
+       {
+               I2C_BOARD_INFO("tlv320aic23", 0x1a),
+       },
+};
+
 static struct platform_device *platform_devices[] __initdata = {
        &leds_gpio,
 };
 
+static struct imxmmc_platform_data sdhc_pdata = {
+       .dat3_card_detect = 1,
+};
+
+struct imx_ssi_platform_data eukrea_mbimx27_ssi_pdata = {
+       .flags = IMX_SSI_DMA | IMX_SSI_USE_I2S_SLAVE,
+};
+
 /*
  * system init for baseboard usage. Will be called by cpuimx27 init.
  *
@@ -222,21 +326,52 @@ void __init eukrea_mbimx27_baseboard_init(void)
        mxc_gpio_setup_multiple_pins(eukrea_mbimx27_pins,
                ARRAY_SIZE(eukrea_mbimx27_pins), "MBIMX27");
 
-       mxc_register_device(&mxc_uart_device1, &uart_pdata[0]);
-       mxc_register_device(&mxc_uart_device2, &uart_pdata[1]);
+#if defined(CONFIG_SND_SOC_EUKREA_TLV320) \
+       || defined(CONFIG_SND_SOC_EUKREA_TLV320_MODULE)
+       /* SSI unit master I2S codec connected to SSI_PINS_4*/
+       mxc_audmux_v1_configure_port(MX27_AUDMUX_HPCR1_SSI0,
+                       MXC_AUDMUX_V1_PCR_SYN |
+                       MXC_AUDMUX_V1_PCR_TFSDIR |
+                       MXC_AUDMUX_V1_PCR_TCLKDIR |
+                       MXC_AUDMUX_V1_PCR_RFSDIR |
+                       MXC_AUDMUX_V1_PCR_RCLKDIR |
+                       MXC_AUDMUX_V1_PCR_TFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
+                       MXC_AUDMUX_V1_PCR_RFCSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4) |
+                       MXC_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR3_SSI_PINS_4)
+       );
+       mxc_audmux_v1_configure_port(MX27_AUDMUX_HPCR3_SSI_PINS_4,
+                       MXC_AUDMUX_V1_PCR_SYN |
+                       MXC_AUDMUX_V1_PCR_RXDSEL(MX27_AUDMUX_HPCR1_SSI0)
+       );
+#endif
+
+       imx27_add_imx_uart1(&uart_pdata);
+       imx27_add_imx_uart2(&uart_pdata);
+#if !defined(MACH_EUKREA_CPUIMX27_USEUART4)
+       imx27_add_imx_uart3(&uart_pdata);
+#endif
 
        mxc_register_device(&mxc_fb_device, &eukrea_mbimx27_fb_data);
-       mxc_register_device(&mxc_sdhc_device0, NULL);
+       mxc_register_device(&mxc_sdhc_device0, &sdhc_pdata);
 
-#if defined(CONFIG_TOUCHSCREEN_ADS7846)
+       i2c_register_board_info(0, eukrea_mbimx27_i2c_devices,
+                               ARRAY_SIZE(eukrea_mbimx27_i2c_devices));
+
+       mxc_register_device(&imx_ssi_device0, &eukrea_mbimx27_ssi_pdata);
+
+#if defined(CONFIG_TOUCHSCREEN_ADS7846) \
        || defined(CONFIG_TOUCHSCREEN_ADS7846_MODULE)
-       /* SPI and ADS7846 Touchscreen controler init */
-       mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
+       /* ADS7846 Touchscreen controller init */
        mxc_gpio_mode(GPIO_PORTD | 25 | GPIO_GPIO | GPIO_IN);
-       mxc_register_device(&mxc_spi_device0, &eukrea_mbimx27_spi_0_data);
+       ads7846_dev_init();
+#endif
+
+#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
+       /* SPI_CS0 init */
+       mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
+       imx27_add_spi_imx0(&eukrea_mbimx27_spi0_data);
        spi_register_board_info(eukrea_mbimx27_spi_board_info,
                        ARRAY_SIZE(eukrea_mbimx27_spi_board_info));
-       ads7846_dev_init();
 #endif
 
        /* Leds configuration */
@@ -244,6 +379,14 @@ void __init eukrea_mbimx27_baseboard_init(void)
        mxc_gpio_mode(GPIO_PORTF | 19 | GPIO_GPIO | GPIO_OUT);
        /* Backlight */
        mxc_gpio_mode(GPIO_PORTE | 5 | GPIO_GPIO | GPIO_OUT);
+       gpio_request(GPIO_PORTE | 5, "backlight");
+       platform_device_register(&eukrea_mbimx27_bl_dev);
+       /* LCD Reset */
+       mxc_gpio_mode(GPIO_PORTA | 25 | GPIO_GPIO | GPIO_OUT);
+       gpio_request(GPIO_PORTA | 25, "lcd_enable");
+       platform_device_register(&eukrea_mbimx27_lcd_powerdev);
+
+       mxc_register_device(&imx_kpp_device, &eukrea_mbimx27_keymap_data);
 
        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
 }
diff --git a/arch/arm/mach-imx/include/mach/dma-mx1-mx2.h b/arch/arm/mach-imx/include/mach/dma-mx1-mx2.h
new file mode 100644 (file)
index 0000000..df5f522
--- /dev/null
@@ -0,0 +1,10 @@
+#ifndef __MACH_DMA_MX1_MX2_H__
+#define __MACH_DMA_MX1_MX2_H__
+/*
+ * Don't use this header in new code, it will go away when all users are
+ * converted to mach/dma-v1.h
+ */
+
+#include <mach/dma-v1.h>
+
+#endif /* ifndef __MACH_DMA_MX1_MX2_H__ */
similarity index 93%
rename from arch/arm/plat-mxc/include/mach/dma-mx1-mx2.h
rename to arch/arm/mach-imx/include/mach/dma-v1.h
index 7c4870bd5a2144e39697501ce4b85e42e1e36459..287431cc13e59d32f4e592d6e1d58eb247c378b2 100644 (file)
@@ -1,5 +1,5 @@
 /*
- *  linux/arch/arm/plat-mxc/include/mach/dma-mx1-mx2.h
+ *  linux/arch/arm/mach-imx/include/mach/dma-v1.h
  *
  *  i.MX DMA registration and IRQ dispatching
  *
  * MA 02110-1301, USA.
  */
 
-#ifndef __ASM_ARCH_MXC_DMA_H
-#define __ASM_ARCH_MXC_DMA_H
+#ifndef __MACH_DMA_V1_H__
+#define __MACH_DMA_V1_H__
+
+#define imx_has_dma_v1()       (cpu_is_mx1() || cpu_is_mx21() || cpu_is_mx27())
 
 #define IMX_DMA_CHANNELS  16
 
@@ -102,4 +104,4 @@ enum imx_dma_prio {
 
 int imx_dma_request_by_prio(const char *name, enum imx_dma_prio prio);
 
-#endif /* _ASM_ARCH_MXC_DMA_H */
+#endif /* __MACH_DMA_V1_H__ */
similarity index 66%
rename from arch/arm/mach-mx2/mach-cpuimx27.c
rename to arch/arm/mach-imx/mach-cpuimx27.c
index 1f616dcaabc9bbf1089438c29e81bc57d0140dea..575ff1ae85a738f84cf48720d19e850b96caa0e5 100644 (file)
 #include <linux/mtd/physmap.h>
 #include <linux/platform_device.h>
 #include <linux/serial_8250.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/ulpi.h>
+#include <linux/fsl_devices.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/time.h>
 #include <asm/mach/map.h>
 
-#include <mach/board-eukrea_cpuimx27.h>
+#include <mach/eukrea-baseboards.h>
 #include <mach/common.h>
 #include <mach/hardware.h>
-#include <mach/i2c.h>
 #include <mach/iomux-mx27.h>
-#include <mach/imx-uart.h>
 #include <mach/mxc_nand.h>
+#include <mach/mxc_ehci.h>
+#include <mach/ulpi.h>
 
+#include "devices-imx27.h"
 #include "devices.h"
 
 static int eukrea_cpuimx27_pins[] = {
@@ -49,10 +53,12 @@ static int eukrea_cpuimx27_pins[] = {
        PE14_PF_UART1_CTS,
        PE15_PF_UART1_RTS,
        /* UART4 */
+#if defined(MACH_EUKREA_CPUIMX27_USEUART4)
        PB26_AF_UART4_RTS,
        PB28_AF_UART4_TXD,
        PB29_AF_UART4_CTS,
        PB31_AF_UART4_RXD,
+#endif
        /* FEC */
        PD0_AIN_FEC_TXD0,
        PD1_AIN_FEC_TXD1,
@@ -76,19 +82,47 @@ static int eukrea_cpuimx27_pins[] = {
        PD17_PF_I2C_DATA,
        PD18_PF_I2C_CLK,
        /* SDHC2 */
+#if defined(CONFIG_MACH_EUKREA_CPUIMX27_USESDHC2)
        PB4_PF_SD2_D0,
        PB5_PF_SD2_D1,
        PB6_PF_SD2_D2,
        PB7_PF_SD2_D3,
        PB8_PF_SD2_CMD,
        PB9_PF_SD2_CLK,
+#endif
 #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
        /* Quad UART's IRQ */
-       GPIO_PORTD | 22 | GPIO_GPIO | GPIO_IN,
-       GPIO_PORTD | 23 | GPIO_GPIO | GPIO_IN,
-       GPIO_PORTD | 27 | GPIO_GPIO | GPIO_IN,
-       GPIO_PORTD | 30 | GPIO_GPIO | GPIO_IN,
+       GPIO_PORTB | 22 | GPIO_GPIO | GPIO_IN,
+       GPIO_PORTB | 23 | GPIO_GPIO | GPIO_IN,
+       GPIO_PORTB | 27 | GPIO_GPIO | GPIO_IN,
+       GPIO_PORTB | 30 | GPIO_GPIO | GPIO_IN,
 #endif
+       /* OTG */
+       PC7_PF_USBOTG_DATA5,
+       PC8_PF_USBOTG_DATA6,
+       PC9_PF_USBOTG_DATA0,
+       PC10_PF_USBOTG_DATA2,
+       PC11_PF_USBOTG_DATA1,
+       PC12_PF_USBOTG_DATA4,
+       PC13_PF_USBOTG_DATA3,
+       PE0_PF_USBOTG_NXT,
+       PE1_PF_USBOTG_STP,
+       PE2_PF_USBOTG_DIR,
+       PE24_PF_USBOTG_CLK,
+       PE25_PF_USBOTG_DATA7,
+       /* USBH2 */
+       PA0_PF_USBH2_CLK,
+       PA1_PF_USBH2_DIR,
+       PA2_PF_USBH2_DATA7,
+       PA3_PF_USBH2_NXT,
+       PA4_PF_USBH2_STP,
+       PD19_AF_USBH2_DATA4,
+       PD20_AF_USBH2_DATA3,
+       PD21_AF_USBH2_DATA6,
+       PD22_AF_USBH2_DATA0,
+       PD23_AF_USBH2_DATA2,
+       PD24_AF_USBH2_DATA1,
+       PD26_AF_USBH2_DATA5,
 };
 
 static struct physmap_flash_data eukrea_cpuimx27_flash_data = {
@@ -111,15 +145,12 @@ static struct platform_device eukrea_cpuimx27_nor_mtd_device = {
        .resource = &eukrea_cpuimx27_flash_resource,
 };
 
-static struct imxuart_platform_data uart_pdata[] = {
-       {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       },
+static const struct imxuart_platform_data uart_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
 };
 
-static struct mxc_nand_platform_data eukrea_cpuimx27_nand_board_info = {
+static const struct mxc_nand_platform_data
+cpuimx27_nand_board_info __initconst = {
        .width = 1,
        .hw_ecc = 1,
 };
@@ -127,9 +158,11 @@ static struct mxc_nand_platform_data eukrea_cpuimx27_nand_board_info = {
 static struct platform_device *platform_devices[] __initdata = {
        &eukrea_cpuimx27_nor_mtd_device,
        &mxc_fec_device,
+       &mxc_wdt,
+       &mxc_w1_master_device,
 };
 
-static struct imxi2c_platform_data eukrea_cpuimx27_i2c_1_data = {
+static const struct imxi2c_platform_data cpuimx27_i2c1_data __initconst = {
        .bitrate = 100000,
 };
 
@@ -182,34 +215,83 @@ static struct platform_device serial_device = {
 };
 #endif
 
+#if defined(CONFIG_USB_ULPI)
+static struct mxc_usbh_platform_data otg_pdata = {
+       .portsc = MXC_EHCI_MODE_ULPI,
+       .flags  = MXC_EHCI_INTERFACE_DIFF_UNI,
+};
+
+static struct mxc_usbh_platform_data usbh2_pdata = {
+       .portsc = MXC_EHCI_MODE_ULPI,
+       .flags  = MXC_EHCI_INTERFACE_DIFF_UNI,
+};
+#endif
+
+static struct fsl_usb2_platform_data otg_device_pdata = {
+       .operating_mode = FSL_USB2_DR_DEVICE,
+       .phy_mode       = FSL_USB2_PHY_ULPI,
+};
+
+static int otg_mode_host;
+
+static int __init eukrea_cpuimx27_otg_mode(char *options)
+{
+       if (!strcmp(options, "host"))
+               otg_mode_host = 1;
+       else if (!strcmp(options, "device"))
+               otg_mode_host = 0;
+       else
+               pr_info("otg_mode neither \"host\" nor \"device\". "
+                       "Defaulting to device\n");
+       return 0;
+}
+__setup("otg_mode=", eukrea_cpuimx27_otg_mode);
+
 static void __init eukrea_cpuimx27_init(void)
 {
        mxc_gpio_setup_multiple_pins(eukrea_cpuimx27_pins,
                ARRAY_SIZE(eukrea_cpuimx27_pins), "CPUIMX27");
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata[0]);
+       imx27_add_imx_uart0(&uart_pdata);
 
-       mxc_register_device(&imx27_nand_device,
-                       &eukrea_cpuimx27_nand_board_info);
+       imx27_add_mxc_nand(&cpuimx27_nand_board_info);
 
        i2c_register_board_info(0, eukrea_cpuimx27_i2c_devices,
                                ARRAY_SIZE(eukrea_cpuimx27_i2c_devices));
 
-       mxc_register_device(&mxc_i2c_device0, &eukrea_cpuimx27_i2c_1_data);
+       imx27_add_i2c_imx1(&cpuimx27_i2c1_data);
 
        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
 
 #if defined(CONFIG_MACH_EUKREA_CPUIMX27_USESDHC2)
        /* SDHC2 can be used for Wifi */
        mxc_register_device(&mxc_sdhc_device1, NULL);
+#endif
+#if defined(MACH_EUKREA_CPUIMX27_USEUART4)
        /* in which case UART4 is also used for Bluetooth */
-       mxc_register_device(&mxc_uart_device3, &uart_pdata[1]);
+       imx27_add_imx_uart3(&uart_pdata);
 #endif
 
 #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
        platform_device_register(&serial_device);
 #endif
 
+#if defined(CONFIG_USB_ULPI)
+       if (otg_mode_host) {
+               otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
+                               USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
+
+               mxc_register_device(&mxc_otg_host, &otg_pdata);
+       }
+
+       usbh2_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
+                               USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
+
+       mxc_register_device(&mxc_usbh2, &usbh2_pdata);
+#endif
+       if (!otg_mode_host)
+               mxc_register_device(&mxc_otg_udc_device, &otg_device_pdata);
+
 #ifdef CONFIG_MACH_EUKREA_MBIMX27_BASEBOARD
        eukrea_mbimx27_baseboard_init();
 #endif
similarity index 86%
rename from arch/arm/mach-mx2/mach-imx27lite.c
rename to arch/arm/mach-imx/mach-imx27lite.c
index b5710bf18b9684d7f65682e52060aa16b4f48b1b..22a2b5d912136590addc1fcd05f32d905b1af8d0 100644 (file)
  * 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
  */
 
 #include <linux/platform_device.h>
 #include <asm/mach/map.h>
 #include <mach/hardware.h>
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx27.h>
-#include <mach/board-mx27lite.h>
 
+#include "devices-imx27.h"
 #include "devices.h"
 
 static unsigned int mx27lite_pins[] = {
@@ -59,7 +54,7 @@ static unsigned int mx27lite_pins[] = {
        PF23_AIN_FEC_TX_EN,
 };
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -71,7 +66,7 @@ static void __init mx27lite_init(void)
 {
        mxc_gpio_setup_multiple_pins(mx27lite_pins, ARRAY_SIZE(mx27lite_pins),
                "imx27lite");
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       imx27_add_imx_uart0(&uart_pdata);
        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
 }
 
similarity index 81%
rename from arch/arm/mach-mx1/mach-mx1ads.c
rename to arch/arm/mach-imx/mach-mx1ads.c
index 51f3cfd83db2ee4615d68824797db1b755a61fb1..77a760cfadc0260dba05324318e00e3d5605defd 100644 (file)
 #include <mach/common.h>
 #include <mach/hardware.h>
 #include <mach/i2c.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx1.h>
 #include <mach/irqs.h>
 
+#include "devices-imx1.h"
 #include "devices.h"
 
 static int mx1ads_pins[] = {
@@ -58,12 +58,12 @@ static int mx1ads_pins[] = {
  * UARTs platform data
  */
 
-static struct imxuart_platform_data uart_pdata[] = {
-       {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       },
+static const struct imxuart_platform_data uart0_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
+};
+       
+static const struct imxuart_platform_data uart1_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
 };
 
 /*
@@ -75,8 +75,8 @@ static struct physmap_flash_data mx1ads_flash_data = {
 };
 
 static struct resource flash_resource = {
-       .start  = IMX_CS0_PHYS,
-       .end    = IMX_CS0_PHYS + SZ_32M - 1,
+       .start  = MX1_CS0_PHYS,
+       .end    = MX1_CS0_PHYS + SZ_32M - 1,
        .flags  = IORESOURCE_MEM,
 };
 
@@ -98,7 +98,7 @@ static struct pcf857x_platform_data pcf857x_data[] = {
        }
 };
 
-static struct imxi2c_platform_data mx1ads_i2c_data = {
+static const struct imxi2c_platform_data mx1ads_i2c_data __initconst = {
        .bitrate = 100000,
 };
 
@@ -121,8 +121,8 @@ static void __init mx1ads_init(void)
                ARRAY_SIZE(mx1ads_pins), "mx1ads");
 
        /* UART */
-       mxc_register_device(&imx_uart1_device, &uart_pdata[0]);
-       mxc_register_device(&imx_uart2_device, &uart_pdata[1]);
+       imx1_add_imx_uart0(&uart0_pdata);
+       imx1_add_imx_uart1(&uart1_pdata);
 
        /* Physmap flash */
        mxc_register_device(&flash_device, &mx1ads_flash_data);
@@ -131,7 +131,7 @@ static void __init mx1ads_init(void)
        i2c_register_board_info(0, mx1ads_i2c_devices,
                                ARRAY_SIZE(mx1ads_i2c_devices));
 
-       mxc_register_device(&imx_i2c_device, &mx1ads_i2c_data);
+       imx1_add_i2c_imx(&mx1ads_i2c_data);
 }
 
 static void __init mx1ads_timer_init(void)
@@ -145,8 +145,8 @@ struct sys_timer mx1ads_timer = {
 
 MACHINE_START(MX1ADS, "Freescale MX1ADS")
        /* Maintainer: Sascha Hauer, Pengutronix */
-       .phys_io        = IMX_IO_PHYS,
-       .io_pg_offst    = (IMX_IO_BASE >> 18) & 0xfffc,
+       .phys_io        = MX1_IO_BASE_ADDR,
+       .io_pg_offst    = (MX1_IO_BASE_ADDR_VIRT >> 18) & 0xfffc,
        .boot_params    = MX1_PHYS_OFFSET + 0x100,
        .map_io         = mx1_map_io,
        .init_irq       = mx1_init_irq,
@@ -155,8 +155,8 @@ MACHINE_START(MX1ADS, "Freescale MX1ADS")
 MACHINE_END
 
 MACHINE_START(MXLADS, "Freescale MXLADS")
-       .phys_io        = IMX_IO_PHYS,
-       .io_pg_offst    = (IMX_IO_BASE >> 18) & 0xfffc,
+       .phys_io        = MX1_IO_BASE_ADDR,
+       .io_pg_offst    = (MX1_IO_BASE_ADDR_VIRT >> 18) & 0xfffc,
        .boot_params    = MX1_PHYS_OFFSET + 0x100,
        .map_io         = mx1_map_io,
        .init_irq       = mx1_init_irq,
similarity index 77%
rename from arch/arm/mach-mx2/mach-mx21ads.c
rename to arch/arm/mach-imx/mach-mx21ads.c
index 113e58d7cb4025962f0eebd85ac3fbc5b63dc398..96d7f8189f3253a0feb79d0278c51abbc3e4e5bf 100644 (file)
  * 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
  */
 
 #include <linux/platform_device.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/time.h>
 #include <asm/mach/map.h>
-#include <mach/imx-uart.h>
 #include <mach/imxfb.h>
 #include <mach/iomux-mx21.h>
 #include <mach/mxc_nand.h>
 #include <mach/mmc.h>
-#include <mach/board-mx21ads.h>
 
+#include "devices-imx21.h"
 #include "devices.h"
 
+/*
+ * Memory-mapped I/O on MX21ADS base board
+ */
+#define MX21ADS_MMIO_BASE_ADDR   0xf5000000
+#define MX21ADS_MMIO_SIZE        SZ_16M
+
+#define MX21ADS_REG_ADDR(offset)    (void __force __iomem *) \
+               (MX21ADS_MMIO_BASE_ADDR + (offset))
+
+#define MX21ADS_CS8900A_IRQ         IRQ_GPIOE(11)
+#define MX21ADS_CS8900A_IOBASE_REG  MX21ADS_REG_ADDR(0x000000)
+#define MX21ADS_ST16C255_IOBASE_REG MX21ADS_REG_ADDR(0x200000)
+#define MX21ADS_VERSION_REG         MX21ADS_REG_ADDR(0x400000)
+#define MX21ADS_IO_REG              MX21ADS_REG_ADDR(0x800000)
+
+/* MX21ADS_IO_REG bit definitions */
+#define MX21ADS_IO_SD_WP        0x0001 /* read */
+#define MX21ADS_IO_TP6          0x0001 /* write */
+#define MX21ADS_IO_SW_SEL       0x0002 /* read */
+#define MX21ADS_IO_TP7          0x0002 /* write */
+#define MX21ADS_IO_RESET_E_UART 0x0004
+#define MX21ADS_IO_RESET_BASE   0x0008
+#define MX21ADS_IO_CSI_CTL2     0x0010
+#define MX21ADS_IO_CSI_CTL1     0x0020
+#define MX21ADS_IO_CSI_CTL0     0x0040
+#define MX21ADS_IO_UART1_EN     0x0080
+#define MX21ADS_IO_UART4_EN     0x0100
+#define MX21ADS_IO_LCDON        0x0200
+#define MX21ADS_IO_IRDA_EN      0x0400
+#define MX21ADS_IO_IRDA_FIR_SEL 0x0800
+#define MX21ADS_IO_IRDA_MD0_B   0x1000
+#define MX21ADS_IO_IRDA_MD1     0x2000
+#define MX21ADS_IO_LED4_ON      0x4000
+#define MX21ADS_IO_LED3_ON      0x8000
+
 static unsigned int mx21ads_pins[] = {
 
        /* CS8900A */
@@ -133,14 +163,13 @@ static struct platform_device mx21ads_nor_mtd_device = {
        .resource = &mx21ads_flash_resource,
 };
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata_rts __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
-static struct imxuart_platform_data uart_norts_pdata = {
+static const struct imxuart_platform_data uart_pdata_norts __initconst = {
 };
 
-
 static int mx21ads_fb_init(struct platform_device *pdev)
 {
        u16 tmp;
@@ -227,7 +256,8 @@ static struct imxmmc_platform_data mx21ads_sdhc_pdata = {
        .exit = mx21ads_sdhc_exit,
 };
 
-static struct mxc_nand_platform_data mx21ads_nand_board_info = {
+static const struct mxc_nand_platform_data
+mx21ads_nand_board_info __initconst = {
        .width = 1,
        .hw_ecc = 1,
 };
@@ -263,12 +293,12 @@ static void __init mx21ads_board_init(void)
        mxc_gpio_setup_multiple_pins(mx21ads_pins, ARRAY_SIZE(mx21ads_pins),
                        "mx21ads");
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
-       mxc_register_device(&mxc_uart_device2, &uart_norts_pdata);
-       mxc_register_device(&mxc_uart_device3, &uart_pdata);
+       imx21_add_imx_uart0(&uart_pdata_rts);
+       imx21_add_imx_uart2(&uart_pdata_norts);
+       imx21_add_imx_uart3(&uart_pdata_rts);
        mxc_register_device(&mxc_fb_device, &mx21ads_fb_data);
        mxc_register_device(&mxc_sdhc_device0, &mx21ads_sdhc_pdata);
-       mxc_register_device(&imx21_nand_device, &mx21ads_nand_board_info);
+       imx21_add_mxc_nand(&mx21ads_nand_board_info);
 
        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
 }
similarity index 74%
rename from arch/arm/mach-mx2/mach-mx27_3ds.c
rename to arch/arm/mach-imx/mach-mx27_3ds.c
index b2f4e0db3fb3eeea439f25627bdc043dec6b5c76..e66ffaa1c26c26dbd4ba2b7d7b75c2455b06f5a1 100644 (file)
  * 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
+ */
+
+/*
+ * This machine is known as:
+ *  - i.MX27 3-Stack Development System
+ *  - i.MX27 Platform Development Kit (i.MX27 PDK)
  */
 
 #include <linux/platform_device.h>
 #include <linux/gpio.h>
+#include <linux/input/matrix_keypad.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/time.h>
 #include <mach/hardware.h>
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx27.h>
-#include <mach/board-mx27pdk.h>
 
+#include "devices-imx27.h"
 #include "devices.h"
 
 static unsigned int mx27pdk_pins[] = {
@@ -58,7 +60,7 @@ static unsigned int mx27pdk_pins[] = {
        PF23_AIN_FEC_TX_EN,
 };
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -66,12 +68,34 @@ static struct platform_device *platform_devices[] __initdata = {
        &mxc_fec_device,
 };
 
+/*
+ * Matrix keyboard
+ */
+
+static const uint32_t mx27_3ds_keymap[] = {
+       KEY(0, 0, KEY_UP),
+       KEY(0, 1, KEY_DOWN),
+       KEY(1, 0, KEY_RIGHT),
+       KEY(1, 1, KEY_LEFT),
+       KEY(1, 2, KEY_ENTER),
+       KEY(2, 0, KEY_F6),
+       KEY(2, 1, KEY_F8),
+       KEY(2, 2, KEY_F9),
+       KEY(2, 3, KEY_F10),
+};
+
+static struct matrix_keymap_data mx27_3ds_keymap_data = {
+       .keymap         = mx27_3ds_keymap,
+       .keymap_size    = ARRAY_SIZE(mx27_3ds_keymap),
+};
+
 static void __init mx27pdk_init(void)
 {
        mxc_gpio_setup_multiple_pins(mx27pdk_pins, ARRAY_SIZE(mx27pdk_pins),
                "mx27pdk");
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       imx27_add_imx_uart0(&uart_pdata);
        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
+       mxc_register_device(&imx_kpp_device, &mx27_3ds_keymap_data);
 }
 
 static void __init mx27pdk_timer_init(void)
similarity index 82%
rename from arch/arm/mach-mx2/mach-mx27ads.c
rename to arch/arm/mach-imx/mach-mx27ads.c
index 6ce323669e58f3efea4f10951b7cff0a38355f07..9c77da98a10eec59060e016088a63516a343aff2 100644 (file)
  * 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
  */
 
 #include <linux/platform_device.h>
 #include <asm/mach/time.h>
 #include <asm/mach/map.h>
 #include <mach/gpio.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx27.h>
-#include <mach/board-mx27ads.h>
 #include <mach/mxc_nand.h>
-#include <mach/i2c.h>
 #include <mach/imxfb.h>
 #include <mach/mmc.h>
 
+#include "devices-imx27.h"
 #include "devices.h"
 
+/*
+ * Base address of PBC controller, CS4
+ */
+#define PBC_BASE_ADDRESS        0xf4300000
+#define PBC_REG_ADDR(offset)    (void __force __iomem *) \
+               (PBC_BASE_ADDRESS + (offset))
+
+/* When the PBC address connection is fixed in h/w, defined as 1 */
+#define PBC_ADDR_SH             0
+
+/* Offsets for the PBC Controller register */
+/*
+ * PBC Board version register offset
+ */
+#define PBC_VERSION_REG         PBC_REG_ADDR(0x00000 >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 1 set address.
+ */
+#define PBC_BCTRL1_SET_REG      PBC_REG_ADDR(0x00008 >> PBC_ADDR_SH)
+/*
+ * PBC Board control register 1 clear address.
+ */
+#define PBC_BCTRL1_CLEAR_REG    PBC_REG_ADDR(0x0000C >> PBC_ADDR_SH)
+
+/* PBC Board Control Register 1 bit definitions */
+#define PBC_BCTRL1_LCDON        0x0800 /* Enable the LCD */
+
+/* to determine the correct external crystal reference */
+#define CKIH_27MHZ_BIT_SET      (1 << 3)
+
 static unsigned int mx27ads_pins[] = {
        /* UART0 */
        PE12_PF_UART1_TXD,
@@ -141,7 +165,8 @@ static unsigned int mx27ads_pins[] = {
        PB9_PF_SD2_CLK,
 };
 
-static struct mxc_nand_platform_data mx27ads_nand_board_info = {
+static const struct mxc_nand_platform_data
+mx27ads_nand_board_info __initconst = {
        .width = 1,
        .hw_ecc = 1,
 };
@@ -168,7 +193,7 @@ static struct platform_device mx27ads_nor_mtd_device = {
        .resource = &mx27ads_flash_resource,
 };
 
-static struct imxi2c_platform_data mx27ads_i2c_data = {
+static const struct imxi2c_platform_data mx27ads_i2c1_data __initconst = {
        .bitrate = 100000,
 };
 
@@ -263,20 +288,8 @@ static struct platform_device *platform_devices[] __initdata = {
        &mxc_w1_master_device,
 };
 
-static struct imxuart_platform_data uart_pdata[] = {
-       {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       },
+static const struct imxuart_platform_data uart_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
 };
 
 static void __init mx27ads_board_init(void)
@@ -284,18 +297,18 @@ static void __init mx27ads_board_init(void)
        mxc_gpio_setup_multiple_pins(mx27ads_pins, ARRAY_SIZE(mx27ads_pins),
                        "mx27ads");
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata[0]);
-       mxc_register_device(&mxc_uart_device1, &uart_pdata[1]);
-       mxc_register_device(&mxc_uart_device2, &uart_pdata[2]);
-       mxc_register_device(&mxc_uart_device3, &uart_pdata[3]);
-       mxc_register_device(&mxc_uart_device4, &uart_pdata[4]);
-       mxc_register_device(&mxc_uart_device5, &uart_pdata[5]);
-       mxc_register_device(&imx27_nand_device, &mx27ads_nand_board_info);
+       imx27_add_imx_uart0(&uart_pdata);
+       imx27_add_imx_uart1(&uart_pdata);
+       imx27_add_imx_uart2(&uart_pdata);
+       imx27_add_imx_uart3(&uart_pdata);
+       imx27_add_imx_uart4(&uart_pdata);
+       imx27_add_imx_uart5(&uart_pdata);
+       imx27_add_mxc_nand(&mx27ads_nand_board_info);
 
        /* only the i2c master 1 is used on this CPU card */
        i2c_register_board_info(1, mx27ads_i2c_devices,
                                ARRAY_SIZE(mx27ads_i2c_devices));
-       mxc_register_device(&mxc_i2c_device1, &mx27ads_i2c_data);
+       imx27_add_i2c_imx1(&mx27ads_i2c1_data);
        mxc_register_device(&mxc_fb_device, &mx27ads_fb_data);
        mxc_register_device(&mxc_sdhc_device0, &sdhc1_pdata);
        mxc_register_device(&mxc_sdhc_device1, &sdhc2_pdata);
@@ -342,4 +355,3 @@ MACHINE_START(MX27ADS, "Freescale i.MX27ADS")
        .init_machine   = mx27ads_board_init,
        .timer          = &mx27ads_timer,
 MACHINE_END
-
similarity index 86%
rename from arch/arm/mach-mx2/mach-mxt_td60.c
rename to arch/arm/mach-imx/mach-mxt_td60.c
index bc3855992677d34a4cd6ed9064c089d85e568022..a3a1e452d4c5a15bef12ced37d70d275fabd2fad 100644 (file)
  * 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
  */
 
 #include <linux/platform_device.h>
 #include <asm/mach/time.h>
 #include <asm/mach/map.h>
 #include <linux/gpio.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx27.h>
 #include <mach/mxc_nand.h>
-#include <mach/i2c.h>
 #include <linux/i2c/pca953x.h>
 #include <mach/imxfb.h>
 #include <mach/mmc.h>
 
+#include "devices-imx27.h"
 #include "devices.h"
 
 static unsigned int mxt_td60_pins[] __initdata = {
@@ -128,12 +123,13 @@ static unsigned int mxt_td60_pins[] __initdata = {
        PB9_PF_SD2_CLK,
 };
 
-static struct mxc_nand_platform_data mxt_td60_nand_board_info = {
+static const struct mxc_nand_platform_data
+mxt_td60_nand_board_info __initconst = {
        .width = 1,
        .hw_ecc = 1,
 };
 
-static struct imxi2c_platform_data mxt_td60_i2c_data = {
+static const struct imxi2c_platform_data mxt_td60_i2c0_data __initconst = {
        .bitrate = 100000,
 };
 
@@ -173,7 +169,7 @@ static struct i2c_board_info mxt_td60_i2c_devices[] = {
        },
 };
 
-static struct imxi2c_platform_data mxt_td60_i2c2_data = {
+static const struct imxi2c_platform_data mxt_td60_i2c1_data __initconst = {
        .bitrate = 100000,
 };
 
@@ -239,14 +235,8 @@ static struct platform_device *platform_devices[] __initdata = {
        &mxc_fec_device,
 };
 
-static struct imxuart_platform_data uart_pdata[] = {
-       {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       },
+static const struct imxuart_platform_data uart_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
 };
 
 static void __init mxt_td60_board_init(void)
@@ -254,10 +244,10 @@ static void __init mxt_td60_board_init(void)
        mxc_gpio_setup_multiple_pins(mxt_td60_pins, ARRAY_SIZE(mxt_td60_pins),
                        "MXT_TD60");
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata[0]);
-       mxc_register_device(&mxc_uart_device1, &uart_pdata[1]);
-       mxc_register_device(&mxc_uart_device2, &uart_pdata[2]);
-       mxc_register_device(&imx27_nand_device, &mxt_td60_nand_board_info);
+       imx27_add_imx_uart0(&uart_pdata);
+       imx27_add_imx_uart1(&uart_pdata);
+       imx27_add_imx_uart2(&uart_pdata);
+       imx27_add_mxc_nand(&mxt_td60_nand_board_info);
 
        i2c_register_board_info(0, mxt_td60_i2c_devices,
                                ARRAY_SIZE(mxt_td60_i2c_devices));
@@ -265,8 +255,8 @@ static void __init mxt_td60_board_init(void)
        i2c_register_board_info(1, mxt_td60_i2c2_devices,
                                ARRAY_SIZE(mxt_td60_i2c2_devices));
 
-       mxc_register_device(&mxc_i2c_device0, &mxt_td60_i2c_data);
-       mxc_register_device(&mxc_i2c_device1, &mxt_td60_i2c2_data);
+       imx27_add_i2c_imx0(&mxt_td60_i2c0_data);
+       imx27_add_i2c_imx1(&mxt_td60_i2c1_data);
        mxc_register_device(&mxc_fb_device, &mxt_td60_fb_data);
        mxc_register_device(&mxc_sdhc_device0, &sdhc1_pdata);
 
similarity index 80%
rename from arch/arm/mach-mx2/mach-pca100.c
rename to arch/arm/mach-imx/mach-pca100.c
index a87422ed4ff5a1ea9bd4f07605092bc646842ca9..6c92deaf468f6677559655fe366fba8aad97006c 100644 (file)
 #include <mach/common.h>
 #include <mach/hardware.h>
 #include <mach/iomux-mx27.h>
-#include <mach/i2c.h>
 #include <asm/mach/time.h>
-#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
-#include <mach/spi.h>
-#endif
-#include <mach/imx-uart.h>
 #include <mach/audmux.h>
 #include <mach/ssi.h>
 #include <mach/mxc_nand.h>
 #include <mach/mmc.h>
 #include <mach/mxc_ehci.h>
 #include <mach/ulpi.h>
+#include <mach/imxfb.h>
 
+#include "devices-imx27.h"
 #include "devices.h"
 
 #define OTG_PHY_CS_GPIO (GPIO_PORTB + 23)
 #define USBH2_PHY_CS_GPIO (GPIO_PORTB + 24)
+#define SPI1_SS0 (GPIO_PORTD + 28)
+#define SPI1_SS1 (GPIO_PORTD + 27)
+#define SD2_CD (GPIO_PORTC + 29)
 
 static int pca100_pins[] = {
        /* UART1 */
@@ -68,6 +68,7 @@ static int pca100_pins[] = {
        PB7_PF_SD2_D3,
        PB8_PF_SD2_CMD,
        PB9_PF_SD2_CLK,
+       SD2_CD | GPIO_GPIO | GPIO_IN,
        /* FEC */
        PD0_AIN_FEC_TXD0,
        PD1_AIN_FEC_TXD1,
@@ -131,13 +132,42 @@ static int pca100_pins[] = {
        PD23_AF_USBH2_DATA2,
        PD24_AF_USBH2_DATA1,
        PD26_AF_USBH2_DATA5,
+       /* display */
+       PA5_PF_LSCLK,
+       PA6_PF_LD0,
+       PA7_PF_LD1,
+       PA8_PF_LD2,
+       PA9_PF_LD3,
+       PA10_PF_LD4,
+       PA11_PF_LD5,
+       PA12_PF_LD6,
+       PA13_PF_LD7,
+       PA14_PF_LD8,
+       PA15_PF_LD9,
+       PA16_PF_LD10,
+       PA17_PF_LD11,
+       PA18_PF_LD12,
+       PA19_PF_LD13,
+       PA20_PF_LD14,
+       PA21_PF_LD15,
+       PA22_PF_LD16,
+       PA23_PF_LD17,
+       PA26_PF_PS,
+       PA28_PF_HSYNC,
+       PA29_PF_VSYNC,
+       PA31_PF_OE_ACD,
+       /* free GPIO */
+       GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN, /* GPIO0_IRQ */
+       GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN, /* GPIO1_IRQ */
+       GPIO_PORTE | 5 | GPIO_GPIO | GPIO_IN, /* GPIO2_IRQ */
 };
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
-static struct mxc_nand_platform_data pca100_nand_board_info = {
+static const struct mxc_nand_platform_data
+pca100_nand_board_info __initconst = {
        .width = 1,
        .hw_ecc = 1,
 };
@@ -148,7 +178,7 @@ static struct platform_device *platform_devices[] __initdata = {
        &mxc_wdt,
 };
 
-static struct imxi2c_platform_data pca100_i2c_1_data = {
+static const struct imxi2c_platform_data pca100_i2c1_data __initconst = {
        .bitrate = 100000,
 };
 
@@ -189,9 +219,9 @@ static struct spi_board_info pca100_spi_board_info[] __initdata = {
        },
 };
 
-static int pca100_spi_cs[] = {GPIO_PORTD + 28, GPIO_PORTD + 27};
+static int pca100_spi_cs[] = {SPI1_SS0, SPI1_SS1};
 
-static struct spi_imx_master pca100_spi_0_data = {
+static const struct spi_imx_master pca100_spi0_data __initconst = {
        .chipselect     = pca100_spi_cs,
        .num_chipselect = ARRAY_SIZE(pca100_spi_cs),
 };
@@ -253,6 +283,7 @@ static struct imxmmc_platform_data sdhc_pdata = {
        .exit = pca100_sdhc2_exit,
 };
 
+#if defined(CONFIG_USB_ULPI)
 static int otg_phy_init(struct platform_device *pdev)
 {
        gpio_set_value(OTG_PHY_CS_GPIO, 0);
@@ -276,6 +307,7 @@ static struct mxc_usbh_platform_data usbh2_pdata = {
        .portsc = MXC_EHCI_MODE_ULPI,
        .flags  = MXC_EHCI_INTERFACE_DIFF_UNI,
 };
+#endif
 
 static struct fsl_usb2_platform_data otg_device_pdata = {
        .operating_mode = FSL_USB2_DR_DEVICE,
@@ -297,6 +329,45 @@ static int __init pca100_otg_mode(char *options)
 }
 __setup("otg_mode=", pca100_otg_mode);
 
+/* framebuffer info */
+static struct imx_fb_videomode pca100_fb_modes[] = {
+       {
+               .mode = {
+                       .name           = "EMERGING-ETV570G0DHU",
+                       .refresh        = 60,
+                       .xres           = 640,
+                       .yres           = 480,
+                       .pixclock       = 39722, /* in ps (25.175 MHz) */
+                       .hsync_len      = 30,
+                       .left_margin    = 114,
+                       .right_margin   = 16,
+                       .vsync_len      = 3,
+                       .upper_margin   = 32,
+                       .lower_margin   = 0,
+               },
+               /*
+                * TFT
+                * Pixel pol active high
+                * HSYNC active low
+                * VSYNC active low
+                * use HSYNC for ACD count
+                * line clock disable while idle
+                * always enable line clock even if no data
+                */
+               .pcr = 0xf0c08080,
+               .bpp = 16,
+       },
+};
+
+static struct imx_fb_platform_data pca100_fb_data = {
+       .mode = pca100_fb_modes,
+       .num_modes = ARRAY_SIZE(pca100_fb_modes),
+
+       .pwmr           = 0x00A903FF,
+       .lscr1          = 0x00120300,
+       .dmacr          = 0x00020010,
+};
+
 static void __init pca100_init(void)
 {
        int ret;
@@ -320,33 +391,24 @@ static void __init pca100_init(void)
 
        mxc_register_device(&imx_ssi_device0, &pca100_ssi_pdata);
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       imx27_add_imx_uart0(&uart_pdata);
 
-       mxc_gpio_mode(GPIO_PORTC | 29 | GPIO_GPIO | GPIO_IN);
        mxc_register_device(&mxc_sdhc_device1, &sdhc_pdata);
 
-       mxc_register_device(&imx27_nand_device, &pca100_nand_board_info);
+       imx27_add_mxc_nand(&pca100_nand_board_info);
 
        /* only the i2c master 1 is used on this CPU card */
        i2c_register_board_info(1, pca100_i2c_devices,
                                ARRAY_SIZE(pca100_i2c_devices));
 
-       mxc_register_device(&mxc_i2c_device1, &pca100_i2c_1_data);
-
-       mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_OUT);
-       mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_OUT);
-
-       /* GPIO0_IRQ */
-       mxc_gpio_mode(GPIO_PORTC | 31 | GPIO_GPIO | GPIO_IN);
-       /* GPIO1_IRQ */
-       mxc_gpio_mode(GPIO_PORTC | 25 | GPIO_GPIO | GPIO_IN);
-       /* GPIO2_IRQ */
-       mxc_gpio_mode(GPIO_PORTE | 5 | GPIO_GPIO | GPIO_IN);
+       imx27_add_i2c_imx1(&pca100_i2c1_data);
 
 #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
+       mxc_gpio_mode(GPIO_PORTD | 28 | GPIO_GPIO | GPIO_IN);
+       mxc_gpio_mode(GPIO_PORTD | 27 | GPIO_GPIO | GPIO_IN);
        spi_register_board_info(pca100_spi_board_info,
                                ARRAY_SIZE(pca100_spi_board_info));
-       mxc_register_device(&mxc_spi_device0, &pca100_spi_0_data);
+       imx27_add_spi_imx0(&pca100_spi_0_data);
 #endif
 
        gpio_request(OTG_PHY_CS_GPIO, "usb-otg-cs");
@@ -372,6 +434,8 @@ static void __init pca100_init(void)
                mxc_register_device(&mxc_otg_udc_device, &otg_device_pdata);
        }
 
+       mxc_register_device(&mxc_fb_device, &pca100_fb_data);
+
        platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
 }
 
similarity index 91%
rename from arch/arm/mach-mx2/mach-pcm038.c
rename to arch/arm/mach-imx/mach-pcm038.c
index 36c89431679a93edd5e66118ce9eb9b5838b9045..9212e8f37001d050418b505bdb7c8874b94cd9f0 100644 (file)
 #include <mach/board-pcm038.h>
 #include <mach/common.h>
 #include <mach/hardware.h>
-#include <mach/i2c.h>
 #include <mach/iomux-mx27.h>
-#include <mach/imx-uart.h>
 #include <mach/mxc_nand.h>
-#include <mach/spi.h>
 #include <mach/mxc_ehci.h>
 #include <mach/ulpi.h>
 
+#include "devices-imx27.h"
 #include "devices.h"
 
 static int pcm038_pins[] = {
@@ -162,17 +160,12 @@ static struct platform_device pcm038_nor_mtd_device = {
        .resource = &pcm038_flash_resource,
 };
 
-static struct imxuart_platform_data uart_pdata[] = {
-       {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       }, {
-               .flags = IMXUART_HAVE_RTSCTS,
-       },
+static const struct imxuart_platform_data uart_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
 };
 
-static struct mxc_nand_platform_data pcm038_nand_board_info = {
+static const struct mxc_nand_platform_data
+pcm038_nand_board_info __initconst = {
        .width = 1,
        .hw_ecc = 1,
 };
@@ -192,7 +185,7 @@ static void __init pcm038_init_sram(void)
        mx27_setup_weimcs(1, 0x0000d843, 0x22252521, 0x22220a00);
 }
 
-static struct imxi2c_platform_data pcm038_i2c_1_data = {
+static const struct imxi2c_platform_data pcm038_i2c1_data __initconst = {
        .bitrate = 100000,
 };
 
@@ -215,7 +208,7 @@ static struct i2c_board_info pcm038_i2c_devices[] = {
 
 static int pcm038_spi_cs[] = {GPIO_PORTD + 28};
 
-static struct spi_imx_master pcm038_spi_0_data = {
+static const struct spi_imx_master pcm038_spi0_data __initconst = {
        .chipselect = pcm038_spi_cs,
        .num_chipselect = ARRAY_SIZE(pcm038_spi_cs),
 };
@@ -305,18 +298,18 @@ static void __init pcm038_init(void)
 
        pcm038_init_sram();
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata[0]);
-       mxc_register_device(&mxc_uart_device1, &uart_pdata[1]);
-       mxc_register_device(&mxc_uart_device2, &uart_pdata[2]);
+       imx27_add_imx_uart0(&uart_pdata);
+       imx27_add_imx_uart1(&uart_pdata);
+       imx27_add_imx_uart2(&uart_pdata);
 
        mxc_gpio_mode(PE16_AF_OWIRE);
-       mxc_register_device(&imx27_nand_device, &pcm038_nand_board_info);
+       imx27_add_mxc_nand(&pcm038_nand_board_info);
 
        /* only the i2c master 1 is used on this CPU card */
        i2c_register_board_info(1, pcm038_i2c_devices,
                                ARRAY_SIZE(pcm038_i2c_devices));
 
-       mxc_register_device(&mxc_i2c_device1, &pcm038_i2c_1_data);
+       imx27_add_i2c_imx1(&pcm038_i2c1_data);
 
        /* PE18 for user-LED D40 */
        mxc_gpio_mode(GPIO_PORTE | 18 | GPIO_GPIO | GPIO_OUT);
@@ -326,7 +319,7 @@ static void __init pcm038_init(void)
        /* MC13783 IRQ */
        mxc_gpio_mode(GPIO_PORTB | 23 | GPIO_GPIO | GPIO_IN);
 
-       mxc_register_device(&mxc_spi_device0, &pcm038_spi_0_data);
+       imx27_add_spi_imx0(&pcm038_spi0_data);
        spi_register_board_info(pcm038_spi_board_info,
                                ARRAY_SIZE(pcm038_spi_board_info));
 
similarity index 89%
rename from arch/arm/mach-mx1/mach-scb9328.c
rename to arch/arm/mach-imx/mach-scb9328.c
index 7587a7a12460242d9f4b25b2233efef6dc5bab65..88bf0d1e26e6ebb3400e07db4f545e3f86c97b9b 100644 (file)
 #include <mach/common.h>
 #include <mach/hardware.h>
 #include <mach/irqs.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx1.h>
 
+#include "devices-imx1.h"
 #include "devices.h"
 
 /*
  * This scb9328 has a 32MiB flash
  */
 static struct resource flash_resource = {
-       .start  = IMX_CS0_PHYS,
-       .end    = IMX_CS0_PHYS + (32 * 1024 * 1024) - 1,
+       .start  = MX1_CS0_PHYS,
+       .end    = MX1_CS0_PHYS + (32 * 1024 * 1024) - 1,
        .flags  = IORESOURCE_MEM,
 };
 
@@ -70,13 +70,13 @@ static struct dm9000_plat_data dm9000_platdata = {
 static struct resource dm9000x_resources[] = {
        {
                .name   = "address area",
-               .start  = IMX_CS5_PHYS,
-               .end    = IMX_CS5_PHYS + 1,
+               .start  = MX1_CS5_PHYS,
+               .end    = MX1_CS5_PHYS + 1,
                .flags  = IORESOURCE_MEM,       /* address access */
        }, {
                .name   = "data area",
-               .start  = IMX_CS5_PHYS + 4,
-               .end    = IMX_CS5_PHYS + 5,
+               .start  = MX1_CS5_PHYS + 4,
+               .end    = MX1_CS5_PHYS + 5,
                .flags  = IORESOURCE_MEM,       /* data access */
        }, {
                .start  = IRQ_GPIOC(3),
@@ -108,14 +108,13 @@ static int uart1_mxc_init(struct platform_device *pdev)
                        ARRAY_SIZE(mxc_uart1_pins), "UART1");
 }
 
-static int uart1_mxc_exit(struct platform_device *pdev)
+static void uart1_mxc_exit(struct platform_device *pdev)
 {
        mxc_gpio_release_multiple_pins(mxc_uart1_pins,
                        ARRAY_SIZE(mxc_uart1_pins));
-       return 0;
 }
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .init = uart1_mxc_init,
        .exit = uart1_mxc_exit,
        .flags = IMXUART_HAVE_RTSCTS,
@@ -131,7 +130,7 @@ static struct platform_device *devices[] __initdata = {
  */
 static void __init scb9328_init(void)
 {
-       mxc_register_device(&imx_uart1_device, &uart_pdata);
+       imx1_add_imx_uart0(&uart_pdata);
 
        printk(KERN_INFO"Scb9328: Adding devices\n");
        platform_add_devices(devices, ARRAY_SIZE(devices));
similarity index 68%
rename from arch/arm/mach-mx1/generic.c
rename to arch/arm/mach-imx/mm-imx1.c
index 7f9fc1034c0884b186e2ccb7ec6bc5348598d50a..9be92b96dc8961d02efe8a019ac95a46d1647295 100644 (file)
@@ -3,7 +3,7 @@
  *  Created: april 20th, 2004
  *  Copyright: Synertronixx GmbH
  *
- *  Common code for i.MX machines
+ *  Common code for i.MX1 machines
  *
  * 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
  * 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
- *
  */
 #include <linux/kernel.h>
 #include <linux/init.h>
 
 static struct map_desc imx_io_desc[] __initdata = {
        {
-               .virtual        = IMX_IO_BASE,
-               .pfn            = __phys_to_pfn(IMX_IO_PHYS),
-               .length         = IMX_IO_SIZE,
-               .type           = MT_DEVICE
+               .virtual = MX1_IO_BASE_ADDR_VIRT,
+               .pfn = __phys_to_pfn(MX1_IO_BASE_ADDR),
+               .length = MX1_IO_SIZE,
+               .type = MT_DEVICE
        }
 };
 
 void __init mx1_map_io(void)
 {
        mxc_set_cpu_type(MXC_CPU_MX1);
-       mxc_arch_reset_init(IO_ADDRESS(WDT_BASE_ADDR));
+       mxc_arch_reset_init(MX1_IO_ADDRESS(MX1_WDT_BASE_ADDR));
 
        iotable_init(imx_io_desc, ARRAY_SIZE(imx_io_desc));
 }
 
+int imx1_register_gpios(void);
+
 void __init mx1_init_irq(void)
 {
-       mxc_init_irq(IO_ADDRESS(AVIC_BASE_ADDR));
+       mxc_init_irq(MX1_IO_ADDRESS(MX1_AVIC_BASE_ADDR));
+       imx1_register_gpios();
 }
-
similarity index 95%
rename from arch/arm/mach-mx2/mm-imx21.c
rename to arch/arm/mach-imx/mm-imx21.c
index 64134314d012a43b43f80d2690abaad92f5cee0b..12faeeaa0a9706ce4ea2eb0c774abff437dc9901 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * arch/arm/mach-mx2/mm-imx21.c
+ * arch/arm/mach-imx/mm-imx21.c
  *
  * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
  *
@@ -77,7 +77,10 @@ void __init mx21_map_io(void)
        iotable_init(imx21_io_desc, ARRAY_SIZE(imx21_io_desc));
 }
 
+int imx21_register_gpios(void);
+
 void __init mx21_init_irq(void)
 {
        mxc_init_irq(MX21_IO_ADDRESS(MX21_AVIC_BASE_ADDR));
+       imx21_register_gpios();
 }
similarity index 95%
rename from arch/arm/mach-mx2/mm-imx27.c
rename to arch/arm/mach-imx/mm-imx27.c
index 3366ed44cfd5a60b283d2266bd083ffe664047e0..a24622957ff2dc3eeed0f1e949d4a12fc35a9e30 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * arch/arm/mach-mx2/mm-imx27.c
+ * arch/arm/mach-imx/mm-imx27.c
  *
  * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
  *
@@ -77,7 +77,10 @@ void __init mx27_map_io(void)
        iotable_init(imx27_io_desc, ARRAY_SIZE(imx27_io_desc));
 }
 
+int imx27_register_gpios(void);
+
 void __init mx27_init_irq(void)
 {
        mxc_init_irq(MX27_IO_ADDRESS(MX27_AVIC_BASE_ADDR));
+       imx27_register_gpios();
 }
diff --git a/arch/arm/mach-imx/pm-imx27.c b/arch/arm/mach-imx/pm-imx27.c
new file mode 100644 (file)
index 0000000..afc17ce
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * i.MX27 Power Management Routines
+ *
+ * Based on Freescale's BSP
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License.
+ */
+
+#include <linux/kernel.h>
+#include <linux/suspend.h>
+#include <linux/io.h>
+#include <mach/system.h>
+#include <mach/mx27.h>
+
+static int mx27_suspend_enter(suspend_state_t state)
+{
+       u32 cscr;
+       switch (state) {
+       case PM_SUSPEND_MEM:
+               /* Clear MPEN and SPEN to disable MPLL/SPLL */
+               cscr = __raw_readl(MX27_IO_ADDRESS(MX27_CCM_BASE_ADDR));
+               cscr &= 0xFFFFFFFC;
+               __raw_writel(cscr, MX27_IO_ADDRESS(MX27_CCM_BASE_ADDR));
+               /* Executes WFI */
+               arch_idle();
+               break;
+
+       default:
+               return -EINVAL;
+       }
+       return 0;
+}
+
+static struct platform_suspend_ops mx27_suspend_ops = {
+       .enter = mx27_suspend_enter,
+       .valid = suspend_valid_only_mem,
+};
+
+static int __init mx27_pm_init(void)
+{
+       suspend_set_ops(&mx27_suspend_ops);
+       return 0;
+}
+
+device_initcall(mx27_pm_init);
diff --git a/arch/arm/mach-integrator/common.h b/arch/arm/mach-integrator/common.h
new file mode 100644 (file)
index 0000000..5f96e15
--- /dev/null
@@ -0,0 +1 @@
+void integrator_reserve(void);
index b02cfc06e0aeeff452a2c3813523fccd53f1edf2..8f4fb6d638f7ea66717a5afb5d962ef0d88723a3 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/spinlock.h>
 #include <linux/interrupt.h>
 #include <linux/irq.h>
+#include <linux/memblock.h>
 #include <linux/sched.h>
 #include <linux/smp.h>
 #include <linux/termios.h>
@@ -30,6 +31,7 @@
 #include <asm/system.h>
 #include <asm/leds.h>
 #include <asm/mach/time.h>
+#include <asm/pgtable.h>
 
 static struct amba_pl010_data integrator_uart_data;
 
@@ -119,8 +121,13 @@ static struct clk uartclk = {
        .rate   = 14745600,
 };
 
+static struct clk dummy_apb_pclk;
+
 static struct clk_lookup lookups[] = {
-       {       /* UART0 */
+       {       /* Bus clock */
+               .con_id         = "apb_pclk",
+               .clk            = &dummy_apb_pclk,
+       }, {    /* UART0 */
                .dev_id         = "mb:16",
                .clk            = &uartclk,
        }, {    /* UART1 */
@@ -215,3 +222,13 @@ void cm_control(u32 mask, u32 set)
 }
 
 EXPORT_SYMBOL(cm_control);
+
+/*
+ * We need to stop things allocating the low memory; ideally we need a
+ * better implementation of GFP_DMA which does not assume that DMA-able
+ * memory starts at zero.
+ */
+void __init integrator_reserve(void)
+{
+       memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
+}
index 227cf4d05088ec85bf870e1423b7044d0758d133..6ab5a03ab9d8b0a7f45311595b0ee1fa16474ef3 100644 (file)
@@ -48,6 +48,8 @@
 #include <asm/mach/map.h>
 #include <asm/mach/time.h>
 
+#include "common.h"
+
 /* 
  * All IO addresses are mapped onto VA 0xFFFx.xxxx, where x.xxxx
  * is the (PA >> 12).
@@ -502,6 +504,7 @@ MACHINE_START(INTEGRATOR, "ARM-Integrator")
        .io_pg_offst    = ((0xf1600000) >> 18) & 0xfffc,
        .boot_params    = 0x00000100,
        .map_io         = ap_map_io,
+       .reserve        = integrator_reserve,
        .init_irq       = ap_init_irq,
        .timer          = &ap_timer,
        .init_machine   = ap_init,
index cde57b2b83b57a36288382ef5b57a39ae895d802..05db40e3c4f75a7fcf661718269cdcf330d7f9cc 100644 (file)
@@ -43,6 +43,8 @@
 
 #include <plat/timer-sp.h>
 
+#include "common.h"
+
 #define INTCP_PA_FLASH_BASE            0x24000000
 #define INTCP_FLASH_SIZE               SZ_32M
 
@@ -601,6 +603,7 @@ MACHINE_START(CINTEGRATOR, "ARM-IntegratorCP")
        .io_pg_offst    = ((0xf1600000) >> 18) & 0xfffc,
        .boot_params    = 0x00000100,
        .map_io         = intcp_map_io,
+       .reserve        = integrator_reserve,
        .init_irq       = intcp_init_irq,
        .timer          = &cp_timer,
        .init_machine   = intcp_init,
index 9cef0590d5aa3d4af92e62d41601b7057f94e0b3..6467d99fa2ee4a0c674d9071dad669cb5caa7b32 100644 (file)
@@ -505,10 +505,10 @@ void __init pci_v3_preinit(void)
        /*
         * Hook in our fault handler for PCI errors
         */
-       hook_fault_code(4, v3_pci_fault, SIGBUS, "external abort on linefetch");
-       hook_fault_code(6, v3_pci_fault, SIGBUS, "external abort on linefetch");
-       hook_fault_code(8, v3_pci_fault, SIGBUS, "external abort on non-linefetch");
-       hook_fault_code(10, v3_pci_fault, SIGBUS, "external abort on non-linefetch");
+       hook_fault_code(4, v3_pci_fault, SIGBUS, 0, "external abort on linefetch");
+       hook_fault_code(6, v3_pci_fault, SIGBUS, 0, "external abort on linefetch");
+       hook_fault_code(8, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
+       hook_fault_code(10, v3_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
 
        spin_lock_irqsave(&v3_lock, flags);
 
index 25b1da9a5035469fcf4355e80082f3dd7af586c8..7415e4338651e7c84e2e3a587092a1c1859cda1d 100644 (file)
@@ -69,6 +69,4 @@ static inline unsigned long __lbus_to_virt(dma_addr_t x)
 #endif /* CONFIG_ARCH_IOP13XX */
 #endif /* !ASSEMBLY */
 
-#define PFN_TO_NID(addr)       (0)
-
 #endif
index 6d5a90813d31b6b96532b3b1a5cdb555e972ec41..773ea0c95b9f6fc91d8c9c57f3a3bd0f714b306d 100644 (file)
@@ -987,7 +987,7 @@ void __init iop13xx_pci_init(void)
                iop13xx_atux_setup();
        }
 
-       hook_fault_code(16+6, iop13xx_pci_abort, SIGBUS,
+       hook_fault_code(16+6, iop13xx_pci_abort, SIGBUS, 0,
                        "imprecise external abort");
 }
 
index 90771cad06f86f7fe3238021ce8ae39ce90cadc2..f797c5f538b094e2d600c78b85d70d70ff25d295 100644 (file)
@@ -209,7 +209,7 @@ ixp2000_pci_preinit(void)
                        "the needed workaround has not been configured in");
 #endif
 
-       hook_fault_code(16+6, ixp2000_pci_abort_handler, SIGBUS,
+       hook_fault_code(16+6, ixp2000_pci_abort_handler, SIGBUS, 0,
                                "PCI config cycle to non-existent device");
 }
 
index 4b0e598a91c91f4573d927a8016d91aab0154f7d..563819a83292db81f72b147986b98b573868149f 100644 (file)
@@ -229,7 +229,7 @@ void __init ixp23xx_pci_preinit(void)
 {
        ixp23xx_pci_common_init();
 
-       hook_fault_code(16+6, ixp23xx_pci_abort_handler, SIGBUS,
+       hook_fault_code(16+6, ixp23xx_pci_abort_handler, SIGBUS, 0,
                        "PCI config cycle to non-existent device");
 
        *IXP23XX_PCI_ADDR_EXT = 0x0000e000;
index e3181534c7f9dba7fe1cc8f6e4185aae21c8c87b..61cd4d64b98596c7507dcaf67d069dbe22508e50 100644 (file)
@@ -348,7 +348,7 @@ int dma_needs_bounce(struct device *dev, dma_addr_t dma_addr, size_t size)
  * This is really ugly and we need a better way of specifying
  * DMA-capable regions of memory.
  */
-void __init ixp4xx_adjust_zones(int node, unsigned long *zone_size,
+void __init ixp4xx_adjust_zones(unsigned long *zone_size,
        unsigned long *zhole_size)
 {
        unsigned int sz = SZ_64M >> PAGE_SHIFT;
@@ -356,7 +356,7 @@ void __init ixp4xx_adjust_zones(int node, unsigned long *zone_size,
        /*
         * Only adjust if > 64M on current system
         */
-       if (node || (zone_size[0] <= sz))
+       if (zone_size[0] <= sz)
                return;
 
        zone_size[1] = zone_size[0] - sz;
@@ -382,7 +382,8 @@ void __init ixp4xx_pci_preinit(void)
 
 
        /* hook in our fault handler for PCI errors */
-       hook_fault_code(16+6, abort_handler, SIGBUS, "imprecise external abort");
+       hook_fault_code(16+6, abort_handler, SIGBUS, 0,
+                       "imprecise external abort");
 
        pr_debug("setup PCI-AHB(inbound) and AHB-PCI(outbound) address mappings\n");
 
index 98f5e5e2098001398d45930d2fb5d33b3452f0ea..0136eaa29224a538cfdd65179dd59432fa7b1488 100644 (file)
 
 #if !defined(__ASSEMBLY__) && defined(CONFIG_PCI)
 
-void ixp4xx_adjust_zones(int node, unsigned long *size, unsigned long *holes);
+void ixp4xx_adjust_zones(unsigned long *size, unsigned long *holes);
 
-#define arch_adjust_zones(node, size, holes) \
-       ixp4xx_adjust_zones(node, size, holes)
+#define arch_adjust_zones(size, holes) \
+       ixp4xx_adjust_zones(size, holes)
 
 #define ISA_DMA_THRESHOLD (SZ_64M - 1)
 #define MAX_DMA_ADDRESS                (PAGE_OFFSET + SZ_64M)
index 29b2163b1fe3b3cff4ce40e9c23b112c360e1a56..cc25501b57fa8edf270752e0a719f2564965f44a 100644 (file)
@@ -75,6 +75,13 @@ config MACH_OPENRD_CLIENT
          Say 'Y' here if you want your kernel to support the
          Marvell OpenRD Client Board.
 
+config MACH_OPENRD_ULTIMATE
+       bool "Marvell OpenRD Ultimate Board"
+       select MACH_OPENRD
+       help
+         Say 'Y' here if you want your kernel to support the
+         Marvell OpenRD Ultimate Board.
+
 config MACH_NETSPACE_V2
        bool "LaCie Network Space v2 NAS Board"
        help
@@ -87,6 +94,12 @@ config MACH_INETSPACE_V2
          Say 'Y' here if you want your kernel to support the
          LaCie Internet Space v2 NAS.
 
+config MACH_NETSPACE_MAX_V2
+       bool "LaCie Network Space Max v2 NAS Board"
+       help
+         Say 'Y' here if you want your kernel to support the
+         LaCie Network Space Max v2 NAS.
+
 config MACH_NET2BIG_V2
        bool "LaCie 2Big Network v2 NAS Board"
        help
@@ -99,6 +112,12 @@ config MACH_NET5BIG_V2
          Say 'Y' here if you want your kernel to support the
          LaCie 5Big Network v2 NAS.
 
+config MACH_T5325
+       bool "HP t5325 Thin Client"
+       help
+         Say 'Y' here if you want your kernel to support the
+         HP t5325 Thin Client.
+
 endmenu
 
 endif
index c0cd5d362002c325cee09cc8a8c8a59cfaaebf26..295d7baa6ae11150956e004330259859ef3c4ec6 100644 (file)
@@ -12,7 +12,9 @@ obj-$(CONFIG_MACH_TS41X)              += ts41x-setup.o tsx1x-common.o
 obj-$(CONFIG_MACH_OPENRD)              += openrd-setup.o
 obj-$(CONFIG_MACH_NETSPACE_V2)         += netspace_v2-setup.o
 obj-$(CONFIG_MACH_INETSPACE_V2)                += netspace_v2-setup.o
+obj-$(CONFIG_MACH_NETSPACE_MAX_V2)     += netspace_v2-setup.o
 obj-$(CONFIG_MACH_NET2BIG_V2)          += netxbig_v2-setup.o
 obj-$(CONFIG_MACH_NET5BIG_V2)          += netxbig_v2-setup.o
+obj-$(CONFIG_MACH_T5325)               += t5325-setup.o
 
 obj-$(CONFIG_CPU_IDLE)                 += cpuidle.o
index 2e69168fc699881d9928964c266eb7c866c00ee2..8d03bcef5182c8a9696159c8c220da833ee2cbd6 100644 (file)
@@ -31,6 +31,8 @@
 #define ATTR_DEV_CS0           0x3e
 #define ATTR_PCIE_IO           0xe0
 #define ATTR_PCIE_MEM          0xe8
+#define ATTR_PCIE1_IO          0xd0
+#define ATTR_PCIE1_MEM         0xd8
 #define ATTR_SRAM              0x01
 
 /*
@@ -106,17 +108,21 @@ void __init kirkwood_setup_cpu_mbus(void)
                      TARGET_PCIE, ATTR_PCIE_IO, KIRKWOOD_PCIE_IO_BUS_BASE);
        setup_cpu_win(1, KIRKWOOD_PCIE_MEM_PHYS_BASE, KIRKWOOD_PCIE_MEM_SIZE,
                      TARGET_PCIE, ATTR_PCIE_MEM, KIRKWOOD_PCIE_MEM_BUS_BASE);
+       setup_cpu_win(2, KIRKWOOD_PCIE1_IO_PHYS_BASE, KIRKWOOD_PCIE1_IO_SIZE,
+                     TARGET_PCIE, ATTR_PCIE1_IO, KIRKWOOD_PCIE1_IO_BUS_BASE);
+       setup_cpu_win(3, KIRKWOOD_PCIE1_MEM_PHYS_BASE, KIRKWOOD_PCIE1_MEM_SIZE,
+                     TARGET_PCIE, ATTR_PCIE1_MEM, KIRKWOOD_PCIE1_MEM_BUS_BASE);
 
        /*
         * Setup window for NAND controller.
         */
-       setup_cpu_win(2, KIRKWOOD_NAND_MEM_PHYS_BASE, KIRKWOOD_NAND_MEM_SIZE,
+       setup_cpu_win(4, KIRKWOOD_NAND_MEM_PHYS_BASE, KIRKWOOD_NAND_MEM_SIZE,
                      TARGET_DEV_BUS, ATTR_DEV_NAND, -1);
 
        /*
         * Setup window for SRAM.
         */
-       setup_cpu_win(3, KIRKWOOD_SRAM_PHYS_BASE, KIRKWOOD_SRAM_SIZE,
+       setup_cpu_win(5, KIRKWOOD_SRAM_PHYS_BASE, KIRKWOOD_SRAM_SIZE,
                      TARGET_SRAM, ATTR_SRAM, -1);
 
        /*
index 6072eaa5e66acf81f080d72374fbfd1dfbe7382c..9dd67c7b44590dafa63dcb11204998fe8c3d3ad3 100644 (file)
@@ -43,6 +43,11 @@ static struct map_desc kirkwood_io_desc[] __initdata = {
                .pfn            = __phys_to_pfn(KIRKWOOD_PCIE_IO_PHYS_BASE),
                .length         = KIRKWOOD_PCIE_IO_SIZE,
                .type           = MT_DEVICE,
+       }, {
+               .virtual        = KIRKWOOD_PCIE1_IO_VIRT_BASE,
+               .pfn            = __phys_to_pfn(KIRKWOOD_PCIE1_IO_PHYS_BASE),
+               .length         = KIRKWOOD_PCIE1_IO_SIZE,
+               .type           = MT_DEVICE,
        }, {
                .virtual        = KIRKWOOD_REGS_VIRT_BASE,
                .pfn            = __phys_to_pfn(KIRKWOOD_REGS_PHYS_BASE),
@@ -402,7 +407,7 @@ void __init kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data)
        u32 dev, rev;
 
        kirkwood_pcie_id(&dev, &rev);
-       if (rev == 0 /* catch all Kirkwood Z0's */
+       if (rev == 0 && dev != MV88F6282_DEV_ID) /* catch all Kirkwood Z0's */
                mvsdio_data->clock = 100000000;
        else
                mvsdio_data->clock = 200000000;
@@ -847,8 +852,10 @@ int __init kirkwood_find_tclk(void)
        u32 dev, rev;
 
        kirkwood_pcie_id(&dev, &rev);
-       if (dev == MV88F6281_DEV_ID && (rev == MV88F6281_REV_A0 ||
-                                       rev == MV88F6281_REV_A1))
+
+       if ((dev == MV88F6281_DEV_ID && (rev == MV88F6281_REV_A0 ||
+                                       rev == MV88F6281_REV_A1)) ||
+           (dev == MV88F6282_DEV_ID))
                return 200000000;
 
        return 166666667;
@@ -891,13 +898,22 @@ static char * __init kirkwood_id(void)
                        return "MV88F6192-Z0";
                else if (rev == MV88F6192_REV_A0)
                        return "MV88F6192-A0";
+               else if (rev == MV88F6192_REV_A1)
+                       return "MV88F6192-A1";
                else
                        return "MV88F6192-Rev-Unsupported";
        } else if (dev == MV88F6180_DEV_ID) {
                if (rev == MV88F6180_REV_A0)
                        return "MV88F6180-Rev-A0";
+               else if (rev == MV88F6180_REV_A1)
+                       return "MV88F6180-Rev-A1";
                else
                        return "MV88F6180-Rev-Unsupported";
+       } else if (dev == MV88F6282_DEV_ID) {
+               if (rev == MV88F6282_REV_A0)
+                       return "MV88F6282-Rev-A0";
+               else
+                       return "MV88F6282-Rev-Unsupported";
        } else {
                return "Device-Unknown";
        }
@@ -949,12 +965,14 @@ void __init kirkwood_init(void)
 static int __init kirkwood_clock_gate(void)
 {
        unsigned int curr = readl(CLOCK_GATING_CTRL);
+       u32 dev, rev;
 
+       kirkwood_pcie_id(&dev, &rev);
        printk(KERN_DEBUG "Gating clock of unused units\n");
        printk(KERN_DEBUG "before: 0x%08x\n", curr);
 
        /* Make sure those units are accessible */
-       writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0, CLOCK_GATING_CTRL);
+       writel(curr | CGC_SATA0 | CGC_SATA1 | CGC_PEX0 | CGC_PEX1, CLOCK_GATING_CTRL);
 
        /* For SATA: first shutdown the phy */
        if (!(kirkwood_clk_ctrl & CGC_SATA0)) {
@@ -979,6 +997,18 @@ static int __init kirkwood_clock_gate(void)
                writel(readl(PCIE_LINK_CTRL) & ~0x10, PCIE_LINK_CTRL);
        }
 
+       /* For PCIe 1: first shutdown the phy */
+       if (dev == MV88F6282_DEV_ID) {
+               if (!(kirkwood_clk_ctrl & CGC_PEX1)) {
+                       writel(readl(PCIE1_LINK_CTRL) | 0x10, PCIE1_LINK_CTRL);
+                       while (1)
+                               if (readl(PCIE1_STATUS) & 0x1)
+                                       break;
+                       writel(readl(PCIE1_LINK_CTRL) & ~0x10, PCIE1_LINK_CTRL);
+               }
+       } else  /* keep this bit set for devices that don't have PCIe1 */
+               kirkwood_clk_ctrl |= CGC_PEX1;
+
        /* Now gate clock the required units */
        writel(kirkwood_clk_ctrl, CLOCK_GATING_CTRL);
        printk(KERN_DEBUG " after: 0x%08x\n", readl(CLOCK_GATING_CTRL));
index 05e8a8a5692e8150535973105b1f50bed60bcfea..5b2c1c18d641670eed6600753cc1691cb18d7efd 100644 (file)
@@ -18,6 +18,9 @@ struct mvsdio_platform_data;
 struct mtd_partition;
 struct mtd_info;
 
+#define KW_PCIE0       (1 << 0)
+#define KW_PCIE1       (1 << 1)
+
 /*
  * Basic Kirkwood init functions used early by machine-setup.
  */
@@ -34,7 +37,7 @@ void kirkwood_ehci_init(void);
 void kirkwood_ge00_init(struct mv643xx_eth_platform_data *eth_data);
 void kirkwood_ge01_init(struct mv643xx_eth_platform_data *eth_data);
 void kirkwood_ge00_switch_init(struct dsa_platform_data *d, int irq);
-void kirkwood_pcie_init(void);
+void kirkwood_pcie_init(unsigned int portmask);
 void kirkwood_sata_init(struct mv_sata_platform_data *sata_data);
 void kirkwood_sdio_init(struct mvsdio_platform_data *mvsdio_data);
 void kirkwood_spi_init(void);
index 39bdf4bcace959322cc966d613cc976007dbe020..16f6691e7c685cc6af9266b56bcd0af1265a60ef 100644 (file)
@@ -51,6 +51,14 @@ static struct mvsdio_platform_data db88f6281_mvsdio_data = {
 };
 
 static unsigned int db88f6281_mpp_config[] __initdata = {
+       MPP0_NF_IO2,
+       MPP1_NF_IO3,
+       MPP2_NF_IO4,
+       MPP3_NF_IO5,
+       MPP4_NF_IO6,
+       MPP5_NF_IO7,
+       MPP18_NF_IO0,
+       MPP19_NF_IO1,
        MPP37_GPIO,
        MPP38_GPIO,
        0
@@ -74,9 +82,15 @@ static void __init db88f6281_init(void)
 
 static int __init db88f6281_pci_init(void)
 {
-       if (machine_is_db88f6281_bp())
-               kirkwood_pcie_init();
+       if (machine_is_db88f6281_bp()) {
+               u32 dev, rev;
 
+               kirkwood_pcie_id(&dev, &rev);
+               if (dev == MV88F6282_DEV_ID)
+                       kirkwood_pcie_init(KW_PCIE1 | KW_PCIE0);
+               else
+                       kirkwood_pcie_init(KW_PCIE0);
+       }
        return 0;
 }
 subsys_initcall(db88f6281_pci_init);
index 418f5017c50e1d916468ebc99e5b958a706d98f6..aff0e1327e38f8f360fa25dc5291722a2c7df9fe 100644 (file)
@@ -59,8 +59,9 @@
 #define CGC_SATA1              (1 << 15)
 #define CGC_XOR1               (1 << 16)
 #define CGC_CRYPTO             (1 << 17)
+#define CGC_PEX1               (1 << 18)
 #define CGC_GE1                        (1 << 19)
 #define CGC_TDM                        (1 << 20)
-#define CGC_RESERVED           ((1 << 18) | (0x6 << 21))
+#define CGC_RESERVED           (0x6 << 21)
 
 #endif
index f00a0a45a67e5356bf08d722a4c5bda29b4a57ce..9da2eb59180b2128af2d14bed71091d2bd574b1d 100644 (file)
@@ -23,6 +23,7 @@
 #define IRQ_KIRKWOOD_XOR_10    7
 #define IRQ_KIRKWOOD_XOR_11    8
 #define IRQ_KIRKWOOD_PCIE      9
+#define IRQ_KIRKWOOD_PCIE1     10
 #define IRQ_KIRKWOOD_GE00_SUM  11
 #define IRQ_KIRKWOOD_GE01_SUM  15
 #define IRQ_KIRKWOOD_USB       19
index a15cf0ee22bd802c7aaefb4a04b067540eabcd1b..d141af4c274422a542634b33581f9488385def59 100644 (file)
  * Marvell Kirkwood address maps.
  *
  * phys
- * e0000000    PCIe Memory space
+ * e0000000    PCIe #0 Memory space
+ * e8000000    PCIe #1 Memory space
  * f1000000    on-chip peripheral registers
- * f2000000    PCIe I/O space
- * f3000000    NAND controller address window
- * f4000000    Security Accelerator SRAM
+ * f2000000    PCIe #0 I/O space
+ * f3000000    PCIe #1 I/O space
+ * f4000000    NAND controller address window
+ * f5000000    Security Accelerator SRAM
  *
  * virt                phys            size
- * fee00000    f1000000        1M      on-chip peripheral registers
- * fef00000    f2000000        1M      PCIe I/O space
+ * fed00000    f1000000        1M      on-chip peripheral registers
+ * fee00000    f2000000        1M      PCIe #0 I/O space
+ * fef00000    f3000000        1M      PCIe #1 I/O space
  */
 
-#define KIRKWOOD_SRAM_PHYS_BASE                0xf4000000
+#define KIRKWOOD_SRAM_PHYS_BASE                0xf5000000
 #define KIRKWOOD_SRAM_SIZE             SZ_2K
 
-#define KIRKWOOD_NAND_MEM_PHYS_BASE    0xf3000000
+#define KIRKWOOD_NAND_MEM_PHYS_BASE    0xf4000000
 #define KIRKWOOD_NAND_MEM_SIZE         SZ_1K
 
+#define KIRKWOOD_PCIE1_IO_PHYS_BASE    0xf3000000
+#define KIRKWOOD_PCIE1_IO_VIRT_BASE    0xfef00000
+#define KIRKWOOD_PCIE1_IO_BUS_BASE     0x00000000
+#define KIRKWOOD_PCIE1_IO_SIZE         SZ_1M
+
 #define KIRKWOOD_PCIE_IO_PHYS_BASE     0xf2000000
-#define KIRKWOOD_PCIE_IO_VIRT_BASE     0xfef00000
+#define KIRKWOOD_PCIE_IO_VIRT_BASE     0xfee00000
 #define KIRKWOOD_PCIE_IO_BUS_BASE      0x00000000
 #define KIRKWOOD_PCIE_IO_SIZE          SZ_1M
 
 #define KIRKWOOD_REGS_PHYS_BASE                0xf1000000
-#define KIRKWOOD_REGS_VIRT_BASE                0xfee00000
+#define KIRKWOOD_REGS_VIRT_BASE                0xfed00000
 #define KIRKWOOD_REGS_SIZE             SZ_1M
 
 #define KIRKWOOD_PCIE_MEM_PHYS_BASE    0xe0000000
 #define KIRKWOOD_PCIE_MEM_BUS_BASE     0xe0000000
 #define KIRKWOOD_PCIE_MEM_SIZE         SZ_128M
 
+#define KIRKWOOD_PCIE1_MEM_PHYS_BASE   0xe8000000
+#define KIRKWOOD_PCIE1_MEM_BUS_BASE    0xe8000000
+#define KIRKWOOD_PCIE1_MEM_SIZE                SZ_128M
+
 /*
  * Register Map
  */
@@ -72,6 +84,9 @@
 #define PCIE_VIRT_BASE         (KIRKWOOD_REGS_VIRT_BASE | 0x40000)
 #define PCIE_LINK_CTRL         (PCIE_VIRT_BASE | 0x70)
 #define PCIE_STATUS            (PCIE_VIRT_BASE | 0x1a04)
+#define PCIE1_VIRT_BASE                (KIRKWOOD_REGS_VIRT_BASE | 0x44000)
+#define PCIE1_LINK_CTRL                (PCIE1_VIRT_BASE | 0x70)
+#define PCIE1_STATUS           (PCIE1_VIRT_BASE | 0x1a04)
 
 #define USB_PHYS_BASE          (KIRKWOOD_REGS_PHYS_BASE | 0x50000)
 
 #define MV88F6192_DEV_ID       0x6192
 #define MV88F6192_REV_Z0       0
 #define MV88F6192_REV_A0       2
+#define MV88F6192_REV_A1       3
 
 #define MV88F6180_DEV_ID       0x6180
 #define MV88F6180_REV_A0       2
+#define MV88F6180_REV_A1       3
 
+#define MV88F6282_DEV_ID       0x6282
+#define MV88F6282_REV_A0       0
 #endif
diff --git a/arch/arm/mach-kirkwood/include/mach/leds-ns2.h b/arch/arm/mach-kirkwood/include/mach/leds-ns2.h
new file mode 100644 (file)
index 0000000..e21272e
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * arch/arm/mach-kirkwood/include/mach/leds-ns2.h
+ *
+ * Platform data structure for Network Space v2 LED driver
+ *
+ * This file is licensed under the terms of the GNU General Public
+ * License version 2.  This program is licensed "as is" without any
+ * warranty of any kind, whether express or implied.
+ */
+
+#ifndef __MACH_LEDS_NS2_H
+#define __MACH_LEDS_NS2_H
+
+struct ns2_led {
+       const char      *name;
+       const char      *default_trigger;
+       unsigned        cmd;
+       unsigned        slow;
+};
+
+struct ns2_led_platform_data {
+       int             num_leds;
+       struct ns2_led  *leds;
+};
+
+#endif /* __MACH_LEDS_NS2_H */
index a5900f64e38c112e7fb195ea2cdca7281cc64af7..065187d177c6299f12543c3198c23c7cbd8f2476 100644 (file)
@@ -23,7 +23,8 @@ static unsigned int __init kirkwood_variant(void)
 
        kirkwood_pcie_id(&dev, &rev);
 
-       if (dev == MV88F6281_DEV_ID && rev >= MV88F6281_REV_A0)
+       if ((dev == MV88F6281_DEV_ID && rev >= MV88F6281_REV_A0) ||
+           (dev == MV88F6282_DEV_ID))
                return MPP_F6281_MASK;
        if (dev == MV88F6192_DEV_ID && rev >= MV88F6192_REV_A0)
                return MPP_F6192_MASK;
index bc74278ed311c2bef402d6e16d808111669ed96e..9b0a94d85c3ee6b4e2238c0db2e65117f63f44eb 100644 (file)
@@ -11,7 +11,7 @@
 #ifndef __KIRKWOOD_MPP_H
 #define __KIRKWOOD_MPP_H
 
-#define MPP(_num, _sel, _in, _out, _F6180, _F6190, _F6192, _F6281) ( \
+#define MPP(_num, _sel, _in, _out, _F6180, _F6190, _F6192, _F6281, _F6282) ( \
        /* MPP number */                ((_num) & 0xff) | \
        /* MPP select value */          (((_sel) & 0xf) << 8) | \
        /* may be input signal */       ((!!(_in)) << 12) | \
        /* available on F6180 */        ((!!(_F6180)) << 14) | \
        /* available on F6190 */        ((!!(_F6190)) << 15) | \
        /* available on F6192 */        ((!!(_F6192)) << 16) | \
-       /* available on F6281 */        ((!!(_F6281)) << 17))
+       /* available on F6281 */        ((!!(_F6281)) << 17) | \
+       /* available on F6282 */        ((!!(_F6282)) << 18))
 
 #define MPP_NUM(x)     ((x) & 0xff)
 #define MPP_SEL(x)     (((x) >> 8) & 0xf)
 
-                               /*   num sel  i  o  6180 6190 6192 6281 */
-
-#define MPP_INPUT_MASK         MPP(  0, 0x0, 1, 0, 0,   0,   0,   0    )
-#define MPP_OUTPUT_MASK                MPP(  0, 0x0, 0, 1, 0,   0,   0,   0    )
-
-#define MPP_F6180_MASK         MPP(  0, 0x0, 0, 0, 1,   0,   0,   0    )
-#define MPP_F6190_MASK         MPP(  0, 0x0, 0, 0, 0,   1,   0,   0    )
-#define MPP_F6192_MASK         MPP(  0, 0x0, 0, 0, 0,   0,   1,   0    )
-#define MPP_F6281_MASK         MPP(  0, 0x0, 0, 0, 0,   0,   0,   1    )
-
-#define MPP0_GPIO              MPP(  0, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP0_NF_IO2            MPP(  0, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP0_SPI_SCn           MPP(  0, 0x2, 0, 1, 1,   1,   1,   1    )
-
-#define MPP1_GPO               MPP(  1, 0x0, 0, 1, 1,   1,   1,   1    )
-#define MPP1_NF_IO3            MPP(  1, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP1_SPI_MOSI          MPP(  1, 0x2, 0, 1, 1,   1,   1,   1    )
-
-#define MPP2_GPO               MPP(  2, 0x0, 0, 1, 1,   1,   1,   1    )
-#define MPP2_NF_IO4            MPP(  2, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP2_SPI_SCK           MPP(  2, 0x2, 0, 1, 1,   1,   1,   1    )
-
-#define MPP3_GPO               MPP(  3, 0x0, 0, 1, 1,   1,   1,   1    )
-#define MPP3_NF_IO5            MPP(  3, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP3_SPI_MISO          MPP(  3, 0x2, 1, 0, 1,   1,   1,   1    )
-
-#define MPP4_GPIO              MPP(  4, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP4_NF_IO6            MPP(  4, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP4_UART0_RXD         MPP(  4, 0x2, 1, 0, 1,   1,   1,   1    )
-#define MPP4_SATA1_ACTn                MPP(  4, 0x5, 0, 1, 0,   0,   1,   1    )
-#define MPP4_PTP_CLK           MPP(  4, 0xd, 1, 0, 1,   1,   1,   1    )
-
-#define MPP5_GPO               MPP(  5, 0x0, 0, 1, 1,   1,   1,   1    )
-#define MPP5_NF_IO7            MPP(  5, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP5_UART0_TXD         MPP(  5, 0x2, 0, 1, 1,   1,   1,   1    )
-#define MPP5_PTP_TRIG_GEN      MPP(  5, 0x4, 0, 1, 1,   1,   1,   1    )
-#define MPP5_SATA0_ACTn                MPP(  5, 0x5, 0, 1, 0,   1,   1,   1    )
-
-#define MPP6_SYSRST_OUTn       MPP(  6, 0x1, 0, 1, 1,   1,   1,   1    )
-#define MPP6_SPI_MOSI          MPP(  6, 0x2, 0, 1, 1,   1,   1,   1    )
-#define MPP6_PTP_TRIG_GEN      MPP(  6, 0x3, 0, 1, 1,   1,   1,   1    )
-
-#define MPP7_GPO               MPP(  7, 0x0, 0, 1, 1,   1,   1,   1    )
-#define MPP7_PEX_RST_OUTn      MPP(  7, 0x1, 0, 1, 1,   1,   1,   1    )
-#define MPP7_SPI_SCn           MPP(  7, 0x2, 0, 1, 1,   1,   1,   1    )
-#define MPP7_PTP_TRIG_GEN      MPP(  7, 0x3, 0, 1, 1,   1,   1,   1    )
-
-#define MPP8_GPIO              MPP(  8, 0x0, 1, 1, 1,    1,  1,   1    )
-#define MPP8_TW_SDA            MPP(  8, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP8_UART0_RTS         MPP(  8, 0x2, 0, 1, 1,   1,   1,   1    )
-#define MPP8_UART1_RTS         MPP(  8, 0x3, 0, 1, 1,   1,   1,   1    )
-#define MPP8_MII0_RXERR                MPP(  8, 0x4, 1, 0, 0,   1,   1,   1    )
-#define MPP8_SATA1_PRESENTn    MPP(  8, 0x5, 0, 1, 0,   0,   1,   1    )
-#define MPP8_PTP_CLK           MPP(  8, 0xc, 1, 0, 1,   1,   1,   1    )
-#define MPP8_MII0_COL          MPP(  8, 0xd, 1, 0, 1,   1,   1,   1    )
-
-#define MPP9_GPIO              MPP(  9, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP9_TW_SCK            MPP(  9, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP9_UART0_CTS         MPP(  9, 0x2, 1, 0, 1,   1,   1,   1    )
-#define MPP9_UART1_CTS         MPP(  9, 0x3, 1, 0, 1,   1,   1,   1    )
-#define MPP9_SATA0_PRESENTn    MPP(  9, 0x5, 0, 1, 0,   1,   1,   1    )
-#define MPP9_PTP_EVENT_REQ     MPP(  9, 0xc, 1, 0, 1,   1,   1,   1    )
-#define MPP9_MII0_CRS          MPP(  9, 0xd, 1, 0, 1,   1,   1,   1    )
-
-#define MPP10_GPO              MPP( 10, 0x0, 0, 1, 1,   1,   1,   1    )
-#define MPP10_SPI_SCK          MPP( 10, 0x2, 0, 1, 1,   1,   1,   1    )
-#define MPP10_UART0_TXD                MPP( 10, 0X3, 0, 1, 1,   1,   1,   1    )
-#define MPP10_SATA1_ACTn       MPP( 10, 0x5, 0, 1, 0,   0,   1,   1    )
-#define MPP10_PTP_TRIG_GEN     MPP( 10, 0xc, 0, 1, 1,   1,   1,   1    )
-
-#define MPP11_GPIO             MPP( 11, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP11_SPI_MISO         MPP( 11, 0x2, 1, 0, 1,   1,   1,   1    )
-#define MPP11_UART0_RXD                MPP( 11, 0x3, 1, 0, 1,   1,   1,   1    )
-#define MPP11_PTP_EVENT_REQ    MPP( 11, 0x4, 1, 0, 1,   1,   1,   1    )
-#define MPP11_PTP_TRIG_GEN     MPP( 11, 0xc, 0, 1, 1,   1,   1,   1    )
-#define MPP11_PTP_CLK          MPP( 11, 0xd, 1, 0, 1,   1,   1,   1    )
-#define MPP11_SATA0_ACTn       MPP( 11, 0x5, 0, 1, 0,   1,   1,   1    )
-
-#define MPP12_GPO              MPP( 12, 0x0, 0, 1, 1,   1,   1,   1    )
-#define MPP12_SD_CLK           MPP( 12, 0x1, 0, 1, 1,   1,   1,   1    )
-
-#define MPP13_GPIO             MPP( 13, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP13_SD_CMD           MPP( 13, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP13_UART1_TXD                MPP( 13, 0x3, 0, 1, 1,   1,   1,   1    )
-
-#define MPP14_GPIO             MPP( 14, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP14_SD_D0            MPP( 14, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP14_UART1_RXD                MPP( 14, 0x3, 1, 0, 1,   1,   1,   1    )
-#define MPP14_SATA1_PRESENTn   MPP( 14, 0x4, 0, 1, 0,   0,   1,   1    )
-#define MPP14_MII0_COL         MPP( 14, 0xd, 1, 0, 1,   1,   1,   1    )
-
-#define MPP15_GPIO             MPP( 15, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP15_SD_D1            MPP( 15, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP15_UART0_RTS                MPP( 15, 0x2, 0, 1, 1,   1,   1,   1    )
-#define MPP15_UART1_TXD                MPP( 15, 0x3, 0, 1, 1,   1,   1,   1    )
-#define MPP15_SATA0_ACTn       MPP( 15, 0x4, 0, 1, 0,   1,   1,   1    )
-
-#define MPP16_GPIO             MPP( 16, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP16_SD_D2            MPP( 16, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP16_UART0_CTS                MPP( 16, 0x2, 1, 0, 1,   1,   1,   1    )
-#define MPP16_UART1_RXD                MPP( 16, 0x3, 1, 0, 1,   1,   1,   1    )
-#define MPP16_SATA1_ACTn       MPP( 16, 0x4, 0, 1, 0,   0,   1,   1    )
-#define MPP16_MII0_CRS         MPP( 16, 0xd, 1, 0, 1,   1,   1,   1    )
-
-#define MPP17_GPIO             MPP( 17, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP17_SD_D3            MPP( 17, 0x1, 1, 1, 1,   1,   1,   1    )
-#define MPP17_SATA0_PRESENTn   MPP( 17, 0x4, 0, 1, 0,   1,   1,   1    )
-
-#define MPP18_GPO              MPP( 18, 0x0, 0, 1, 1,   1,   1,   1    )
-#define MPP18_NF_IO0           MPP( 18, 0x1, 1, 1, 1,   1,   1,   1    )
-
-#define MPP19_GPO              MPP( 19, 0x0, 0, 1, 1,   1,   1,   1    )
-#define MPP19_NF_IO1           MPP( 19, 0x1, 1, 1, 1,   1,   1,   1    )
-
-#define MPP20_GPIO             MPP( 20, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP20_TSMP0            MPP( 20, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP20_TDM_CH0_TX_QL    MPP( 20, 0x2, 0, 1, 0,   0,   1,   1    )
-#define MPP20_GE1_0            MPP( 20, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP20_AUDIO_SPDIFI     MPP( 20, 0x4, 1, 0, 0,   0,   1,   1    )
-#define MPP20_SATA1_ACTn       MPP( 20, 0x5, 0, 1, 0,   0,   1,   1    )
-
-#define MPP21_GPIO             MPP( 21, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP21_TSMP1            MPP( 21, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP21_TDM_CH0_RX_QL    MPP( 21, 0x2, 0, 1, 0,   0,   1,   1    )
-#define MPP21_GE1_1            MPP( 21, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP21_AUDIO_SPDIFO     MPP( 21, 0x4, 0, 1, 0,   0,   1,   1    )
-#define MPP21_SATA0_ACTn       MPP( 21, 0x5, 0, 1, 0,   1,   1,   1    )
-
-#define MPP22_GPIO             MPP( 22, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP22_TSMP2            MPP( 22, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP22_TDM_CH2_TX_QL    MPP( 22, 0x2, 0, 1, 0,   0,   1,   1    )
-#define MPP22_GE1_2            MPP( 22, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP22_AUDIO_SPDIFRMKCLK        MPP( 22, 0x4, 0, 1, 0,   0,   1,   1    )
-#define MPP22_SATA1_PRESENTn   MPP( 22, 0x5, 0, 1, 0,   0,   1,   1    )
-
-#define MPP23_GPIO             MPP( 23, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP23_TSMP3            MPP( 23, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP23_TDM_CH2_RX_QL    MPP( 23, 0x2, 1, 0, 0,   0,   1,   1    )
-#define MPP23_GE1_3            MPP( 23, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP23_AUDIO_I2SBCLK    MPP( 23, 0x4, 0, 1, 0,   0,   1,   1    )
-#define MPP23_SATA0_PRESENTn   MPP( 23, 0x5, 0, 1, 0,   1,   1,   1    )
-
-#define MPP24_GPIO             MPP( 24, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP24_TSMP4            MPP( 24, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP24_TDM_SPI_CS0      DEV( 24, 0x2, 0, 1, 0,   0,   1,   1    )
-#define MPP24_GE1_4            MPP( 24, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP24_AUDIO_I2SDO      MPP( 24, 0x4, 0, 1, 0,   0,   1,   1    )
-
-#define MPP25_GPIO             MPP( 25, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP25_TSMP5            MPP( 25, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP25_TDM_SPI_SCK      MPP( 25, 0x2, 0, 1, 0,   0,   1,   1    )
-#define MPP25_GE1_5            MPP( 25, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP25_AUDIO_I2SLRCLK   MPP( 25, 0x4, 0, 1, 0,   0,   1,   1    )
-
-#define MPP26_GPIO             MPP( 26, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP26_TSMP6            MPP( 26, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP26_TDM_SPI_MISO     MPP( 26, 0x2, 1, 0, 0,   0,   1,   1    )
-#define MPP26_GE1_6            MPP( 26, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP26_AUDIO_I2SMCLK    MPP( 26, 0x4, 0, 1, 0,   0,   1,   1    )
-
-#define MPP27_GPIO             MPP( 27, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP27_TSMP7            MPP( 27, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP27_TDM_SPI_MOSI     MPP( 27, 0x2, 0, 1, 0,   0,   1,   1    )
-#define MPP27_GE1_7            MPP( 27, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP27_AUDIO_I2SDI      MPP( 27, 0x4, 1, 0, 0,   0,   1,   1    )
-
-#define MPP28_GPIO             MPP( 28, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP28_TSMP8            MPP( 28, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP28_TDM_CODEC_INTn   MPP( 28, 0x2, 0, 0, 0,   0,   1,   1    )
-#define MPP28_GE1_8            MPP( 28, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP28_AUDIO_EXTCLK     MPP( 28, 0x4, 1, 0, 0,   0,   1,   1    )
-
-#define MPP29_GPIO             MPP( 29, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP29_TSMP9            MPP( 29, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP29_TDM_CODEC_RSTn   MPP( 29, 0x2, 0, 0, 0,   0,   1,   1    )
-#define MPP29_GE1_9            MPP( 29, 0x3, 0, 0, 0,   1,   1,   1    )
-
-#define MPP30_GPIO             MPP( 30, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP30_TSMP10           MPP( 30, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP30_TDM_PCLK         MPP( 30, 0x2, 1, 1, 0,   0,   1,   1    )
-#define MPP30_GE1_10           MPP( 30, 0x3, 0, 0, 0,   1,   1,   1    )
-
-#define MPP31_GPIO             MPP( 31, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP31_TSMP11           MPP( 31, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP31_TDM_FS           MPP( 31, 0x2, 1, 1, 0,   0,   1,   1    )
-#define MPP31_GE1_11           MPP( 31, 0x3, 0, 0, 0,   1,   1,   1    )
-
-#define MPP32_GPIO             MPP( 32, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP32_TSMP12           MPP( 32, 0x1, 1, 1, 0,   0,   1,   1    )
-#define MPP32_TDM_DRX          MPP( 32, 0x2, 1, 0, 0,   0,   1,   1    )
-#define MPP32_GE1_12           MPP( 32, 0x3, 0, 0, 0,   1,   1,   1    )
-
-#define MPP33_GPIO             MPP( 33, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP33_TDM_DTX          MPP( 33, 0x2, 0, 1, 0,   0,   1,   1    )
-#define MPP33_GE1_13           MPP( 33, 0x3, 0, 0, 0,   1,   1,   1    )
-
-#define MPP34_GPIO             MPP( 34, 0x0, 1, 1, 0,   1,   1,   1    )
-#define MPP34_TDM_SPI_CS1      MPP( 34, 0x2, 0, 1, 0,   0,   1,   1    )
-#define MPP34_GE1_14           MPP( 34, 0x3, 0, 0, 0,   1,   1,   1    )
-
-#define MPP35_GPIO             MPP( 35, 0x0, 1, 1, 1,   1,   1,   1    )
-#define MPP35_TDM_CH0_TX_QL    MPP( 35, 0x2, 0, 1, 0,   0,   1,   1    )
-#define MPP35_GE1_15           MPP( 35, 0x3, 0, 0, 0,   1,   1,   1    )
-#define MPP35_SATA0_ACTn       MPP( 35, 0x5, 0, 1, 0,   1,   1,   1    )
-#define MPP35_MII0_RXERR       MPP( 35, 0xc, 1, 0, 1,   1,   1,   1    )
-
-#define MPP36_GPIO             MPP( 36, 0x0, 1, 1, 1,   0,   0,   1    )
-#define MPP36_TSMP0            MPP( 36, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP36_TDM_SPI_CS1      MPP( 36, 0x2, 0, 1, 0,   0,   0,   1    )
-#define MPP36_AUDIO_SPDIFI     MPP( 36, 0x4, 1, 0, 1,   0,   0,   1    )
-
-#define MPP37_GPIO             MPP( 37, 0x0, 1, 1, 1,   0,   0,   1    )
-#define MPP37_TSMP1            MPP( 37, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP37_TDM_CH2_TX_QL    MPP( 37, 0x2, 0, 1, 0,   0,   0,   1    )
-#define MPP37_AUDIO_SPDIFO     MPP( 37, 0x4, 0, 1, 1,   0,   0,   1    )
-
-#define MPP38_GPIO             MPP( 38, 0x0, 1, 1, 1,   0,   0,   1    )
-#define MPP38_TSMP2            MPP( 38, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP38_TDM_CH2_RX_QL    MPP( 38, 0x2, 0, 1, 0,   0,   0,   1    )
-#define MPP38_AUDIO_SPDIFRMLCLK        MPP( 38, 0x4, 0, 1, 1,   0,   0,   1    )
-
-#define MPP39_GPIO             MPP( 39, 0x0, 1, 1, 1,   0,   0,   1    )
-#define MPP39_TSMP3            MPP( 39, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP39_TDM_SPI_CS0      MPP( 39, 0x2, 0, 1, 0,   0,   0,   1    )
-#define MPP39_AUDIO_I2SBCLK    MPP( 39, 0x4, 0, 1, 1,   0,   0,   1    )
-
-#define MPP40_GPIO             MPP( 40, 0x0, 1, 1, 1,   0,   0,   1    )
-#define MPP40_TSMP4            MPP( 40, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP40_TDM_SPI_SCK      MPP( 40, 0x2, 0, 1, 0,   0,   0,   1    )
-#define MPP40_AUDIO_I2SDO      MPP( 40, 0x4, 0, 1, 1,   0,   0,   1    )
-
-#define MPP41_GPIO             MPP( 41, 0x0, 1, 1, 1,   0,   0,   1    )
-#define MPP41_TSMP5            MPP( 41, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP41_TDM_SPI_MISO     MPP( 41, 0x2, 1, 0, 0,   0,   0,   1    )
-#define MPP41_AUDIO_I2SLRC     MPP( 41, 0x4, 0, 1, 1,   0,   0,   1    )
-
-#define MPP42_GPIO             MPP( 42, 0x0, 1, 1, 1,   0,   0,   1    )
-#define MPP42_TSMP6            MPP( 42, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP42_TDM_SPI_MOSI     MPP( 42, 0x2, 0, 1, 0,   0,   0,   1    )
-#define MPP42_AUDIO_I2SMCLK    MPP( 42, 0x4, 0, 1, 1,   0,   0,   1    )
-
-#define MPP43_GPIO             MPP( 43, 0x0, 1, 1, 1,   0,   0,   1    )
-#define MPP43_TSMP7            MPP( 43, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP43_TDM_CODEC_INTn   MPP( 43, 0x2, 0, 0, 0,   0,   0,   1    )
-#define MPP43_AUDIO_I2SDI      MPP( 43, 0x4, 1, 0, 1,   0,   0,   1    )
-
-#define MPP44_GPIO             MPP( 44, 0x0, 1, 1, 1,   0,   0,   1    )
-#define MPP44_TSMP8            MPP( 44, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP44_TDM_CODEC_RSTn   MPP( 44, 0x2, 0, 0, 0,   0,   0,   1    )
-#define MPP44_AUDIO_EXTCLK     MPP( 44, 0x4, 1, 0, 1,   0,   0,   1    )
-
-#define MPP45_GPIO             MPP( 45, 0x0, 1, 1, 0,   0,   0,   1    )
-#define MPP45_TSMP9            MPP( 45, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP45_TDM_PCLK         MPP( 45, 0x2, 1, 1, 0,   0,   0,   1    )
-
-#define MPP46_GPIO             MPP( 46, 0x0, 1, 1, 0,   0,   0,   1    )
-#define MPP46_TSMP10           MPP( 46, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP46_TDM_FS           MPP( 46, 0x2, 1, 1, 0,   0,   0,   1    )
-
-#define MPP47_GPIO             MPP( 47, 0x0, 1, 1, 0,   0,   0,   1    )
-#define MPP47_TSMP11           MPP( 47, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP47_TDM_DRX          MPP( 47, 0x2, 1, 0, 0,   0,   0,   1    )
-
-#define MPP48_GPIO             MPP( 48, 0x0, 1, 1, 0,   0,   0,   1    )
-#define MPP48_TSMP12           MPP( 48, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP48_TDM_DTX          MPP( 48, 0x2, 0, 1, 0,   0,   0,   1    )
-
-#define MPP49_GPIO             MPP( 49, 0x0, 1, 1, 0,   0,   0,   1    )
-#define MPP49_TSMP9            MPP( 49, 0x1, 1, 1, 0,   0,   0,   1    )
-#define MPP49_TDM_CH0_RX_QL    MPP( 49, 0x2, 0, 1, 0,   0,   0,   1    )
-#define MPP49_PTP_CLK          MPP( 49, 0x5, 1, 0, 0,   0,   0,   1    )
+                               /*   num sel  i  o  6180 6190 6192 6281 6282 */
+
+#define MPP_INPUT_MASK         MPP(  0, 0x0, 1, 0, 0,   0,   0,   0,   0 )
+#define MPP_OUTPUT_MASK                MPP(  0, 0x0, 0, 1, 0,   0,   0,   0,   0 )
+
+#define MPP_F6180_MASK         MPP(  0, 0x0, 0, 0, 1,   0,   0,   0,   0 )
+#define MPP_F6190_MASK         MPP(  0, 0x0, 0, 0, 0,   1,   0,   0,   0 )
+#define MPP_F6192_MASK         MPP(  0, 0x0, 0, 0, 0,   0,   1,   0,   0 )
+#define MPP_F6281_MASK         MPP(  0, 0x0, 0, 0, 0,   0,   0,   1,   0 )
+#define MPP_F6282_MASK         MPP(  0, 0x0, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP0_GPIO              MPP(  0, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP0_NF_IO2            MPP(  0, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP0_SPI_SCn           MPP(  0, 0x2, 0, 1, 1,   1,   1,   1,   1 )
+
+#define MPP1_GPO               MPP(  1, 0x0, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP1_NF_IO3            MPP(  1, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP1_SPI_MOSI          MPP(  1, 0x2, 0, 1, 1,   1,   1,   1,   1 )
+
+#define MPP2_GPO               MPP(  2, 0x0, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP2_NF_IO4            MPP(  2, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP2_SPI_SCK           MPP(  2, 0x2, 0, 1, 1,   1,   1,   1,   1 )
+
+#define MPP3_GPO               MPP(  3, 0x0, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP3_NF_IO5            MPP(  3, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP3_SPI_MISO          MPP(  3, 0x2, 1, 0, 1,   1,   1,   1,   1 )
+
+#define MPP4_GPIO              MPP(  4, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP4_NF_IO6            MPP(  4, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP4_UART0_RXD         MPP(  4, 0x2, 1, 0, 1,   1,   1,   1,   1 )
+#define MPP4_SATA1_ACTn                MPP(  4, 0x5, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP4_LCD_VGA_HSYNC     MPP(  4, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+#define MPP4_PTP_CLK           MPP(  4, 0xd, 1, 0, 1,   1,   1,   1,   0 )
+
+#define MPP5_GPO               MPP(  5, 0x0, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP5_NF_IO7            MPP(  5, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP5_UART0_TXD         MPP(  5, 0x2, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP5_PTP_TRIG_GEN      MPP(  5, 0x4, 0, 1, 1,   1,   1,   1,   0 )
+#define MPP5_SATA0_ACTn                MPP(  5, 0x5, 0, 1, 0,   1,   1,   1,   1 )
+#define MPP5_LCD_VGA_VSYNC     MPP(  5, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP6_SYSRST_OUTn       MPP(  6, 0x1, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP6_SPI_MOSI          MPP(  6, 0x2, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP6_PTP_TRIG_GEN      MPP(  6, 0x3, 0, 1, 1,   1,   1,   1,   0 )
+
+#define MPP7_GPO               MPP(  7, 0x0, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP7_PEX_RST_OUTn      MPP(  7, 0x1, 0, 1, 1,   1,   1,   1,   0 )
+#define MPP7_SPI_SCn           MPP(  7, 0x2, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP7_PTP_TRIG_GEN      MPP(  7, 0x3, 0, 1, 1,   1,   1,   1,   0 )
+#define MPP7_LCD_PWM           MPP(  7, 0xb, 0, 1, 0,   0,   0,   0,   1 )
+
+#define MPP8_GPIO              MPP(  8, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP8_TW0_SDA           MPP(  8, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP8_UART0_RTS         MPP(  8, 0x2, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP8_UART1_RTS         MPP(  8, 0x3, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP8_MII0_RXERR                MPP(  8, 0x4, 1, 0, 0,   1,   1,   1,   1 )
+#define MPP8_SATA1_PRESENTn    MPP(  8, 0x5, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP8_PTP_CLK           MPP(  8, 0xc, 1, 0, 1,   1,   1,   1,   0 )
+#define MPP8_MII0_COL          MPP(  8, 0xd, 1, 0, 1,   1,   1,   1,   1 )
+
+#define MPP9_GPIO              MPP(  9, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP9_TW0_SCK           MPP(  9, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP9_UART0_CTS         MPP(  9, 0x2, 1, 0, 1,   1,   1,   1,   1 )
+#define MPP9_UART1_CTS         MPP(  9, 0x3, 1, 0, 1,   1,   1,   1,   1 )
+#define MPP9_SATA0_PRESENTn    MPP(  9, 0x5, 0, 1, 0,   1,   1,   1,   1 )
+#define MPP9_PTP_EVENT_REQ     MPP(  9, 0xc, 1, 0, 1,   1,   1,   1,   0 )
+#define MPP9_MII0_CRS          MPP(  9, 0xd, 1, 0, 1,   1,   1,   1,   1 )
+
+#define MPP10_GPO              MPP( 10, 0x0, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP10_SPI_SCK          MPP( 10, 0x2, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP10_UART0_TXD                MPP( 10, 0X3, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP10_SATA1_ACTn       MPP( 10, 0x5, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP10_PTP_TRIG_GEN     MPP( 10, 0xc, 0, 1, 1,   1,   1,   1,   0 )
+
+#define MPP11_GPIO             MPP( 11, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP11_SPI_MISO         MPP( 11, 0x2, 1, 0, 1,   1,   1,   1,   1 )
+#define MPP11_UART0_RXD                MPP( 11, 0x3, 1, 0, 1,   1,   1,   1,   1 )
+#define MPP11_PTP_EVENT_REQ    MPP( 11, 0x4, 1, 0, 1,   1,   1,   1,   0 )
+#define MPP11_PTP_TRIG_GEN     MPP( 11, 0xc, 0, 1, 1,   1,   1,   1,   0 )
+#define MPP11_PTP_CLK          MPP( 11, 0xd, 1, 0, 1,   1,   1,   1,   0 )
+#define MPP11_SATA0_ACTn       MPP( 11, 0x5, 0, 1, 0,   1,   1,   1,   1 )
+
+#define MPP12_GPO              MPP( 12, 0x0, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP12_SD_CLK           MPP( 12, 0x1, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP12_AU_SPDIF0                MPP( 12, 0xa, 0, 1, 0,   0,   0,   0,   1 )
+#define MPP12_SPI_MOSI         MPP( 12, 0xb, 0, 1, 0,   0,   0,   0,   1 )
+#define MPP12_TW1_SDA          MPP( 12, 0xd, 1, 0, 0,   0,   0,   0,   1 )
+
+#define MPP13_GPIO             MPP( 13, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP13_SD_CMD           MPP( 13, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP13_UART1_TXD                MPP( 13, 0x3, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP13_AU_SPDIFRMCLK    MPP( 13, 0xa, 0, 1, 0,   0,   0,   0,   1 )
+#define MPP13_LCDPWM           MPP( 13, 0xb, 0, 1, 0,   0,   0,   0,   1 )
+
+#define MPP14_GPIO             MPP( 14, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP14_SD_D0            MPP( 14, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP14_UART1_RXD                MPP( 14, 0x3, 1, 0, 1,   1,   1,   1,   1 )
+#define MPP14_SATA1_PRESENTn   MPP( 14, 0x4, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP14_AU_SPDIFI                MPP( 14, 0xa, 1, 0, 0,   0,   0,   0,   1 )
+#define MPP14_AU_I2SDI         MPP( 14, 0xb, 1, 0, 0,   0,   0,   0,   1 )
+#define MPP14_MII0_COL         MPP( 14, 0xd, 1, 0, 1,   1,   1,   1,   1 )
+
+#define MPP15_GPIO             MPP( 15, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP15_SD_D1            MPP( 15, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP15_UART0_RTS                MPP( 15, 0x2, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP15_UART1_TXD                MPP( 15, 0x3, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP15_SATA0_ACTn       MPP( 15, 0x4, 0, 1, 0,   1,   1,   1,   1 )
+#define MPP15_SPI_CSn          MPP( 15, 0xb, 0, 1, 0,   0,   0,   0,   1 )
+
+#define MPP16_GPIO             MPP( 16, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP16_SD_D2            MPP( 16, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP16_UART0_CTS                MPP( 16, 0x2, 1, 0, 1,   1,   1,   1,   1 )
+#define MPP16_UART1_RXD                MPP( 16, 0x3, 1, 0, 1,   1,   1,   1,   1 )
+#define MPP16_SATA1_ACTn       MPP( 16, 0x4, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP16_LCD_EXT_REF_CLK  MPP( 16, 0xb, 1, 0, 0,   0,   0,   0,   1 )
+#define MPP16_MII0_CRS         MPP( 16, 0xd, 1, 0, 1,   1,   1,   1,   1 )
+
+#define MPP17_GPIO             MPP( 17, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP17_SD_D3            MPP( 17, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP17_SATA0_PRESENTn   MPP( 17, 0x4, 0, 1, 0,   1,   1,   1,   1 )
+#define MPP17_SATA1_ACTn       MPP( 17, 0xa, 0, 1, 0,   0,   0,   0,   1 )
+#define MPP17_TW1_SCK          MPP( 17, 0xd, 1, 1, 0,   0,   0,   0,   1 )
+
+#define MPP18_GPO              MPP( 18, 0x0, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP18_NF_IO0           MPP( 18, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP18_PEX0_CLKREQ      MPP( 18, 0x2, 0, 1, 0,   0,   0,   0,   1 )
+
+#define MPP19_GPO              MPP( 19, 0x0, 0, 1, 1,   1,   1,   1,   1 )
+#define MPP19_NF_IO1           MPP( 19, 0x1, 1, 1, 1,   1,   1,   1,   1 )
+
+#define MPP20_GPIO             MPP( 20, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP20_TSMP0            MPP( 20, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP20_TDM_CH0_TX_QL    MPP( 20, 0x2, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP20_GE1_TXD0         MPP( 20, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP20_AU_SPDIFI                MPP( 20, 0x4, 1, 0, 0,   0,   1,   1,   1 )
+#define MPP20_SATA1_ACTn       MPP( 20, 0x5, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP20_LCD_D0           MPP( 20, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP21_GPIO             MPP( 21, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP21_TSMP1            MPP( 21, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP21_TDM_CH0_RX_QL    MPP( 21, 0x2, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP21_GE1_TXD1         MPP( 21, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP21_AU_SPDIFO                MPP( 21, 0x4, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP21_SATA0_ACTn       MPP( 21, 0x5, 0, 1, 0,   1,   1,   1,   1 )
+#define MPP21_LCD_D1           MPP( 21, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP22_GPIO             MPP( 22, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP22_TSMP2            MPP( 22, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP22_TDM_CH2_TX_QL    MPP( 22, 0x2, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP22_GE1_TXD2         MPP( 22, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP22_AU_SPDIFRMKCLK   MPP( 22, 0x4, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP22_SATA1_PRESENTn   MPP( 22, 0x5, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP22_LCD_D2           MPP( 22, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP23_GPIO             MPP( 23, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP23_TSMP3            MPP( 23, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP23_TDM_CH2_RX_QL    MPP( 23, 0x2, 1, 0, 0,   0,   1,   1,   1 )
+#define MPP23_GE1_TXD3         MPP( 23, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP23_AU_I2SBCLK       MPP( 23, 0x4, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP23_SATA0_PRESENTn   MPP( 23, 0x5, 0, 1, 0,   1,   1,   1,   1 )
+#define MPP23_LCD_D3           MPP( 23, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP24_GPIO             MPP( 24, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP24_TSMP4            MPP( 24, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP24_TDM_SPI_CS0      MPP( 24, 0x2, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP24_GE1_RXD0         MPP( 24, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP24_AU_I2SDO         MPP( 24, 0x4, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP24_LCD_D4           MPP( 24, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP25_GPIO             MPP( 25, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP25_TSMP5            MPP( 25, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP25_TDM_SPI_SCK      MPP( 25, 0x2, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP25_GE1_RXD1         MPP( 25, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP25_AU_I2SLRCLK      MPP( 25, 0x4, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP25_LCD_D5           MPP( 25, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP26_GPIO             MPP( 26, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP26_TSMP6            MPP( 26, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP26_TDM_SPI_MISO     MPP( 26, 0x2, 1, 0, 0,   0,   1,   1,   1 )
+#define MPP26_GE1_RXD2         MPP( 26, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP26_AU_I2SMCLK       MPP( 26, 0x4, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP26_LCD_D6           MPP( 26, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP27_GPIO             MPP( 27, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP27_TSMP7            MPP( 27, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP27_TDM_SPI_MOSI     MPP( 27, 0x2, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP27_GE1_RXD3         MPP( 27, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP27_AU_I2SDI         MPP( 27, 0x4, 1, 0, 0,   0,   1,   1,   1 )
+#define MPP27_LCD_D7           MPP( 27, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP28_GPIO             MPP( 28, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP28_TSMP8            MPP( 28, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP28_TDM_CODEC_INTn   MPP( 28, 0x2, 0, 0, 0,   0,   1,   1,   1 )
+#define MPP28_GE1_COL          MPP( 28, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP28_AU_EXTCLK                MPP( 28, 0x4, 1, 0, 0,   0,   1,   1,   1 )
+#define MPP28_LCD_D8           MPP( 28, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP29_GPIO             MPP( 29, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP29_TSMP9            MPP( 29, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP29_TDM_CODEC_RSTn   MPP( 29, 0x2, 0, 0, 0,   0,   1,   1,   1 )
+#define MPP29_GE1_TCLK         MPP( 29, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP29_LCD_D9           MPP( 29, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP30_GPIO             MPP( 30, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP30_TSMP10           MPP( 30, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP30_TDM_PCLK         MPP( 30, 0x2, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP30_GE1_RXCTL                MPP( 30, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP30_LCD_D10          MPP( 30, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP31_GPIO             MPP( 31, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP31_TSMP11           MPP( 31, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP31_TDM_FS           MPP( 31, 0x2, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP31_GE1_RXCLK                MPP( 31, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP31_LCD_D11          MPP( 31, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP32_GPIO             MPP( 32, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP32_TSMP12           MPP( 32, 0x1, 1, 1, 0,   0,   1,   1,   1 )
+#define MPP32_TDM_DRX          MPP( 32, 0x2, 1, 0, 0,   0,   1,   1,   1 )
+#define MPP32_GE1_TCLKOUT      MPP( 32, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP32_LCD_D12          MPP( 32, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP33_GPO              MPP( 33, 0x0, 0, 1, 0,   1,   1,   1,   1 )
+#define MPP33_TDM_DTX          MPP( 33, 0x2, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP33_GE1_TXCTL                MPP( 33, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP33_LCD_D13          MPP( 33, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP34_GPIO             MPP( 34, 0x0, 1, 1, 0,   1,   1,   1,   1 )
+#define MPP34_TDM_SPI_CS1      MPP( 34, 0x2, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP34_GE1_TXEN         MPP( 34, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP34_SATA1_ACTn       MPP( 34, 0x5, 0, 1, 0,   0,   0,   1,   1 )
+#define MPP34_LCD_D14          MPP( 34, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP35_GPIO             MPP( 35, 0x0, 1, 1, 1,   1,   1,   1,   1 )
+#define MPP35_TDM_CH0_TX_QL    MPP( 35, 0x2, 0, 1, 0,   0,   1,   1,   1 )
+#define MPP35_GE1_RXERR                MPP( 35, 0x3, 0, 0, 0,   1,   1,   1,   1 )
+#define MPP35_SATA0_ACTn       MPP( 35, 0x5, 0, 1, 0,   1,   1,   1,   1 )
+#define MPP35_LCD_D15          MPP( 22, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+#define MPP35_MII0_RXERR       MPP( 35, 0xc, 1, 0, 1,   1,   1,   1,   1 )
+
+#define MPP36_GPIO             MPP( 36, 0x0, 1, 1, 1,   0,   0,   1,   1 )
+#define MPP36_TSMP0            MPP( 36, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP36_TDM_SPI_CS1      MPP( 36, 0x2, 0, 1, 0,   0,   0,   1,   1 )
+#define MPP36_AU_SPDIFI                MPP( 36, 0x4, 1, 0, 1,   0,   0,   1,   1 )
+#define MPP36_TW1_SDA          MPP( 36, 0xb, 1, 1, 0,   0,   0,   0,   1 )
+
+#define MPP37_GPIO             MPP( 37, 0x0, 1, 1, 1,   0,   0,   1,   1 )
+#define MPP37_TSMP1            MPP( 37, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP37_TDM_CH2_TX_QL    MPP( 37, 0x2, 0, 1, 0,   0,   0,   1,   1 )
+#define MPP37_AU_SPDIFO                MPP( 37, 0x4, 0, 1, 1,   0,   0,   1,   1 )
+#define MPP37_TW1_SCK          MPP( 37, 0xb, 1, 1, 0,   0,   0,   0,   1 )
+
+#define MPP38_GPIO             MPP( 38, 0x0, 1, 1, 1,   0,   0,   1,   1 )
+#define MPP38_TSMP2            MPP( 38, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP38_TDM_CH2_RX_QL    MPP( 38, 0x2, 0, 1, 0,   0,   0,   1,   1 )
+#define MPP38_AU_SPDIFRMLCLK   MPP( 38, 0x4, 0, 1, 1,   0,   0,   1,   1 )
+#define MPP38_LCD_D18          MPP( 38, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP39_GPIO             MPP( 39, 0x0, 1, 1, 1,   0,   0,   1,   1 )
+#define MPP39_TSMP3            MPP( 39, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP39_TDM_SPI_CS0      MPP( 39, 0x2, 0, 1, 0,   0,   0,   1,   1 )
+#define MPP39_AU_I2SBCLK       MPP( 39, 0x4, 0, 1, 1,   0,   0,   1,   1 )
+#define MPP39_LCD_D19          MPP( 39, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP40_GPIO             MPP( 40, 0x0, 1, 1, 1,   0,   0,   1,   1 )
+#define MPP40_TSMP4            MPP( 40, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP40_TDM_SPI_SCK      MPP( 40, 0x2, 0, 1, 0,   0,   0,   1,   1 )
+#define MPP40_AU_I2SDO         MPP( 40, 0x4, 0, 1, 1,   0,   0,   1,   1 )
+#define MPP40_LCD_D20          MPP( 40, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP41_GPIO             MPP( 41, 0x0, 1, 1, 1,   0,   0,   1,   1 )
+#define MPP41_TSMP5            MPP( 41, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP41_TDM_SPI_MISO     MPP( 41, 0x2, 1, 0, 0,   0,   0,   1,   1 )
+#define MPP41_AU_I2SLRCLK      MPP( 41, 0x4, 0, 1, 1,   0,   0,   1,   1 )
+#define MPP41_LCD_D21          MPP( 41, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP42_GPIO             MPP( 42, 0x0, 1, 1, 1,   0,   0,   1,   1 )
+#define MPP42_TSMP6            MPP( 42, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP42_TDM_SPI_MOSI     MPP( 42, 0x2, 0, 1, 0,   0,   0,   1,   1 )
+#define MPP42_AU_I2SMCLK       MPP( 42, 0x4, 0, 1, 1,   0,   0,   1,   1 )
+#define MPP42_LCD_D22          MPP( 42, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP43_GPIO             MPP( 43, 0x0, 1, 1, 1,   0,   0,   1,   1 )
+#define MPP43_TSMP7            MPP( 43, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP43_TDM_CODEC_INTn   MPP( 43, 0x2, 0, 0, 0,   0,   0,   1,   1 )
+#define MPP43_AU_I2SDI         MPP( 43, 0x4, 1, 0, 1,   0,   0,   1,   1 )
+#define MPP43_LCD_D23          MPP( 22, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP44_GPIO             MPP( 44, 0x0, 1, 1, 1,   0,   0,   1,   1 )
+#define MPP44_TSMP8            MPP( 44, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP44_TDM_CODEC_RSTn   MPP( 44, 0x2, 0, 0, 0,   0,   0,   1,   1 )
+#define MPP44_AU_EXTCLK                MPP( 44, 0x4, 1, 0, 1,   0,   0,   1,   1 )
+#define MPP44_LCD_CLK          MPP( 44, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP45_GPIO             MPP( 45, 0x0, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP45_TSMP9            MPP( 45, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP45_TDM_PCLK         MPP( 45, 0x2, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP245_LCD_E           MPP( 45, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP46_GPIO             MPP( 46, 0x0, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP46_TSMP10           MPP( 46, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP46_TDM_FS           MPP( 46, 0x2, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP46_LCD_HSYNC                MPP( 46, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP47_GPIO             MPP( 47, 0x0, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP47_TSMP11           MPP( 47, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP47_TDM_DRX          MPP( 47, 0x2, 1, 0, 0,   0,   0,   1,   1 )
+#define MPP47_LCD_VSYNC                MPP( 47, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP48_GPIO             MPP( 48, 0x0, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP48_TSMP12           MPP( 48, 0x1, 1, 1, 0,   0,   0,   1,   1 )
+#define MPP48_TDM_DTX          MPP( 48, 0x2, 0, 1, 0,   0,   0,   1,   1 )
+#define MPP48_LCD_D16          MPP( 22, 0xb, 0, 0, 0,   0,   0,   0,   1 )
+
+#define MPP49_GPIO             MPP( 49, 0x0, 1, 1, 0,   0,   0,   1,   0 )
+#define MPP49_GPO              MPP( 49, 0x0, 0, 1, 0,   0,   0,   0,   1 )
+#define MPP49_TSMP9            MPP( 49, 0x1, 1, 1, 0,   0,   0,   1,   0 )
+#define MPP49_TDM_CH0_RX_QL    MPP( 49, 0x2, 0, 1, 0,   0,   0,   1,   1 )
+#define MPP49_PTP_CLK          MPP( 49, 0x5, 1, 0, 0,   0,   0,   1,   0 )
+#define MPP49_PEX0_CLKREQ      MPP( 49, 0xa, 0, 1, 0,   0,   0,   0,   1 )
+#define MPP49_LCD_D17          MPP( 49, 0xb, 0, 0, 0,   0,   0,   0,   1 )
 
 #define MPP_MAX                        49
 
index 5e6f711b1c6753713b8819078ec0bc053566f200..c6b92b42eb4e5a627fcceb74b61078bc8e589f4a 100644 (file)
@@ -155,7 +155,7 @@ static void __init mv88f6281gtw_ge_init(void)
 static int __init mv88f6281gtw_ge_pci_init(void)
 {
        if (machine_is_mv88f6281gtw_ge())
-               kirkwood_pcie_init();
+               kirkwood_pcie_init(KW_PCIE0);
 
        return 0;
 }
index 3ae158d72681f13a2a6f9e0246c08e3a3f618d3a..d26bf324738bde48e5be8b5c5cf13978a9f03730 100644 (file)
@@ -39,6 +39,7 @@
 #include <asm/mach/arch.h>
 #include <asm/mach/time.h>
 #include <mach/kirkwood.h>
+#include <mach/leds-ns2.h>
 #include <plat/time.h>
 #include "common.h"
 #include "mpp.h"
@@ -126,6 +127,18 @@ static void __init netspace_v2_sata_power_init(void)
        }
        if (err)
                pr_err("netspace_v2: failed to setup SATA0 power\n");
+
+       if (machine_is_netspace_max_v2()) {
+               err = gpio_request(NETSPACE_V2_GPIO_SATA1_POWER, "SATA1 power");
+               if (err == 0) {
+                       err = gpio_direction_output(
+                                       NETSPACE_V2_GPIO_SATA1_POWER, 1);
+                       if (err)
+                               gpio_free(NETSPACE_V2_GPIO_SATA1_POWER);
+               }
+               if (err)
+                       pr_err("netspace_v2: failed to setup SATA1 power\n");
+       }
 }
 
 /*****************************************************************************
@@ -160,36 +173,12 @@ static struct platform_device netspace_v2_gpio_buttons = {
  * GPIO LEDs
  ****************************************************************************/
 
-/*
- * The blue front LED is wired to a CPLD and can blink in relation with the
- * SATA activity.
- *
- * The following array detail the different LED registers and the combination
- * of their possible values:
- *
- *  cmd_led   |  slow_led  | /SATA active | LED state
- *            |            |              |
- *     1      |     0      |      x       |  off
- *     -      |     1      |      x       |  on
- *     0      |     0      |      1       |  on
- *     0      |     0      |      0       |  blink (rate 300ms)
- */
-
 #define NETSPACE_V2_GPIO_RED_LED       12
-#define NETSPACE_V2_GPIO_BLUE_LED_SLOW 29
-#define NETSPACE_V2_GPIO_BLUE_LED_CMD  30
-
 
 static struct gpio_led netspace_v2_gpio_led_pins[] = {
        {
-               .name                   = "ns_v2:blue:sata",
-               .default_trigger        = "default-on",
-               .gpio                   = NETSPACE_V2_GPIO_BLUE_LED_CMD,
-               .active_low             = 1,
-       },
-       {
-               .name                   = "ns_v2:red:fail",
-               .gpio                   = NETSPACE_V2_GPIO_RED_LED,
+               .name   = "ns_v2:red:fail",
+               .gpio   = NETSPACE_V2_GPIO_RED_LED,
        },
 };
 
@@ -206,22 +195,33 @@ static struct platform_device netspace_v2_gpio_leds = {
        },
 };
 
-static void __init netspace_v2_gpio_leds_init(void)
-{
-       int err;
+/*****************************************************************************
+ * Dual-GPIO CPLD LEDs
+ ****************************************************************************/
 
-       /* Configure register slow_led to allow SATA activity LED blinking */
-       err = gpio_request(NETSPACE_V2_GPIO_BLUE_LED_SLOW, "blue LED slow");
-       if (err == 0) {
-               err = gpio_direction_output(NETSPACE_V2_GPIO_BLUE_LED_SLOW, 0);
-               if (err)
-                       gpio_free(NETSPACE_V2_GPIO_BLUE_LED_SLOW);
-       }
-       if (err)
-               pr_err("netspace_v2: failed to configure blue LED slow GPIO\n");
+#define NETSPACE_V2_GPIO_BLUE_LED_SLOW 29
+#define NETSPACE_V2_GPIO_BLUE_LED_CMD  30
 
-       platform_device_register(&netspace_v2_gpio_leds);
-}
+static struct ns2_led netspace_v2_led_pins[] = {
+       {
+               .name   = "ns_v2:blue:sata",
+               .cmd    = NETSPACE_V2_GPIO_BLUE_LED_CMD,
+               .slow   = NETSPACE_V2_GPIO_BLUE_LED_SLOW,
+       },
+};
+
+static struct ns2_led_platform_data netspace_v2_leds_data = {
+       .num_leds       = ARRAY_SIZE(netspace_v2_led_pins),
+       .leds           = netspace_v2_led_pins,
+};
+
+static struct platform_device netspace_v2_leds = {
+       .name           = "leds-ns2",
+       .id             = -1,
+       .dev            = {
+               .platform_data  = &netspace_v2_leds_data,
+       },
+};
 
 /*****************************************************************************
  * Timer
@@ -249,17 +249,21 @@ static unsigned int netspace_v2_mpp_config[] __initdata = {
        MPP4_NF_IO6,
        MPP5_NF_IO7,
        MPP6_SYSRST_OUTn,
-       MPP8_TW_SDA,
-       MPP9_TW_SCK,
+       MPP7_GPO,               /* Fan speed (bit 1) */
+       MPP8_TW0_SDA,
+       MPP9_TW0_SCK,
        MPP10_UART0_TXD,
        MPP11_UART0_RXD,
        MPP12_GPO,              /* Red led */
        MPP14_GPIO,             /* USB fuse */
        MPP16_GPIO,             /* SATA 0 power */
+       MPP17_GPIO,             /* SATA 1 power */
        MPP18_NF_IO0,
        MPP19_NF_IO1,
        MPP20_SATA1_ACTn,
        MPP21_SATA0_ACTn,
+       MPP22_GPIO,             /* Fan speed (bit 0) */
+       MPP23_GPIO,             /* Fan power */
        MPP24_GPIO,             /* USB mode select */
        MPP25_GPIO,             /* Fan rotation fail */
        MPP26_GPIO,             /* USB device vbus */
@@ -268,6 +272,7 @@ static unsigned int netspace_v2_mpp_config[] __initdata = {
        MPP30_GPIO,             /* Blue led (command register) */
        MPP31_GPIO,             /* Board power off */
        MPP32_GPIO,             /* Power button (0 = Released, 1 = Pushed) */
+       MPP33_GPO,              /* Fan speed (bit 2) */
        0
 };
 
@@ -299,7 +304,8 @@ static void __init netspace_v2_init(void)
        i2c_register_board_info(0, netspace_v2_i2c_info,
                                ARRAY_SIZE(netspace_v2_i2c_info));
 
-       netspace_v2_gpio_leds_init();
+       platform_device_register(&netspace_v2_leds);
+       platform_device_register(&netspace_v2_gpio_leds);
        platform_device_register(&netspace_v2_gpio_buttons);
 
        if (gpio_request(NETSPACE_V2_GPIO_POWER_OFF, "power-off") == 0 &&
@@ -332,3 +338,15 @@ MACHINE_START(INETSPACE_V2, "LaCie Internet Space v2")
        .timer          = &netspace_v2_timer,
 MACHINE_END
 #endif
+
+#ifdef CONFIG_MACH_NETSPACE_MAX_V2
+MACHINE_START(NETSPACE_MAX_V2, "LaCie Network Space Max v2")
+       .phys_io        = KIRKWOOD_REGS_PHYS_BASE,
+       .io_pg_offst    = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = netspace_v2_init,
+       .map_io         = kirkwood_map_io,
+       .init_irq       = kirkwood_init_irq,
+       .timer          = &netspace_v2_timer,
+MACHINE_END
+#endif
index 8a2bb0228e4f1d73b26b266d5e9c07bae49049ef..2bd14c5079de7c0e7379439523aed3422173f383 100644 (file)
@@ -270,8 +270,8 @@ static unsigned int net2big_v2_mpp_config[] __initdata = {
        MPP3_SPI_MISO,
        MPP6_SYSRST_OUTn,
        MPP7_GPO,               /* Request power-off */
-       MPP8_TW_SDA,
-       MPP9_TW_SCK,
+       MPP8_TW0_SDA,
+       MPP9_TW0_SCK,
        MPP10_UART0_TXD,
        MPP11_UART0_RXD,
        MPP13_GPIO,             /* Rear power switch (on|auto) */
@@ -306,8 +306,8 @@ static unsigned int net5big_v2_mpp_config[] __initdata = {
        MPP3_SPI_MISO,
        MPP6_SYSRST_OUTn,
        MPP7_GPO,               /* Request power-off */
-       MPP8_TW_SDA,
-       MPP9_TW_SCK,
+       MPP8_TW0_SDA,
+       MPP9_TW0_SCK,
        MPP10_UART0_TXD,
        MPP11_UART0_RXD,
        MPP13_GPIO,             /* Rear power switch (on|auto) */
@@ -315,20 +315,20 @@ static unsigned int net5big_v2_mpp_config[] __initdata = {
        MPP15_GPIO,             /* Rear power switch (auto|off) */
        MPP16_GPIO,             /* SATA HDD1 power */
        MPP17_GPIO,             /* SATA HDD2 power */
-       MPP20_GE1_0,
-       MPP21_GE1_1,
-       MPP22_GE1_2,
-       MPP23_GE1_3,
-       MPP24_GE1_4,
-       MPP25_GE1_5,
-       MPP26_GE1_6,
-       MPP27_GE1_7,
+       MPP20_GE1_TXD0,
+       MPP21_GE1_TXD1,
+       MPP22_GE1_TXD2,
+       MPP23_GE1_TXD3,
+       MPP24_GE1_RXD0,
+       MPP25_GE1_RXD1,
+       MPP26_GE1_RXD2,
+       MPP27_GE1_RXD3,
        MPP28_GPIO,             /* USB enable host vbus */
        MPP29_GPIO,             /* CPLD extension ALE */
-       MPP30_GE1_10,
-       MPP31_GE1_11,
-       MPP32_GE1_12,
-       MPP33_GE1_13,
+       MPP30_GE1_RXCTL,
+       MPP31_GE1_RXCLK,
+       MPP32_GE1_TCLKOUT,
+       MPP33_GE1_TXCTL,
        MPP34_GPIO,             /* Rear Push button */
        MPP35_GPIO,             /* Inhibit switch power-off */
        MPP36_GPIO,             /* SATA HDD1 presence */
index ad3f1ec3379689556296ef1ccf3b425c07f8007a..fd64cd2b4e0ad0cd8780ef33f25f5821407d49c8 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * arch/arm/mach-kirkwood/openrd-setup.c
  *
- * Marvell OpenRD (Base|Client) Board Setup
+ * Marvell OpenRD (Base|Client|Ultimate) Board Setup
  *
  * This file is licensed under the terms of the GNU General Public
  * License version 2.  This program is licensed "as is" without any
@@ -73,9 +73,15 @@ static void __init openrd_init(void)
 
        kirkwood_ehci_init();
 
+       if (machine_is_openrd_ultimate()) {
+               openrd_ge00_data.phy_addr = MV643XX_ETH_PHY_ADDR(0);
+               openrd_ge01_data.phy_addr = MV643XX_ETH_PHY_ADDR(1);
+       }
+
        kirkwood_ge00_init(&openrd_ge00_data);
-       if (machine_is_openrd_client())
+       if (!machine_is_openrd_base())
                kirkwood_ge01_init(&openrd_ge01_data);
+
        kirkwood_sata_init(&openrd_sata_data);
        kirkwood_sdio_init(&openrd_mvsdio_data);
 
@@ -84,8 +90,10 @@ static void __init openrd_init(void)
 
 static int __init openrd_pci_init(void)
 {
-       if (machine_is_openrd_base() || machine_is_openrd_client())
-               kirkwood_pcie_init();
+       if (machine_is_openrd_base() ||
+           machine_is_openrd_client() ||
+           machine_is_openrd_ultimate())
+               kirkwood_pcie_init(KW_PCIE0);
 
        return 0;
 }
@@ -116,3 +124,16 @@ MACHINE_START(OPENRD_CLIENT, "Marvell OpenRD Client Board")
        .timer          = &kirkwood_timer,
 MACHINE_END
 #endif
+
+#ifdef CONFIG_MACH_OPENRD_ULTIMATE
+MACHINE_START(OPENRD_ULTIMATE, "Marvell OpenRD Ultimate Board")
+       /* Maintainer: Dhaval Vasa <dhaval.vasa@einfochips.com> */
+       .phys_io        = KIRKWOOD_REGS_PHYS_BASE,
+       .io_pg_offst    = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = openrd_init,
+       .map_io         = kirkwood_map_io,
+       .init_irq       = kirkwood_init_irq,
+       .timer          = &kirkwood_timer,
+MACHINE_END
+#endif
index dee1eff50d3933d2252a2f66aed2f1d7456d69c3..55e7f00836b7cdba68a9662729119e977904a2dd 100644 (file)
 #include <mach/bridge-regs.h>
 #include "common.h"
 
+void __init kirkwood_pcie_id(u32 *dev, u32 *rev)
+{
+       *dev = orion_pcie_dev_id((void __iomem *)PCIE_VIRT_BASE);
+       *rev = orion_pcie_rev((void __iomem *)PCIE_VIRT_BASE);
+}
 
-#define PCIE_BASE      ((void __iomem *)PCIE_VIRT_BASE)
+struct pcie_port {
+       u8                      root_bus_nr;
+       void __iomem            *base;
+       spinlock_t              conf_lock;
+       int                     irq;
+       struct resource         res[2];
+};
 
-void __init kirkwood_pcie_id(u32 *dev, u32 *rev)
+static int pcie_port_map[2];
+static int num_pcie_ports;
+
+static inline struct pcie_port *bus_to_port(struct pci_bus *bus)
 {
-       *dev = orion_pcie_dev_id(PCIE_BASE);
-       *rev = orion_pcie_rev(PCIE_BASE);
+       struct pci_sys_data *sys = bus->sysdata;
+       return sys->private_data;
 }
 
-static int pcie_valid_config(int bus, int dev)
+static int pcie_valid_config(struct pcie_port *pp, int bus, int dev)
 {
        /*
         * Don't go out when trying to access --
         * 1. nonexisting device on local bus
         * 2. where there's no device connected (no link)
         */
-       if (bus == 0 && dev == 0)
+       if (bus == pp->root_bus_nr && dev == 0)
                return 1;
 
-       if (!orion_pcie_link_up(PCIE_BASE))
+       if (!orion_pcie_link_up(pp->base))
                return 0;
 
-       if (bus == 0 && dev != 1)
+       if (bus == pp->root_bus_nr && dev != 1)
                return 0;
 
        return 1;
@@ -52,22 +66,22 @@ static int pcie_valid_config(int bus, int dev)
  * and then reading the PCIE_CONF_DATA register. Need to make sure these
  * transactions are atomic.
  */
-static DEFINE_SPINLOCK(kirkwood_pcie_lock);
 
 static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
                        int size, u32 *val)
 {
+       struct pcie_port *pp = bus_to_port(bus);
        unsigned long flags;
        int ret;
 
-       if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0) {
+       if (pcie_valid_config(pp, bus->number, PCI_SLOT(devfn)) == 0) {
                *val = 0xffffffff;
                return PCIBIOS_DEVICE_NOT_FOUND;
        }
 
-       spin_lock_irqsave(&kirkwood_pcie_lock, flags);
-       ret = orion_pcie_rd_conf(PCIE_BASE, bus, devfn, where, size, val);
-       spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
+       spin_lock_irqsave(&pp->conf_lock, flags);
+       ret = orion_pcie_rd_conf(pp->base, bus, devfn, where, size, val);
+       spin_unlock_irqrestore(&pp->conf_lock, flags);
 
        return ret;
 }
@@ -75,15 +89,16 @@ static int pcie_rd_conf(struct pci_bus *bus, u32 devfn, int where,
 static int pcie_wr_conf(struct pci_bus *bus, u32 devfn,
                        int where, int size, u32 val)
 {
+       struct pcie_port *pp = bus_to_port(bus);
        unsigned long flags;
        int ret;
 
-       if (pcie_valid_config(bus->number, PCI_SLOT(devfn)) == 0)
+       if (pcie_valid_config(pp, bus->number, PCI_SLOT(devfn)) == 0)
                return PCIBIOS_DEVICE_NOT_FOUND;
 
-       spin_lock_irqsave(&kirkwood_pcie_lock, flags);
-       ret = orion_pcie_wr_conf(PCIE_BASE, bus, devfn, where, size, val);
-       spin_unlock_irqrestore(&kirkwood_pcie_lock, flags);
+       spin_lock_irqsave(&pp->conf_lock, flags);
+       ret = orion_pcie_wr_conf(pp->base, bus, devfn, where, size, val);
+       spin_unlock_irqrestore(&pp->conf_lock, flags);
 
        return ret;
 }
@@ -93,50 +108,98 @@ static struct pci_ops pcie_ops = {
        .write = pcie_wr_conf,
 };
 
-
-static int __init kirkwood_pcie_setup(int nr, struct pci_sys_data *sys)
+static void __init pcie0_ioresources_init(struct pcie_port *pp)
 {
-       struct resource *res;
-       extern unsigned int kirkwood_clk_ctrl;
+       pp->base = (void __iomem *)PCIE_VIRT_BASE;
+       pp->irq = IRQ_KIRKWOOD_PCIE;
 
        /*
-        * Generic PCIe unit setup.
+        * IORESOURCE_IO
         */
-       orion_pcie_setup(PCIE_BASE, &kirkwood_mbus_dram_info);
+       pp->res[0].name = "PCIe 0 I/O Space";
+       pp->res[0].start = KIRKWOOD_PCIE_IO_PHYS_BASE;
+       pp->res[0].end = pp->res[0].start + KIRKWOOD_PCIE_IO_SIZE - 1;
+       pp->res[0].flags = IORESOURCE_IO;
 
        /*
-        * Request resources.
+        * IORESOURCE_MEM
         */
-       res = kzalloc(sizeof(struct resource) * 2, GFP_KERNEL);
-       if (!res)
-               panic("pcie_setup unable to alloc resources");
+       pp->res[1].name = "PCIe 0 MEM";
+       pp->res[1].start = KIRKWOOD_PCIE_MEM_PHYS_BASE;
+       pp->res[1].end = pp->res[1].start + KIRKWOOD_PCIE_MEM_SIZE - 1;
+       pp->res[1].flags = IORESOURCE_MEM;
+}
+
+static void __init pcie1_ioresources_init(struct pcie_port *pp)
+{
+       pp->base = (void __iomem *)PCIE1_VIRT_BASE;
+       pp->irq = IRQ_KIRKWOOD_PCIE1;
 
        /*
         * IORESOURCE_IO
         */
-       res[0].name = "PCIe I/O Space";
-       res[0].flags = IORESOURCE_IO;
-       res[0].start = KIRKWOOD_PCIE_IO_BUS_BASE;
-       res[0].end = res[0].start + KIRKWOOD_PCIE_IO_SIZE - 1;
-       if (request_resource(&ioport_resource, &res[0]))
-               panic("Request PCIe IO resource failed\n");
-       sys->resource[0] = &res[0];
+       pp->res[0].name = "PCIe 1 I/O Space";
+       pp->res[0].start = KIRKWOOD_PCIE1_IO_PHYS_BASE;
+       pp->res[0].end = pp->res[0].start + KIRKWOOD_PCIE1_IO_SIZE - 1;
+       pp->res[0].flags = IORESOURCE_IO;
 
        /*
         * IORESOURCE_MEM
         */
-       res[1].name = "PCIe Memory Space";
-       res[1].flags = IORESOURCE_MEM;
-       res[1].start = KIRKWOOD_PCIE_MEM_BUS_BASE;
-       res[1].end = res[1].start + KIRKWOOD_PCIE_MEM_SIZE - 1;
-       if (request_resource(&iomem_resource, &res[1]))
-               panic("Request PCIe Memory resource failed\n");
-       sys->resource[1] = &res[1];
+       pp->res[1].name = "PCIe 1 MEM";
+       pp->res[1].start = KIRKWOOD_PCIE1_MEM_PHYS_BASE;
+       pp->res[1].end = pp->res[1].start + KIRKWOOD_PCIE1_MEM_SIZE - 1;
+       pp->res[1].flags = IORESOURCE_MEM;
+}
+
+static int __init kirkwood_pcie_setup(int nr, struct pci_sys_data *sys)
+{
+       extern unsigned int kirkwood_clk_ctrl;
+       struct pcie_port *pp;
+       int index;
 
+       if (nr >= num_pcie_ports)
+               return 0;
+
+       index = pcie_port_map[nr];
+       printk(KERN_INFO "PCI: bus%d uses PCIe port %d\n", sys->busnr, index);
+
+       pp = kzalloc(sizeof(*pp), GFP_KERNEL);
+       if (!pp)
+               panic("PCIe: failed to allocate pcie_port data");
+       sys->private_data = pp;
+       pp->root_bus_nr = sys->busnr;
+       spin_lock_init(&pp->conf_lock);
+
+       switch (index) {
+       case 0:
+               kirkwood_clk_ctrl |= CGC_PEX0;
+               pcie0_ioresources_init(pp);
+               break;
+       case 1:
+               kirkwood_clk_ctrl |= CGC_PEX1;
+               pcie1_ioresources_init(pp);
+               break;
+       default:
+               panic("PCIe setup: invalid controller %d", index);
+       }
+
+       if (request_resource(&ioport_resource, &pp->res[0]))
+               panic("Request PCIe%d IO resource failed\n", index);
+       if (request_resource(&iomem_resource, &pp->res[1]))
+               panic("Request PCIe%d Memory resource failed\n", index);
+
+       sys->resource[0] = &pp->res[0];
+       sys->resource[1] = &pp->res[1];
        sys->resource[2] = NULL;
        sys->io_offset = 0;
 
-       kirkwood_clk_ctrl |= CGC_PEX0;
+       /*
+        * Generic PCIe unit setup.
+        */
+       orion_pcie_set_local_bus_nr(pp->base, sys->busnr);
+
+       orion_pcie_setup(pp->base, &kirkwood_mbus_dram_info);
 
        return 1;
 }
@@ -163,7 +226,7 @@ kirkwood_pcie_scan_bus(int nr, struct pci_sys_data *sys)
 {
        struct pci_bus *bus;
 
-       if (nr == 0) {
+       if (nr < num_pcie_ports) {
                bus = pci_scan_bus(sys->busnr, &pcie_ops, sys);
        } else {
                bus = NULL;
@@ -175,18 +238,37 @@ kirkwood_pcie_scan_bus(int nr, struct pci_sys_data *sys)
 
 static int __init kirkwood_pcie_map_irq(struct pci_dev *dev, u8 slot, u8 pin)
 {
-       return IRQ_KIRKWOOD_PCIE;
+       struct pcie_port *pp = bus_to_port(dev->bus);
+
+       return pp->irq;
 }
 
 static struct hw_pci kirkwood_pci __initdata = {
-       .nr_controllers = 1,
        .swizzle        = pci_std_swizzle,
        .setup          = kirkwood_pcie_setup,
        .scan           = kirkwood_pcie_scan_bus,
        .map_irq        = kirkwood_pcie_map_irq,
 };
 
-void __init kirkwood_pcie_init(void)
+static void __init add_pcie_port(int index, unsigned long base)
 {
+       printk(KERN_INFO "Kirkwood PCIe port %d: ", index);
+
+       if (orion_pcie_link_up((void __iomem *)base)) {
+               printk(KERN_INFO "link up\n");
+               pcie_port_map[num_pcie_ports++] = index;
+       } else
+               printk(KERN_INFO "link down, ignoring\n");
+}
+
+void __init kirkwood_pcie_init(unsigned int portmask)
+{
+       if (portmask & KW_PCIE0)
+               add_pcie_port(0, PCIE_VIRT_BASE);
+
+       if (portmask & KW_PCIE1)
+               add_pcie_port(1, PCIE1_VIRT_BASE);
+
+       kirkwood_pci.nr_controllers = num_pcie_ports;
        pci_common_init(&kirkwood_pci);
 }
index 3bf6304158f64354b410461c87d9ec0778ba26cf..c34718c2cfe511373df10338e28c399a092c7744 100644 (file)
@@ -71,7 +71,7 @@ static void __init rd88f6192_init(void)
 static int __init rd88f6192_pci_init(void)
 {
        if (machine_is_rd88f6192_nas())
-               kirkwood_pcie_init();
+               kirkwood_pcie_init(KW_PCIE0);
 
        return 0;
 }
index 31708ddbc83e13d5d97b31bdbaf3c13eeb735c1a..3d1477135e12d8fb0edacb8067304a18f04bc111 100644 (file)
@@ -107,7 +107,7 @@ static void __init rd88f6281_init(void)
 static int __init rd88f6281_pci_init(void)
 {
        if (machine_is_rd88f6281())
-               kirkwood_pcie_init();
+               kirkwood_pcie_init(KW_PCIE0);
 
        return 0;
 }
diff --git a/arch/arm/mach-kirkwood/t5325-setup.c b/arch/arm/mach-kirkwood/t5325-setup.c
new file mode 100644 (file)
index 0000000..d01bf89
--- /dev/null
@@ -0,0 +1,194 @@
+/*
+ *
+ * HP t5325 Thin Client setup
+ *
+ * Copyright (C) 2010  Martin Michlmayr <tbm@cyrius.com>
+ *
+ * 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 <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/mtd/physmap.h>
+#include <linux/spi/flash.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/orion_spi.h>
+#include <linux/i2c.h>
+#include <linux/mv643xx_eth.h>
+#include <linux/ata_platform.h>
+#include <linux/gpio.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <mach/kirkwood.h>
+#include "common.h"
+#include "mpp.h"
+
+struct mtd_partition hp_t5325_partitions[] = {
+       {
+               .name           = "u-boot env",
+               .size           = SZ_64K,
+               .offset         = SZ_512K + SZ_256K,
+       },
+       {
+               .name           = "permanent u-boot env",
+               .size           = SZ_64K,
+               .offset         = MTDPART_OFS_APPEND,
+               .mask_flags     = MTD_WRITEABLE,
+       },
+       {
+               .name           = "HP env",
+               .size           = SZ_64K,
+               .offset         = MTDPART_OFS_APPEND,
+       },
+       {
+               .name           = "u-boot",
+               .size           = SZ_512K,
+               .offset         = 0,
+               .mask_flags     = MTD_WRITEABLE,
+       },
+       {
+               .name           = "SSD firmware",
+               .size           = SZ_256K,
+               .offset         = SZ_512K,
+       },
+};
+
+const struct flash_platform_data hp_t5325_flash = {
+       .type           = "mx25l8005",
+       .name           = "spi_flash",
+       .parts          = hp_t5325_partitions,
+       .nr_parts       = ARRAY_SIZE(hp_t5325_partitions),
+};
+
+struct spi_board_info __initdata hp_t5325_spi_slave_info[] = {
+       {
+               .modalias       = "m25p80",
+               .platform_data  = &hp_t5325_flash,
+               .irq            = -1,
+       },
+};
+
+static struct mv643xx_eth_platform_data hp_t5325_ge00_data = {
+       .phy_addr       = MV643XX_ETH_PHY_ADDR(8),
+};
+
+static struct mv_sata_platform_data hp_t5325_sata_data = {
+       .n_ports        = 2,
+};
+
+static struct gpio_keys_button hp_t5325_buttons[] = {
+       {
+               .code           = KEY_POWER,
+               .gpio           = 45,
+               .desc           = "Power",
+               .active_low     = 1,
+       },
+};
+
+static struct gpio_keys_platform_data hp_t5325_button_data = {
+       .buttons        = hp_t5325_buttons,
+       .nbuttons       = ARRAY_SIZE(hp_t5325_buttons),
+};
+
+static struct platform_device hp_t5325_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &hp_t5325_button_data,
+       }
+};
+
+static unsigned int hp_t5325_mpp_config[] __initdata = {
+       MPP0_NF_IO2,
+       MPP1_SPI_MOSI,
+       MPP2_SPI_SCK,
+       MPP3_SPI_MISO,
+       MPP4_NF_IO6,
+       MPP5_NF_IO7,
+       MPP6_SYSRST_OUTn,
+       MPP7_SPI_SCn,
+       MPP8_TW0_SDA,
+       MPP9_TW0_SCK,
+       MPP10_UART0_TXD,
+       MPP11_UART0_RXD,
+       MPP12_SD_CLK,
+       MPP13_GPIO,
+       MPP14_GPIO,
+       MPP15_GPIO,
+       MPP16_GPIO,
+       MPP17_GPIO,
+       MPP18_NF_IO0,
+       MPP19_NF_IO1,
+       MPP20_GPIO,
+       MPP21_GPIO,
+       MPP22_GPIO,
+       MPP23_GPIO,
+       MPP32_GPIO,
+       MPP33_GE1_TXCTL,
+       MPP39_AU_I2SBCLK,
+       MPP40_AU_I2SDO,
+       MPP41_AU_I2SLRCLK,
+       MPP42_AU_I2SMCLK,
+       MPP45_GPIO,             /* Power button */
+       MPP48_GPIO,             /* Board power off */
+       0
+};
+
+#define HP_T5325_GPIO_POWER_OFF                48
+
+static void hp_t5325_power_off(void)
+{
+       gpio_set_value(HP_T5325_GPIO_POWER_OFF, 1);
+}
+
+static void __init hp_t5325_init(void)
+{
+       /*
+        * Basic setup. Needs to be called early.
+        */
+       kirkwood_init();
+       kirkwood_mpp_conf(hp_t5325_mpp_config);
+
+       kirkwood_uart0_init();
+       spi_register_board_info(hp_t5325_spi_slave_info,
+                               ARRAY_SIZE(hp_t5325_spi_slave_info));
+       kirkwood_spi_init();
+       kirkwood_i2c_init();
+       kirkwood_ge00_init(&hp_t5325_ge00_data);
+       kirkwood_sata_init(&hp_t5325_sata_data);
+       kirkwood_ehci_init();
+       platform_device_register(&hp_t5325_button_device);
+
+       if (gpio_request(HP_T5325_GPIO_POWER_OFF, "power-off") == 0 &&
+           gpio_direction_output(HP_T5325_GPIO_POWER_OFF, 0) == 0)
+               pm_power_off = hp_t5325_power_off;
+       else
+               pr_err("t5325: failed to configure power-off GPIO\n");
+}
+
+static int __init hp_t5325_pci_init(void)
+{
+       if (machine_is_t5325())
+               kirkwood_pcie_init(KW_PCIE0);
+
+       return 0;
+}
+subsys_initcall(hp_t5325_pci_init);
+
+MACHINE_START(T5325, "HP t5325 Thin Client")
+       /* Maintainer: Martin Michlmayr <tbm@cyrius.com> */
+       .phys_io        = KIRKWOOD_REGS_PHYS_BASE,
+       .io_pg_offst    = ((KIRKWOOD_REGS_VIRT_BASE) >> 18) & 0xfffc,
+       .boot_params    = 0x00000100,
+       .init_machine   = hp_t5325_init,
+       .map_io         = kirkwood_map_io,
+       .init_irq       = kirkwood_init_irq,
+       .timer          = &kirkwood_timer,
+MACHINE_END
index 2830f0fe80e09d0b37c14a9589972a012cc733b2..a5bd7fde04a9429068f856070225cf816b96bb56 100644 (file)
@@ -74,8 +74,8 @@ static unsigned int qnap_ts219_mpp_config[] __initdata = {
        MPP3_SPI_MISO,
        MPP4_SATA1_ACTn,
        MPP5_SATA0_ACTn,
-       MPP8_TW_SDA,
-       MPP9_TW_SCK,
+       MPP8_TW0_SDA,
+       MPP9_TW0_SCK,
        MPP10_UART0_TXD,
        MPP11_UART0_RXD,
        MPP13_UART1_TXD,        /* PIC controller */
@@ -83,6 +83,7 @@ static unsigned int qnap_ts219_mpp_config[] __initdata = {
        MPP15_GPIO,             /* USB Copy button */
        MPP16_GPIO,             /* Reset button */
        MPP36_GPIO,             /* RAM: 0: 256 MB, 1: 512 MB */
+       MPP44_GPIO,             /* Board ID: 0: TS-11x, 1: TS-21x */
        0
 };
 
@@ -110,10 +111,10 @@ static void __init qnap_ts219_init(void)
 
 static int __init ts219_pci_init(void)
 {
-   if (machine_is_ts219())
-           kirkwood_pcie_init();
+       if (machine_is_ts219())
+               kirkwood_pcie_init(KW_PCIE0);
 
-   return 0;
+       return 0;
 }
 subsys_initcall(ts219_pci_init);
 
index de49c2d9e74b0b262072721630aeac92f6a57e7a..2e14afef07a2ace0708e144b98bf4ef1f2a446b1 100644 (file)
@@ -2,7 +2,7 @@
  *
  * QNAP TS-410, TS-410U, TS-419P and TS-419U Turbo NAS Board Setup
  *
- * Copyright (C) 2009  Martin Michlmayr <tbm@cyrius.com>
+ * Copyright (C) 2009-2010  Martin Michlmayr <tbm@cyrius.com>
  * Copyright (C) 2008  Byron Bradley <byron.bbradley@gmail.com>
  *
  * This program is free software; you can redistribute it and/or
@@ -17,6 +17,7 @@
 #include <linux/i2c.h>
 #include <linux/mv643xx_eth.h>
 #include <linux/ata_platform.h>
+#include <linux/gpio.h>
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
 #include <asm/mach-types.h>
@@ -26,6 +27,8 @@
 #include "mpp.h"
 #include "tsx1x-common.h"
 
+#define QNAP_TS41X_JUMPER_JP1  45
+
 static struct i2c_board_info __initdata qnap_ts41x_i2c_rtc = {
        I2C_BOARD_INFO("s35390a", 0x30),
 };
@@ -78,31 +81,31 @@ static unsigned int qnap_ts41x_mpp_config[] __initdata = {
        MPP3_SPI_MISO,
        MPP6_SYSRST_OUTn,
        MPP7_PEX_RST_OUTn,
-       MPP8_TW_SDA,
-       MPP9_TW_SCK,
+       MPP8_TW0_SDA,
+       MPP9_TW0_SCK,
        MPP10_UART0_TXD,
        MPP11_UART0_RXD,
        MPP13_UART1_TXD,        /* PIC controller */
        MPP14_UART1_RXD,        /* PIC controller */
        MPP15_SATA0_ACTn,
        MPP16_SATA1_ACTn,
-       MPP20_GE1_0,
-       MPP21_GE1_1,
-       MPP22_GE1_2,
-       MPP23_GE1_3,
-       MPP24_GE1_4,
-       MPP25_GE1_5,
-       MPP26_GE1_6,
-       MPP27_GE1_7,
-       MPP30_GE1_10,
-       MPP31_GE1_11,
-       MPP32_GE1_12,
-       MPP33_GE1_13,
+       MPP20_GE1_TXD0,
+       MPP21_GE1_TXD1,
+       MPP22_GE1_TXD2,
+       MPP23_GE1_TXD3,
+       MPP24_GE1_RXD0,
+       MPP25_GE1_RXD1,
+       MPP26_GE1_RXD2,
+       MPP27_GE1_RXD3,
+       MPP30_GE1_RXCTL,
+       MPP31_GE1_RXCLK,
+       MPP32_GE1_TCLKOUT,
+       MPP33_GE1_TXCTL,
        MPP36_GPIO,             /* RAM: 0: 256 MB, 1: 512 MB */
        MPP37_GPIO,             /* Reset button */
        MPP43_GPIO,             /* USB Copy button */
        MPP44_GPIO,             /* Board ID: 0: TS-419U, 1: TS-419 */
-       MPP45_GPIO,             /* JP1: 0: console, 1: LCD */
+       MPP45_GPIO,             /* JP1: 0: LCD, 1: serial console */
        MPP46_GPIO,             /* External SATA HDD1 error indicator */
        MPP47_GPIO,             /* External SATA HDD2 error indicator */
        MPP48_GPIO,             /* External SATA HDD3 error indicator */
@@ -131,12 +134,14 @@ static void __init qnap_ts41x_init(void)
 
        pm_power_off = qnap_tsx1x_power_off;
 
+       if (gpio_request(QNAP_TS41X_JUMPER_JP1, "JP1") == 0)
+               gpio_export(QNAP_TS41X_JUMPER_JP1, 0);
 }
 
 static int __init ts41x_pci_init(void)
 {
        if (machine_is_ts41x())
-               kirkwood_pcie_init();
+               kirkwood_pcie_init(KW_PCIE0);
 
    return 0;
 }
index 78499667eb7b3241c3a5c1dfbbc69df4840a3991..5fcd082a17f9bff9b0d8a0818b199ebffd5833d2 100644 (file)
@@ -268,8 +268,8 @@ static void __init ks8695_pci_preinit(void)
        __raw_writel(0, KS8695_PCI_VA + KS8695_PIOBAC);
 
        /* hook in fault handlers */
-       hook_fault_code(8, ks8695_pci_fault, SIGBUS, "external abort on non-linefetch");
-       hook_fault_code(10, ks8695_pci_fault, SIGBUS, "external abort on non-linefetch");
+       hook_fault_code(8, ks8695_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
+       hook_fault_code(10, ks8695_pci_fault, SIGBUS, 0, "external abort on non-linefetch");
 }
 
 static void ks8695_show_pciregs(void)
diff --git a/arch/arm/mach-l7200/Makefile b/arch/arm/mach-l7200/Makefile
deleted file mode 100644 (file)
index 4bd8ebd..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-#
-# Makefile for the linux kernel.
-#
-
-# Object file lists.
-
-obj-y                  := core.o
-obj-m                  :=
-obj-n                  :=
-obj-                   :=
-
diff --git a/arch/arm/mach-l7200/Makefile.boot b/arch/arm/mach-l7200/Makefile.boot
deleted file mode 100644 (file)
index 6c72ecb..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-   zreladdr-y  := 0xf0008000
-
diff --git a/arch/arm/mach-l7200/core.c b/arch/arm/mach-l7200/core.c
deleted file mode 100644 (file)
index 50d2324..0000000
+++ /dev/null
@@ -1,100 +0,0 @@
-/*
- *  linux/arch/arm/mm/mm-lusl7200.c
- *
- *  Copyright (C) 2000 Steve Hill (sjhill@cotw.com)
- *
- *  Extra MM routines for L7200 architecture
- */
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/irq.h>
-#include <linux/device.h>
-
-#include <asm/types.h>
-#include <asm/irq.h>
-#include <asm/mach-types.h>
-#include <mach/hardware.h>
-#include <asm/page.h>
-
-#include <asm/mach/arch.h>
-#include <asm/mach/map.h>
-#include <asm/mach/irq.h>
-
-/*
- * IRQ base register
- */
-#define        IRQ_BASE        (IO_BASE_2 + 0x1000)
-
-/* 
- * Normal IRQ registers
- */
-#define IRQ_STATUS     (*(volatile unsigned long *) (IRQ_BASE + 0x000))
-#define IRQ_RAWSTATUS  (*(volatile unsigned long *) (IRQ_BASE + 0x004))
-#define IRQ_ENABLE     (*(volatile unsigned long *) (IRQ_BASE + 0x008))
-#define IRQ_ENABLECLEAR        (*(volatile unsigned long *) (IRQ_BASE + 0x00c))
-#define IRQ_SOFT       (*(volatile unsigned long *) (IRQ_BASE + 0x010))
-#define IRQ_SOURCESEL  (*(volatile unsigned long *) (IRQ_BASE + 0x018))
-
-/* 
- * Fast IRQ registers
- */
-#define FIQ_STATUS     (*(volatile unsigned long *) (IRQ_BASE + 0x100))
-#define FIQ_RAWSTATUS  (*(volatile unsigned long *) (IRQ_BASE + 0x104))
-#define FIQ_ENABLE     (*(volatile unsigned long *) (IRQ_BASE + 0x108))
-#define FIQ_ENABLECLEAR        (*(volatile unsigned long *) (IRQ_BASE + 0x10c))
-#define FIQ_SOFT       (*(volatile unsigned long *) (IRQ_BASE + 0x110))
-#define FIQ_SOURCESEL  (*(volatile unsigned long *) (IRQ_BASE + 0x118))
-
-static void l7200_mask_irq(unsigned int irq)
-{
-       IRQ_ENABLECLEAR = 1 << irq;
-}
-
-static void l7200_unmask_irq(unsigned int irq)
-{
-       IRQ_ENABLE = 1 << irq;
-}
-
-static struct irq_chip l7200_irq_chip = {
-       .ack            = l7200_mask_irq,
-       .mask           = l7200_mask_irq,
-       .unmask         = l7200_unmask_irq
-};
-static void __init l7200_init_irq(void)
-{
-       int irq;
-
-       IRQ_ENABLECLEAR = 0xffffffff;   /* clear all interrupt enables */
-       FIQ_ENABLECLEAR = 0xffffffff;   /* clear all fast interrupt enables */
-
-       for (irq = 0; irq < NR_IRQS; irq++) {
-               set_irq_chip(irq, &l7200_irq_chip);
-               set_irq_flags(irq, IRQF_VALID);
-               set_irq_handler(irq, handle_level_irq);
-       }
-
-       init_FIQ();
-}
-
-static struct map_desc l7200_io_desc[] __initdata = {
-       { IO_BASE,      IO_START,       IO_SIZE,        MT_DEVICE },
-       { IO_BASE_2,    IO_START_2,     IO_SIZE_2,      MT_DEVICE },
-       { AUX_BASE,     AUX_START,      AUX_SIZE,       MT_DEVICE },
-       { FLASH1_BASE,  FLASH1_START,   FLASH1_SIZE,    MT_DEVICE },
-       { FLASH2_BASE,  FLASH2_START,   FLASH2_SIZE,    MT_DEVICE }
-};
-
-static void __init l7200_map_io(void)
-{
-       iotable_init(l7200_io_desc, ARRAY_SIZE(l7200_io_desc));
-}
-
-MACHINE_START(L7200, "LinkUp Systems L7200")
-       /* Maintainer: Steve Hill / Scott McConnell */
-       .phys_io        = 0x80040000,
-       .io_pg_offst    = ((0xd0000000) >> 18) & 0xfffc,
-       .map_io         = l7200_map_io,
-       .init_irq       = l7200_init_irq,
-MACHINE_END
-
diff --git a/arch/arm/mach-l7200/include/mach/aux_reg.h b/arch/arm/mach-l7200/include/mach/aux_reg.h
deleted file mode 100644 (file)
index 4671558..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/aux_reg.h
- *
- * Copyright (C) 2000 Steve Hill (sjhill@cotw.com)
- *
- * Changelog:
- *   08-02-2000        SJH     Created file
- */
-#ifndef _ASM_ARCH_AUXREG_H
-#define _ASM_ARCH_AUXREG_H
-
-#include <mach/hardware.h>
-
-#define l7200aux_reg   *((volatile unsigned int *) (AUX_BASE))
-
-/*
- * Auxillary register values
- */
-#define AUX_CLEAR              0x00000000
-#define AUX_DIAG_LED_ON                0x00000002
-#define AUX_RTS_UART1          0x00000004
-#define AUX_DTR_UART1          0x00000008
-#define AUX_KBD_COLUMN_12_HIGH 0x00000010
-#define AUX_KBD_COLUMN_12_OFF  0x00000020
-#define AUX_KBD_COLUMN_13_HIGH 0x00000040
-#define AUX_KBD_COLUMN_13_OFF  0x00000080
-
-#endif
diff --git a/arch/arm/mach-l7200/include/mach/debug-macro.S b/arch/arm/mach-l7200/include/mach/debug-macro.S
deleted file mode 100644 (file)
index b69ed34..0000000
+++ /dev/null
@@ -1,40 +0,0 @@
-/* arch/arm/mach-l7200/include/mach/debug-macro.S
- *
- * Debugging macro include header
- *
- *  Copyright (C) 1994-1999 Russell King
- *  Moved from linux/arch/arm/kernel/debug.S by Ben Dooks
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
-*/
-
-               .equ    io_virt, IO_BASE
-               .equ    io_phys, IO_START
-
-               .macro  addruart, rx, tmp
-               mrc     p15, 0, \rx, c1, c0
-               tst     \rx, #1                 @ MMU enabled?
-               moveq   \rx, #io_phys           @ physical base address
-               movne   \rx, #io_virt           @ virtual address
-               add     \rx, \rx, #0x00044000   @ UART1
-@              add     \rx, \rx, #0x00045000   @ UART2
-               .endm
-
-               .macro  senduart,rd,rx
-               str     \rd, [\rx, #0x0]        @ UARTDR
-               .endm
-
-               .macro  waituart,rd,rx
-1001:          ldr     \rd, [\rx, #0x18]       @ UARTFLG
-               tst     \rd, #1 << 5            @ UARTFLGUTXFF - 1 when full
-               bne     1001b
-               .endm
-
-               .macro  busyuart,rd,rx
-1001:          ldr     \rd, [\rx, #0x18]       @ UARTFLG
-               tst     \rd, #1 << 3            @ UARTFLGUBUSY - 1 when busy
-               bne     1001b
-               .endm
diff --git a/arch/arm/mach-l7200/include/mach/entry-macro.S b/arch/arm/mach-l7200/include/mach/entry-macro.S
deleted file mode 100644 (file)
index 1726d91..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/entry-macro.S
- *
- * Low-level IRQ helper macros for L7200-based platforms
- *
- * This file is licensed under  the terms of the GNU General Public
- * License version 2. This program is licensed "as is" without any
- * warranty of any kind, whether express or implied.
- */
-#include <mach/hardware.h>
-
-               .equ    irq_base_addr,  IO_BASE_2
-
-               .macro  disable_fiq
-               .endm
-
-               .macro  get_irqnr_preamble, base, tmp
-               .endm
-
-               .macro  arch_ret_to_user, tmp1, tmp2
-               .endm
-
-               .macro  get_irqnr_and_base, irqnr, irqstat, base, tmp
-               mov     \irqstat, #irq_base_addr                @ Virt addr IRQ regs
-               add     \irqstat, \irqstat, #0x00001000         @ Status reg
-               ldr     \irqstat, [\irqstat, #0]                @ get interrupts
-               mov     \irqnr, #0
-1001:          tst     \irqstat, #1
-               addeq   \irqnr, \irqnr, #1
-               moveq   \irqstat, \irqstat, lsr #1
-               tsteq   \irqnr, #32
-               beq     1001b
-               teq     \irqnr, #32
-               .endm
-
diff --git a/arch/arm/mach-l7200/include/mach/gp_timers.h b/arch/arm/mach-l7200/include/mach/gp_timers.h
deleted file mode 100644 (file)
index 2b7086a..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/gp_timers.h
- *
- * Copyright (C) 2000 Steve Hill (sjhill@cotw.com)
- *
- * Changelog:
- *   07-28-2000        SJH     Created file
- *   08-02-2000        SJH     Used structure for registers
- */
-#ifndef _ASM_ARCH_GPTIMERS_H
-#define _ASM_ARCH_GPTIMERS_H
-
-#include <mach/hardware.h>
-
-/*
- * Layout of L7200 general purpose timer registers
- */
-struct GPT_Regs {
-       unsigned int TIMERLOAD;
-       unsigned int TIMERVALUE;
-       unsigned int TIMERCONTROL;
-       unsigned int TIMERCLEAR;
-};
-
-#define GPT_BASE               (IO_BASE_2 + 0x3000)
-#define l7200_timer1_regs      ((volatile struct GPT_Regs *) (GPT_BASE))
-#define l7200_timer2_regs      ((volatile struct GPT_Regs *) (GPT_BASE + 0x20))
-
-/*
- * General register values
- */
-#define        GPT_PRESCALE_1          0x00000000
-#define        GPT_PRESCALE_16         0x00000004
-#define        GPT_PRESCALE_256        0x00000008
-#define GPT_MODE_FREERUN       0x00000000
-#define GPT_MODE_PERIODIC      0x00000040
-#define GPT_ENABLE             0x00000080
-#define GPT_BZTOG              0x00000100
-#define GPT_BZMOD              0x00000200
-#define GPT_LOAD_MASK          0x0000ffff
-
-#endif
diff --git a/arch/arm/mach-l7200/include/mach/gpio.h b/arch/arm/mach-l7200/include/mach/gpio.h
deleted file mode 100644 (file)
index c7b0a5d..0000000
+++ /dev/null
@@ -1,105 +0,0 @@
-/****************************************************************************/
-/*
- *      arch/arm/mach-l7200/include/mach/gpio.h
- *
- *      Registers and  helper functions for the L7200 Link-Up Systems
- *      GPIO.
- *
- *      (C) Copyright 2000, S A McConnell  (samcconn@cotw.com)
- *
- *  This file is subject to the terms and conditions of the GNU General Public
- *  License. See the file COPYING in the main directory of this archive for
- *  more details.
- */
-
-/****************************************************************************/
-
-#define GPIO_OFF   0x00005000  /* Offset from IO_START to the GPIO reg's. */
-
-/* IO_START and IO_BASE are defined in hardware.h */
-
-#define GPIO_START (IO_START_2 + GPIO_OFF) /* Physical addr of the GPIO reg. */
-#define GPIO_BASE  (IO_BASE_2  + GPIO_OFF) /* Virtual addr of the GPIO reg. */
-
-/* Offsets from the start of the GPIO for all the registers. */
-#define PADR_OFF     0x000
-#define PADDR_OFF    0x004
-#define PASBSR_OFF   0x008
-#define PAEENR_OFF   0x00c
-#define PAESNR_OFF   0x010
-#define PAESTR_OFF   0x014
-#define PAIMR_OFF    0x018
-#define PAINT_OFF    0x01c
-
-#define PBDR_OFF     0x020
-#define PBDDR_OFF    0x024
-#define PBSBSR_OFF   0x028
-#define PBIMR_OFF    0x038
-#define PBINT_OFF    0x03c
-
-#define PCDR_OFF     0x040
-#define PCDDR_OFF    0x044
-#define PCSBSR_OFF   0x048
-#define PCIMR_OFF    0x058
-#define PCINT_OFF    0x05c
-
-#define PDDR_OFF     0x060
-#define PDDDR_OFF    0x064
-#define PDSBSR_OFF   0x068
-#define PDEENR_OFF   0x06c
-#define PDESNR_OFF   0x070
-#define PDESTR_OFF   0x074
-#define PDIMR_OFF    0x078
-#define PDINT_OFF    0x07c
-
-#define PEDR_OFF     0x080
-#define PEDDR_OFF    0x084
-#define PESBSR_OFF   0x088
-#define PEEENR_OFF   0x08c
-#define PEESNR_OFF   0x090
-#define PEESTR_OFF   0x094
-#define PEIMR_OFF    0x098
-#define PEINT_OFF    0x09c
-
-/* Define the GPIO registers for use by device drivers and the kernel. */
-#define PADR   (*(volatile unsigned long *)(GPIO_BASE+PADR_OFF))
-#define PADDR  (*(volatile unsigned long *)(GPIO_BASE+PADDR_OFF))
-#define PASBSR (*(volatile unsigned long *)(GPIO_BASE+PASBSR_OFF))
-#define PAEENR (*(volatile unsigned long *)(GPIO_BASE+PAEENR_OFF))
-#define PAESNR (*(volatile unsigned long *)(GPIO_BASE+PAESNR_OFF))
-#define PAESTR (*(volatile unsigned long *)(GPIO_BASE+PAESTR_OFF))
-#define PAIMR  (*(volatile unsigned long *)(GPIO_BASE+PAIMR_OFF))
-#define PAINT  (*(volatile unsigned long *)(GPIO_BASE+PAINT_OFF))
-
-#define PBDR   (*(volatile unsigned long *)(GPIO_BASE+PBDR_OFF))
-#define PBDDR  (*(volatile unsigned long *)(GPIO_BASE+PBDDR_OFF))
-#define PBSBSR (*(volatile unsigned long *)(GPIO_BASE+PBSBSR_OFF))
-#define PBIMR  (*(volatile unsigned long *)(GPIO_BASE+PBIMR_OFF))
-#define PBINT  (*(volatile unsigned long *)(GPIO_BASE+PBINT_OFF))
-
-#define PCDR   (*(volatile unsigned long *)(GPIO_BASE+PCDR_OFF))
-#define PCDDR  (*(volatile unsigned long *)(GPIO_BASE+PCDDR_OFF))
-#define PCSBSR (*(volatile unsigned long *)(GPIO_BASE+PCSBSR_OFF))
-#define PCIMR  (*(volatile unsigned long *)(GPIO_BASE+PCIMR_OFF))
-#define PCINT  (*(volatile unsigned long *)(GPIO_BASE+PCINT_OFF))
-
-#define PDDR   (*(volatile unsigned long *)(GPIO_BASE+PDDR_OFF))
-#define PDDDR  (*(volatile unsigned long *)(GPIO_BASE+PDDDR_OFF))
-#define PDSBSR (*(volatile unsigned long *)(GPIO_BASE+PDSBSR_OFF))
-#define PDEENR (*(volatile unsigned long *)(GPIO_BASE+PDEENR_OFF))
-#define PDESNR (*(volatile unsigned long *)(GPIO_BASE+PDESNR_OFF))
-#define PDESTR (*(volatile unsigned long *)(GPIO_BASE+PDESTR_OFF))
-#define PDIMR  (*(volatile unsigned long *)(GPIO_BASE+PDIMR_OFF))
-#define PDINT  (*(volatile unsigned long *)(GPIO_BASE+PDINT_OFF))
-
-#define PEDR   (*(volatile unsigned long *)(GPIO_BASE+PEDR_OFF))
-#define PEDDR  (*(volatile unsigned long *)(GPIO_BASE+PEDDR_OFF))
-#define PESBSR (*(volatile unsigned long *)(GPIO_BASE+PESBSR_OFF))
-#define PEEENR (*(volatile unsigned long *)(GPIO_BASE+PEEENR_OFF))
-#define PEESNR (*(volatile unsigned long *)(GPIO_BASE+PEESNR_OFF))
-#define PEESTR (*(volatile unsigned long *)(GPIO_BASE+PEESTR_OFF))
-#define PEIMR  (*(volatile unsigned long *)(GPIO_BASE+PEIMR_OFF))
-#define PEINT  (*(volatile unsigned long *)(GPIO_BASE+PEINT_OFF))
-
-#define VEE_EN         0x02
-#define BACKLIGHT_EN   0x04
diff --git a/arch/arm/mach-l7200/include/mach/hardware.h b/arch/arm/mach-l7200/include/mach/hardware.h
deleted file mode 100644 (file)
index c31909c..0000000
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/hardware.h
- *
- * Copyright (C) 2000 Rob Scott (rscott@mtrob.fdns.net)
- *                    Steve Hill (sjhill@cotw.com)
- *
- * This file contains the hardware definitions for the 
- * LinkUp Systems L7200 SOC development board.
- *
- * Changelog:
- *   02-01-2000         RS     Created L7200 version, derived from rpc code
- *   03-21-2000        SJH     Cleaned up file
- *   04-21-2000         RS     Changed mapping of I/O in virtual space
- *   04-25-2000        SJH     Removed unused symbols and such
- *   05-05-2000        SJH     Complete rewrite
- *   07-31-2000        SJH     Added undocumented debug auxillary port to
- *                     get at last two columns for keyboard driver
- */
-#ifndef __ASM_ARCH_HARDWARE_H
-#define __ASM_ARCH_HARDWARE_H
-
-/* Hardware addresses of major areas.
- *  *_START is the physical address
- *  *_SIZE  is the size of the region
- *  *_BASE  is the virtual address
- */
-#define RAM_START              0xf0000000
-#define RAM_SIZE               0x02000000
-#define RAM_BASE               0xc0000000
-
-#define IO_START               0x80000000      /* I/O */
-#define IO_SIZE                        0x01000000
-#define IO_BASE                        0xd0000000
-
-#define IO_START_2             0x90000000      /* I/O */
-#define IO_SIZE_2              0x01000000
-#define IO_BASE_2              0xd1000000
-
-#define AUX_START              0x1a000000      /* AUX PORT */
-#define AUX_SIZE               0x01000000
-#define AUX_BASE               0xd2000000
-
-#define FLASH1_START           0x00000000      /* FLASH BANK 1 */
-#define FLASH1_SIZE            0x01000000
-#define FLASH1_BASE            0xd3000000
-
-#define FLASH2_START           0x10000000      /* FLASH BANK 2 */
-#define FLASH2_SIZE            0x01000000
-#define FLASH2_BASE            0xd4000000
-
-#define ISA_START              0x20000000      /* ISA */
-#define ISA_SIZE               0x20000000
-#define ISA_BASE               0xe0000000
-
-#define PCIO_BASE              IO_BASE
-
-#endif
diff --git a/arch/arm/mach-l7200/include/mach/io.h b/arch/arm/mach-l7200/include/mach/io.h
deleted file mode 100644 (file)
index a770a89..0000000
+++ /dev/null
@@ -1,21 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/io.h
- *
- * Copyright (C) 2000 Steve Hill (sjhill@cotw.com)
- *
- * Changelog:
- *  03-21-2000 SJH     Created from arch/arm/mach-nexuspci/include/mach/io.h
- *  08-31-2000 SJH     Added in IO functions necessary for new drivers
- */
-#ifndef __ASM_ARM_ARCH_IO_H
-#define __ASM_ARM_ARCH_IO_H
-
-#define IO_SPACE_LIMIT 0xffffffff
-
-/*
- * There are not real ISA nor PCI buses, so we fake it.
- */
-#define __io(a)                __typesafe_io(a)
-#define __mem_pci(a)   (a)
-
-#endif
diff --git a/arch/arm/mach-l7200/include/mach/irqs.h b/arch/arm/mach-l7200/include/mach/irqs.h
deleted file mode 100644 (file)
index 7edffd7..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/irqs.h
- *
- * Copyright (C) 2000 Rob Scott (rscott@mtrob.fdns.net)
- *                    Steve Hill (sjhill@cotw.com)
- *
- * Changelog:
- *   01-02-2000 RS     Create l7200 version
- *   03-28-2000 SJH    Removed unused interrupt
- *   07-28-2000 SJH    Added pseudo-keyboard interrupt
- */
-
-/*
- * NOTE: The second timer (Timer 2) is used as the keyboard
- *       interrupt when the keyboard driver is enabled.
- */
-
-#define NR_IRQS          32
-
-#define IRQ_STWDOG        0   /* Watchdog timer */
-#define IRQ_PROG          1   /* Programmable interrupt */
-#define IRQ_DEBUG_RX      2   /* Comm Rx debug */
-#define IRQ_DEBUG_TX      3   /* Comm Tx debug */
-#define IRQ_GCTC1         4   /* Timer 1 */
-#define IRQ_GCTC2         5   /* Timer 2 / Keyboard */
-#define IRQ_DMA           6   /* DMA controller */
-#define IRQ_CLCD          7   /* Color LCD controller */
-#define IRQ_SM_RX         8   /* Smart card */
-#define IRQ_SM_TX         9   /* Smart cart */
-#define IRQ_SM_RST       10   /* Smart card */
-#define IRQ_SIB          11   /* Serial Interface Bus */
-#define IRQ_MMC          12   /* MultiMediaCard */
-#define IRQ_SSP1         13   /* Synchronous Serial Port 1 */
-#define IRQ_SSP2         14   /* Synchronous Serial Port 1 */
-#define IRQ_SPI          15   /* SPI slave */
-#define IRQ_UART_1       16   /* UART 1 */
-#define IRQ_UART_2       17   /* UART 2 */
-#define IRQ_IRDA         18   /* IRDA */
-#define IRQ_RTC_TICK     19   /* Real Time Clock tick */
-#define IRQ_RTC_ALARM    20   /* Real Time Clock alarm */
-#define IRQ_GPIO         21   /* General Purpose IO */
-#define IRQ_GPIO_DMA     22   /* General Purpose IO, DMA */
-#define IRQ_M2M          23   /* Memory to memory DMA  */
-#define IRQ_RESERVED     24   /* RESERVED, don't use */
-#define IRQ_INTF         25   /* External active low interrupt */
-#define IRQ_INT0         26   /* External active low interrupt */
-#define IRQ_INT1         27   /* External active low interrupt */
-#define IRQ_INT2         28   /* External active low interrupt */
-#define IRQ_UCB1200      29   /* Interrupt generated by UCB1200*/
-#define IRQ_BAT_LO       30   /* Low batery or external power */
-#define IRQ_MEDIA_CHG    31   /* Media change interrupt */
-
-/*
- * This is the offset of the FIQ "IRQ" numbers
- */
-#define FIQ_START      64
diff --git a/arch/arm/mach-l7200/include/mach/memory.h b/arch/arm/mach-l7200/include/mach/memory.h
deleted file mode 100644 (file)
index 9fb40ed..0000000
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/memory.h
- *
- * Copyright (c) 2000 Steve Hill (sjhill@cotw.com)
- * Copyright (c) 2000 Rob Scott (rscott@mtrob.fdns.net)
- *
- * Changelog:
- *  03-13-2000 SJH     Created
- *  04-13-2000  RS      Changed bus macros for new addr
- *  05-03-2000  SJH     Removed bus macros and fixed virt_to_phys macro
- */
-#ifndef __ASM_ARCH_MEMORY_H
-#define __ASM_ARCH_MEMORY_H
-
-/*
- * Physical DRAM offset on the L7200 SDB.
- */
-#define PHYS_OFFSET     UL(0xf0000000)
-
-/*
- * Cache flushing area - ROM
- */
-#define FLUSH_BASE_PHYS                0x40000000
-#define FLUSH_BASE             0xdf000000
-
-#endif
diff --git a/arch/arm/mach-l7200/include/mach/pmpcon.h b/arch/arm/mach-l7200/include/mach/pmpcon.h
deleted file mode 100644 (file)
index 3959871..0000000
+++ /dev/null
@@ -1,46 +0,0 @@
-/****************************************************************************/
-/*
- *  arch/arm/mach-l7200/include/mach/pmpcon.h
- *
- *   Registers and  helper functions for the L7200 Link-Up Systems
- *   DC/DC converter register.
- *
- *   (C) Copyright 2000, S A McConnell  (samcconn@cotw.com)
- *
- *  This file is subject to the terms and conditions of the GNU General Public
- *  License. See the file COPYING in the main directory of this archive for
- *  more details.
- */
-
-/****************************************************************************/
-
-#define PMPCON_OFF 0x00006000  /* Offset from IO_START_2. */
-
-/* IO_START_2 and IO_BASE_2 are defined in hardware.h */
-
-#define PMPCON_START (IO_START_2 + PMPCON_OFF)  /* Physical address of reg. */
-#define PMPCON_BASE  (IO_BASE_2  + PMPCON_OFF)  /* Virtual address of reg. */
-
-
-#define PMPCON (*(volatile unsigned int *)(PMPCON_BASE))
-
-#define PWM2_50CYCLE 0x800
-#define CONTRAST     0x9
-
-#define PWM1H (CONTRAST)
-#define PWM1L (CONTRAST << 4)
-
-#define PMPCON_VALUE  (PWM2_50CYCLE | PWM1L | PWM1H) 
-       
-/* PMPCON = 0x811;   // too light and fuzzy
- * PMPCON = 0x844;   
- * PMPCON = 0x866;   // better color poor depth
- * PMPCON = 0x888;   // Darker but better depth 
- * PMPCON = 0x899;   // Darker even better depth
- * PMPCON = 0x8aa;   // too dark even better depth
- * PMPCON = 0X8cc;   // Way too dark
- */
-
-/* As CONTRAST value increases the greater the depth perception and
- * the darker the colors.
- */
diff --git a/arch/arm/mach-l7200/include/mach/pmu.h b/arch/arm/mach-l7200/include/mach/pmu.h
deleted file mode 100644 (file)
index a2da7ae..0000000
+++ /dev/null
@@ -1,125 +0,0 @@
-/****************************************************************************/
-/*
- *  arch/arm/mach-l7200/include/mach/pmu.h
- *
- *   Registers and  helper functions for the L7200 Link-Up Systems
- *   Power Management Unit (PMU).
- *
- *   (C) Copyright 2000, S A McConnell  (samcconn@cotw.com)
- *
- *  This file is subject to the terms and conditions of the GNU General Public
- *  License. See the file COPYING in the main directory of this archive for
- *  more details.
- */
-
-/****************************************************************************/
-
-#define PMU_OFF   0x00050000  /* Offset from IO_START to the PMU registers. */
-
-/* IO_START and IO_BASE are defined in hardware.h */
-
-#define PMU_START (IO_START + PMU_OFF)  /* Physical addr. of the PMU reg. */
-#define PMU_BASE  (IO_BASE  + PMU_OFF)  /* Virtual addr. of the PMU reg. */
-
-
-/* Define the PMU registers for use by device drivers and the kernel. */
-
-typedef struct {
-     unsigned int CURRENT;  /* Current configuration register */
-     unsigned int NEXT;     /* Next configuration register */
-     unsigned int reserved;
-     unsigned int RUN;      /* Run configuration register */
-     unsigned int COMM;     /* Configuration command register */
-     unsigned int SDRAM;    /* SDRAM configuration bypass register */
-} pmu_interface;
-
-#define PMU ((volatile pmu_interface *)(PMU_BASE))
-
-
-/* Macro's for reading the common register fields. */
-
-#define GET_TRANSOP(reg)  ((reg >> 25) & 0x03) /* Bits 26-25 */
-#define GET_OSCEN(reg)    ((reg >> 16) & 0x01)
-#define GET_OSCMUX(reg)   ((reg >> 15) & 0x01)
-#define GET_PLLMUL(reg)   ((reg >>  9) & 0x3f) /* Bits 14-9 */
-#define GET_PLLEN(reg)    ((reg >>  8) & 0x01)
-#define GET_PLLMUX(reg)   ((reg >>  7) & 0x01)
-#define GET_BCLK_DIV(reg) ((reg >>  3) & 0x03) /* Bits 4-3 */
-#define GET_SDRB_SEL(reg) ((reg >>  2) & 0x01)
-#define GET_SDRF_SEL(reg) ((reg >>  1) & 0x01)
-#define GET_FASTBUS(reg)  (reg & 0x1)
-
-/* CFG_NEXT register */
-
-#define CFG_NEXT_CLOCKRECOVERY ((PMU->NEXT >> 18) & 0x7f)   /* Bits 24-18 */
-#define CFG_NEXT_INTRET        ((PMU->NEXT >> 17) & 0x01)
-#define CFG_NEXT_SDR_STOP      ((PMU->NEXT >>  6) & 0x01)
-#define CFG_NEXT_SYSCLKEN      ((PMU->NEXT >>  5) & 0x01)
-
-/* Useful field values that can be used to construct the
- * CFG_NEXT and CFG_RUN registers.
- */
-
-#define TRANSOP_NOP      0<<25  /* NOCHANGE_NOSTALL */
-#define NOCHANGE_STALL   1<<25
-#define CHANGE_NOSTALL   2<<25
-#define CHANGE_STALL     3<<25
-
-#define INTRET           1<<17
-#define OSCEN            1<<16
-#define OSCMUX           1<<15
-
-/* PLL frequencies */
-
-#define PLLMUL_0         0<<9         /*  3.6864 MHz */
-#define PLLMUL_1         1<<9         /*  ?????? MHz */
-#define PLLMUL_5         5<<9         /*  18.432 MHz */
-#define PLLMUL_10       10<<9         /*  36.864 MHz */
-#define PLLMUL_18       18<<9         /*  ?????? MHz */
-#define PLLMUL_20       20<<9         /*  73.728 MHz */
-#define PLLMUL_32       32<<9         /*  ?????? MHz */
-#define PLLMUL_35       35<<9         /* 129.024 MHz */
-#define PLLMUL_36       36<<9         /*  ?????? MHz */
-#define PLLMUL_39       39<<9         /*  ?????? MHz */
-#define PLLMUL_40       40<<9         /* 147.456 MHz */
-
-/* Clock recovery times */
-
-#define CRCLOCK_1        1<<18
-#define CRCLOCK_2        2<<18
-#define CRCLOCK_4        4<<18
-#define CRCLOCK_8        8<<18
-#define CRCLOCK_16      16<<18
-#define CRCLOCK_32      32<<18
-#define CRCLOCK_63      63<<18
-#define CRCLOCK_127    127<<18
-
-#define PLLEN            1<<8
-#define PLLMUX           1<<7
-#define SDR_STOP         1<<6
-#define SYSCLKEN         1<<5
-
-#define BCLK_DIV_4       2<<3
-#define BCLK_DIV_2       1<<3
-#define BCLK_DIV_1       0<<3
-
-#define SDRB_SEL         1<<2
-#define SDRF_SEL         1<<1
-#define FASTBUS          1<<0
-
-
-/* CFG_SDRAM */
-
-#define SDRREFFQ         1<<0  /* Only if SDRSTOPRQ is not set. */
-#define SDRREFACK        1<<1  /* Read-only */
-#define SDRSTOPRQ        1<<2  /* Only if SDRREFFQ is not set. */
-#define SDRSTOPACK       1<<3  /* Read-only */
-#define PICEN            1<<4  /* Enable Co-procesor */
-#define PICTEST          1<<5
-
-#define GET_SDRREFFQ    ((PMU->SDRAM >> 0) & 0x01)
-#define GET_SDRREFACK   ((PMU->SDRAM >> 1) & 0x01) /* Read-only */
-#define GET_SDRSTOPRQ   ((PMU->SDRAM >> 2) & 0x01)
-#define GET_SDRSTOPACK  ((PMU->SDRAM >> 3) & 0x01) /* Read-only */
-#define GET_PICEN       ((PMU->SDRAM >> 4) & 0x01)
-#define GET_PICTEST     ((PMU->SDRAM >> 5) & 0x01)
diff --git a/arch/arm/mach-l7200/include/mach/serial.h b/arch/arm/mach-l7200/include/mach/serial.h
deleted file mode 100644 (file)
index adc05e5..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/serial.h
- *
- * Copyright (c) 2000 Rob Scott (rscott@mtrob.fdns.net)
- *                    Steve Hill (sjhill@cotw.com)
- *
- * Changelog:
- *  03-20-2000  SJH     Created
- *  03-26-2000  SJH     Added flags for serial ports
- *  03-27-2000  SJH     Corrected BASE_BAUD value
- *  04-14-2000  RS      Made register addr dependent on IO_BASE
- *  05-03-2000  SJH     Complete rewrite
- *  05-09-2000 SJH     Stripped out architecture specific serial stuff
- *                      and placed it in a separate file
- *  07-28-2000 SJH     Moved base baud rate variable
- */
-#ifndef __ASM_ARCH_SERIAL_H
-#define __ASM_ARCH_SERIAL_H
-
-/*
- * This assumes you have a 3.6864 MHz clock for your UART.
- */
-#define BASE_BAUD      3686400
-
-/*
- * Standard COM flags
- */
-#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
-
-#define STD_SERIAL_PORT_DEFNS          \
-       /* MAGIC UART CLK   PORT       IRQ     FLAGS */                 \
-       { 0, BASE_BAUD, UART1_BASE, IRQ_UART_1, STD_COM_FLAGS },  /* ttyLU0 */ \
-       { 0, BASE_BAUD, UART2_BASE, IRQ_UART_2, STD_COM_FLAGS },  /* ttyLU1 */ \
-
-#define EXTRA_SERIAL_PORT_DEFNS
-
-#endif
diff --git a/arch/arm/mach-l7200/include/mach/serial_l7200.h b/arch/arm/mach-l7200/include/mach/serial_l7200.h
deleted file mode 100644 (file)
index 645f1c5..0000000
+++ /dev/null
@@ -1,101 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/serial_l7200.h
- *
- * Copyright (c) 2000 Steven Hill (sjhill@cotw.com)
- *
- * Changelog:
- *  05-09-2000 SJH     Created
- */
-#ifndef __ASM_ARCH_SERIAL_L7200_H
-#define __ASM_ARCH_SERIAL_L7200_H
-
-#include <mach/memory.h>
-
-/*
- * This assumes you have a 3.6864 MHz clock for your UART.
- */
-#define BASE_BAUD 3686400
-
-/*
- * UART base register addresses
- */
-#define UART1_BASE     (IO_BASE + 0x00044000)
-#define UART2_BASE     (IO_BASE + 0x00045000)
-
-/*
- * UART register offsets
- */
-#define UARTDR                 0x00    /* Tx/Rx data */
-#define RXSTAT                 0x04    /* Rx status */
-#define H_UBRLCR               0x08    /* mode register high */
-#define M_UBRLCR               0x0C    /* mode reg mid (MSB of baud)*/
-#define L_UBRLCR               0x10    /* mode reg low (LSB of baud)*/
-#define UARTCON                        0x14    /* control register */
-#define UARTFLG                        0x18    /* flag register */
-#define UARTINTSTAT            0x1C    /* FIFO IRQ status register */
-#define UARTINTMASK            0x20    /* FIFO IRQ mask register */
-
-/*
- * UART baud rate register values
- */
-#define BR_110                 0x827
-#define BR_1200                        0x06e
-#define BR_2400                        0x05f
-#define BR_4800                        0x02f
-#define BR_9600                        0x017
-#define BR_14400               0x00f
-#define BR_19200               0x00b
-#define BR_38400               0x005
-#define BR_57600               0x003
-#define BR_76800               0x002
-#define BR_115200              0x001
-
-/*
- * Receiver status register (RXSTAT) mask values
- */
-#define RXSTAT_NO_ERR          0x00    /* No error */
-#define RXSTAT_FRM_ERR         0x01    /* Framing error */
-#define RXSTAT_PAR_ERR         0x02    /* Parity error */
-#define RXSTAT_OVR_ERR         0x04    /* Overrun error */
-
-/*
- * High byte of UART bit rate and line control register (H_UBRLCR) values
- */
-#define UBRLCR_BRK             0x01    /* generate break on tx */
-#define UBRLCR_PEN             0x02    /* enable parity */
-#define UBRLCR_PDIS            0x00    /* disable parity */
-#define UBRLCR_EVEN            0x04    /* 1= even parity,0 = odd parity */
-#define UBRLCR_STP2            0x08    /* transmit 2 stop bits */
-#define UBRLCR_FIFO            0x10    /* enable FIFO */
-#define UBRLCR_LEN5            0x60    /* word length5 */
-#define UBRLCR_LEN6            0x40    /* word length6 */
-#define UBRLCR_LEN7            0x20    /* word length7 */
-#define UBRLCR_LEN8            0x00    /* word length8 */
-
-/*
- * UART control register (UARTCON) values
- */
-#define UARTCON_UARTEN         0x01    /* Enable UART */
-#define UARTCON_DMAONERR       0x08    /* Mask RxDmaRq when errors occur */
-
-/*
- * UART flag register (UARTFLG) mask values
- */
-#define UARTFLG_UTXFF          0x20    /* Transmit FIFO full */
-#define UARTFLG_URXFE          0x10    /* Receiver FIFO empty */
-#define UARTFLG_UBUSY          0x08    /* Transmitter busy */
-#define UARTFLG_DCD            0x04    /* Data carrier detect */
-#define UARTFLG_DSR            0x02    /* Data set ready */
-#define UARTFLG_CTS            0x01    /* Clear to send */
-
-/*
- * UART interrupt status/clear registers (UARTINTSTAT/CLR) values
- */
-#define UART_TXINT             0x01    /* TX interrupt */
-#define UART_RXINT             0x02    /* RX interrupt */
-#define UART_RXERRINT          0x04    /* RX error interrupt */
-#define UART_MSINT             0x08    /* Modem Status interrupt */
-#define UART_UDINT             0x10    /* UART Disabled interrupt */
-#define UART_ALLIRQS           0x1f    /* All interrupts */
-
-#endif
diff --git a/arch/arm/mach-l7200/include/mach/sib.h b/arch/arm/mach-l7200/include/mach/sib.h
deleted file mode 100644 (file)
index 9657287..0000000
+++ /dev/null
@@ -1,119 +0,0 @@
-/****************************************************************************/
-/*
- *  arch/arm/mach-l7200/include/mach/sib.h
- *
- *  Registers and helper functions for the Serial Interface Bus.
- *
- *  (C) Copyright 2000, S A McConnell  (samcconn@cotw.com)
- *
- *  This file is subject to the terms and conditions of the GNU General Public
- *  License. See the file COPYING in the main directory of this archive for
- *  more details.
- */
-
-/****************************************************************************/
-
-#define SIB_OFF   0x00040000  /* Offset from IO_START to the SIB reg's. */
-
-/* IO_START and IO_BASE are defined in hardware.h */
-
-#define SIB_START (IO_START + SIB_OFF) /* Physical addr of the SIB reg. */
-#define SIB_BASE  (IO_BASE  + SIB_OFF) /* Virtual addr of the SIB reg.  */
-
-/* Offsets from the start of the SIB for all the registers. */
-
-/* Define the SIB registers for use by device drivers and the kernel. */
-
-typedef struct
-{
-     unsigned int MCCR;    /* SIB Control Register           Offset: 0x00 */
-     unsigned int RES1;    /* Reserved                       Offset: 0x04 */
-     unsigned int MCDR0;   /* SIB Data Register 0            Offset: 0x08 */
-     unsigned int MCDR1;   /* SIB Data Register 1            Offset: 0x0c */
-     unsigned int MCDR2;   /* SIB Data Register 2 (UCB1x00)  Offset: 0x10 */
-     unsigned int RES2;    /* Reserved                       Offset: 0x14 */
-     unsigned int MCSR;    /* SIB Status Register            Offset: 0x18 */
-} SIB_Interface;
-
-#define SIB ((volatile SIB_Interface *) (SIB_BASE))
-
-/* MCCR */
-
-#define INTERNAL_FREQ   9216000  /* Hertz */
-#define AUDIO_FREQ         5000  /* Hertz */
-#define TELECOM_FREQ       5000  /* Hertz */
-
-#define AUDIO_DIVIDE    (INTERNAL_FREQ / (32 * AUDIO_FREQ))
-#define TELECOM_DIVIDE  (INTERNAL_FREQ / (32 * TELECOM_FREQ))
-
-#define MCCR_ASD57      AUDIO_DIVIDE
-#define MCCR_TSD57      (TELECOM_DIVIDE << 8)
-#define MCCR_MCE        (1 << 16)             /* SIB enable */
-#define MCCR_ECS        (1 << 17)             /* External Clock Select */
-#define MCCR_ADM        (1 << 18)             /* A/D Data Sampling */
-#define MCCR_PMC        (1 << 26)             /* PIN Multiplexer Control */
-
-
-#define GET_ASD ((SIB->MCCR >>  0) & 0x3f) /* Audio Sample Rate Div. */
-#define GET_TSD ((SIB->MCCR >>  8) & 0x3f) /* Telcom Sample Rate Div. */
-#define GET_MCE ((SIB->MCCR >> 16) & 0x01) /* SIB Enable */
-#define GET_ECS ((SIB->MCCR >> 17) & 0x01) /* External Clock Select */
-#define GET_ADM ((SIB->MCCR >> 18) & 0x01) /* A/D Data Sampling Mode */
-#define GET_TTM ((SIB->MCCR >> 19) & 0x01) /* Telco Trans. FIFO I mask */ 
-#define GET_TRM ((SIB->MCCR >> 20) & 0x01) /* Telco Recv. FIFO I mask */
-#define GET_ATM ((SIB->MCCR >> 21) & 0x01) /* Audio Trans. FIFO I mask */ 
-#define GET_ARM ((SIB->MCCR >> 22) & 0x01) /* Audio Recv. FIFO I mask */
-#define GET_LBM ((SIB->MCCR >> 23) & 0x01) /* Loop Back Mode */
-#define GET_ECP ((SIB->MCCR >> 24) & 0x03) /* Extern. Clck Prescale sel */
-#define GET_PMC ((SIB->MCCR >> 26) & 0x01) /* PIN Multiplexer Control */
-#define GET_ERI ((SIB->MCCR >> 27) & 0x01) /* External Read Interrupt */
-#define GET_EWI ((SIB->MCCR >> 28) & 0x01) /* External Write Interrupt */
-
-/* MCDR0 */
-
-#define AUDIO_RECV     ((SIB->MCDR0 >> 4) & 0xfff)
-#define AUDIO_WRITE(v) ((SIB->MCDR0 = (v & 0xfff) << 4))
-
-/* MCDR1 */
-
-#define TELECOM_RECV     ((SIB->MCDR1 >> 2) & 032fff)
-#define TELECOM_WRITE(v) ((SIB->MCDR1 = (v & 0x3fff) << 2))
-
-
-/* MCSR */
-
-#define MCSR_ATU (1 << 4)  /* Audio Transmit FIFO Underrun */
-#define MCSR_ARO (1 << 5)  /* Audio Receive  FIFO Underrun */
-#define MCSR_TTU (1 << 6)  /* TELECOM Transmit FIFO Underrun */
-#define MCSR_TRO (1 << 7)  /* TELECOM Receive  FIFO Underrun */
-
-#define MCSR_CLEAR_UNDERUN_BITS (MCSR_ATU | MCSR_ARO | MCSR_TTU | MCSR_TRO)
-
-
-#define GET_ATS ((SIB->MCSR >>  0) & 0x01) /* Audio Transmit FIFO Service Req*/
-#define GET_ARS ((SIB->MCSR >>  1) & 0x01) /* Audio Recv FIFO Service Request*/
-#define GET_TTS ((SIB->MCSR >>  2) & 0x01) /* TELECOM Transmit FIFO  Flag */
-#define GET_TRS ((SIB->MCSR >>  3) & 0x01) /* TELECOM Recv FIFO Service Req. */
-#define GET_ATU ((SIB->MCSR >>  4) & 0x01) /* Audio Transmit FIFO Underrun */
-#define GET_ARO ((SIB->MCSR >>  5) & 0x01) /* Audio Receive  FIFO Underrun */
-#define GET_TTU ((SIB->MCSR >>  6) & 0x01) /* TELECOM Transmit FIFO Underrun */
-#define GET_TRO ((SIB->MCSR >>  7) & 0x01) /* TELECOM Receive  FIFO Underrun */
-#define GET_ANF ((SIB->MCSR >>  8) & 0x01) /* Audio Transmit FIFO not full */
-#define GET_ANE ((SIB->MCSR >>  9) & 0x01) /* Audio Receive FIFO not empty */
-#define GET_TNF ((SIB->MCSR >> 10) & 0x01) /* Telecom Transmit FIFO not full */
-#define GET_TNE ((SIB->MCSR >> 11) & 0x01) /* Telecom Receive FIFO not empty */
-#define GET_CWC ((SIB->MCSR >> 12) & 0x01) /* Codec Write Complete */
-#define GET_CRC ((SIB->MCSR >> 13) & 0x01) /* Codec Read Complete */
-#define GET_ACE ((SIB->MCSR >> 14) & 0x01) /* Audio Codec Enabled */
-#define GET_TCE ((SIB->MCSR >> 15) & 0x01) /* Telecom Codec Enabled */
-
-/* MCDR2 */
-
-#define MCDR2_rW               (1 << 16)
-
-#define WRITE_MCDR2(reg, data) (SIB->MCDR2 =((reg<<17)|MCDR2_rW|(data&0xffff)))
-#define MCDR2_WRITE_COMPLETE   GET_CWC
-
-#define INITIATE_MCDR2_READ(reg) (SIB->MCDR2 = (reg << 17))
-#define MCDR2_READ_COMPLETE      GET_CRC
-#define MCDR2_READ               (SIB->MCDR2 & 0xffff)
diff --git a/arch/arm/mach-l7200/include/mach/sys-clock.h b/arch/arm/mach-l7200/include/mach/sys-clock.h
deleted file mode 100644 (file)
index e9729a3..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/****************************************************************************/
-/*
- *  arch/arm/mach-l7200/include/mach/sys-clock.h
- *
- *   Registers and  helper functions for the L7200 Link-Up Systems
- *   System clocks.
- *
- *   (C) Copyright 2000, S A McConnell  (samcconn@cotw.com)
- *
- *  This file is subject to the terms and conditions of the GNU General Public
- *  License. See the file COPYING in the main directory of this archive for
- *  more details.
- */
-
-/****************************************************************************/
-
-#define SYS_CLOCK_OFF   0x00050030  /* Offset from IO_START. */
-
-/* IO_START and IO_BASE are defined in hardware.h */
-
-#define SYS_CLOCK_START (IO_START + SYS_CLOCK_OFF)  /* Physical address */
-#define SYS_CLOCK_BASE  (IO_BASE  + SYS_CLOCK_OFF)  /* Virtual address  */
-
-/* Define the interface to the SYS_CLOCK */
-
-typedef struct
-{
-     unsigned int ENABLE;
-     unsigned int ESYNC;
-     unsigned int SELECT;
-} sys_clock_interface;
-
-#define SYS_CLOCK   ((volatile sys_clock_interface *)(SYS_CLOCK_BASE))
-
-//#define CLOCK_EN    (*(volatile unsigned long *)(PMU_BASE+CLOCK_EN_OFF))
-//#define CLOCK_ESYNC (*(volatile unsigned long *)(PMU_BASE+CLOCK_ESYNC_OFF))
-//#define CLOCK_SEL   (*(volatile unsigned long *)(PMU_BASE+CLOCK_SEL_OFF))
-
-/* SYS_CLOCK -> ENABLE */
-
-#define SYN_EN          1<<0
-#define B18M_EN         1<<1
-#define CLK3M6_EN       1<<2
-#define BUART_EN        1<<3
-#define CLK18MU_EN      1<<4
-#define FIR_EN          1<<5
-#define MIRN_EN         1<<6
-#define UARTM_EN        1<<7
-#define SIBADC_EN       1<<8
-#define ALTD_EN         1<<9
-#define CLCLK_EN        1<<10
-
-/* SYS_CLOCK -> SELECT */
-
-#define CLK18M_DIV      1<<0
-#define MIR_SEL         1<<1
-#define SSP_SEL         1<<4
-#define MM_DIV          1<<5
-#define MM_SEL          1<<6
-#define ADC_SEL_2       0<<7
-#define ADC_SEL_4       1<<7
-#define ADC_SEL_8       3<<7
-#define ADC_SEL_16      7<<7
-#define ADC_SEL_32      0x0f<<7
-#define ADC_SEL_64      0x1f<<7
-#define ADC_SEL_128     0x3f<<7
-#define ALTD_SEL        1<<13
diff --git a/arch/arm/mach-l7200/include/mach/system.h b/arch/arm/mach-l7200/include/mach/system.h
deleted file mode 100644 (file)
index e0dd3b6..0000000
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/system.h
- *
- * Copyright (c) 2000 Steve Hill (sjhill@cotw.com)
- *
- * Changelog
- *  03-21-2000  SJH    Created
- *  04-26-2000  SJH    Fixed functions
- *  05-03-2000  SJH    Removed usage of obsolete 'iomd.h'
- *  05-31-2000  SJH    Properly implemented 'arch_idle'
- */
-#ifndef __ASM_ARCH_SYSTEM_H
-#define __ASM_ARCH_SYSTEM_H
-
-#include <mach/hardware.h>
-
-static inline void arch_idle(void)
-{
-       *(unsigned long *)(IO_BASE + 0x50004) = 1;      /* idle mode */
-}
-
-static inline void arch_reset(char mode, const char *cmd)
-{
-       if (mode == 's') {
-               cpu_reset(0);
-       }
-}
-
-#endif
diff --git a/arch/arm/mach-l7200/include/mach/time.h b/arch/arm/mach-l7200/include/mach/time.h
deleted file mode 100644 (file)
index 061771c..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/time.h
- *
- * Copyright (C) 2000 Rob Scott (rscott@mtrob.fdns.net)
- *                    Steve Hill (sjhill@cotw.com)
- *
- * Changelog:
- *   01-02-2000        RS      Created l7200 version, derived from rpc code
- *   05-03-2000        SJH     Complete rewrite
- */
-#ifndef _ASM_ARCH_TIME_H
-#define _ASM_ARCH_TIME_H
-
-#include <mach/irqs.h>
-
-/*
- * RTC base register address
- */
-#define RTC_BASE       (IO_BASE_2 + 0x2000)
-
-/*
- * RTC registers
- */
-#define RTC_RTCDR      (*(volatile unsigned char *) (RTC_BASE + 0x000))
-#define RTC_RTCMR      (*(volatile unsigned char *) (RTC_BASE + 0x004))
-#define RTC_RTCS       (*(volatile unsigned char *) (RTC_BASE + 0x008))
-#define RTC_RTCC       (*(volatile unsigned char *) (RTC_BASE + 0x008))
-#define RTC_RTCDV      (*(volatile unsigned char *) (RTC_BASE + 0x00c))
-#define RTC_RTCCR      (*(volatile unsigned char *) (RTC_BASE + 0x010))
-
-/*
- * RTCCR register values
- */
-#define RTC_RATE_32    0x00      /* 32 Hz tick */
-#define RTC_RATE_64    0x10      /* 64 Hz tick */
-#define RTC_RATE_128   0x20      /* 128 Hz tick */
-#define RTC_RATE_256   0x30      /* 256 Hz tick */
-#define RTC_EN_ALARM   0x01      /* Enable alarm */
-#define RTC_EN_TIC     0x04      /* Enable counter */
-#define RTC_EN_STWDOG  0x08      /* Enable watchdog */
-
-/*
- * Handler for RTC timer interrupt
- */
-static irqreturn_t
-timer_interrupt(int irq, void *dev_id)
-{
-       struct pt_regs *regs = get_irq_regs();
-       do_timer(1);
-#ifndef CONFIG_SMP
-       update_process_times(user_mode(regs));
-#endif
-       do_profile(regs);
-       RTC_RTCC = 0;                           /* Clear interrupt */
-
-       return IRQ_HANDLED;
-}
-
-/*
- * Set up RTC timer interrupt, and return the current time in seconds.
- */
-void __init time_init(void)
-{
-       RTC_RTCC = 0;                           /* Clear interrupt */
-
-       timer_irq.handler = timer_interrupt;
-
-       setup_irq(IRQ_RTC_TICK, &timer_irq);
-
-       RTC_RTCCR = RTC_RATE_128 | RTC_EN_TIC;  /* Set rate and enable timer */
-}
-
-#endif
diff --git a/arch/arm/mach-l7200/include/mach/timex.h b/arch/arm/mach-l7200/include/mach/timex.h
deleted file mode 100644 (file)
index ffc96a6..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/timex.h
- *
- * Copyright (C) 2000 Rob Scott (rscott@mtrob.fdns.net)
- *                    Steve Hill (sjhill@cotw.com)
- *
- * 04-21-2000  RS Created file
- * 05-03-2000 SJH Tick rate was wrong
- *
- */
-
-/*
- * On the ARM720T, clock ticks are set to 128 Hz.
- *
- * NOTE: The actual RTC value is set in 'time.h' which
- *       must be changed when choosing a different tick
- *       rate. The value of HZ in 'param.h' must also
- *       be changed to match below.
- */
-#define CLOCK_TICK_RATE                128
diff --git a/arch/arm/mach-l7200/include/mach/uncompress.h b/arch/arm/mach-l7200/include/mach/uncompress.h
deleted file mode 100644 (file)
index 591c962..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/uncompress.h
- *
- * Copyright (C) 2000 Steve Hill (sjhill@cotw.com)
- *
- * Changelog:
- *  05-01-2000 SJH     Created
- *  05-13-2000 SJH     Filled in function bodies
- *  07-26-2000 SJH     Removed hard coded baud rate
- */
-
-#include <mach/hardware.h>
-
-#define IO_UART  IO_START + 0x00044000
-
-#define __raw_writeb(v,p)      (*(volatile unsigned char *)(p) = (v))
-#define __raw_readb(p)         (*(volatile unsigned char *)(p))
-
-static inline void putc(int c)
-{
-       while(__raw_readb(IO_UART + 0x18) & 0x20 ||
-             __raw_readb(IO_UART + 0x18) & 0x08)
-               barrier();
-
-       __raw_writeb(c, IO_UART + 0x00);
-}
-
-static inline void flush(void)
-{
-}
-
-static __inline__ void arch_decomp_setup(void)
-{
-       __raw_writeb(0x00, IO_UART + 0x08);     /* Set HSB */
-       __raw_writeb(0x00, IO_UART + 0x20);     /* Disable IRQs */
-       __raw_writeb(0x01, IO_UART + 0x14);     /* Enable UART */
-}
-
-#define arch_decomp_wdog()
diff --git a/arch/arm/mach-l7200/include/mach/vmalloc.h b/arch/arm/mach-l7200/include/mach/vmalloc.h
deleted file mode 100644 (file)
index 85f0abb..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-/*
- * arch/arm/mach-l7200/include/mach/vmalloc.h
- */
-#define VMALLOC_END       (PAGE_OFFSET + 0x10000000)
index 189d20e543e75f41b52a39f4f009e30ed87ed2d5..edb8f5faf5d5032c9047d4c743a66e1230dbe0e8 100644 (file)
  */
 #define PHYS_OFFSET    UL(0xc0000000)
 
-#ifdef CONFIG_DISCONTIGMEM
-
-/*
- * Given a kernel address, find the home node of the underlying memory.
- */
-
-# ifdef CONFIG_LH7A40X_ONE_BANK_PER_NODE
-#  define KVADDR_TO_NID(addr) \
-  (  ((((unsigned long) (addr) - PAGE_OFFSET) >> 24) &  1)\
-   | ((((unsigned long) (addr) - PAGE_OFFSET) >> 25) & ~1))
-# else  /* 2 banks per node */
-#  define KVADDR_TO_NID(addr) \
-      (((unsigned long) (addr) - PAGE_OFFSET) >> 26)
-# endif
-
-/*
- * Given a page frame number, convert it to a node id.
- */
-
-# ifdef CONFIG_LH7A40X_ONE_BANK_PER_NODE
-#  define PFN_TO_NID(pfn) \
-  (((((pfn) - PHYS_PFN_OFFSET) >> (24 - PAGE_SHIFT)) &  1)\
- | ((((pfn) - PHYS_PFN_OFFSET) >> (25 - PAGE_SHIFT)) & ~1))
-# else  /* 2 banks per node */
-#  define PFN_TO_NID(pfn) \
-    (((pfn) - PHYS_PFN_OFFSET) >> (26 - PAGE_SHIFT))
-#endif
-
-/*
- * Given a kaddr, LOCAL_MEM_MAP finds the owning node of the memory
- * and returns the index corresponding to the appropriate page in the
- * node's mem_map.
- */
-
-# ifdef CONFIG_LH7A40X_ONE_BANK_PER_NODE
-#  define LOCAL_MAP_NR(addr) \
-       (((unsigned long)(addr) & 0x003fffff) >> PAGE_SHIFT)
-# else  /* 2 banks per node */
-#  define LOCAL_MAP_NR(addr) \
-       (((unsigned long)(addr) & 0x01ffffff) >> PAGE_SHIFT)
-# endif
-
-#endif
-
 /*
  * Sparsemem version of the above
  */
diff --git a/arch/arm/mach-lpc32xx/Kconfig b/arch/arm/mach-lpc32xx/Kconfig
new file mode 100644 (file)
index 0000000..fde6635
--- /dev/null
@@ -0,0 +1,33 @@
+if ARCH_LPC32XX
+
+menu "Individual UART enable selections"
+
+config ARCH_LPC32XX_UART3_SELECT
+       bool "Add support for standard UART3"
+       help
+        Adds support for standard UART 3 when the 8250 serial support
+        is enabled.
+
+config ARCH_LPC32XX_UART4_SELECT
+       bool "Add support for standard UART4"
+       help
+        Adds support for standard UART 4 when the 8250 serial support
+        is enabled.
+
+config ARCH_LPC32XX_UART5_SELECT
+       bool "Add support for standard UART5"
+       default y
+       help
+        Adds support for standard UART 5 when the 8250 serial support
+        is enabled.
+
+config ARCH_LPC32XX_UART6_SELECT
+       bool "Add support for standard UART6"
+       help
+        Adds support for standard UART 6 when the 8250 serial support
+        is enabled.
+
+endmenu
+
+endif
+
diff --git a/arch/arm/mach-lpc32xx/Makefile b/arch/arm/mach-lpc32xx/Makefile
new file mode 100644 (file)
index 0000000..a5fc5d0
--- /dev/null
@@ -0,0 +1,8 @@
+#
+# Makefile for the linux kernel.
+#
+
+obj-y  := timer.o irq.o common.o serial.o clock.o
+obj-y  += gpiolib.o pm.o suspend.o
+obj-y  += phy3250.o
+
diff --git a/arch/arm/mach-lpc32xx/Makefile.boot b/arch/arm/mach-lpc32xx/Makefile.boot
new file mode 100644 (file)
index 0000000..b796b41
--- /dev/null
@@ -0,0 +1,4 @@
+   zreladdr-y  := 0x80008000
+params_phys-y  := 0x80000100
+initrd_phys-y  := 0x82000000
+
diff --git a/arch/arm/mach-lpc32xx/clock.c b/arch/arm/mach-lpc32xx/clock.c
new file mode 100644 (file)
index 0000000..32d6379
--- /dev/null
@@ -0,0 +1,1137 @@
+/*
+ * arch/arm/mach-lpc32xx/clock.c
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+/*
+ * LPC32xx clock management driver overview
+ *
+ * The LPC32XX contains a number of high level system clocks that can be
+ * generated from different sources. These system clocks are used to
+ * generate the CPU and bus rates and the individual peripheral clocks in
+ * the system. When Linux is started by the boot loader, the system
+ * clocks are already running. Stopping a system clock during normal
+ * Linux operation should never be attempted, as peripherals that require
+ * those clocks will quit working (ie, DRAM).
+ *
+ * The LPC32xx high level clock tree looks as follows. Clocks marked with
+ * an asterisk are always on and cannot be disabled. Clocks marked with
+ * an ampersand can only be disabled in CPU suspend mode. Clocks marked
+ * with a caret are always on if it is the selected clock for the SYSCLK
+ * source. The clock that isn't used for SYSCLK can be enabled and
+ * disabled normally.
+ *                               32KHz oscillator*
+ *                               /      |      \
+ *                             RTC*   PLL397^ TOUCH
+ *                                     /
+ *               Main oscillator^     /
+ *                   |        \      /
+ *                   |         SYSCLK&
+ *                   |            \
+ *                   |             \
+ *                USB_PLL       HCLK_PLL&
+ *                   |           |    |
+ *            USB host/device  PCLK&  |
+ *                               |    |
+ *                             Peripherals
+ *
+ * The CPU and chip bus rates are derived from the HCLK PLL, which can
+ * generate various clock rates up to 266MHz and beyond. The internal bus
+ * rates (PCLK and HCLK) are generated from dividers based on the HCLK
+ * PLL rate. HCLK can be a ratio of 1:1, 1:2, or 1:4 or HCLK PLL rate,
+ * while PCLK can be 1:1 to 1:32 of HCLK PLL rate. Most peripherals high
+ * level clocks are based on either HCLK or PCLK, but have their own
+ * dividers as part of the IP itself. Because of this, the system clock
+ * rates should not be changed.
+ *
+ * The HCLK PLL is clocked from SYSCLK, which can be derived from the
+ * main oscillator or PLL397. PLL397 generates a rate that is 397 times
+ * the 32KHz oscillator rate. The main oscillator runs at the selected
+ * oscillator/crystal rate on the mosc_in pin of the LPC32xx. This rate
+ * is normally 13MHz, but depends on the selection of external crystals
+ * or oscillators. If USB operation is required, the main oscillator must
+ * be used in the system.
+ *
+ * Switching SYSCLK between sources during normal Linux operation is not
+ * supported. SYSCLK is preset in the bootloader. Because of the
+ * complexities of clock management during clock frequency changes,
+ * there are some limitations to the clock driver explained below:
+ * - The PLL397 and main oscillator can be enabled and disabled by the
+ *   clk_enable() and clk_disable() functions unless SYSCLK is based
+ *   on that clock. This allows the other oscillator that isn't driving
+ *   the HCLK PLL to be used as another system clock that can be routed
+ *   to an external pin.
+ * - The muxed SYSCLK input and HCLK_PLL rate cannot be changed with
+ *   this driver.
+ * - HCLK and PCLK rates cannot be changed as part of this driver.
+ * - Most peripherals have their own dividers are part of the peripheral
+ *   block. Changing SYSCLK, HCLK PLL, HCLK, or PCLK sources or rates
+ *   will also impact the individual peripheral rates.
+ */
+
+#include <linux/kernel.h>
+#include <linux/list.h>
+#include <linux/errno.h>
+#include <linux/device.h>
+#include <linux/err.h>
+#include <linux/clk.h>
+#include <linux/amba/bus.h>
+#include <linux/amba/clcd.h>
+
+#include <mach/hardware.h>
+#include <asm/clkdev.h>
+#include <mach/clkdev.h>
+#include <mach/platform.h>
+#include "clock.h"
+#include "common.h"
+
+static struct clk clk_armpll;
+static struct clk clk_usbpll;
+static DEFINE_MUTEX(clkm_lock);
+
+/*
+ * Post divider values for PLLs based on selected register value
+ */
+static const u32 pll_postdivs[4] = {1, 2, 4, 8};
+
+static unsigned long local_return_parent_rate(struct clk *clk)
+{
+       /*
+        * If a clock has a rate of 0, then it inherits it's parent
+        * clock rate
+        */
+       while (clk->rate == 0)
+               clk = clk->parent;
+
+       return clk->rate;
+}
+
+/* 32KHz clock has a fixed rate and is not stoppable */
+static struct clk osc_32KHz = {
+       .rate           = LPC32XX_CLOCK_OSC_FREQ,
+       .get_rate       = local_return_parent_rate,
+};
+
+static int local_pll397_enable(struct clk *clk, int enable)
+{
+       u32 reg;
+       unsigned long timeout = 1 + msecs_to_jiffies(10);
+
+       reg = __raw_readl(LPC32XX_CLKPWR_PLL397_CTRL);
+
+       if (enable == 0) {
+               reg |= LPC32XX_CLKPWR_SYSCTRL_PLL397_DIS;
+               __raw_writel(reg, LPC32XX_CLKPWR_PLL397_CTRL);
+       } else {
+               /* Enable PLL397 */
+               reg &= ~LPC32XX_CLKPWR_SYSCTRL_PLL397_DIS;
+               __raw_writel(reg, LPC32XX_CLKPWR_PLL397_CTRL);
+
+               /* Wait for PLL397 lock */
+               while (((__raw_readl(LPC32XX_CLKPWR_PLL397_CTRL) &
+                       LPC32XX_CLKPWR_SYSCTRL_PLL397_STS) == 0) &&
+                       (timeout > jiffies))
+                       cpu_relax();
+
+               if ((__raw_readl(LPC32XX_CLKPWR_PLL397_CTRL) &
+                       LPC32XX_CLKPWR_SYSCTRL_PLL397_STS) == 0)
+                       return -ENODEV;
+       }
+
+       return 0;
+}
+
+static int local_oscmain_enable(struct clk *clk, int enable)
+{
+       u32 reg;
+       unsigned long timeout = 1 + msecs_to_jiffies(10);
+
+       reg = __raw_readl(LPC32XX_CLKPWR_MAIN_OSC_CTRL);
+
+       if (enable == 0) {
+               reg |= LPC32XX_CLKPWR_MOSC_DISABLE;
+               __raw_writel(reg, LPC32XX_CLKPWR_MAIN_OSC_CTRL);
+       } else {
+               /* Enable main oscillator */
+               reg &= ~LPC32XX_CLKPWR_MOSC_DISABLE;
+               __raw_writel(reg, LPC32XX_CLKPWR_MAIN_OSC_CTRL);
+
+               /* Wait for main oscillator to start */
+               while (((__raw_readl(LPC32XX_CLKPWR_MAIN_OSC_CTRL) &
+                       LPC32XX_CLKPWR_MOSC_DISABLE) != 0) &&
+                       (timeout > jiffies))
+                       cpu_relax();
+
+               if ((__raw_readl(LPC32XX_CLKPWR_MAIN_OSC_CTRL) &
+                       LPC32XX_CLKPWR_MOSC_DISABLE) != 0)
+                       return -ENODEV;
+       }
+
+       return 0;
+}
+
+static struct clk osc_pll397 = {
+       .parent         = &osc_32KHz,
+       .enable         = local_pll397_enable,
+       .rate           = LPC32XX_CLOCK_OSC_FREQ * 397,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk osc_main = {
+       .enable         = local_oscmain_enable,
+       .rate           = LPC32XX_MAIN_OSC_FREQ,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_sys;
+
+/*
+ * Convert a PLL register value to a PLL output frequency
+ */
+u32 clk_get_pllrate_from_reg(u32 inputclk, u32 regval)
+{
+       struct clk_pll_setup pllcfg;
+
+       pllcfg.cco_bypass_b15 = 0;
+       pllcfg.direct_output_b14 = 0;
+       pllcfg.fdbk_div_ctrl_b13 = 0;
+       if ((regval & LPC32XX_CLKPWR_HCLKPLL_CCO_BYPASS) != 0)
+               pllcfg.cco_bypass_b15 = 1;
+       if ((regval & LPC32XX_CLKPWR_HCLKPLL_POSTDIV_BYPASS) != 0)
+               pllcfg.direct_output_b14 = 1;
+       if ((regval & LPC32XX_CLKPWR_HCLKPLL_FDBK_SEL_FCLK) != 0)
+               pllcfg.fdbk_div_ctrl_b13 = 1;
+       pllcfg.pll_m = 1 + ((regval >> 1) & 0xFF);
+       pllcfg.pll_n = 1 + ((regval >> 9) & 0x3);
+       pllcfg.pll_p = pll_postdivs[((regval >> 11) & 0x3)];
+
+       return clk_check_pll_setup(inputclk, &pllcfg);
+}
+
+/*
+ * Setup the HCLK PLL with a PLL structure
+ */
+static u32 local_clk_pll_setup(struct clk_pll_setup *PllSetup)
+{
+       u32 tv, tmp = 0;
+
+       if (PllSetup->analog_on != 0)
+               tmp |= LPC32XX_CLKPWR_HCLKPLL_POWER_UP;
+       if (PllSetup->cco_bypass_b15 != 0)
+               tmp |= LPC32XX_CLKPWR_HCLKPLL_CCO_BYPASS;
+       if (PllSetup->direct_output_b14 != 0)
+               tmp |= LPC32XX_CLKPWR_HCLKPLL_POSTDIV_BYPASS;
+       if (PllSetup->fdbk_div_ctrl_b13 != 0)
+               tmp |= LPC32XX_CLKPWR_HCLKPLL_FDBK_SEL_FCLK;
+
+       tv = ffs(PllSetup->pll_p) - 1;
+       if ((!is_power_of_2(PllSetup->pll_p)) || (tv > 3))
+               return 0;
+
+       tmp |= LPC32XX_CLKPWR_HCLKPLL_POSTDIV_2POW(tv);
+       tmp |= LPC32XX_CLKPWR_HCLKPLL_PREDIV_PLUS1(PllSetup->pll_n - 1);
+       tmp |= LPC32XX_CLKPWR_HCLKPLL_PLLM(PllSetup->pll_m - 1);
+
+       return tmp;
+}
+
+/*
+ * Update the ARM core PLL frequency rate variable from the actual PLL setting
+ */
+static void local_update_armpll_rate(void)
+{
+       u32 clkin, pllreg;
+
+       clkin = clk_armpll.parent->rate;
+       pllreg = __raw_readl(LPC32XX_CLKPWR_HCLKPLL_CTRL) & 0x1FFFF;
+
+       clk_armpll.rate = clk_get_pllrate_from_reg(clkin, pllreg);
+}
+
+/*
+ * Find a PLL configuration for the selected input frequency
+ */
+static u32 local_clk_find_pll_cfg(u32 pllin_freq, u32 target_freq,
+       struct clk_pll_setup *pllsetup)
+{
+       u32 ifreq, freqtol, m, n, p, fclkout;
+
+       /* Determine frequency tolerance limits */
+       freqtol = target_freq / 250;
+       ifreq = pllin_freq;
+
+       /* Is direct bypass mode possible? */
+       if (abs(pllin_freq - target_freq) <= freqtol) {
+               pllsetup->analog_on = 0;
+               pllsetup->cco_bypass_b15 = 1;
+               pllsetup->direct_output_b14 = 1;
+               pllsetup->fdbk_div_ctrl_b13 = 1;
+               pllsetup->pll_p = pll_postdivs[0];
+               pllsetup->pll_n = 1;
+               pllsetup->pll_m = 1;
+               return clk_check_pll_setup(ifreq, pllsetup);
+       } else if (target_freq <= ifreq) {
+               pllsetup->analog_on = 0;
+               pllsetup->cco_bypass_b15 = 1;
+               pllsetup->direct_output_b14 = 0;
+               pllsetup->fdbk_div_ctrl_b13 = 1;
+               pllsetup->pll_n = 1;
+               pllsetup->pll_m = 1;
+               for (p = 0; p <= 3; p++) {
+                       pllsetup->pll_p = pll_postdivs[p];
+                       fclkout = clk_check_pll_setup(ifreq, pllsetup);
+                       if (abs(target_freq - fclkout) <= freqtol)
+                               return fclkout;
+               }
+       }
+
+       /* Is direct mode possible? */
+       pllsetup->analog_on = 1;
+       pllsetup->cco_bypass_b15 = 0;
+       pllsetup->direct_output_b14 = 1;
+       pllsetup->fdbk_div_ctrl_b13 = 0;
+       pllsetup->pll_p = pll_postdivs[0];
+       for (m = 1; m <= 256; m++) {
+               for (n = 1; n <= 4; n++) {
+                       /* Compute output frequency for this value */
+                       pllsetup->pll_n = n;
+                       pllsetup->pll_m = m;
+                       fclkout = clk_check_pll_setup(ifreq,
+                               pllsetup);
+                       if (abs(target_freq - fclkout) <=
+                               freqtol)
+                               return fclkout;
+               }
+       }
+
+       /* Is integer mode possible? */
+       pllsetup->analog_on = 1;
+       pllsetup->cco_bypass_b15 = 0;
+       pllsetup->direct_output_b14 = 0;
+       pllsetup->fdbk_div_ctrl_b13 = 1;
+       for (m = 1; m <= 256; m++) {
+               for (n = 1; n <= 4; n++) {
+                       for (p = 0; p < 4; p++) {
+                               /* Compute output frequency */
+                               pllsetup->pll_p = pll_postdivs[p];
+                               pllsetup->pll_n = n;
+                               pllsetup->pll_m = m;
+                               fclkout = clk_check_pll_setup(
+                                       ifreq, pllsetup);
+                               if (abs(target_freq - fclkout) <= freqtol)
+                                       return fclkout;
+                       }
+               }
+       }
+
+       /* Try non-integer mode */
+       pllsetup->analog_on = 1;
+       pllsetup->cco_bypass_b15 = 0;
+       pllsetup->direct_output_b14 = 0;
+       pllsetup->fdbk_div_ctrl_b13 = 0;
+       for (m = 1; m <= 256; m++) {
+               for (n = 1; n <= 4; n++) {
+                       for (p = 0; p < 4; p++) {
+                               /* Compute output frequency */
+                               pllsetup->pll_p = pll_postdivs[p];
+                               pllsetup->pll_n = n;
+                               pllsetup->pll_m = m;
+                               fclkout = clk_check_pll_setup(
+                                       ifreq, pllsetup);
+                               if (abs(target_freq - fclkout) <= freqtol)
+                                       return fclkout;
+                       }
+               }
+       }
+
+       return 0;
+}
+
+static struct clk clk_armpll = {
+       .parent         = &clk_sys,
+       .get_rate       = local_return_parent_rate,
+};
+
+/*
+ * Setup the USB PLL with a PLL structure
+ */
+static u32 local_clk_usbpll_setup(struct clk_pll_setup *pHCLKPllSetup)
+{
+       u32 reg, tmp = local_clk_pll_setup(pHCLKPllSetup);
+
+       reg = __raw_readl(LPC32XX_CLKPWR_USB_CTRL) & ~0x1FFFF;
+       reg |= tmp;
+       __raw_writel(reg, LPC32XX_CLKPWR_USB_CTRL);
+
+       return clk_check_pll_setup(clk_usbpll.parent->rate,
+               pHCLKPllSetup);
+}
+
+static int local_usbpll_enable(struct clk *clk, int enable)
+{
+       u32 reg;
+       int ret = -ENODEV;
+       unsigned long timeout = 1 + msecs_to_jiffies(10);
+
+       reg = __raw_readl(LPC32XX_CLKPWR_USB_CTRL);
+
+       if (enable == 0) {
+               reg &= ~(LPC32XX_CLKPWR_USBCTRL_CLK_EN1 |
+                       LPC32XX_CLKPWR_USBCTRL_CLK_EN2);
+               __raw_writel(reg, LPC32XX_CLKPWR_USB_CTRL);
+       } else if (reg & LPC32XX_CLKPWR_USBCTRL_PLL_PWRUP) {
+               reg |= LPC32XX_CLKPWR_USBCTRL_CLK_EN1;
+               __raw_writel(reg, LPC32XX_CLKPWR_USB_CTRL);
+
+               /* Wait for PLL lock */
+               while ((timeout > jiffies) & (ret == -ENODEV)) {
+                       reg = __raw_readl(LPC32XX_CLKPWR_USB_CTRL);
+                       if (reg & LPC32XX_CLKPWR_USBCTRL_PLL_STS)
+                               ret = 0;
+               }
+
+               if (ret == 0) {
+                       reg |= LPC32XX_CLKPWR_USBCTRL_CLK_EN2;
+                       __raw_writel(reg, LPC32XX_CLKPWR_USB_CTRL);
+               }
+       }
+
+       return ret;
+}
+
+static unsigned long local_usbpll_round_rate(struct clk *clk,
+       unsigned long rate)
+{
+       u32 clkin, usbdiv;
+       struct clk_pll_setup pllsetup;
+
+       /*
+        * Unlike other clocks, this clock has a KHz input rate, so bump
+        * it up to work with the PLL function
+        */
+       rate = rate * 1000;
+
+       clkin = clk->parent->rate;
+       usbdiv = (__raw_readl(LPC32XX_CLKPWR_USBCLK_PDIV) &
+               LPC32XX_CLKPWR_USBPDIV_PLL_MASK) + 1;
+       clkin = clkin / usbdiv;
+
+       /* Try to find a good rate setup */
+       if (local_clk_find_pll_cfg(clkin, rate, &pllsetup) == 0)
+               return 0;
+
+       return clk_check_pll_setup(clkin, &pllsetup);
+}
+
+static int local_usbpll_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 clkin, reg, usbdiv;
+       struct clk_pll_setup pllsetup;
+
+       /*
+        * Unlike other clocks, this clock has a KHz input rate, so bump
+        * it up to work with the PLL function
+        */
+       rate = rate * 1000;
+
+       clkin = clk->get_rate(clk);
+       usbdiv = (__raw_readl(LPC32XX_CLKPWR_USBCLK_PDIV) &
+               LPC32XX_CLKPWR_USBPDIV_PLL_MASK) + 1;
+       clkin = clkin / usbdiv;
+
+       /* Try to find a good rate setup */
+       if (local_clk_find_pll_cfg(clkin, rate, &pllsetup) == 0)
+               return -EINVAL;
+
+       local_usbpll_enable(clk, 0);
+
+       reg = __raw_readl(LPC32XX_CLKPWR_USB_CTRL);
+       reg |= LPC32XX_CLKPWR_USBCTRL_CLK_EN1;
+       __raw_writel(reg, LPC32XX_CLKPWR_USB_CTRL);
+
+       pllsetup.analog_on = 1;
+       local_clk_usbpll_setup(&pllsetup);
+
+       clk->rate = clk_check_pll_setup(clkin, &pllsetup);
+
+       reg = __raw_readl(LPC32XX_CLKPWR_USB_CTRL);
+       reg |= LPC32XX_CLKPWR_USBCTRL_CLK_EN2;
+       __raw_writel(reg, LPC32XX_CLKPWR_USB_CTRL);
+
+       return 0;
+}
+
+static struct clk clk_usbpll = {
+       .parent         = &osc_main,
+       .set_rate       = local_usbpll_set_rate,
+       .enable         = local_usbpll_enable,
+       .rate           = 48000, /* In KHz */
+       .get_rate       = local_return_parent_rate,
+       .round_rate     = local_usbpll_round_rate,
+};
+
+static u32 clk_get_hclk_div(void)
+{
+       static const u32 hclkdivs[4] = {1, 2, 4, 4};
+       return hclkdivs[LPC32XX_CLKPWR_HCLKDIV_DIV_2POW(
+               __raw_readl(LPC32XX_CLKPWR_HCLK_DIV))];
+}
+
+static struct clk clk_hclk = {
+       .parent         = &clk_armpll,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_pclk = {
+       .parent         = &clk_armpll,
+       .get_rate       = local_return_parent_rate,
+};
+
+static int local_onoff_enable(struct clk *clk, int enable)
+{
+       u32 tmp;
+
+       tmp = __raw_readl(clk->enable_reg);
+
+       if (enable == 0)
+               tmp &= ~clk->enable_mask;
+       else
+               tmp |= clk->enable_mask;
+
+       __raw_writel(tmp, clk->enable_reg);
+
+       return 0;
+}
+
+/* Peripheral clock sources */
+static struct clk clk_timer0 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1,
+       .enable_mask    = LPC32XX_CLKPWR_TMRPWMCLK_TIMER0_EN,
+       .get_rate       = local_return_parent_rate,
+};
+static struct clk clk_timer1 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1,
+       .enable_mask    = LPC32XX_CLKPWR_TMRPWMCLK_TIMER1_EN,
+       .get_rate       = local_return_parent_rate,
+};
+static struct clk clk_timer2 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1,
+       .enable_mask    = LPC32XX_CLKPWR_TMRPWMCLK_TIMER2_EN,
+       .get_rate       = local_return_parent_rate,
+};
+static struct clk clk_timer3 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1,
+       .enable_mask    = LPC32XX_CLKPWR_TMRPWMCLK_TIMER3_EN,
+       .get_rate       = local_return_parent_rate,
+};
+static struct clk clk_wdt = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_TIMER_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_PWMCLK_WDOG_EN,
+       .get_rate       = local_return_parent_rate,
+};
+static struct clk clk_vfp9 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_DEBUG_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_VFP_CLOCK_ENABLE_BIT,
+       .get_rate       = local_return_parent_rate,
+};
+static struct clk clk_dma = {
+       .parent         = &clk_hclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_DMA_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_DMACLKCTRL_CLK_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_uart3 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_UART_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_UARTCLKCTRL_UART3_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_uart4 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_UART_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_UARTCLKCTRL_UART4_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_uart5 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_UART_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_UARTCLKCTRL_UART5_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_uart6 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_UART_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_UARTCLKCTRL_UART6_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_i2c0 = {
+       .parent         = &clk_hclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_I2C_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_I2CCLK_I2C1CLK_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_i2c1 = {
+       .parent         = &clk_hclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_I2C_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_I2CCLK_I2C2CLK_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_i2c2 = {
+       .parent         = &clk_pclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = io_p2v(LPC32XX_USB_BASE + 0xFF4),
+       .enable_mask    = 0x4,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_ssp0 = {
+       .parent         = &clk_hclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_SSP_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_SSPCTRL_SSPCLK0_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_ssp1 = {
+       .parent         = &clk_hclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_SSP_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_SSPCTRL_SSPCLK1_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_kscan = {
+       .parent         = &osc_32KHz,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_KEY_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_KEYCLKCTRL_CLK_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_nand = {
+       .parent         = &clk_hclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_NAND_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_NANDCLK_SLCCLK_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_i2s0 = {
+       .parent         = &clk_hclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_I2S_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_I2SCTRL_I2SCLK0_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_i2s1 = {
+       .parent         = &clk_hclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_I2S_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_I2SCTRL_I2SCLK1_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_net = {
+       .parent         = &clk_hclk,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_MACCLK_CTRL,
+       .enable_mask    = (LPC32XX_CLKPWR_MACCTRL_DMACLK_EN |
+               LPC32XX_CLKPWR_MACCTRL_MMIOCLK_EN |
+               LPC32XX_CLKPWR_MACCTRL_HRCCLK_EN),
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_rtc = {
+       .parent         = &osc_32KHz,
+       .rate           = 1, /* 1 Hz */
+       .get_rate       = local_return_parent_rate,
+};
+
+static struct clk clk_usbd = {
+       .parent         = &clk_usbpll,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_USB_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_USBCTRL_HCLK_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static int tsc_onoff_enable(struct clk *clk, int enable)
+{
+       u32 tmp;
+
+       /* Make sure 32KHz clock is the selected clock */
+       tmp = __raw_readl(LPC32XX_CLKPWR_ADC_CLK_CTRL_1);
+       tmp &= ~LPC32XX_CLKPWR_ADCCTRL1_PCLK_SEL;
+       __raw_writel(tmp, LPC32XX_CLKPWR_ADC_CLK_CTRL_1);
+
+       if (enable == 0)
+               __raw_writel(0, clk->enable_reg);
+       else
+               __raw_writel(clk->enable_mask, clk->enable_reg);
+
+       return 0;
+}
+
+static struct clk clk_tsc = {
+       .parent         = &osc_32KHz,
+       .enable         = tsc_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_ADC_CLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_ADC32CLKCTRL_CLK_EN,
+       .get_rate       = local_return_parent_rate,
+};
+
+static int mmc_onoff_enable(struct clk *clk, int enable)
+{
+       u32 tmp;
+
+       tmp = __raw_readl(LPC32XX_CLKPWR_MS_CTRL) &
+               ~LPC32XX_CLKPWR_MSCARD_SDCARD_EN;
+
+       /* If rate is 0, disable clock */
+       if (enable != 0)
+               tmp |= LPC32XX_CLKPWR_MSCARD_SDCARD_EN;
+
+       __raw_writel(tmp, LPC32XX_CLKPWR_MS_CTRL);
+
+       return 0;
+}
+
+static unsigned long mmc_get_rate(struct clk *clk)
+{
+       u32 div, rate, oldclk;
+
+       /* The MMC clock must be on when accessing an MMC register */
+       oldclk = __raw_readl(LPC32XX_CLKPWR_MS_CTRL);
+       __raw_writel(oldclk | LPC32XX_CLKPWR_MSCARD_SDCARD_EN,
+               LPC32XX_CLKPWR_MS_CTRL);
+       div = __raw_readl(LPC32XX_CLKPWR_MS_CTRL);
+       __raw_writel(oldclk, LPC32XX_CLKPWR_MS_CTRL);
+
+       /* Get the parent clock rate */
+       rate = clk->parent->get_rate(clk->parent);
+
+       /* Get the MMC controller clock divider value */
+       div = div & LPC32XX_CLKPWR_MSCARD_SDCARD_DIV(0xf);
+
+       if (!div)
+               div = 1;
+
+       return rate / div;
+}
+
+static unsigned long mmc_round_rate(struct clk *clk, unsigned long rate)
+{
+       unsigned long div, prate;
+
+       /* Get the parent clock rate */
+       prate = clk->parent->get_rate(clk->parent);
+
+       if (rate >= prate)
+               return prate;
+
+       div = prate / rate;
+       if (div > 0xf)
+               div = 0xf;
+
+       return prate / div;
+}
+
+static int mmc_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 oldclk, tmp;
+       unsigned long prate, div, crate = mmc_round_rate(clk, rate);
+
+       prate = clk->parent->get_rate(clk->parent);
+
+       div = prate / crate;
+
+       /* The MMC clock must be on when accessing an MMC register */
+       oldclk = __raw_readl(LPC32XX_CLKPWR_MS_CTRL);
+       __raw_writel(oldclk | LPC32XX_CLKPWR_MSCARD_SDCARD_EN,
+               LPC32XX_CLKPWR_MS_CTRL);
+       tmp = __raw_readl(LPC32XX_CLKPWR_MS_CTRL) &
+               ~LPC32XX_CLKPWR_MSCARD_SDCARD_DIV(0xf);
+       tmp |= LPC32XX_CLKPWR_MSCARD_SDCARD_DIV(div);
+       __raw_writel(tmp, LPC32XX_CLKPWR_MS_CTRL);
+
+       __raw_writel(oldclk, LPC32XX_CLKPWR_MS_CTRL);
+
+       return 0;
+}
+
+static struct clk clk_mmc = {
+       .parent         = &clk_armpll,
+       .set_rate       = mmc_set_rate,
+       .get_rate       = mmc_get_rate,
+       .round_rate     = mmc_round_rate,
+       .enable         = mmc_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_MS_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_MSCARD_SDCARD_EN,
+};
+
+static unsigned long clcd_get_rate(struct clk *clk)
+{
+       u32 tmp, div, rate, oldclk;
+
+       /* The LCD clock must be on when accessing an LCD register */
+       oldclk = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL);
+       __raw_writel(oldclk | LPC32XX_CLKPWR_LCDCTRL_CLK_EN,
+               LPC32XX_CLKPWR_LCDCLK_CTRL);
+       tmp = __raw_readl(io_p2v(LPC32XX_LCD_BASE + CLCD_TIM2));
+       __raw_writel(oldclk, LPC32XX_CLKPWR_LCDCLK_CTRL);
+
+       rate = clk->parent->get_rate(clk->parent);
+
+       /* Only supports internal clocking */
+       if (tmp & TIM2_BCD)
+               return rate;
+
+       div = (tmp & 0x1F) | ((tmp & 0xF8) >> 22);
+       tmp = rate / (2 + div);
+
+       return tmp;
+}
+
+static int clcd_set_rate(struct clk *clk, unsigned long rate)
+{
+       u32 tmp, prate, div, oldclk;
+
+       /* The LCD clock must be on when accessing an LCD register */
+       oldclk = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL);
+       __raw_writel(oldclk | LPC32XX_CLKPWR_LCDCTRL_CLK_EN,
+               LPC32XX_CLKPWR_LCDCLK_CTRL);
+
+       tmp = __raw_readl(io_p2v(LPC32XX_LCD_BASE + CLCD_TIM2)) | TIM2_BCD;
+       prate = clk->parent->get_rate(clk->parent);
+
+       if (rate < prate) {
+               /* Find closest divider */
+               div = prate / rate;
+               if (div >= 2) {
+                       div -= 2;
+                       tmp &= ~TIM2_BCD;
+               }
+
+               tmp &= ~(0xF800001F);
+               tmp |= (div & 0x1F);
+               tmp |= (((div >> 5) & 0x1F) << 27);
+       }
+
+       __raw_writel(tmp, io_p2v(LPC32XX_LCD_BASE + CLCD_TIM2));
+       __raw_writel(oldclk, LPC32XX_CLKPWR_LCDCLK_CTRL);
+
+       return 0;
+}
+
+static unsigned long clcd_round_rate(struct clk *clk, unsigned long rate)
+{
+       u32 prate, div;
+
+       prate = clk->parent->get_rate(clk->parent);
+
+       if (rate >= prate)
+               rate = prate;
+       else {
+               div = prate / rate;
+               if (div > 0x3ff)
+                       div = 0x3ff;
+
+               rate = prate / div;
+       }
+
+       return rate;
+}
+
+static struct clk clk_lcd = {
+       .parent         = &clk_hclk,
+       .set_rate       = clcd_set_rate,
+       .get_rate       = clcd_get_rate,
+       .round_rate     = clcd_round_rate,
+       .enable         = local_onoff_enable,
+       .enable_reg     = LPC32XX_CLKPWR_LCDCLK_CTRL,
+       .enable_mask    = LPC32XX_CLKPWR_LCDCTRL_CLK_EN,
+};
+
+static inline void clk_lock(void)
+{
+       mutex_lock(&clkm_lock);
+}
+
+static inline void clk_unlock(void)
+{
+       mutex_unlock(&clkm_lock);
+}
+
+static void local_clk_disable(struct clk *clk)
+{
+       WARN_ON(clk->usecount == 0);
+
+       /* Don't attempt to disable clock if it has no users */
+       if (clk->usecount > 0) {
+               clk->usecount--;
+
+               /* Only disable clock when it has no more users */
+               if ((clk->usecount == 0) && (clk->enable))
+                       clk->enable(clk, 0);
+
+               /* Check parent clocks, they may need to be disabled too */
+               if (clk->parent)
+                       local_clk_disable(clk->parent);
+       }
+}
+
+static int local_clk_enable(struct clk *clk)
+{
+       int ret = 0;
+
+       /* Enable parent clocks first and update use counts */
+       if (clk->parent)
+               ret = local_clk_enable(clk->parent);
+
+       if (!ret) {
+               /* Only enable clock if it's currently disabled */
+               if ((clk->usecount == 0) && (clk->enable))
+                       ret = clk->enable(clk, 1);
+
+               if (!ret)
+                       clk->usecount++;
+               else if (clk->parent)
+                       local_clk_disable(clk->parent);
+       }
+
+       return ret;
+}
+
+/*
+ * clk_enable - inform the system when the clock source should be running.
+ */
+int clk_enable(struct clk *clk)
+{
+       int ret;
+
+       clk_lock();
+       ret = local_clk_enable(clk);
+       clk_unlock();
+
+       return ret;
+}
+EXPORT_SYMBOL(clk_enable);
+
+/*
+ * clk_disable - inform the system when the clock source is no longer required
+ */
+void clk_disable(struct clk *clk)
+{
+       clk_lock();
+       local_clk_disable(clk);
+       clk_unlock();
+}
+EXPORT_SYMBOL(clk_disable);
+
+/*
+ * clk_get_rate - obtain the current clock rate (in Hz) for a clock source
+ */
+unsigned long clk_get_rate(struct clk *clk)
+{
+       unsigned long rate;
+
+       clk_lock();
+       rate = clk->get_rate(clk);
+       clk_unlock();
+
+       return rate;
+}
+EXPORT_SYMBOL(clk_get_rate);
+
+/*
+ * clk_set_rate - set the clock rate for a clock source
+ */
+int clk_set_rate(struct clk *clk, unsigned long rate)
+{
+       int ret = -EINVAL;
+
+       /*
+        * Most system clocks can only be enabled or disabled, with
+        * the actual rate set as part of the peripheral dividers
+        * instead of high level clock control
+        */
+       if (clk->set_rate) {
+               clk_lock();
+               ret = clk->set_rate(clk, rate);
+               clk_unlock();
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL(clk_set_rate);
+
+/*
+ * clk_round_rate - adjust a rate to the exact rate a clock can provide
+ */
+long clk_round_rate(struct clk *clk, unsigned long rate)
+{
+       clk_lock();
+
+       if (clk->round_rate)
+               rate = clk->round_rate(clk, rate);
+       else
+               rate = clk->get_rate(clk);
+
+       clk_unlock();
+
+       return rate;
+}
+EXPORT_SYMBOL(clk_round_rate);
+
+/*
+ * clk_set_parent - set the parent clock source for this clock
+ */
+int clk_set_parent(struct clk *clk, struct clk *parent)
+{
+       /* Clock re-parenting is not supported */
+       return -EINVAL;
+}
+EXPORT_SYMBOL(clk_set_parent);
+
+/*
+ * clk_get_parent - get the parent clock source for this clock
+ */
+struct clk *clk_get_parent(struct clk *clk)
+{
+       return clk->parent;
+}
+EXPORT_SYMBOL(clk_get_parent);
+
+#define _REGISTER_CLOCK(d, n, c) \
+       { \
+               .dev_id = (d), \
+               .con_id = (n), \
+               .clk = &(c), \
+       },
+
+static struct clk_lookup lookups[] = {
+       _REGISTER_CLOCK(NULL, "osc_32KHz", osc_32KHz)
+       _REGISTER_CLOCK(NULL, "osc_pll397", osc_pll397)
+       _REGISTER_CLOCK(NULL, "osc_main", osc_main)
+       _REGISTER_CLOCK(NULL, "sys_ck", clk_sys)
+       _REGISTER_CLOCK(NULL, "arm_pll_ck", clk_armpll)
+       _REGISTER_CLOCK(NULL, "ck_pll5", clk_usbpll)
+       _REGISTER_CLOCK(NULL, "hclk_ck", clk_hclk)
+       _REGISTER_CLOCK(NULL, "pclk_ck", clk_pclk)
+       _REGISTER_CLOCK(NULL, "timer0_ck", clk_timer0)
+       _REGISTER_CLOCK(NULL, "timer1_ck", clk_timer1)
+       _REGISTER_CLOCK(NULL, "timer2_ck", clk_timer2)
+       _REGISTER_CLOCK(NULL, "timer3_ck", clk_timer3)
+       _REGISTER_CLOCK(NULL, "vfp9_ck", clk_vfp9)
+       _REGISTER_CLOCK(NULL, "clk_dmac", clk_dma)
+       _REGISTER_CLOCK("pnx4008-watchdog", NULL, clk_wdt)
+       _REGISTER_CLOCK(NULL, "uart3_ck", clk_uart3)
+       _REGISTER_CLOCK(NULL, "uart4_ck", clk_uart4)
+       _REGISTER_CLOCK(NULL, "uart5_ck", clk_uart5)
+       _REGISTER_CLOCK(NULL, "uart6_ck", clk_uart6)
+       _REGISTER_CLOCK("pnx-i2c.0", NULL, clk_i2c0)
+       _REGISTER_CLOCK("pnx-i2c.1", NULL, clk_i2c1)
+       _REGISTER_CLOCK("pnx-i2c.2", NULL, clk_i2c2)
+       _REGISTER_CLOCK("dev:ssp0", NULL, clk_ssp0)
+       _REGISTER_CLOCK("dev:ssp1", NULL, clk_ssp1)
+       _REGISTER_CLOCK("lpc32xx_keys.0", NULL, clk_kscan)
+       _REGISTER_CLOCK("lpc32xx-nand.0", "nand_ck", clk_nand)
+       _REGISTER_CLOCK("tbd", "i2s0_ck", clk_i2s0)
+       _REGISTER_CLOCK("tbd", "i2s1_ck", clk_i2s1)
+       _REGISTER_CLOCK("lpc32xx-ts", NULL, clk_tsc)
+       _REGISTER_CLOCK("dev:mmc0", "MCLK", clk_mmc)
+       _REGISTER_CLOCK("lpc-net.0", NULL, clk_net)
+       _REGISTER_CLOCK("dev:clcd", NULL, clk_lcd)
+       _REGISTER_CLOCK("lpc32xx_udc", "ck_usbd", clk_usbd)
+       _REGISTER_CLOCK("lpc32xx_rtc", NULL, clk_rtc)
+};
+
+static int __init clk_init(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(lookups); i++)
+               clkdev_add(&lookups[i]);
+
+       /*
+        * Setup muxed SYSCLK for HCLK PLL base -this selects the
+        * parent clock used for the ARM PLL and is used to derive
+        * the many system clock rates in the device.
+        */
+       if (clk_is_sysclk_mainosc() != 0)
+               clk_sys.parent = &osc_main;
+       else
+               clk_sys.parent = &osc_pll397;
+
+       clk_sys.rate = clk_sys.parent->rate;
+
+       /* Compute the current ARM PLL and USB PLL frequencies */
+       local_update_armpll_rate();
+
+       /* Compute HCLK and PCLK bus rates */
+       clk_hclk.rate = clk_hclk.parent->rate / clk_get_hclk_div();
+       clk_pclk.rate = clk_pclk.parent->rate / clk_get_pclk_div();
+
+       /*
+        * Enable system clocks - this step is somewhat formal, as the
+        * clocks are already running, but it does get the clock data
+        * inline with the actual system state. Never disable these
+        * clocks as they will only stop if the system is going to sleep.
+        * In that case, the chip/system power management functions will
+        * handle clock gating.
+        */
+       if (clk_enable(&clk_hclk) || clk_enable(&clk_pclk))
+               printk(KERN_ERR "Error enabling system HCLK and PCLK\n");
+
+       /*
+        * Timers 0 and 1 were enabled and are being used by the high
+        * resolution tick function prior to this driver being initialized.
+        * Tag them now as used.
+        */
+       if (clk_enable(&clk_timer0) || clk_enable(&clk_timer1))
+               printk(KERN_ERR "Error enabling timer tick clocks\n");
+
+       return 0;
+}
+core_initcall(clk_init);
+
diff --git a/arch/arm/mach-lpc32xx/clock.h b/arch/arm/mach-lpc32xx/clock.h
new file mode 100644 (file)
index 0000000..c0a8434
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * arch/arm/mach-lpc32xx/clock.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __LPC32XX_CLOCK_H
+#define __LPC32XX_CLOCK_H
+
+struct clk {
+       struct list_head node;
+       struct clk *parent;
+       u32 rate;
+       u32 usecount;
+
+       int (*set_rate) (struct clk *, unsigned long);
+       unsigned long (*round_rate) (struct clk *, unsigned long);
+       unsigned long (*get_rate) (struct clk *clk);
+       int (*enable) (struct clk *, int);
+
+       /* Register address and bit mask for simple clocks */
+       void __iomem *enable_reg;
+       u32 enable_mask;
+};
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/common.c b/arch/arm/mach-lpc32xx/common.c
new file mode 100644 (file)
index 0000000..ee24dc2
--- /dev/null
@@ -0,0 +1,271 @@
+/*
+ * arch/arm/mach-lpc32xx/common.c
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/err.h>
+#include <linux/i2c.h>
+#include <linux/i2c-pnx.h>
+#include <linux/io.h>
+
+#include <asm/mach/map.h>
+
+#include <mach/i2c.h>
+#include <mach/hardware.h>
+#include <mach/platform.h>
+#include "common.h"
+
+/*
+ * Watchdog timer
+ */
+static struct resource watchdog_resources[] = {
+       [0] = {
+               .start = LPC32XX_WDTIM_BASE,
+               .end = LPC32XX_WDTIM_BASE + SZ_4K - 1,
+               .flags = IORESOURCE_MEM,
+       },
+};
+
+struct platform_device lpc32xx_watchdog_device = {
+       .name = "pnx4008-watchdog",
+       .id = -1,
+       .num_resources = ARRAY_SIZE(watchdog_resources),
+       .resource = watchdog_resources,
+};
+
+/*
+ * I2C busses
+ */
+static struct i2c_pnx_data i2c0_data = {
+       .name = I2C_CHIP_NAME "1",
+       .base = LPC32XX_I2C1_BASE,
+       .irq = IRQ_LPC32XX_I2C_1,
+};
+
+static struct i2c_pnx_data i2c1_data = {
+       .name = I2C_CHIP_NAME "2",
+       .base = LPC32XX_I2C2_BASE,
+       .irq = IRQ_LPC32XX_I2C_2,
+};
+
+static struct i2c_pnx_data i2c2_data = {
+       .name = "USB-I2C",
+       .base = LPC32XX_OTG_I2C_BASE,
+       .irq = IRQ_LPC32XX_USB_I2C,
+};
+
+struct platform_device lpc32xx_i2c0_device = {
+       .name = "pnx-i2c",
+       .id = 0,
+       .dev = {
+               .platform_data = &i2c0_data,
+       },
+};
+
+struct platform_device lpc32xx_i2c1_device = {
+       .name = "pnx-i2c",
+       .id = 1,
+       .dev = {
+               .platform_data = &i2c1_data,
+       },
+};
+
+struct platform_device lpc32xx_i2c2_device = {
+       .name = "pnx-i2c",
+       .id = 2,
+       .dev = {
+               .platform_data = &i2c2_data,
+       },
+};
+
+/*
+ * Returns the unique ID for the device
+ */
+void lpc32xx_get_uid(u32 devid[4])
+{
+       int i;
+
+       for (i = 0; i < 4; i++)
+               devid[i] = __raw_readl(LPC32XX_CLKPWR_DEVID(i << 2));
+}
+
+/*
+ * Returns SYSCLK source
+ * 0 = PLL397, 1 = main oscillator
+ */
+int clk_is_sysclk_mainosc(void)
+{
+       if ((__raw_readl(LPC32XX_CLKPWR_SYSCLK_CTRL) &
+               LPC32XX_CLKPWR_SYSCTRL_SYSCLKMUX) == 0)
+               return 1;
+
+       return 0;
+}
+
+/*
+ * System reset via the watchdog timer
+ */
+void lpc32xx_watchdog_reset(void)
+{
+       /* Make sure WDT clocks are enabled */
+       __raw_writel(LPC32XX_CLKPWR_PWMCLK_WDOG_EN,
+               LPC32XX_CLKPWR_TIMER_CLK_CTRL);
+
+       /* Instant assert of RESETOUT_N with pulse length 1mS */
+       __raw_writel(13000, io_p2v(LPC32XX_WDTIM_BASE + 0x18));
+       __raw_writel(0x70, io_p2v(LPC32XX_WDTIM_BASE + 0xC));
+}
+
+/*
+ * Detects and returns IRAM size for the device variation
+ */
+#define LPC32XX_IRAM_BANK_SIZE SZ_128K
+static u32 iram_size;
+u32 lpc32xx_return_iram_size(void)
+{
+       if (iram_size == 0) {
+               u32 savedval1, savedval2;
+               void __iomem *iramptr1, *iramptr2;
+
+               iramptr1 = io_p2v(LPC32XX_IRAM_BASE);
+               iramptr2 = io_p2v(LPC32XX_IRAM_BASE + LPC32XX_IRAM_BANK_SIZE);
+               savedval1 = __raw_readl(iramptr1);
+               savedval2 = __raw_readl(iramptr2);
+
+               if (savedval1 == savedval2) {
+                       __raw_writel(savedval2 + 1, iramptr2);
+                       if (__raw_readl(iramptr1) == savedval2 + 1)
+                               iram_size = LPC32XX_IRAM_BANK_SIZE;
+                       else
+                               iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
+                       __raw_writel(savedval2, iramptr2);
+               } else
+                       iram_size = LPC32XX_IRAM_BANK_SIZE * 2;
+       }
+
+       return iram_size;
+}
+
+/*
+ * Computes PLL rate from PLL register and input clock
+ */
+u32 clk_check_pll_setup(u32 ifreq, struct clk_pll_setup *pllsetup)
+{
+       u32 ilfreq, p, m, n, fcco, fref, cfreq;
+       int mode;
+
+       /*
+        * PLL requirements
+        * ifreq must be >= 1MHz and <= 20MHz
+        * FCCO must be >= 156MHz and <= 320MHz
+        * FREF must be >= 1MHz and <= 27MHz
+        * Assume the passed input data is not valid
+        */
+
+       ilfreq = ifreq;
+       m = pllsetup->pll_m;
+       n = pllsetup->pll_n;
+       p = pllsetup->pll_p;
+
+       mode = (pllsetup->cco_bypass_b15 << 2) |
+               (pllsetup->direct_output_b14 << 1) |
+       pllsetup->fdbk_div_ctrl_b13;
+
+       switch (mode) {
+       case 0x0: /* Non-integer mode */
+               cfreq = (m * ilfreq) / (2 * p * n);
+               fcco = (m * ilfreq) / n;
+               fref = ilfreq / n;
+               break;
+
+       case 0x1: /* integer mode */
+               cfreq = (m * ilfreq) / n;
+               fcco = (m * ilfreq) / (n * 2 * p);
+               fref = ilfreq / n;
+               break;
+
+       case 0x2:
+       case 0x3: /* Direct mode */
+               cfreq = (m * ilfreq) / n;
+               fcco = cfreq;
+               fref = ilfreq / n;
+               break;
+
+       case 0x4:
+       case 0x5: /* Bypass mode */
+               cfreq = ilfreq / (2 * p);
+               fcco = 156000000;
+               fref = 1000000;
+               break;
+
+       case 0x6:
+       case 0x7: /* Direct bypass mode */
+       default:
+               cfreq = ilfreq;
+               fcco = 156000000;
+               fref = 1000000;
+               break;
+       }
+
+       if (fcco < 156000000 || fcco > 320000000)
+               cfreq = 0;
+
+       if (fref < 1000000 || fref > 27000000)
+               cfreq = 0;
+
+       return (u32) cfreq;
+}
+
+u32 clk_get_pclk_div(void)
+{
+       return 1 + ((__raw_readl(LPC32XX_CLKPWR_HCLK_DIV) >> 2) & 0x1F);
+}
+
+static struct map_desc lpc32xx_io_desc[] __initdata = {
+       {
+               .virtual        = IO_ADDRESS(LPC32XX_AHB0_START),
+               .pfn            = __phys_to_pfn(LPC32XX_AHB0_START),
+               .length         = LPC32XX_AHB0_SIZE,
+               .type           = MT_DEVICE
+       },
+       {
+               .virtual        = IO_ADDRESS(LPC32XX_AHB1_START),
+               .pfn            = __phys_to_pfn(LPC32XX_AHB1_START),
+               .length         = LPC32XX_AHB1_SIZE,
+               .type           = MT_DEVICE
+       },
+       {
+               .virtual        = IO_ADDRESS(LPC32XX_FABAPB_START),
+               .pfn            = __phys_to_pfn(LPC32XX_FABAPB_START),
+               .length         = LPC32XX_FABAPB_SIZE,
+               .type           = MT_DEVICE
+       },
+       {
+               .virtual        = IO_ADDRESS(LPC32XX_IRAM_BASE),
+               .pfn            = __phys_to_pfn(LPC32XX_IRAM_BASE),
+               .length         = (LPC32XX_IRAM_BANK_SIZE * 2),
+               .type           = MT_DEVICE
+       },
+};
+
+void __init lpc32xx_map_io(void)
+{
+       iotable_init(lpc32xx_io_desc, ARRAY_SIZE(lpc32xx_io_desc));
+}
diff --git a/arch/arm/mach-lpc32xx/common.h b/arch/arm/mach-lpc32xx/common.h
new file mode 100644 (file)
index 0000000..f82211f
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * arch/arm/mach-lpc32xx/common.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2009-2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __LPC32XX_COMMON_H
+#define __LPC32XX_COMMON_H
+
+#include <linux/platform_device.h>
+
+/*
+ * Arch specific platform device structures
+ */
+extern struct platform_device lpc32xx_watchdog_device;
+extern struct platform_device lpc32xx_i2c0_device;
+extern struct platform_device lpc32xx_i2c1_device;
+extern struct platform_device lpc32xx_i2c2_device;
+
+/*
+ * Other arch specific structures and functions
+ */
+extern struct sys_timer lpc32xx_timer;
+extern void __init lpc32xx_init_irq(void);
+extern void __init lpc32xx_map_io(void);
+extern void __init lpc32xx_serial_init(void);
+extern void __init lpc32xx_gpio_init(void);
+
+/*
+ * Structure used for setting up and querying the PLLS
+ */
+struct clk_pll_setup {
+       int analog_on;
+       int cco_bypass_b15;
+       int direct_output_b14;
+       int fdbk_div_ctrl_b13;
+       int pll_p;
+       int pll_n;
+       u32 pll_m;
+};
+
+extern int clk_is_sysclk_mainosc(void);
+extern u32 clk_check_pll_setup(u32 ifreq, struct clk_pll_setup *pllsetup);
+extern u32 clk_get_pllrate_from_reg(u32 inputclk, u32 regval);
+extern u32 clk_get_pclk_div(void);
+
+/*
+ * Returns the LPC32xx unique 128-bit chip ID
+ */
+extern void lpc32xx_get_uid(u32 devid[4]);
+
+extern void lpc32xx_watchdog_reset(void);
+extern u32 lpc32xx_return_iram_size(void);
+
+/*
+ * Pointers used for sizing and copying suspend function data
+ */
+extern int lpc32xx_sys_suspend(void);
+extern int lpc32xx_sys_suspend_sz;
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/gpiolib.c b/arch/arm/mach-lpc32xx/gpiolib.c
new file mode 100644 (file)
index 0000000..69061ea
--- /dev/null
@@ -0,0 +1,446 @@
+/*
+ * arch/arm/mach-lpc32xx/gpiolib.c
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/errno.h>
+#include <linux/gpio.h>
+
+#include <mach/hardware.h>
+#include <mach/platform.h>
+#include "common.h"
+
+#define LPC32XX_GPIO_P3_INP_STATE              _GPREG(0x000)
+#define LPC32XX_GPIO_P3_OUTP_SET               _GPREG(0x004)
+#define LPC32XX_GPIO_P3_OUTP_CLR               _GPREG(0x008)
+#define LPC32XX_GPIO_P3_OUTP_STATE             _GPREG(0x00C)
+#define LPC32XX_GPIO_P2_DIR_SET                        _GPREG(0x010)
+#define LPC32XX_GPIO_P2_DIR_CLR                        _GPREG(0x014)
+#define LPC32XX_GPIO_P2_DIR_STATE              _GPREG(0x018)
+#define LPC32XX_GPIO_P2_INP_STATE              _GPREG(0x01C)
+#define LPC32XX_GPIO_P2_OUTP_SET               _GPREG(0x020)
+#define LPC32XX_GPIO_P2_OUTP_CLR               _GPREG(0x024)
+#define LPC32XX_GPIO_P2_MUX_SET                        _GPREG(0x028)
+#define LPC32XX_GPIO_P2_MUX_CLR                        _GPREG(0x02C)
+#define LPC32XX_GPIO_P2_MUX_STATE              _GPREG(0x030)
+#define LPC32XX_GPIO_P0_INP_STATE              _GPREG(0x040)
+#define LPC32XX_GPIO_P0_OUTP_SET               _GPREG(0x044)
+#define LPC32XX_GPIO_P0_OUTP_CLR               _GPREG(0x048)
+#define LPC32XX_GPIO_P0_OUTP_STATE             _GPREG(0x04C)
+#define LPC32XX_GPIO_P0_DIR_SET                        _GPREG(0x050)
+#define LPC32XX_GPIO_P0_DIR_CLR                        _GPREG(0x054)
+#define LPC32XX_GPIO_P0_DIR_STATE              _GPREG(0x058)
+#define LPC32XX_GPIO_P1_INP_STATE              _GPREG(0x060)
+#define LPC32XX_GPIO_P1_OUTP_SET               _GPREG(0x064)
+#define LPC32XX_GPIO_P1_OUTP_CLR               _GPREG(0x068)
+#define LPC32XX_GPIO_P1_OUTP_STATE             _GPREG(0x06C)
+#define LPC32XX_GPIO_P1_DIR_SET                        _GPREG(0x070)
+#define LPC32XX_GPIO_P1_DIR_CLR                        _GPREG(0x074)
+#define LPC32XX_GPIO_P1_DIR_STATE              _GPREG(0x078)
+
+#define GPIO012_PIN_TO_BIT(x)                  (1 << (x))
+#define GPIO3_PIN_TO_BIT(x)                    (1 << ((x) + 25))
+#define GPO3_PIN_TO_BIT(x)                     (1 << (x))
+#define GPIO012_PIN_IN_SEL(x, y)               (((x) >> (y)) & 1)
+#define GPIO3_PIN_IN_SHIFT(x)                  ((x) == 5 ? 24 : 10 + (x))
+#define GPIO3_PIN_IN_SEL(x, y)                 ((x) >> GPIO3_PIN_IN_SHIFT(y))
+#define GPIO3_PIN5_IN_SEL(x)                   (((x) >> 24) & 1)
+#define GPI3_PIN_IN_SEL(x, y)                  (((x) >> (y)) & 1)
+
+struct gpio_regs {
+       void __iomem *inp_state;
+       void __iomem *outp_set;
+       void __iomem *outp_clr;
+       void __iomem *dir_set;
+       void __iomem *dir_clr;
+};
+
+/*
+ * GPIO names
+ */
+static const char *gpio_p0_names[LPC32XX_GPIO_P0_MAX] = {
+       "p0.0", "p0.1", "p0.2", "p0.3",
+       "p0.4", "p0.5", "p0.6", "p0.7"
+};
+
+static const char *gpio_p1_names[LPC32XX_GPIO_P1_MAX] = {
+       "p1.0", "p1.1", "p1.2", "p1.3",
+       "p1.4", "p1.5", "p1.6", "p1.7",
+       "p1.8", "p1.9", "p1.10", "p1.11",
+       "p1.12", "p1.13", "p1.14", "p1.15",
+       "p1.16", "p1.17", "p1.18", "p1.19",
+       "p1.20", "p1.21", "p1.22", "p1.23",
+};
+
+static const char *gpio_p2_names[LPC32XX_GPIO_P2_MAX] = {
+       "p2.0", "p2.1", "p2.2", "p2.3",
+       "p2.4", "p2.5", "p2.6", "p2.7",
+       "p2.8", "p2.9", "p2.10", "p2.11",
+       "p2.12"
+};
+
+static const char *gpio_p3_names[LPC32XX_GPIO_P3_MAX] = {
+       "gpi000", "gpio01", "gpio02", "gpio03",
+       "gpio04", "gpio05"
+};
+
+static const char *gpi_p3_names[LPC32XX_GPI_P3_MAX] = {
+       "gpi00", "gpi01", "gpi02", "gpi03",
+       "gpi04", "gpi05", "gpi06", "gpi07",
+       "gpi08", "gpi09",  NULL,    NULL,
+        NULL,    NULL,    NULL,   "gpi15",
+       "gpi16", "gpi17", "gpi18", "gpi19",
+       "gpi20", "gpi21", "gpi22", "gpi23",
+       "gpi24", "gpi25", "gpi26", "gpi27"
+};
+
+static const char *gpo_p3_names[LPC32XX_GPO_P3_MAX] = {
+       "gpo00", "gpo01", "gpo02", "gpo03",
+       "gpo04", "gpo05", "gpo06", "gpo07",
+       "gpo08", "gpo09", "gpo10", "gpo11",
+       "gpo12", "gpo13", "gpo14", "gpo15",
+       "gpo16", "gpo17", "gpo18", "gpo19",
+       "gpo20", "gpo21", "gpo22", "gpo23"
+};
+
+static struct gpio_regs gpio_grp_regs_p0 = {
+       .inp_state      = LPC32XX_GPIO_P0_INP_STATE,
+       .outp_set       = LPC32XX_GPIO_P0_OUTP_SET,
+       .outp_clr       = LPC32XX_GPIO_P0_OUTP_CLR,
+       .dir_set        = LPC32XX_GPIO_P0_DIR_SET,
+       .dir_clr        = LPC32XX_GPIO_P0_DIR_CLR,
+};
+
+static struct gpio_regs gpio_grp_regs_p1 = {
+       .inp_state      = LPC32XX_GPIO_P1_INP_STATE,
+       .outp_set       = LPC32XX_GPIO_P1_OUTP_SET,
+       .outp_clr       = LPC32XX_GPIO_P1_OUTP_CLR,
+       .dir_set        = LPC32XX_GPIO_P1_DIR_SET,
+       .dir_clr        = LPC32XX_GPIO_P1_DIR_CLR,
+};
+
+static struct gpio_regs gpio_grp_regs_p2 = {
+       .inp_state      = LPC32XX_GPIO_P2_INP_STATE,
+       .outp_set       = LPC32XX_GPIO_P2_OUTP_SET,
+       .outp_clr       = LPC32XX_GPIO_P2_OUTP_CLR,
+       .dir_set        = LPC32XX_GPIO_P2_DIR_SET,
+       .dir_clr        = LPC32XX_GPIO_P2_DIR_CLR,
+};
+
+static struct gpio_regs gpio_grp_regs_p3 = {
+       .inp_state      = LPC32XX_GPIO_P3_INP_STATE,
+       .outp_set       = LPC32XX_GPIO_P3_OUTP_SET,
+       .outp_clr       = LPC32XX_GPIO_P3_OUTP_CLR,
+       .dir_set        = LPC32XX_GPIO_P2_DIR_SET,
+       .dir_clr        = LPC32XX_GPIO_P2_DIR_CLR,
+};
+
+struct lpc32xx_gpio_chip {
+       struct gpio_chip        chip;
+       struct gpio_regs        *gpio_grp;
+};
+
+static inline struct lpc32xx_gpio_chip *to_lpc32xx_gpio(
+       struct gpio_chip *gpc)
+{
+       return container_of(gpc, struct lpc32xx_gpio_chip, chip);
+}
+
+static void __set_gpio_dir_p012(struct lpc32xx_gpio_chip *group,
+       unsigned pin, int input)
+{
+       if (input)
+               __raw_writel(GPIO012_PIN_TO_BIT(pin),
+                       group->gpio_grp->dir_clr);
+       else
+               __raw_writel(GPIO012_PIN_TO_BIT(pin),
+                       group->gpio_grp->dir_set);
+}
+
+static void __set_gpio_dir_p3(struct lpc32xx_gpio_chip *group,
+       unsigned pin, int input)
+{
+       u32 u = GPIO3_PIN_TO_BIT(pin);
+
+       if (input)
+               __raw_writel(u, group->gpio_grp->dir_clr);
+       else
+               __raw_writel(u, group->gpio_grp->dir_set);
+}
+
+static void __set_gpio_level_p012(struct lpc32xx_gpio_chip *group,
+       unsigned pin, int high)
+{
+       if (high)
+               __raw_writel(GPIO012_PIN_TO_BIT(pin),
+                       group->gpio_grp->outp_set);
+       else
+               __raw_writel(GPIO012_PIN_TO_BIT(pin),
+                       group->gpio_grp->outp_clr);
+}
+
+static void __set_gpio_level_p3(struct lpc32xx_gpio_chip *group,
+       unsigned pin, int high)
+{
+       u32 u = GPIO3_PIN_TO_BIT(pin);
+
+       if (high)
+               __raw_writel(u, group->gpio_grp->outp_set);
+       else
+               __raw_writel(u, group->gpio_grp->outp_clr);
+}
+
+static void __set_gpo_level_p3(struct lpc32xx_gpio_chip *group,
+       unsigned pin, int high)
+{
+       if (high)
+               __raw_writel(GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_set);
+       else
+               __raw_writel(GPO3_PIN_TO_BIT(pin), group->gpio_grp->outp_clr);
+}
+
+static int __get_gpio_state_p012(struct lpc32xx_gpio_chip *group,
+       unsigned pin)
+{
+       return GPIO012_PIN_IN_SEL(__raw_readl(group->gpio_grp->inp_state),
+               pin);
+}
+
+static int __get_gpio_state_p3(struct lpc32xx_gpio_chip *group,
+       unsigned pin)
+{
+       int state = __raw_readl(group->gpio_grp->inp_state);
+
+       /*
+        * P3 GPIO pin input mapping is not contiguous, GPIOP3-0..4 is mapped
+        * to bits 10..14, while GPIOP3-5 is mapped to bit 24.
+        */
+       return GPIO3_PIN_IN_SEL(state, pin);
+}
+
+static int __get_gpi_state_p3(struct lpc32xx_gpio_chip *group,
+       unsigned pin)
+{
+       return GPI3_PIN_IN_SEL(__raw_readl(group->gpio_grp->inp_state), pin);
+}
+
+/*
+ * GENERIC_GPIO primitives.
+ */
+static int lpc32xx_gpio_dir_input_p012(struct gpio_chip *chip,
+       unsigned pin)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       __set_gpio_dir_p012(group, pin, 1);
+
+       return 0;
+}
+
+static int lpc32xx_gpio_dir_input_p3(struct gpio_chip *chip,
+       unsigned pin)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       __set_gpio_dir_p3(group, pin, 1);
+
+       return 0;
+}
+
+static int lpc32xx_gpio_dir_in_always(struct gpio_chip *chip,
+       unsigned pin)
+{
+       return 0;
+}
+
+static int lpc32xx_gpio_get_value_p012(struct gpio_chip *chip, unsigned pin)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       return __get_gpio_state_p012(group, pin);
+}
+
+static int lpc32xx_gpio_get_value_p3(struct gpio_chip *chip, unsigned pin)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       return __get_gpio_state_p3(group, pin);
+}
+
+static int lpc32xx_gpi_get_value(struct gpio_chip *chip, unsigned pin)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       return __get_gpi_state_p3(group, pin);
+}
+
+static int lpc32xx_gpio_dir_output_p012(struct gpio_chip *chip, unsigned pin,
+       int value)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       __set_gpio_dir_p012(group, pin, 0);
+
+       return 0;
+}
+
+static int lpc32xx_gpio_dir_output_p3(struct gpio_chip *chip, unsigned pin,
+       int value)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       __set_gpio_dir_p3(group, pin, 0);
+
+       return 0;
+}
+
+static int lpc32xx_gpio_dir_out_always(struct gpio_chip *chip, unsigned pin,
+       int value)
+{
+       return 0;
+}
+
+static void lpc32xx_gpio_set_value_p012(struct gpio_chip *chip, unsigned pin,
+       int value)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       __set_gpio_level_p012(group, pin, value);
+}
+
+static void lpc32xx_gpio_set_value_p3(struct gpio_chip *chip, unsigned pin,
+       int value)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       __set_gpio_level_p3(group, pin, value);
+}
+
+static void lpc32xx_gpo_set_value(struct gpio_chip *chip, unsigned pin,
+       int value)
+{
+       struct lpc32xx_gpio_chip *group = to_lpc32xx_gpio(chip);
+
+       __set_gpo_level_p3(group, pin, value);
+}
+
+static int lpc32xx_gpio_request(struct gpio_chip *chip, unsigned pin)
+{
+       if (pin < chip->ngpio)
+               return 0;
+
+       return -EINVAL;
+}
+
+static struct lpc32xx_gpio_chip lpc32xx_gpiochip[] = {
+       {
+               .chip = {
+                       .label                  = "gpio_p0",
+                       .direction_input        = lpc32xx_gpio_dir_input_p012,
+                       .get                    = lpc32xx_gpio_get_value_p012,
+                       .direction_output       = lpc32xx_gpio_dir_output_p012,
+                       .set                    = lpc32xx_gpio_set_value_p012,
+                       .request                = lpc32xx_gpio_request,
+                       .base                   = LPC32XX_GPIO_P0_GRP,
+                       .ngpio                  = LPC32XX_GPIO_P0_MAX,
+                       .names                  = gpio_p0_names,
+                       .can_sleep              = 0,
+               },
+               .gpio_grp = &gpio_grp_regs_p0,
+       },
+       {
+               .chip = {
+                       .label                  = "gpio_p1",
+                       .direction_input        = lpc32xx_gpio_dir_input_p012,
+                       .get                    = lpc32xx_gpio_get_value_p012,
+                       .direction_output       = lpc32xx_gpio_dir_output_p012,
+                       .set                    = lpc32xx_gpio_set_value_p012,
+                       .request                = lpc32xx_gpio_request,
+                       .base                   = LPC32XX_GPIO_P1_GRP,
+                       .ngpio                  = LPC32XX_GPIO_P1_MAX,
+                       .names                  = gpio_p1_names,
+                       .can_sleep              = 0,
+               },
+               .gpio_grp = &gpio_grp_regs_p1,
+       },
+       {
+               .chip = {
+                       .label                  = "gpio_p2",
+                       .direction_input        = lpc32xx_gpio_dir_input_p012,
+                       .get                    = lpc32xx_gpio_get_value_p012,
+                       .direction_output       = lpc32xx_gpio_dir_output_p012,
+                       .set                    = lpc32xx_gpio_set_value_p012,
+                       .request                = lpc32xx_gpio_request,
+                       .base                   = LPC32XX_GPIO_P2_GRP,
+                       .ngpio                  = LPC32XX_GPIO_P2_MAX,
+                       .names                  = gpio_p2_names,
+                       .can_sleep              = 0,
+               },
+               .gpio_grp = &gpio_grp_regs_p2,
+       },
+       {
+               .chip = {
+                       .label                  = "gpio_p3",
+                       .direction_input        = lpc32xx_gpio_dir_input_p3,
+                       .get                    = lpc32xx_gpio_get_value_p3,
+                       .direction_output       = lpc32xx_gpio_dir_output_p3,
+                       .set                    = lpc32xx_gpio_set_value_p3,
+                       .request                = lpc32xx_gpio_request,
+                       .base                   = LPC32XX_GPIO_P3_GRP,
+                       .ngpio                  = LPC32XX_GPIO_P3_MAX,
+                       .names                  = gpio_p3_names,
+                       .can_sleep              = 0,
+               },
+               .gpio_grp = &gpio_grp_regs_p3,
+       },
+       {
+               .chip = {
+                       .label                  = "gpi_p3",
+                       .direction_input        = lpc32xx_gpio_dir_in_always,
+                       .get                    = lpc32xx_gpi_get_value,
+                       .request                = lpc32xx_gpio_request,
+                       .base                   = LPC32XX_GPI_P3_GRP,
+                       .ngpio                  = LPC32XX_GPI_P3_MAX,
+                       .names                  = gpi_p3_names,
+                       .can_sleep              = 0,
+               },
+               .gpio_grp = &gpio_grp_regs_p3,
+       },
+       {
+               .chip = {
+                       .label                  = "gpo_p3",
+                       .direction_output       = lpc32xx_gpio_dir_out_always,
+                       .set                    = lpc32xx_gpo_set_value,
+                       .request                = lpc32xx_gpio_request,
+                       .base                   = LPC32XX_GPO_P3_GRP,
+                       .ngpio                  = LPC32XX_GPO_P3_MAX,
+                       .names                  = gpo_p3_names,
+                       .can_sleep              = 0,
+               },
+               .gpio_grp = &gpio_grp_regs_p3,
+       },
+};
+
+void __init lpc32xx_gpio_init(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(lpc32xx_gpiochip); i++)
+               gpiochip_add(&lpc32xx_gpiochip[i].chip);
+}
similarity index 57%
rename from arch/arm/plat-mxc/include/mach/board-pcm043.h
rename to arch/arm/mach-lpc32xx/include/mach/clkdev.h
index 1ac4e1682e5c2f8840a778fd65a6cabf304927ad..9bf0637e29cefd9c6f5fd0c629d06def6305b9b1 100644 (file)
@@ -1,5 +1,9 @@
 /*
- *  Copyright (C) 2008 Sascha Hauer, Pengutronix
+ * arch/arm/mach-lpc32xx/include/mach/clkdev.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
  *
  * 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
  * 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_ARCH_MXC_BOARD_PCM043_H__
-#define __ASM_ARCH_MXC_BOARD_PCM043_H__
+#ifndef __ASM_ARCH_CLKDEV_H
+#define __ASM_ARCH_CLKDEV_H
+
+#define __clk_get(clk) ({ 1; })
+#define __clk_put(clk) do { } while (0)
 
-#endif /* __ASM_ARCH_MXC_BOARD_PCM043_H__ */
+#endif
similarity index 55%
rename from arch/arm/plat-mxc/include/mach/board-mx35pdk.h
rename to arch/arm/mach-lpc32xx/include/mach/debug-macro.S
index 383f1c04df06b0e8c56f84191366e120696e35e2..621744d6b15205954bbad0980b89a2315c343d3f 100644 (file)
@@ -1,5 +1,9 @@
 /*
- *  Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved
+ * arch/arm/mach-lpc32xx/include/mach/debug-macro.S
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
  *
  * 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
  * 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_ARCH_MXC_BOARD_MX35PDK_H__
-#define __ASM_ARCH_MXC_BOARD_MX35PDK_H__
+/*
+ * Debug output is hardcoded to standard UART 5
+*/
+
+       .macro  addruart,rx, tmp
+       mrc     p15, 0, \rx, c1, c0
+       tst     \rx, #1                         @ MMU enabled?
+       ldreq   \rx, =0x40090000
+       ldrne   \rx, =0xF4090000
+       .endm
 
-#endif /* __ASM_ARCH_MXC_BOARD_MX35PDK_H__ */
+#define UART_SHIFT     2
+#include <asm/hardware/debug-8250.S>
diff --git a/arch/arm/mach-lpc32xx/include/mach/entry-macro.S b/arch/arm/mach-lpc32xx/include/mach/entry-macro.S
new file mode 100644 (file)
index 0000000..870227c
--- /dev/null
@@ -0,0 +1,47 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/entry-macro.S
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#include <mach/hardware.h>
+#include <mach/platform.h>
+
+#define LPC32XX_INTC_MASKED_STATUS_OFS 0x8
+
+       .macro  disable_fiq
+       .endm
+
+       .macro  get_irqnr_preamble, base, tmp
+       ldr     \base, =IO_ADDRESS(LPC32XX_MIC_BASE)
+       .endm
+
+       .macro  arch_ret_to_user, tmp1, tmp2
+       .endm
+
+/*
+ * Return IRQ number in irqnr. Also return processor Z flag status in CPSR
+ * as set if an interrupt is pending.
+ */
+       .macro  get_irqnr_and_base, irqnr, irqstat, base, tmp
+       ldr     \irqstat, [\base, #LPC32XX_INTC_MASKED_STATUS_OFS]
+       clz     \irqnr, \irqstat
+       rsb     \irqnr, \irqnr, #31
+       teq     \irqstat, #0
+       .endm
+
+       .macro  irq_prio_table
+       .endm
+
diff --git a/arch/arm/mach-lpc32xx/include/mach/gpio.h b/arch/arm/mach-lpc32xx/include/mach/gpio.h
new file mode 100644 (file)
index 0000000..67d03da
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/gpio.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARCH_GPIO_H
+#define __ASM_ARCH_GPIO_H
+
+#include <asm-generic/gpio.h>
+
+/*
+ * Note!
+ * Muxed GP pins need to be setup to the GP state in the board level
+ * code prior to using this driver.
+ * GPI pins : 28xP3 group
+ * GPO pins : 24xP3 group
+ * GPIO pins: 8xP0 group, 24xP1 group, 13xP2 group, 6xP3 group
+ */
+
+#define LPC32XX_GPIO_P0_MAX 8
+#define LPC32XX_GPIO_P1_MAX 24
+#define LPC32XX_GPIO_P2_MAX 13
+#define LPC32XX_GPIO_P3_MAX 6
+#define LPC32XX_GPI_P3_MAX 28
+#define LPC32XX_GPO_P3_MAX 24
+
+#define LPC32XX_GPIO_P0_GRP 0
+#define LPC32XX_GPIO_P1_GRP (LPC32XX_GPIO_P0_GRP + LPC32XX_GPIO_P0_MAX)
+#define LPC32XX_GPIO_P2_GRP (LPC32XX_GPIO_P1_GRP + LPC32XX_GPIO_P1_MAX)
+#define LPC32XX_GPIO_P3_GRP (LPC32XX_GPIO_P2_GRP + LPC32XX_GPIO_P2_MAX)
+#define LPC32XX_GPI_P3_GRP (LPC32XX_GPIO_P3_GRP + LPC32XX_GPIO_P3_MAX)
+#define LPC32XX_GPO_P3_GRP (LPC32XX_GPI_P3_GRP + LPC32XX_GPI_P3_MAX)
+
+/*
+ * A specific GPIO can be selected with this macro
+ * ie, GPIO_05 can be selected with LPC32XX_GPIO(LPC32XX_GPIO_P3_GRP, 5)
+ * See the LPC32x0 User's guide for GPIO group numbers
+ */
+#define LPC32XX_GPIO(x, y) ((x) + (y))
+
+static inline int gpio_get_value(unsigned gpio)
+{
+       return __gpio_get_value(gpio);
+}
+
+static inline void gpio_set_value(unsigned gpio, int value)
+{
+       __gpio_set_value(gpio, value);
+}
+
+static inline int gpio_cansleep(unsigned gpio)
+{
+       return __gpio_cansleep(gpio);
+}
+
+static inline int gpio_to_irq(unsigned gpio)
+{
+       return __gpio_to_irq(gpio);
+}
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/include/mach/hardware.h b/arch/arm/mach-lpc32xx/include/mach/hardware.h
new file mode 100644 (file)
index 0000000..33e1dde
--- /dev/null
@@ -0,0 +1,34 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/hardware.h
+ *
+ * Copyright (c) 2005 MontaVista Software, Inc. <source@mvista.com>
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARCH_HARDWARE_H
+#define __ASM_ARCH_HARDWARE_H
+
+/*
+ * Start of virtual addresses for IO devices
+ */
+#define IO_BASE                0xF0000000
+
+/*
+ * This macro relies on fact that for all HW i/o addresses bits 20-23 are 0
+ */
+#define IO_ADDRESS(x)  (((((x) & 0xff000000) >> 4) | ((x) & 0xfffff)) |\
+                        IO_BASE)
+
+#define io_p2v(x)      ((void __iomem *) (unsigned long) IO_ADDRESS(x))
+#define io_v2p(x)      ((((x) & 0x0ff00000) << 4) | ((x) & 0x000fffff))
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/include/mach/i2c.h b/arch/arm/mach-lpc32xx/include/mach/i2c.h
new file mode 100644 (file)
index 0000000..034dc92
--- /dev/null
@@ -0,0 +1,63 @@
+/*
+ * PNX4008-specific tweaks for I2C IP3204 block
+ *
+ * Author: Vitaly Wool <vwool@ru.mvista.com>
+ *
+ * 2005 (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+
+#ifndef __ASM_ARCH_I2C_H
+#define __ASM_ARCH_I2C_H
+
+enum {
+       mstatus_tdi = 0x00000001,
+       mstatus_afi = 0x00000002,
+       mstatus_nai = 0x00000004,
+       mstatus_drmi = 0x00000008,
+       mstatus_active = 0x00000020,
+       mstatus_scl = 0x00000040,
+       mstatus_sda = 0x00000080,
+       mstatus_rff = 0x00000100,
+       mstatus_rfe = 0x00000200,
+       mstatus_tff = 0x00000400,
+       mstatus_tfe = 0x00000800,
+};
+
+enum {
+       mcntrl_tdie = 0x00000001,
+       mcntrl_afie = 0x00000002,
+       mcntrl_naie = 0x00000004,
+       mcntrl_drmie = 0x00000008,
+       mcntrl_daie = 0x00000020,
+       mcntrl_rffie = 0x00000040,
+       mcntrl_tffie = 0x00000080,
+       mcntrl_reset = 0x00000100,
+       mcntrl_cdbmode = 0x00000400,
+};
+
+enum {
+       rw_bit = 1 << 0,
+       start_bit = 1 << 8,
+       stop_bit = 1 << 9,
+};
+
+#define I2C_REG_RX(a)  ((a)->ioaddr)           /* Rx FIFO reg (RO) */
+#define I2C_REG_TX(a)  ((a)->ioaddr)           /* Tx FIFO reg (WO) */
+#define I2C_REG_STS(a) ((a)->ioaddr + 0x04)    /* Status reg (RO) */
+#define I2C_REG_CTL(a) ((a)->ioaddr + 0x08)    /* Ctl reg */
+#define I2C_REG_CKL(a) ((a)->ioaddr + 0x0c)    /* Clock divider low */
+#define I2C_REG_CKH(a) ((a)->ioaddr + 0x10)    /* Clock divider high */
+#define I2C_REG_ADR(a) ((a)->ioaddr + 0x14)    /* I2C address */
+#define I2C_REG_RFL(a) ((a)->ioaddr + 0x18)    /* Rx FIFO level (RO) */
+#define I2C_REG_TFL(a) ((a)->ioaddr + 0x1c)    /* Tx FIFO level (RO) */
+#define I2C_REG_RXB(a) ((a)->ioaddr + 0x20)    /* Num of bytes Rx-ed (RO) */
+#define I2C_REG_TXB(a) ((a)->ioaddr + 0x24)    /* Num of bytes Tx-ed (RO) */
+#define I2C_REG_TXS(a) ((a)->ioaddr + 0x28)    /* Tx slave FIFO (RO) */
+#define I2C_REG_STFL(a)        ((a)->ioaddr + 0x2c)    /* Tx slave FIFO level (RO) */
+
+#define I2C_CHIP_NAME          "PNX4008-I2C"
+
+#endif                         /* __ASM_ARCH_I2C_H */
similarity index 57%
rename from arch/arm/plat-mxc/include/mach/board-pcm037.h
rename to arch/arm/mach-lpc32xx/include/mach/io.h
index 13411709b13a067bdc8c7adf9ec6d984acb98f75..9b59ab5cef8942d13108fed8fe8c01c6217ea3b8 100644 (file)
@@ -1,5 +1,9 @@
 /*
- *  Copyright (C) 2008 Sascha Hauer, Pengutronix
+ * arch/arm/mach-lpc32xx/include/mach/io.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
  *
  * 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
  * 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_ARCH_MXC_BOARD_PCM037_H__
-#define __ASM_ARCH_MXC_BOARD_PCM037_H__
+#ifndef __ASM_ARM_ARCH_IO_H
+#define __ASM_ARM_ARCH_IO_H
+
+#define IO_SPACE_LIMIT 0xffffffff
+
+#define __io(a)                __typesafe_io(a)
+#define __mem_pci(a)   (a)
 
-#endif /* __ASM_ARCH_MXC_BOARD_PCM037_H__ */
+#endif
diff --git a/arch/arm/mach-lpc32xx/include/mach/irqs.h b/arch/arm/mach-lpc32xx/include/mach/irqs.h
new file mode 100644 (file)
index 0000000..2667f52
--- /dev/null
@@ -0,0 +1,117 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/irqs.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARM_ARCH_IRQS_H
+#define __ASM_ARM_ARCH_IRQS_H
+
+#define LPC32XX_SIC1_IRQ(n)            (32 + (n))
+#define LPC32XX_SIC2_IRQ(n)            (64 + (n))
+
+/*
+ * MIC interrupts
+ */
+#define IRQ_LPC32XX_SUB1IRQ            0
+#define IRQ_LPC32XX_SUB2IRQ            1
+#define IRQ_LPC32XX_PWM3               3
+#define IRQ_LPC32XX_PWM4               4
+#define IRQ_LPC32XX_HSTIMER            5
+#define IRQ_LPC32XX_WATCH              6
+#define IRQ_LPC32XX_UART_IIR3          7
+#define IRQ_LPC32XX_UART_IIR4          8
+#define IRQ_LPC32XX_UART_IIR5          9
+#define IRQ_LPC32XX_UART_IIR6          10
+#define IRQ_LPC32XX_FLASH              11
+#define IRQ_LPC32XX_SD1                        13
+#define IRQ_LPC32XX_LCD                        14
+#define IRQ_LPC32XX_SD0                        15
+#define IRQ_LPC32XX_TIMER0             16
+#define IRQ_LPC32XX_TIMER1             17
+#define IRQ_LPC32XX_TIMER2             18
+#define IRQ_LPC32XX_TIMER3             19
+#define IRQ_LPC32XX_SSP0               20
+#define IRQ_LPC32XX_SSP1               21
+#define IRQ_LPC32XX_I2S0               22
+#define IRQ_LPC32XX_I2S1               23
+#define IRQ_LPC32XX_UART_IIR7          24
+#define IRQ_LPC32XX_UART_IIR2          25
+#define IRQ_LPC32XX_UART_IIR1          26
+#define IRQ_LPC32XX_MSTIMER            27
+#define IRQ_LPC32XX_DMA                        28
+#define IRQ_LPC32XX_ETHERNET           29
+#define IRQ_LPC32XX_SUB1FIQ            30
+#define IRQ_LPC32XX_SUB2FIQ            31
+
+/*
+ * SIC1 interrupts start at offset 32
+ */
+#define IRQ_LPC32XX_JTAG_COMM_TX       LPC32XX_SIC1_IRQ(1)
+#define IRQ_LPC32XX_JTAG_COMM_RX       LPC32XX_SIC1_IRQ(2)
+#define IRQ_LPC32XX_GPI_11             LPC32XX_SIC1_IRQ(4)
+#define IRQ_LPC32XX_TS_P               LPC32XX_SIC1_IRQ(6)
+#define IRQ_LPC32XX_TS_IRQ             LPC32XX_SIC1_IRQ(7)
+#define IRQ_LPC32XX_TS_AUX             LPC32XX_SIC1_IRQ(8)
+#define IRQ_LPC32XX_SPI2               LPC32XX_SIC1_IRQ(12)
+#define IRQ_LPC32XX_PLLUSB             LPC32XX_SIC1_IRQ(13)
+#define IRQ_LPC32XX_PLLHCLK            LPC32XX_SIC1_IRQ(14)
+#define IRQ_LPC32XX_PLL397             LPC32XX_SIC1_IRQ(17)
+#define IRQ_LPC32XX_I2C_2              LPC32XX_SIC1_IRQ(18)
+#define IRQ_LPC32XX_I2C_1              LPC32XX_SIC1_IRQ(19)
+#define IRQ_LPC32XX_RTC                        LPC32XX_SIC1_IRQ(20)
+#define IRQ_LPC32XX_KEY                        LPC32XX_SIC1_IRQ(22)
+#define IRQ_LPC32XX_SPI1               LPC32XX_SIC1_IRQ(23)
+#define IRQ_LPC32XX_SW                 LPC32XX_SIC1_IRQ(24)
+#define IRQ_LPC32XX_USB_OTG_TIMER      LPC32XX_SIC1_IRQ(25)
+#define IRQ_LPC32XX_USB_OTG_ATX                LPC32XX_SIC1_IRQ(26)
+#define IRQ_LPC32XX_USB_HOST           LPC32XX_SIC1_IRQ(27)
+#define IRQ_LPC32XX_USB_DEV_DMA                LPC32XX_SIC1_IRQ(28)
+#define IRQ_LPC32XX_USB_DEV_LP         LPC32XX_SIC1_IRQ(29)
+#define IRQ_LPC32XX_USB_DEV_HP         LPC32XX_SIC1_IRQ(30)
+#define IRQ_LPC32XX_USB_I2C            LPC32XX_SIC1_IRQ(31)
+
+/*
+ * SIC2 interrupts start at offset 64
+ */
+#define IRQ_LPC32XX_GPIO_00            LPC32XX_SIC2_IRQ(0)
+#define IRQ_LPC32XX_GPIO_01            LPC32XX_SIC2_IRQ(1)
+#define IRQ_LPC32XX_GPIO_02            LPC32XX_SIC2_IRQ(2)
+#define IRQ_LPC32XX_GPIO_03            LPC32XX_SIC2_IRQ(3)
+#define IRQ_LPC32XX_GPIO_04            LPC32XX_SIC2_IRQ(4)
+#define IRQ_LPC32XX_GPIO_05            LPC32XX_SIC2_IRQ(5)
+#define IRQ_LPC32XX_SPI2_DATAIN                LPC32XX_SIC2_IRQ(6)
+#define IRQ_LPC32XX_U2_HCTS            LPC32XX_SIC2_IRQ(7)
+#define IRQ_LPC32XX_P0_P1_IRQ          LPC32XX_SIC2_IRQ(8)
+#define IRQ_LPC32XX_GPI_08             LPC32XX_SIC2_IRQ(9)
+#define IRQ_LPC32XX_GPI_09             LPC32XX_SIC2_IRQ(10)
+#define IRQ_LPC32XX_GPI_19             LPC32XX_SIC2_IRQ(11)
+#define IRQ_LPC32XX_U7_HCTS            LPC32XX_SIC2_IRQ(12)
+#define IRQ_LPC32XX_GPI_07             LPC32XX_SIC2_IRQ(15)
+#define IRQ_LPC32XX_SDIO               LPC32XX_SIC2_IRQ(18)
+#define IRQ_LPC32XX_U5_RX              LPC32XX_SIC2_IRQ(19)
+#define IRQ_LPC32XX_SPI1_DATAIN                LPC32XX_SIC2_IRQ(20)
+#define IRQ_LPC32XX_GPI_00             LPC32XX_SIC2_IRQ(22)
+#define IRQ_LPC32XX_GPI_01             LPC32XX_SIC2_IRQ(23)
+#define IRQ_LPC32XX_GPI_02             LPC32XX_SIC2_IRQ(24)
+#define IRQ_LPC32XX_GPI_03             LPC32XX_SIC2_IRQ(25)
+#define IRQ_LPC32XX_GPI_04             LPC32XX_SIC2_IRQ(26)
+#define IRQ_LPC32XX_GPI_05             LPC32XX_SIC2_IRQ(27)
+#define IRQ_LPC32XX_GPI_06             LPC32XX_SIC2_IRQ(28)
+#define IRQ_LPC32XX_SYSCLK             LPC32XX_SIC2_IRQ(31)
+
+#define NR_IRQS                                96
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/include/mach/memory.h b/arch/arm/mach-lpc32xx/include/mach/memory.h
new file mode 100644 (file)
index 0000000..044e1ac
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/memory.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARCH_MEMORY_H
+#define __ASM_ARCH_MEMORY_H
+
+/*
+ * Physical DRAM offset of bank 0
+ */
+#define PHYS_OFFSET    UL(0x80000000)
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/include/mach/platform.h b/arch/arm/mach-lpc32xx/include/mach/platform.h
new file mode 100644 (file)
index 0000000..14ea8d1
--- /dev/null
@@ -0,0 +1,694 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/platform.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARCH_PLATFORM_H
+#define __ASM_ARCH_PLATFORM_H
+
+#define _SBF(f, v)                             ((v) << (f))
+#define _BIT(n)                                        _SBF(n, 1)
+
+/*
+ * AHB 0 physical base addresses
+ */
+#define LPC32XX_SLC_BASE                       0x20020000
+#define LPC32XX_SSP0_BASE                      0x20084000
+#define LPC32XX_SPI1_BASE                      0x20088000
+#define LPC32XX_SSP1_BASE                      0x2008C000
+#define LPC32XX_SPI2_BASE                      0x20090000
+#define LPC32XX_I2S0_BASE                      0x20094000
+#define LPC32XX_SD_BASE                                0x20098000
+#define LPC32XX_I2S1_BASE                      0x2009C000
+#define LPC32XX_MLC_BASE                       0x200A8000
+#define LPC32XX_AHB0_START                     LPC32XX_SLC_BASE
+#define LPC32XX_AHB0_SIZE                      0x00089000
+
+/*
+ * AHB 1 physical base addresses
+ */
+#define LPC32XX_DMA_BASE                       0x31000000
+#define LPC32XX_USB_BASE                       0x31020000
+#define LPC32XX_USBH_BASE                      0x31020000
+#define LPC32XX_USB_OTG_BASE                   0x31020000
+#define LPC32XX_OTG_I2C_BASE                   0x31020300
+#define LPC32XX_LCD_BASE                       0x31040000
+#define LPC32XX_ETHERNET_BASE                  0x31060000
+#define LPC32XX_EMC_BASE                       0x31080000
+#define LPC32XX_ETB_CFG_BASE                   0x310C0000
+#define LPC32XX_ETB_DATA_BASE                  0x310E0000
+#define LPC32XX_AHB1_START                     LPC32XX_DMA_BASE
+#define LPC32XX_AHB1_SIZE                      0x000E1000
+
+/*
+ * FAB physical base addresses
+ */
+#define LPC32XX_CLK_PM_BASE                    0x40004000
+#define LPC32XX_MIC_BASE                       0x40008000
+#define LPC32XX_SIC1_BASE                      0x4000C000
+#define LPC32XX_SIC2_BASE                      0x40010000
+#define LPC32XX_HS_UART1_BASE                  0x40014000
+#define LPC32XX_HS_UART2_BASE                  0x40018000
+#define LPC32XX_HS_UART7_BASE                  0x4001C000
+#define LPC32XX_RTC_BASE                       0x40024000
+#define LPC32XX_RTC_RAM_BASE                   0x40024080
+#define LPC32XX_GPIO_BASE                      0x40028000
+#define LPC32XX_PWM3_BASE                      0x4002C000
+#define LPC32XX_PWM4_BASE                      0x40030000
+#define LPC32XX_MSTIM_BASE                     0x40034000
+#define LPC32XX_HSTIM_BASE                     0x40038000
+#define LPC32XX_WDTIM_BASE                     0x4003C000
+#define LPC32XX_DEBUG_CTRL_BASE                        0x40040000
+#define LPC32XX_TIMER0_BASE                    0x40044000
+#define LPC32XX_ADC_BASE                       0x40048000
+#define LPC32XX_TIMER1_BASE                    0x4004C000
+#define LPC32XX_KSCAN_BASE                     0x40050000
+#define LPC32XX_UART_CTRL_BASE                 0x40054000
+#define LPC32XX_TIMER2_BASE                    0x40058000
+#define LPC32XX_PWM1_BASE                      0x4005C000
+#define LPC32XX_PWM2_BASE                      0x4005C004
+#define LPC32XX_TIMER3_BASE                    0x40060000
+
+/*
+ * APB physical base addresses
+ */
+#define LPC32XX_UART3_BASE                     0x40080000
+#define LPC32XX_UART4_BASE                     0x40088000
+#define LPC32XX_UART5_BASE                     0x40090000
+#define LPC32XX_UART6_BASE                     0x40098000
+#define LPC32XX_I2C1_BASE                      0x400A0000
+#define LPC32XX_I2C2_BASE                      0x400A8000
+
+/*
+ * FAB and APB base and sizing
+ */
+#define LPC32XX_FABAPB_START                   LPC32XX_CLK_PM_BASE
+#define LPC32XX_FABAPB_SIZE                    0x000A5000
+
+/*
+ * Internal memory bases and sizes
+ */
+#define LPC32XX_IRAM_BASE                      0x08000000
+#define LPC32XX_IROM_BASE                      0x0C000000
+
+/*
+ * External Static Memory Bank Address Space Bases
+ */
+#define LPC32XX_EMC_CS0_BASE                   0xE0000000
+#define LPC32XX_EMC_CS1_BASE                   0xE1000000
+#define LPC32XX_EMC_CS2_BASE                   0xE2000000
+#define LPC32XX_EMC_CS3_BASE                   0xE3000000
+
+/*
+ * External SDRAM Memory Bank Address Space Bases
+ */
+#define LPC32XX_EMC_DYCS0_BASE                 0x80000000
+#define LPC32XX_EMC_DYCS1_BASE                 0xA0000000
+
+/*
+ * Clock and crystal information
+ */
+#define LPC32XX_MAIN_OSC_FREQ                  13000000
+#define LPC32XX_CLOCK_OSC_FREQ                 32768
+
+/*
+ * Clock and Power control register offsets
+ */
+#define _PMREG(x)                              io_p2v(LPC32XX_CLK_PM_BASE +\
+                                               (x))
+#define LPC32XX_CLKPWR_DEBUG_CTRL              _PMREG(0x000)
+#define LPC32XX_CLKPWR_BOOTMAP                 _PMREG(0x014)
+#define LPC32XX_CLKPWR_P01_ER                  _PMREG(0x018)
+#define LPC32XX_CLKPWR_USBCLK_PDIV             _PMREG(0x01C)
+#define LPC32XX_CLKPWR_INT_ER                  _PMREG(0x020)
+#define LPC32XX_CLKPWR_INT_RS                  _PMREG(0x024)
+#define LPC32XX_CLKPWR_INT_SR                  _PMREG(0x028)
+#define LPC32XX_CLKPWR_INT_AP                  _PMREG(0x02C)
+#define LPC32XX_CLKPWR_PIN_ER                  _PMREG(0x030)
+#define LPC32XX_CLKPWR_PIN_RS                  _PMREG(0x034)
+#define LPC32XX_CLKPWR_PIN_SR                  _PMREG(0x038)
+#define LPC32XX_CLKPWR_PIN_AP                  _PMREG(0x03C)
+#define LPC32XX_CLKPWR_HCLK_DIV                        _PMREG(0x040)
+#define LPC32XX_CLKPWR_PWR_CTRL                        _PMREG(0x044)
+#define LPC32XX_CLKPWR_PLL397_CTRL             _PMREG(0x048)
+#define LPC32XX_CLKPWR_MAIN_OSC_CTRL           _PMREG(0x04C)
+#define LPC32XX_CLKPWR_SYSCLK_CTRL             _PMREG(0x050)
+#define LPC32XX_CLKPWR_LCDCLK_CTRL             _PMREG(0x054)
+#define LPC32XX_CLKPWR_HCLKPLL_CTRL            _PMREG(0x058)
+#define LPC32XX_CLKPWR_ADC_CLK_CTRL_1          _PMREG(0x060)
+#define LPC32XX_CLKPWR_USB_CTRL                        _PMREG(0x064)
+#define LPC32XX_CLKPWR_SDRAMCLK_CTRL           _PMREG(0x068)
+#define LPC32XX_CLKPWR_DDR_LAP_NOM             _PMREG(0x06C)
+#define LPC32XX_CLKPWR_DDR_LAP_COUNT           _PMREG(0x070)
+#define LPC32XX_CLKPWR_DDR_LAP_DELAY           _PMREG(0x074)
+#define LPC32XX_CLKPWR_SSP_CLK_CTRL            _PMREG(0x078)
+#define LPC32XX_CLKPWR_I2S_CLK_CTRL            _PMREG(0x07C)
+#define LPC32XX_CLKPWR_MS_CTRL                 _PMREG(0x080)
+#define LPC32XX_CLKPWR_MACCLK_CTRL             _PMREG(0x090)
+#define LPC32XX_CLKPWR_TEST_CLK_SEL            _PMREG(0x0A4)
+#define LPC32XX_CLKPWR_SFW_INT                 _PMREG(0x0A8)
+#define LPC32XX_CLKPWR_I2C_CLK_CTRL            _PMREG(0x0AC)
+#define LPC32XX_CLKPWR_KEY_CLK_CTRL            _PMREG(0x0B0)
+#define LPC32XX_CLKPWR_ADC_CLK_CTRL            _PMREG(0x0B4)
+#define LPC32XX_CLKPWR_PWM_CLK_CTRL            _PMREG(0x0B8)
+#define LPC32XX_CLKPWR_TIMER_CLK_CTRL          _PMREG(0x0BC)
+#define LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1  _PMREG(0x0C0)
+#define LPC32XX_CLKPWR_SPI_CLK_CTRL            _PMREG(0x0C4)
+#define LPC32XX_CLKPWR_NAND_CLK_CTRL           _PMREG(0x0C8)
+#define LPC32XX_CLKPWR_UART3_CLK_CTRL          _PMREG(0x0D0)
+#define LPC32XX_CLKPWR_UART4_CLK_CTRL          _PMREG(0x0D4)
+#define LPC32XX_CLKPWR_UART5_CLK_CTRL          _PMREG(0x0D8)
+#define LPC32XX_CLKPWR_UART6_CLK_CTRL          _PMREG(0x0DC)
+#define LPC32XX_CLKPWR_IRDA_CLK_CTRL           _PMREG(0x0E0)
+#define LPC32XX_CLKPWR_UART_CLK_CTRL           _PMREG(0x0E4)
+#define LPC32XX_CLKPWR_DMA_CLK_CTRL            _PMREG(0x0E8)
+#define LPC32XX_CLKPWR_AUTOCLOCK               _PMREG(0x0EC)
+#define LPC32XX_CLKPWR_DEVID(x)                        _PMREG(0x130 + (x))
+
+/*
+ * clkpwr_debug_ctrl register definitions
+*/
+#define LPC32XX_CLKPWR_VFP_CLOCK_ENABLE_BIT    _BIT(4)
+
+/*
+ * clkpwr_bootmap register definitions
+ */
+#define LPC32XX_CLKPWR_BOOTMAP_SEL_BIT         _BIT(1)
+
+/*
+ * clkpwr_start_gpio register bit definitions
+ */
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO23_BIT      _BIT(31)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO22_BIT      _BIT(30)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO21_BIT      _BIT(29)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO20_BIT      _BIT(28)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO19_BIT      _BIT(27)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO18_BIT      _BIT(26)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO17_BIT      _BIT(25)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO16_BIT      _BIT(24)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO15_BIT      _BIT(23)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO14_BIT      _BIT(22)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO13_BIT      _BIT(21)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO12_BIT      _BIT(20)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO11_BIT      _BIT(19)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO10_BIT      _BIT(18)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO9_BIT       _BIT(17)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO8_BIT       _BIT(16)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO7_BIT       _BIT(15)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO6_BIT       _BIT(14)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO5_BIT       _BIT(13)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO4_BIT       _BIT(12)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO3_BIT       _BIT(11)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO2_BIT       _BIT(10)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO1_BIT       _BIT(9)
+#define LPC32XX_CLKPWR_GPIOSRC_P1IO0_BIT       _BIT(8)
+#define LPC32XX_CLKPWR_GPIOSRC_P0IO7_BIT       _BIT(7)
+#define LPC32XX_CLKPWR_GPIOSRC_P0IO6_BIT       _BIT(6)
+#define LPC32XX_CLKPWR_GPIOSRC_P0IO5_BIT       _BIT(5)
+#define LPC32XX_CLKPWR_GPIOSRC_P0IO4_BIT       _BIT(4)
+#define LPC32XX_CLKPWR_GPIOSRC_P0IO3_BIT       _BIT(3)
+#define LPC32XX_CLKPWR_GPIOSRC_P0IO2_BIT       _BIT(2)
+#define LPC32XX_CLKPWR_GPIOSRC_P0IO1_BIT       _BIT(1)
+#define LPC32XX_CLKPWR_GPIOSRC_P0IO0_BIT       _BIT(0)
+
+/*
+ * clkpwr_usbclk_pdiv register definitions
+ */
+#define LPC32XX_CLKPWR_USBPDIV_PLL_MASK                0xF
+
+/*
+ * clkpwr_start_int, clkpwr_start_raw_sts_int, clkpwr_start_sts_int,
+ * clkpwr_start_pol_int, register bit definitions
+ */
+#define LPC32XX_CLKPWR_INTSRC_ADC_BIT          _BIT(31)
+#define LPC32XX_CLKPWR_INTSRC_TS_P_BIT         _BIT(30)
+#define LPC32XX_CLKPWR_INTSRC_TS_AUX_BIT       _BIT(29)
+#define LPC32XX_CLKPWR_INTSRC_USBAHNEEDCLK_BIT _BIT(26)
+#define LPC32XX_CLKPWR_INTSRC_MSTIMER_BIT      _BIT(25)
+#define LPC32XX_CLKPWR_INTSRC_RTC_BIT          _BIT(24)
+#define LPC32XX_CLKPWR_INTSRC_USBNEEDCLK_BIT   _BIT(23)
+#define LPC32XX_CLKPWR_INTSRC_USB_BIT          _BIT(22)
+#define LPC32XX_CLKPWR_INTSRC_I2C_BIT          _BIT(21)
+#define LPC32XX_CLKPWR_INTSRC_USBOTGTIMER_BIT  _BIT(20)
+#define LPC32XX_CLKPWR_INTSRC_USBATXINT_BIT    _BIT(19)
+#define LPC32XX_CLKPWR_INTSRC_KEY_BIT          _BIT(16)
+#define LPC32XX_CLKPWR_INTSRC_MAC_BIT          _BIT(7)
+#define LPC32XX_CLKPWR_INTSRC_P0P1_BIT         _BIT(6)
+#define LPC32XX_CLKPWR_INTSRC_GPIO_05_BIT      _BIT(5)
+#define LPC32XX_CLKPWR_INTSRC_GPIO_04_BIT      _BIT(4)
+#define LPC32XX_CLKPWR_INTSRC_GPIO_03_BIT      _BIT(3)
+#define LPC32XX_CLKPWR_INTSRC_GPIO_02_BIT      _BIT(2)
+#define LPC32XX_CLKPWR_INTSRC_GPIO_01_BIT      _BIT(1)
+#define LPC32XX_CLKPWR_INTSRC_GPIO_00_BIT      _BIT(0)
+
+/*
+ * clkpwr_start_pin, clkpwr_start_raw_sts_pin, clkpwr_start_sts_pin,
+ * clkpwr_start_pol_pin register bit definitions
+ */
+#define LPC32XX_CLKPWR_EXTSRC_U7_RX_BIT                _BIT(31)
+#define LPC32XX_CLKPWR_EXTSRC_U7_HCTS_BIT      _BIT(30)
+#define LPC32XX_CLKPWR_EXTSRC_U6_IRRX_BIT      _BIT(28)
+#define LPC32XX_CLKPWR_EXTSRC_U5_RX_BIT                _BIT(26)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_28_BIT       _BIT(25)
+#define LPC32XX_CLKPWR_EXTSRC_U3_RX_BIT                _BIT(24)
+#define LPC32XX_CLKPWR_EXTSRC_U2_HCTS_BIT      _BIT(23)
+#define LPC32XX_CLKPWR_EXTSRC_U2_RX_BIT                _BIT(22)
+#define LPC32XX_CLKPWR_EXTSRC_U1_RX_BIT                _BIT(21)
+#define LPC32XX_CLKPWR_EXTSRC_MSDIO_INT_BIT    _BIT(18)
+#define LPC32XX_CLKPWR_EXTSRC_MSDIO_SRT_BIT    _BIT(17)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_06_BIT       _BIT(16)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_05_BIT       _BIT(15)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_04_BIT       _BIT(14)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_03_BIT       _BIT(13)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_02_BIT       _BIT(12)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_01_BIT       _BIT(11)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_00_BIT       _BIT(10)
+#define LPC32XX_CLKPWR_EXTSRC_SYSCLKEN_BIT     _BIT(9)
+#define LPC32XX_CLKPWR_EXTSRC_SPI1_DATIN_BIT   _BIT(8)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_07_BIT       _BIT(7)
+#define LPC32XX_CLKPWR_EXTSRC_SPI2_DATIN_BIT   _BIT(6)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_19_BIT       _BIT(5)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_09_BIT       _BIT(4)
+#define LPC32XX_CLKPWR_EXTSRC_GPI_08_BIT       _BIT(3)
+
+/*
+ * clkpwr_hclk_div register definitions
+ */
+#define LPC32XX_CLKPWR_HCLKDIV_DDRCLK_STOP     (0x0 << 7)
+#define LPC32XX_CLKPWR_HCLKDIV_DDRCLK_NORM     (0x1 << 7)
+#define LPC32XX_CLKPWR_HCLKDIV_DDRCLK_HALF     (0x2 << 7)
+#define LPC32XX_CLKPWR_HCLKDIV_PCLK_DIV(n)     (((n) & 0x1F) << 2)
+#define LPC32XX_CLKPWR_HCLKDIV_DIV_2POW(n)     ((n) & 0x3)
+
+/*
+ * clkpwr_pwr_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_CTRL_FORCE_PCLK         _BIT(10)
+#define LPC32XX_CLKPWR_SDRAM_SELF_RFSH         _BIT(9)
+#define LPC32XX_CLKPWR_UPD_SDRAM_SELF_RFSH     _BIT(8)
+#define LPC32XX_CLKPWR_AUTO_SDRAM_SELF_RFSH    _BIT(7)
+#define LPC32XX_CLKPWR_HIGHCORE_STATE_BIT      _BIT(5)
+#define LPC32XX_CLKPWR_SYSCLKEN_STATE_BIT      _BIT(4)
+#define LPC32XX_CLKPWR_SYSCLKEN_GPIO_EN                _BIT(3)
+#define LPC32XX_CLKPWR_SELECT_RUN_MODE         _BIT(2)
+#define LPC32XX_CLKPWR_HIGHCORE_GPIO_EN                _BIT(1)
+#define LPC32XX_CLKPWR_STOP_MODE_CTRL          _BIT(0)
+
+/*
+ * clkpwr_pll397_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_PLL397_MSLOCK_STS       _BIT(10)
+#define LPC32XX_CLKPWR_PLL397_BYPASS           _BIT(9)
+#define LPC32XX_CLKPWR_PLL397_BIAS_NORM                0x000
+#define LPC32XX_CLKPWR_PLL397_BIAS_N12_5       0x040
+#define LPC32XX_CLKPWR_PLL397_BIAS_N25         0x080
+#define LPC32XX_CLKPWR_PLL397_BIAS_N37_5       0x0C0
+#define LPC32XX_CLKPWR_PLL397_BIAS_P12_5       0x100
+#define LPC32XX_CLKPWR_PLL397_BIAS_P25         0x140
+#define LPC32XX_CLKPWR_PLL397_BIAS_P37_5       0x180
+#define LPC32XX_CLKPWR_PLL397_BIAS_P50         0x1C0
+#define LPC32XX_CLKPWR_PLL397_BIAS_MASK                0x1C0
+#define LPC32XX_CLKPWR_SYSCTRL_PLL397_DIS      _BIT(1)
+#define LPC32XX_CLKPWR_SYSCTRL_PLL397_STS      _BIT(0)
+
+/*
+ * clkpwr_main_osc_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_MOSC_ADD_CAP(n)         (((n) & 0x7F) << 2)
+#define LPC32XX_CLKPWR_MOSC_CAP_MASK           (0x7F << 2)
+#define LPC32XX_CLKPWR_TEST_MODE               _BIT(1)
+#define LPC32XX_CLKPWR_MOSC_DISABLE            _BIT(0)
+
+/*
+ * clkpwr_sysclk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_SYSCTRL_BP_TRIG(n)      (((n) & 0x3FF) << 2)
+#define LPC32XX_CLKPWR_SYSCTRL_BP_MASK         (0x3FF << 2)
+#define LPC32XX_CLKPWR_SYSCTRL_USEPLL397       _BIT(1)
+#define LPC32XX_CLKPWR_SYSCTRL_SYSCLKMUX       _BIT(0)
+
+/*
+ * clkpwr_lcdclk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT12   0x000
+#define LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT16   0x040
+#define LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT15   0x080
+#define LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT24   0x0C0
+#define LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_STN4M   0x100
+#define LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_STN8C   0x140
+#define LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_DSTN4M  0x180
+#define LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_DSTN8C  0x1C0
+#define LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_MSK     0x01C0
+#define LPC32XX_CLKPWR_LCDCTRL_CLK_EN          0x020
+#define LPC32XX_CLKPWR_LCDCTRL_SET_PSCALE(n)   ((n - 1) & 0x1F)
+#define LPC32XX_CLKPWR_LCDCTRL_PSCALE_MSK      0x001F
+
+/*
+ * clkpwr_hclkpll_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_HCLKPLL_POWER_UP                _BIT(16)
+#define LPC32XX_CLKPWR_HCLKPLL_CCO_BYPASS      _BIT(15)
+#define LPC32XX_CLKPWR_HCLKPLL_POSTDIV_BYPASS  _BIT(14)
+#define LPC32XX_CLKPWR_HCLKPLL_FDBK_SEL_FCLK   _BIT(13)
+#define LPC32XX_CLKPWR_HCLKPLL_POSTDIV_2POW(n) (((n) & 0x3) << 11)
+#define LPC32XX_CLKPWR_HCLKPLL_PREDIV_PLUS1(n) (((n) & 0x3) << 9)
+#define LPC32XX_CLKPWR_HCLKPLL_PLLM(n)         (((n) & 0xFF) << 1)
+#define LPC32XX_CLKPWR_HCLKPLL_PLL_STS         _BIT(0)
+
+/*
+ * clkpwr_adc_clk_ctrl_1 register definitions
+ */
+#define LPC32XX_CLKPWR_ADCCTRL1_RTDIV(n)       (((n) & 0xFF) << 0)
+#define LPC32XX_CLKPWR_ADCCTRL1_PCLK_SEL       _BIT(8)
+
+/*
+ * clkpwr_usb_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_USBCTRL_HCLK_EN         _BIT(24)
+#define LPC32XX_CLKPWR_USBCTRL_USBI2C_EN       _BIT(23)
+#define LPC32XX_CLKPWR_USBCTRL_USBDVND_EN      _BIT(22)
+#define LPC32XX_CLKPWR_USBCTRL_USBHSTND_EN     _BIT(21)
+#define LPC32XX_CLKPWR_USBCTRL_PU_ADD          (0x0 << 19)
+#define LPC32XX_CLKPWR_USBCTRL_BUS_KEEPER      (0x1 << 19)
+#define LPC32XX_CLKPWR_USBCTRL_PD_ADD          (0x3 << 19)
+#define LPC32XX_CLKPWR_USBCTRL_CLK_EN2         _BIT(18)
+#define LPC32XX_CLKPWR_USBCTRL_CLK_EN1         _BIT(17)
+#define LPC32XX_CLKPWR_USBCTRL_PLL_PWRUP       _BIT(16)
+#define LPC32XX_CLKPWR_USBCTRL_CCO_BYPASS      _BIT(15)
+#define LPC32XX_CLKPWR_USBCTRL_POSTDIV_BYPASS  _BIT(14)
+#define LPC32XX_CLKPWR_USBCTRL_FDBK_SEL_FCLK   _BIT(13)
+#define LPC32XX_CLKPWR_USBCTRL_POSTDIV_2POW(n) (((n) & 0x3) << 11)
+#define LPC32XX_CLKPWR_USBCTRL_PREDIV_PLUS1(n) (((n) & 0x3) << 9)
+#define LPC32XX_CLKPWR_USBCTRL_FDBK_PLUS1(n)   (((n) & 0xFF) << 1)
+#define LPC32XX_CLKPWR_USBCTRL_PLL_STS         _BIT(0)
+
+/*
+ * clkpwr_sdramclk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_SDRCLK_FASTSLEW_CLK     _BIT(22)
+#define LPC32XX_CLKPWR_SDRCLK_FASTSLEW         _BIT(21)
+#define LPC32XX_CLKPWR_SDRCLK_FASTSLEW_DAT     _BIT(20)
+#define LPC32XX_CLKPWR_SDRCLK_SW_DDR_RESET     _BIT(19)
+#define LPC32XX_CLKPWR_SDRCLK_HCLK_DLY(n)      (((n) & 0x1F) << 14)
+#define LPC32XX_CLKPWR_SDRCLK_DLY_ADDR_STS     _BIT(13)
+#define LPC32XX_CLKPWR_SDRCLK_SENS_FACT(n)     (((n) & 0x7) << 10)
+#define LPC32XX_CLKPWR_SDRCLK_USE_CAL          _BIT(9)
+#define LPC32XX_CLKPWR_SDRCLK_DO_CAL           _BIT(8)
+#define LPC32XX_CLKPWR_SDRCLK_CAL_ON_RTC       _BIT(7)
+#define LPC32XX_CLKPWR_SDRCLK_DQS_DLY(n)       (((n) & 0x1F) << 2)
+#define LPC32XX_CLKPWR_SDRCLK_USE_DDR          _BIT(1)
+#define LPC32XX_CLKPWR_SDRCLK_CLK_DIS          _BIT(0)
+
+/*
+ * clkpwr_ssp_blk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_SSPCTRL_DMA_SSP1RX      _BIT(5)
+#define LPC32XX_CLKPWR_SSPCTRL_DMA_SSP1TX      _BIT(4)
+#define LPC32XX_CLKPWR_SSPCTRL_DMA_SSP0RX      _BIT(3)
+#define LPC32XX_CLKPWR_SSPCTRL_DMA_SSP0TX      _BIT(2)
+#define LPC32XX_CLKPWR_SSPCTRL_SSPCLK1_EN      _BIT(1)
+#define LPC32XX_CLKPWR_SSPCTRL_SSPCLK0_EN      _BIT(0)
+
+/*
+ * clkpwr_i2s_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_I2SCTRL_I2S1_RX_FOR_TX  _BIT(6)
+#define LPC32XX_CLKPWR_I2SCTRL_I2S1_TX_FOR_RX  _BIT(5)
+#define LPC32XX_CLKPWR_I2SCTRL_I2S1_USE_DMA    _BIT(4)
+#define LPC32XX_CLKPWR_I2SCTRL_I2S0_RX_FOR_TX  _BIT(3)
+#define LPC32XX_CLKPWR_I2SCTRL_I2S0_TX_FOR_RX  _BIT(2)
+#define LPC32XX_CLKPWR_I2SCTRL_I2SCLK1_EN      _BIT(1)
+#define LPC32XX_CLKPWR_I2SCTRL_I2SCLK0_EN      _BIT(0)
+
+/*
+ * clkpwr_ms_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_MSCARD_MSDIO_PIN_DIS    _BIT(10)
+#define LPC32XX_CLKPWR_MSCARD_MSDIO_PU_EN      _BIT(9)
+#define LPC32XX_CLKPWR_MSCARD_MSDIO23_DIS      _BIT(8)
+#define LPC32XX_CLKPWR_MSCARD_MSDIO1_DIS       _BIT(7)
+#define LPC32XX_CLKPWR_MSCARD_MSDIO0_DIS       _BIT(6)
+#define LPC32XX_CLKPWR_MSCARD_SDCARD_EN                _BIT(5)
+#define LPC32XX_CLKPWR_MSCARD_SDCARD_DIV(n)    ((n) & 0xF)
+
+/*
+ * clkpwr_macclk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_MACCTRL_NO_ENET_PIS     0x00
+#define LPC32XX_CLKPWR_MACCTRL_USE_MII_PINS    0x08
+#define LPC32XX_CLKPWR_MACCTRL_USE_RMII_PINS   0x18
+#define LPC32XX_CLKPWR_MACCTRL_PINS_MSK                0x18
+#define LPC32XX_CLKPWR_MACCTRL_DMACLK_EN       _BIT(2)
+#define LPC32XX_CLKPWR_MACCTRL_MMIOCLK_EN      _BIT(1)
+#define LPC32XX_CLKPWR_MACCTRL_HRCCLK_EN       _BIT(0)
+
+/*
+ * clkpwr_test_clk_sel register definitions
+ */
+#define LPC32XX_CLKPWR_TESTCLK1_SEL_PERCLK     (0x0 << 5)
+#define LPC32XX_CLKPWR_TESTCLK1_SEL_RTC                (0x1 << 5)
+#define LPC32XX_CLKPWR_TESTCLK1_SEL_MOSC       (0x2 << 5)
+#define LPC32XX_CLKPWR_TESTCLK1_SEL_MASK       (0x3 << 5)
+#define LPC32XX_CLKPWR_TESTCLK_TESTCLK1_EN     _BIT(4)
+#define LPC32XX_CLKPWR_TESTCLK2_SEL_HCLK       (0x0 << 1)
+#define LPC32XX_CLKPWR_TESTCLK2_SEL_PERCLK     (0x1 << 1)
+#define LPC32XX_CLKPWR_TESTCLK2_SEL_USBCLK     (0x2 << 1)
+#define LPC32XX_CLKPWR_TESTCLK2_SEL_MOSC       (0x5 << 1)
+#define LPC32XX_CLKPWR_TESTCLK2_SEL_PLL397     (0x7 << 1)
+#define LPC32XX_CLKPWR_TESTCLK2_SEL_MASK       (0x7 << 1)
+#define LPC32XX_CLKPWR_TESTCLK_TESTCLK2_EN     _BIT(0)
+
+/*
+ * clkpwr_sw_int register definitions
+ */
+#define LPC32XX_CLKPWR_SW_INT(n)               (_BIT(0) | (((n) & 0x7F) << 1))
+#define LPC32XX_CLKPWR_SW_GET_ARG(n)           (((n) & 0xFE) >> 1)
+
+/*
+ * clkpwr_i2c_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_I2CCLK_USBI2CHI_DRIVE   _BIT(4)
+#define LPC32XX_CLKPWR_I2CCLK_I2C2HI_DRIVE     _BIT(3)
+#define LPC32XX_CLKPWR_I2CCLK_I2C1HI_DRIVE     _BIT(2)
+#define LPC32XX_CLKPWR_I2CCLK_I2C2CLK_EN       _BIT(1)
+#define LPC32XX_CLKPWR_I2CCLK_I2C1CLK_EN       _BIT(0)
+
+/*
+ * clkpwr_key_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_KEYCLKCTRL_CLK_EN       0x1
+
+/*
+ * clkpwr_adc_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_ADC32CLKCTRL_CLK_EN     0x1
+
+/*
+ * clkpwr_pwm_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_PWMCLK_PWM2_DIV(n)      (((n) & 0xF) << 8)
+#define LPC32XX_CLKPWR_PWMCLK_PWM1_DIV(n)      (((n) & 0xF) << 4)
+#define LPC32XX_CLKPWR_PWMCLK_PWM2SEL_PCLK     0x8
+#define LPC32XX_CLKPWR_PWMCLK_PWM2CLK_EN       0x4
+#define LPC32XX_CLKPWR_PWMCLK_PWM1SEL_PCLK     0x2
+#define LPC32XX_CLKPWR_PWMCLK_PWM1CLK_EN       0x1
+
+/*
+ * clkpwr_timer_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_PWMCLK_HSTIMER_EN       0x2
+#define LPC32XX_CLKPWR_PWMCLK_WDOG_EN          0x1
+
+/*
+ * clkpwr_timers_pwms_clk_ctrl_1 register definitions
+ */
+#define LPC32XX_CLKPWR_TMRPWMCLK_TIMER3_EN     0x20
+#define LPC32XX_CLKPWR_TMRPWMCLK_TIMER2_EN     0x10
+#define LPC32XX_CLKPWR_TMRPWMCLK_TIMER1_EN     0x08
+#define LPC32XX_CLKPWR_TMRPWMCLK_TIMER0_EN     0x04
+#define LPC32XX_CLKPWR_TMRPWMCLK_PWM4_EN       0x02
+#define LPC32XX_CLKPWR_TMRPWMCLK_PWM3_EN       0x01
+
+/*
+ * clkpwr_spi_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_SPICLK_SET_SPI2DATIO    0x80
+#define LPC32XX_CLKPWR_SPICLK_SET_SPI2CLK      0x40
+#define LPC32XX_CLKPWR_SPICLK_USE_SPI2         0x20
+#define LPC32XX_CLKPWR_SPICLK_SPI2CLK_EN       0x10
+#define LPC32XX_CLKPWR_SPICLK_SET_SPI1DATIO    0x08
+#define LPC32XX_CLKPWR_SPICLK_SET_SPI1CLK      0x04
+#define LPC32XX_CLKPWR_SPICLK_USE_SPI1         0x02
+#define LPC32XX_CLKPWR_SPICLK_SPI1CLK_EN       0x01
+
+/*
+ * clkpwr_nand_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_NANDCLK_INTSEL_MLC      0x20
+#define LPC32XX_CLKPWR_NANDCLK_DMA_RNB         0x10
+#define LPC32XX_CLKPWR_NANDCLK_DMA_INT         0x08
+#define LPC32XX_CLKPWR_NANDCLK_SEL_SLC         0x04
+#define LPC32XX_CLKPWR_NANDCLK_MLCCLK_EN       0x02
+#define LPC32XX_CLKPWR_NANDCLK_SLCCLK_EN       0x01
+
+/*
+ * clkpwr_uart3_clk_ctrl, clkpwr_uart4_clk_ctrl, clkpwr_uart5_clk_ctrl
+ * and clkpwr_uart6_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_UART_Y_DIV(y)           ((y) & 0xFF)
+#define LPC32XX_CLKPWR_UART_X_DIV(x)           (((x) & 0xFF) << 8)
+#define LPC32XX_CLKPWR_UART_USE_HCLK           _BIT(16)
+
+/*
+ * clkpwr_irda_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_IRDA_Y_DIV(y)           ((y) & 0xFF)
+#define LPC32XX_CLKPWR_IRDA_X_DIV(x)           (((x) & 0xFF) << 8)
+
+/*
+ * clkpwr_uart_clk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_UARTCLKCTRL_UART6_EN    _BIT(3)
+#define LPC32XX_CLKPWR_UARTCLKCTRL_UART5_EN    _BIT(2)
+#define LPC32XX_CLKPWR_UARTCLKCTRL_UART4_EN    _BIT(1)
+#define LPC32XX_CLKPWR_UARTCLKCTRL_UART3_EN    _BIT(0)
+
+/*
+ * clkpwr_dmaclk_ctrl register definitions
+ */
+#define LPC32XX_CLKPWR_DMACLKCTRL_CLK_EN       0x1
+
+/*
+ * clkpwr_autoclock register definitions
+ */
+#define LPC32XX_CLKPWR_AUTOCLK_USB_EN          0x40
+#define LPC32XX_CLKPWR_AUTOCLK_IRAM_EN         0x02
+#define LPC32XX_CLKPWR_AUTOCLK_IROM_EN         0x01
+
+/*
+ * Interrupt controller register offsets
+ */
+#define LPC32XX_INTC_MASK(x)                   io_p2v((x) + 0x00)
+#define LPC32XX_INTC_RAW_STAT(x)               io_p2v((x) + 0x04)
+#define LPC32XX_INTC_STAT(x)                   io_p2v((x) + 0x08)
+#define LPC32XX_INTC_POLAR(x)                  io_p2v((x) + 0x0C)
+#define LPC32XX_INTC_ACT_TYPE(x)               io_p2v((x) + 0x10)
+#define LPC32XX_INTC_TYPE(x)                   io_p2v((x) + 0x14)
+
+/*
+ * Timer/counter register offsets
+ */
+#define LCP32XX_TIMER_IR(x)                    io_p2v((x) + 0x00)
+#define LCP32XX_TIMER_TCR(x)                   io_p2v((x) + 0x04)
+#define LCP32XX_TIMER_TC(x)                    io_p2v((x) + 0x08)
+#define LCP32XX_TIMER_PR(x)                    io_p2v((x) + 0x0C)
+#define LCP32XX_TIMER_PC(x)                    io_p2v((x) + 0x10)
+#define LCP32XX_TIMER_MCR(x)                   io_p2v((x) + 0x14)
+#define LCP32XX_TIMER_MR0(x)                   io_p2v((x) + 0x18)
+#define LCP32XX_TIMER_MR1(x)                   io_p2v((x) + 0x1C)
+#define LCP32XX_TIMER_MR2(x)                   io_p2v((x) + 0x20)
+#define LCP32XX_TIMER_MR3(x)                   io_p2v((x) + 0x24)
+#define LCP32XX_TIMER_CCR(x)                   io_p2v((x) + 0x28)
+#define LCP32XX_TIMER_CR0(x)                   io_p2v((x) + 0x2C)
+#define LCP32XX_TIMER_CR1(x)                   io_p2v((x) + 0x30)
+#define LCP32XX_TIMER_CR2(x)                   io_p2v((x) + 0x34)
+#define LCP32XX_TIMER_CR3(x)                   io_p2v((x) + 0x38)
+#define LCP32XX_TIMER_EMR(x)                   io_p2v((x) + 0x3C)
+#define LCP32XX_TIMER_CTCR(x)                  io_p2v((x) + 0x70)
+
+/*
+ * ir register definitions
+ */
+#define LCP32XX_TIMER_CNTR_MTCH_BIT(n)         (1 << ((n) & 0x3))
+#define LCP32XX_TIMER_CNTR_CAPT_BIT(n)         (1 << (4 + ((n) & 0x3)))
+
+/*
+ * tcr register definitions
+ */
+#define LCP32XX_TIMER_CNTR_TCR_EN              0x1
+#define LCP32XX_TIMER_CNTR_TCR_RESET           0x2
+
+/*
+ * mcr register definitions
+ */
+#define LCP32XX_TIMER_CNTR_MCR_MTCH(n)         (0x1 << ((n) * 3))
+#define LCP32XX_TIMER_CNTR_MCR_RESET(n)                (0x1 << (((n) * 3) + 1))
+#define LCP32XX_TIMER_CNTR_MCR_STOP(n)         (0x1 << (((n) * 3) + 2))
+
+/*
+ * Standard UART register offsets
+ */
+#define LPC32XX_UART_DLL_FIFO(x)               io_p2v((x) + 0x00)
+#define LPC32XX_UART_DLM_IER(x)                        io_p2v((x) + 0x04)
+#define LPC32XX_UART_IIR_FCR(x)                        io_p2v((x) + 0x08)
+#define LPC32XX_UART_LCR(x)                    io_p2v((x) + 0x0C)
+#define LPC32XX_UART_MODEM_CTRL(x)             io_p2v((x) + 0x10)
+#define LPC32XX_UART_LSR(x)                    io_p2v((x) + 0x14)
+#define LPC32XX_UART_MODEM_STATUS(x)           io_p2v((x) + 0x18)
+#define LPC32XX_UART_RXLEV(x)                  io_p2v((x) + 0x1C)
+
+/*
+ * UART control structure offsets
+ */
+#define _UCREG(x)                              io_p2v(\
+                                               LPC32XX_UART_CTRL_BASE + (x))
+#define LPC32XX_UARTCTL_CTRL                   _UCREG(0x00)
+#define LPC32XX_UARTCTL_CLKMODE                        _UCREG(0x04)
+#define LPC32XX_UARTCTL_CLOOP                  _UCREG(0x08)
+
+/*
+ * ctrl register definitions
+ */
+#define LPC32XX_UART_U3_MD_CTRL_EN             _BIT(11)
+#define LPC32XX_UART_IRRX6_INV_EN              _BIT(10)
+#define LPC32XX_UART_HDPX_EN                   _BIT(9)
+#define LPC32XX_UART_UART6_IRDAMOD_BYPASS      _BIT(5)
+#define LPC32XX_RT_IRTX6_INV_EN                        _BIT(4)
+#define LPC32XX_RT_IRTX6_INV_MIR_EN            _BIT(3)
+#define LPC32XX_RT_RX_IRPULSE_3_16_115K                _BIT(2)
+#define LPC32XX_RT_TX_IRPULSE_3_16_115K                _BIT(1)
+#define LPC32XX_UART_U5_ROUTE_TO_USB           _BIT(0)
+
+/*
+ * clkmode register definitions
+ */
+#define LPC32XX_UART_ENABLED_CLOCKS(n)         (((n) >> 16) & 0x7F)
+#define LPC32XX_UART_ENABLED_CLOCK(n, u)       (((n) >> (16 + (u))) & 0x1)
+#define LPC32XX_UART_ENABLED_CLKS_ANY          _BIT(14)
+#define LPC32XX_UART_CLKMODE_OFF               0x0
+#define LPC32XX_UART_CLKMODE_ON                        0x1
+#define LPC32XX_UART_CLKMODE_AUTO              0x2
+#define LPC32XX_UART_CLKMODE_MASK(u)           (0x3 << ((((u) - 3) * 2) + 4))
+#define LPC32XX_UART_CLKMODE_LOAD(m, u)                ((m) << ((((u) - 3) * 2) + 4))
+
+/*
+ * GPIO Module Register offsets
+ */
+#define _GPREG(x)                              io_p2v(LPC32XX_GPIO_BASE + (x))
+#define LPC32XX_GPIO_P_MUX_SET                 _GPREG(0x100)
+#define LPC32XX_GPIO_P_MUX_CLR                 _GPREG(0x104)
+#define LPC32XX_GPIO_P_MUX_STATE               _GPREG(0x108)
+#define LPC32XX_GPIO_P3_MUX_SET                        _GPREG(0x110)
+#define LPC32XX_GPIO_P3_MUX_CLR                        _GPREG(0x114)
+#define LPC32XX_GPIO_P3_MUX_STATE              _GPREG(0x118)
+#define LPC32XX_GPIO_P0_MUX_SET                        _GPREG(0x120)
+#define LPC32XX_GPIO_P0_MUX_CLR                        _GPREG(0x124)
+#define LPC32XX_GPIO_P0_MUX_STATE              _GPREG(0x128)
+#define LPC32XX_GPIO_P1_MUX_SET                        _GPREG(0x130)
+#define LPC32XX_GPIO_P1_MUX_CLR                        _GPREG(0x134)
+#define LPC32XX_GPIO_P1_MUX_STATE              _GPREG(0x138)
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/include/mach/system.h b/arch/arm/mach-lpc32xx/include/mach/system.h
new file mode 100644 (file)
index 0000000..df3b0de
--- /dev/null
@@ -0,0 +1,52 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/system.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARCH_SYSTEM_H
+#define __ASM_ARCH_SYSTEM_H
+
+static void arch_idle(void)
+{
+       cpu_do_idle();
+}
+
+static inline void arch_reset(char mode, const char *cmd)
+{
+       extern void lpc32xx_watchdog_reset(void);
+
+       switch (mode) {
+       case 's':
+       case 'h':
+               printk(KERN_CRIT "RESET: Rebooting system\n");
+
+               /* Disable interrupts */
+               local_irq_disable();
+
+               lpc32xx_watchdog_reset();
+               break;
+
+       default:
+               /* Do nothing */
+               break;
+       }
+
+       /* Wait for watchdog to reset system */
+       while (1)
+               ;
+}
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/include/mach/timex.h b/arch/arm/mach-lpc32xx/include/mach/timex.h
new file mode 100644 (file)
index 0000000..8d4066b
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/timex.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARCH_TIMEX_H
+#define __ASM_ARCH_TIMEX_H
+
+/*
+ * Rate in Hz of the main system oscillator. This value should match
+ * the value 'MAIN_OSC_FREQ' in platform.h
+ */
+#define CLOCK_TICK_RATE        13000000
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/include/mach/uncompress.h b/arch/arm/mach-lpc32xx/include/mach/uncompress.h
new file mode 100644 (file)
index 0000000..c142487
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/uncompress.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARM_ARCH_UNCOMPRESS_H
+#define __ASM_ARM_ARCH_UNCOMPRESS_H
+
+#include <linux/io.h>
+
+#include <mach/hardware.h>
+#include <mach/platform.h>
+
+/*
+ * Uncompress output is hardcoded to standard UART 5
+ */
+
+#define UART_FIFO_CTL_TX_RESET (1 << 2)
+#define UART_STATUS_TX_MT      (1 << 6)
+
+#define _UARTREG(x)            (void __iomem *)(LPC32XX_UART5_BASE + (x))
+
+#define LPC32XX_UART_DLLFIFO_O 0x00
+#define LPC32XX_UART_IIRFCR_O  0x08
+#define LPC32XX_UART_LSR_O     0x14
+
+static inline void putc(int ch)
+{
+       /* Wait for transmit FIFO to empty */
+       while ((__raw_readl(_UARTREG(LPC32XX_UART_LSR_O)) &
+               UART_STATUS_TX_MT) == 0)
+               ;
+
+       __raw_writel((u32) ch, _UARTREG(LPC32XX_UART_DLLFIFO_O));
+}
+
+static inline void flush(void)
+{
+       __raw_writel(__raw_readl(_UARTREG(LPC32XX_UART_IIRFCR_O)) |
+               UART_FIFO_CTL_TX_RESET, _UARTREG(LPC32XX_UART_IIRFCR_O));
+}
+
+/* NULL functions; we don't presently need them */
+#define arch_decomp_setup()
+#define arch_decomp_wdog()
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/include/mach/vmalloc.h b/arch/arm/mach-lpc32xx/include/mach/vmalloc.h
new file mode 100644 (file)
index 0000000..d1d936c
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * arch/arm/mach-lpc32xx/include/mach/vmalloc.h
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#ifndef __ASM_ARCH_VMALLOC_H
+#define __ASM_ARCH_VMALLOC_H
+
+#define VMALLOC_END    0xF0000000
+
+#endif
diff --git a/arch/arm/mach-lpc32xx/irq.c b/arch/arm/mach-lpc32xx/irq.c
new file mode 100644 (file)
index 0000000..bd0df26
--- /dev/null
@@ -0,0 +1,432 @@
+/*
+ * arch/arm/mach-lpc32xx/irq.c
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/err.h>
+#include <linux/io.h>
+
+#include <mach/irqs.h>
+#include <mach/hardware.h>
+#include <mach/platform.h>
+#include "common.h"
+
+/*
+ * Default value representing the Activation polarity of all internal
+ * interrupt sources
+ */
+#define MIC_APR_DEFAULT                0x3FF0EFE0
+#define SIC1_APR_DEFAULT       0xFBD27186
+#define SIC2_APR_DEFAULT       0x801810C0
+
+/*
+ * Default value representing the Activation Type of all internal
+ * interrupt sources. All are level sensitive.
+ */
+#define MIC_ATR_DEFAULT                0x00000000
+#define SIC1_ATR_DEFAULT       0x00026000
+#define SIC2_ATR_DEFAULT       0x00000000
+
+struct lpc32xx_event_group_regs {
+       void __iomem *enab_reg;
+       void __iomem *edge_reg;
+       void __iomem *maskstat_reg;
+       void __iomem *rawstat_reg;
+};
+
+static const struct lpc32xx_event_group_regs lpc32xx_event_int_regs = {
+       .enab_reg = LPC32XX_CLKPWR_INT_ER,
+       .edge_reg = LPC32XX_CLKPWR_INT_AP,
+       .maskstat_reg = LPC32XX_CLKPWR_INT_SR,
+       .rawstat_reg = LPC32XX_CLKPWR_INT_RS,
+};
+
+static const struct lpc32xx_event_group_regs lpc32xx_event_pin_regs = {
+       .enab_reg = LPC32XX_CLKPWR_PIN_ER,
+       .edge_reg = LPC32XX_CLKPWR_PIN_AP,
+       .maskstat_reg = LPC32XX_CLKPWR_PIN_SR,
+       .rawstat_reg = LPC32XX_CLKPWR_PIN_RS,
+};
+
+struct lpc32xx_event_info {
+       const struct lpc32xx_event_group_regs *event_group;
+       u32 mask;
+};
+
+/*
+ * Maps an IRQ number to and event mask and register
+ */
+static const struct lpc32xx_event_info lpc32xx_events[NR_IRQS] = {
+       [IRQ_LPC32XX_GPI_08] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_08_BIT,
+       },
+       [IRQ_LPC32XX_GPI_09] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_09_BIT,
+       },
+       [IRQ_LPC32XX_GPI_19] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_19_BIT,
+       },
+       [IRQ_LPC32XX_GPI_07] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_07_BIT,
+       },
+       [IRQ_LPC32XX_GPI_00] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_00_BIT,
+       },
+       [IRQ_LPC32XX_GPI_01] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_01_BIT,
+       },
+       [IRQ_LPC32XX_GPI_02] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_02_BIT,
+       },
+       [IRQ_LPC32XX_GPI_03] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_03_BIT,
+       },
+       [IRQ_LPC32XX_GPI_04] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_04_BIT,
+       },
+       [IRQ_LPC32XX_GPI_05] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_05_BIT,
+       },
+       [IRQ_LPC32XX_GPI_06] = {
+               .event_group = &lpc32xx_event_pin_regs,
+               .mask = LPC32XX_CLKPWR_EXTSRC_GPI_06_BIT,
+       },
+       [IRQ_LPC32XX_GPIO_00] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_00_BIT,
+       },
+       [IRQ_LPC32XX_GPIO_01] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_01_BIT,
+       },
+       [IRQ_LPC32XX_GPIO_02] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_02_BIT,
+       },
+       [IRQ_LPC32XX_GPIO_03] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_03_BIT,
+       },
+       [IRQ_LPC32XX_GPIO_04] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_04_BIT,
+       },
+       [IRQ_LPC32XX_GPIO_05] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_GPIO_05_BIT,
+       },
+       [IRQ_LPC32XX_KEY] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_KEY_BIT,
+       },
+       [IRQ_LPC32XX_USB_OTG_ATX] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_USBATXINT_BIT,
+       },
+       [IRQ_LPC32XX_USB_HOST] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_USB_BIT,
+       },
+       [IRQ_LPC32XX_RTC] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_RTC_BIT,
+       },
+       [IRQ_LPC32XX_MSTIMER] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_MSTIMER_BIT,
+       },
+       [IRQ_LPC32XX_TS_AUX] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_TS_AUX_BIT,
+       },
+       [IRQ_LPC32XX_TS_P] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_TS_P_BIT,
+       },
+       [IRQ_LPC32XX_TS_IRQ] = {
+               .event_group = &lpc32xx_event_int_regs,
+               .mask = LPC32XX_CLKPWR_INTSRC_ADC_BIT,
+       },
+};
+
+static void get_controller(unsigned int irq, unsigned int *base,
+       unsigned int *irqbit)
+{
+       if (irq < 32) {
+               *base = LPC32XX_MIC_BASE;
+               *irqbit = 1 << irq;
+       } else if (irq < 64) {
+               *base = LPC32XX_SIC1_BASE;
+               *irqbit = 1 << (irq - 32);
+       } else {
+               *base = LPC32XX_SIC2_BASE;
+               *irqbit = 1 << (irq - 64);
+       }
+}
+
+static void lpc32xx_mask_irq(unsigned int irq)
+{
+       unsigned int reg, ctrl, mask;
+
+       get_controller(irq, &ctrl, &mask);
+
+       reg = __raw_readl(LPC32XX_INTC_MASK(ctrl)) & ~mask;
+       __raw_writel(reg, LPC32XX_INTC_MASK(ctrl));
+}
+
+static void lpc32xx_unmask_irq(unsigned int irq)
+{
+       unsigned int reg, ctrl, mask;
+
+       get_controller(irq, &ctrl, &mask);
+
+       reg = __raw_readl(LPC32XX_INTC_MASK(ctrl)) | mask;
+       __raw_writel(reg, LPC32XX_INTC_MASK(ctrl));
+}
+
+static void lpc32xx_ack_irq(unsigned int irq)
+{
+       unsigned int ctrl, mask;
+
+       get_controller(irq, &ctrl, &mask);
+
+       __raw_writel(mask, LPC32XX_INTC_RAW_STAT(ctrl));
+
+       /* Also need to clear pending wake event */
+       if (lpc32xx_events[irq].mask != 0)
+               __raw_writel(lpc32xx_events[irq].mask,
+                       lpc32xx_events[irq].event_group->rawstat_reg);
+}
+
+static void __lpc32xx_set_irq_type(unsigned int irq, int use_high_level,
+       int use_edge)
+{
+       unsigned int reg, ctrl, mask;
+
+       get_controller(irq, &ctrl, &mask);
+
+       /* Activation level, high or low */
+       reg = __raw_readl(LPC32XX_INTC_POLAR(ctrl));
+       if (use_high_level)
+               reg |= mask;
+       else
+               reg &= ~mask;
+       __raw_writel(reg, LPC32XX_INTC_POLAR(ctrl));
+
+       /* Activation type, edge or level */
+       reg = __raw_readl(LPC32XX_INTC_ACT_TYPE(ctrl));
+       if (use_edge)
+               reg |= mask;
+       else
+               reg &= ~mask;
+       __raw_writel(reg, LPC32XX_INTC_ACT_TYPE(ctrl));
+
+       /* Use same polarity for the wake events */
+       if (lpc32xx_events[irq].mask != 0) {
+               reg = __raw_readl(lpc32xx_events[irq].event_group->edge_reg);
+
+               if (use_high_level)
+                       reg |= lpc32xx_events[irq].mask;
+               else
+                       reg &= ~lpc32xx_events[irq].mask;
+
+               __raw_writel(reg, lpc32xx_events[irq].event_group->edge_reg);
+       }
+}
+
+static int lpc32xx_set_irq_type(unsigned int irq, unsigned int type)
+{
+       switch (type) {
+       case IRQ_TYPE_EDGE_RISING:
+               /* Rising edge sensitive */
+               __lpc32xx_set_irq_type(irq, 1, 1);
+               break;
+
+       case IRQ_TYPE_EDGE_FALLING:
+               /* Falling edge sensitive */
+               __lpc32xx_set_irq_type(irq, 0, 1);
+               break;
+
+       case IRQ_TYPE_LEVEL_LOW:
+               /* Low level sensitive */
+               __lpc32xx_set_irq_type(irq, 0, 0);
+               break;
+
+       case IRQ_TYPE_LEVEL_HIGH:
+               /* High level sensitive */
+               __lpc32xx_set_irq_type(irq, 1, 0);
+               break;
+
+       /* Other modes are not supported */
+       default:
+               return -EINVAL;
+       }
+
+       /* Ok to use the level handler for all types */
+       set_irq_handler(irq, handle_level_irq);
+
+       return 0;
+}
+
+static int lpc32xx_irq_wake(unsigned int irqno, unsigned int state)
+{
+       unsigned long eventreg;
+
+       if (lpc32xx_events[irqno].mask != 0) {
+               eventreg = __raw_readl(lpc32xx_events[irqno].
+                       event_group->enab_reg);
+
+               if (state)
+                       eventreg |= lpc32xx_events[irqno].mask;
+               else
+                       eventreg &= ~lpc32xx_events[irqno].mask;
+
+               __raw_writel(eventreg,
+                       lpc32xx_events[irqno].event_group->enab_reg);
+
+               return 0;
+       }
+
+       /* Clear event */
+       __raw_writel(lpc32xx_events[irqno].mask,
+               lpc32xx_events[irqno].event_group->rawstat_reg);
+
+       return -ENODEV;
+}
+
+static void __init lpc32xx_set_default_mappings(unsigned int apr,
+       unsigned int atr, unsigned int offset)
+{
+       unsigned int i;
+
+       /* Set activation levels for each interrupt */
+       i = 0;
+       while (i < 32) {
+               __lpc32xx_set_irq_type(offset + i, ((apr >> i) & 0x1),
+                       ((atr >> i) & 0x1));
+               i++;
+       }
+}
+
+static struct irq_chip lpc32xx_irq_chip = {
+       .ack = lpc32xx_ack_irq,
+       .mask = lpc32xx_mask_irq,
+       .unmask = lpc32xx_unmask_irq,
+       .set_type = lpc32xx_set_irq_type,
+       .set_wake = lpc32xx_irq_wake
+};
+
+static void lpc32xx_sic1_handler(unsigned int irq, struct irq_desc *desc)
+{
+       unsigned long ints = __raw_readl(LPC32XX_INTC_STAT(LPC32XX_SIC1_BASE));
+
+       while (ints != 0) {
+               int irqno = fls(ints) - 1;
+
+               ints &= ~(1 << irqno);
+
+               generic_handle_irq(LPC32XX_SIC1_IRQ(irqno));
+       }
+}
+
+static void lpc32xx_sic2_handler(unsigned int irq, struct irq_desc *desc)
+{
+       unsigned long ints = __raw_readl(LPC32XX_INTC_STAT(LPC32XX_SIC2_BASE));
+
+       while (ints != 0) {
+               int irqno = fls(ints) - 1;
+
+               ints &= ~(1 << irqno);
+
+               generic_handle_irq(LPC32XX_SIC2_IRQ(irqno));
+       }
+}
+
+void __init lpc32xx_init_irq(void)
+{
+       unsigned int i;
+
+       /* Setup MIC */
+       __raw_writel(0, LPC32XX_INTC_MASK(LPC32XX_MIC_BASE));
+       __raw_writel(MIC_APR_DEFAULT, LPC32XX_INTC_POLAR(LPC32XX_MIC_BASE));
+       __raw_writel(MIC_ATR_DEFAULT, LPC32XX_INTC_ACT_TYPE(LPC32XX_MIC_BASE));
+
+       /* Setup SIC1 */
+       __raw_writel(0, LPC32XX_INTC_MASK(LPC32XX_SIC1_BASE));
+       __raw_writel(MIC_APR_DEFAULT, LPC32XX_INTC_POLAR(LPC32XX_SIC1_BASE));
+       __raw_writel(MIC_ATR_DEFAULT, LPC32XX_INTC_ACT_TYPE(LPC32XX_SIC1_BASE));
+
+       /* Setup SIC2 */
+       __raw_writel(0, LPC32XX_INTC_MASK(LPC32XX_SIC2_BASE));
+       __raw_writel(MIC_APR_DEFAULT, LPC32XX_INTC_POLAR(LPC32XX_SIC2_BASE));
+       __raw_writel(MIC_ATR_DEFAULT, LPC32XX_INTC_ACT_TYPE(LPC32XX_SIC2_BASE));
+
+       /* Configure supported IRQ's */
+       for (i = 0; i < NR_IRQS; i++) {
+               set_irq_chip(i, &lpc32xx_irq_chip);
+               set_irq_handler(i, handle_level_irq);
+               set_irq_flags(i, IRQF_VALID);
+       }
+
+       /* Set default mappings */
+       lpc32xx_set_default_mappings(MIC_APR_DEFAULT, MIC_ATR_DEFAULT, 0);
+       lpc32xx_set_default_mappings(SIC1_APR_DEFAULT, SIC1_ATR_DEFAULT, 32);
+       lpc32xx_set_default_mappings(SIC2_APR_DEFAULT, SIC2_ATR_DEFAULT, 64);
+
+       /* mask all interrupts except SUBIRQ */
+       __raw_writel(0, LPC32XX_INTC_MASK(LPC32XX_MIC_BASE));
+       __raw_writel(0, LPC32XX_INTC_MASK(LPC32XX_SIC1_BASE));
+       __raw_writel(0, LPC32XX_INTC_MASK(LPC32XX_SIC2_BASE));
+
+       /* MIC SUBIRQx interrupts will route handling to the chain handlers */
+       set_irq_chained_handler(IRQ_LPC32XX_SUB1IRQ, lpc32xx_sic1_handler);
+       set_irq_chained_handler(IRQ_LPC32XX_SUB2IRQ, lpc32xx_sic2_handler);
+
+       /* Initially disable all wake events */
+       __raw_writel(0, LPC32XX_CLKPWR_P01_ER);
+       __raw_writel(0, LPC32XX_CLKPWR_INT_ER);
+       __raw_writel(0, LPC32XX_CLKPWR_PIN_ER);
+
+       /*
+        * Default wake activation polarities, all pin sources are low edge
+        * triggered
+        */
+       __raw_writel(LPC32XX_CLKPWR_INTSRC_TS_P_BIT |
+               LPC32XX_CLKPWR_INTSRC_MSTIMER_BIT |
+               LPC32XX_CLKPWR_INTSRC_RTC_BIT,
+               LPC32XX_CLKPWR_INT_AP);
+       __raw_writel(0, LPC32XX_CLKPWR_PIN_AP);
+
+       /* Clear latched wake event states */
+       __raw_writel(__raw_readl(LPC32XX_CLKPWR_PIN_RS),
+               LPC32XX_CLKPWR_PIN_RS);
+       __raw_writel(__raw_readl(LPC32XX_CLKPWR_INT_RS),
+               LPC32XX_CLKPWR_INT_RS);
+}
diff --git a/arch/arm/mach-lpc32xx/phy3250.c b/arch/arm/mach-lpc32xx/phy3250.c
new file mode 100644 (file)
index 0000000..bc9a42d
--- /dev/null
@@ -0,0 +1,397 @@
+/*
+ * arch/arm/mach-lpc32xx/phy3250.c
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/sysdev.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/dma-mapping.h>
+#include <linux/device.h>
+#include <linux/spi/spi.h>
+#include <linux/spi/eeprom.h>
+#include <linux/leds.h>
+#include <linux/gpio.h>
+#include <linux/amba/bus.h>
+#include <linux/amba/clcd.h>
+#include <linux/amba/pl022.h>
+
+#include <asm/setup.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+
+#include <mach/hardware.h>
+#include <mach/platform.h>
+#include "common.h"
+
+/*
+ * Mapped GPIOLIB GPIOs
+ */
+#define SPI0_CS_GPIO   LPC32XX_GPIO(LPC32XX_GPIO_P3_GRP, 5)
+#define LCD_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 0)
+#define BKL_POWER_GPIO LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 4)
+#define LED_GPIO       LPC32XX_GPIO(LPC32XX_GPO_P3_GRP, 1)
+
+/*
+ * AMBA LCD controller
+ */
+static struct clcd_panel conn_lcd_panel = {
+       .mode           = {
+               .name           = "QVGA portrait",
+               .refresh        = 60,
+               .xres           = 240,
+               .yres           = 320,
+               .pixclock       = 191828,
+               .left_margin    = 22,
+               .right_margin   = 11,
+               .upper_margin   = 2,
+               .lower_margin   = 1,
+               .hsync_len      = 5,
+               .vsync_len      = 2,
+               .sync           = 0,
+               .vmode          = FB_VMODE_NONINTERLACED,
+       },
+       .width          = -1,
+       .height         = -1,
+       .tim2           = (TIM2_IVS | TIM2_IHS),
+       .cntl           = (CNTL_BGR | CNTL_LCDTFT | CNTL_LCDVCOMP(1) |
+                               CNTL_LCDBPP16_565),
+       .bpp            = 16,
+};
+#define PANEL_SIZE (3 * SZ_64K)
+
+static int lpc32xx_clcd_setup(struct clcd_fb *fb)
+{
+       dma_addr_t dma;
+
+       fb->fb.screen_base = dma_alloc_writecombine(&fb->dev->dev,
+               PANEL_SIZE, &dma, GFP_KERNEL);
+       if (!fb->fb.screen_base) {
+               printk(KERN_ERR "CLCD: unable to map framebuffer\n");
+               return -ENOMEM;
+       }
+
+       fb->fb.fix.smem_start = dma;
+       fb->fb.fix.smem_len = PANEL_SIZE;
+       fb->panel = &conn_lcd_panel;
+
+       if (gpio_request(LCD_POWER_GPIO, "LCD power"))
+               printk(KERN_ERR "Error requesting gpio %u",
+                       LCD_POWER_GPIO);
+       else if (gpio_direction_output(LCD_POWER_GPIO, 1))
+               printk(KERN_ERR "Error setting gpio %u to output",
+                       LCD_POWER_GPIO);
+
+       if (gpio_request(BKL_POWER_GPIO, "LCD backlight power"))
+               printk(KERN_ERR "Error requesting gpio %u",
+                       BKL_POWER_GPIO);
+       else if (gpio_direction_output(BKL_POWER_GPIO, 1))
+               printk(KERN_ERR "Error setting gpio %u to output",
+                       BKL_POWER_GPIO);
+
+       return 0;
+}
+
+static int lpc32xx_clcd_mmap(struct clcd_fb *fb, struct vm_area_struct *vma)
+{
+       return dma_mmap_writecombine(&fb->dev->dev, vma,
+               fb->fb.screen_base, fb->fb.fix.smem_start,
+               fb->fb.fix.smem_len);
+}
+
+static void lpc32xx_clcd_remove(struct clcd_fb *fb)
+{
+       dma_free_writecombine(&fb->dev->dev, fb->fb.fix.smem_len,
+               fb->fb.screen_base, fb->fb.fix.smem_start);
+}
+
+/*
+ * On some early LCD modules (1307.0), the backlight logic is inverted.
+ * For those board variants, swap the disable and enable states for
+ * BKL_POWER_GPIO.
+*/
+static void clcd_disable(struct clcd_fb *fb)
+{
+       gpio_set_value(BKL_POWER_GPIO, 0);
+       gpio_set_value(LCD_POWER_GPIO, 0);
+}
+
+static void clcd_enable(struct clcd_fb *fb)
+{
+       gpio_set_value(BKL_POWER_GPIO, 1);
+       gpio_set_value(LCD_POWER_GPIO, 1);
+}
+
+static struct clcd_board lpc32xx_clcd_data = {
+       .name           = "Phytec LCD",
+       .check          = clcdfb_check,
+       .decode         = clcdfb_decode,
+       .disable        = clcd_disable,
+       .enable         = clcd_enable,
+       .setup          = lpc32xx_clcd_setup,
+       .mmap           = lpc32xx_clcd_mmap,
+       .remove         = lpc32xx_clcd_remove,
+};
+
+static struct amba_device lpc32xx_clcd_device = {
+       .dev                            = {
+               .coherent_dma_mask      = ~0,
+               .init_name              = "dev:clcd",
+               .platform_data          = &lpc32xx_clcd_data,
+       },
+       .res                            = {
+               .start                  = LPC32XX_LCD_BASE,
+               .end                    = (LPC32XX_LCD_BASE + SZ_4K - 1),
+               .flags                  = IORESOURCE_MEM,
+       },
+       .dma_mask                       = ~0,
+       .irq                            = {IRQ_LPC32XX_LCD, NO_IRQ},
+};
+
+/*
+ * AMBA SSP (SPI)
+ */
+static void phy3250_spi_cs_set(u32 control)
+{
+       gpio_set_value(SPI0_CS_GPIO, (int) control);
+}
+
+static struct pl022_config_chip spi0_chip_info = {
+       .lbm                    = LOOPBACK_DISABLED,
+       .com_mode               = INTERRUPT_TRANSFER,
+       .iface                  = SSP_INTERFACE_MOTOROLA_SPI,
+       .hierarchy              = SSP_MASTER,
+       .slave_tx_disable       = 0,
+       .endian_tx              = SSP_TX_LSB,
+       .endian_rx              = SSP_RX_LSB,
+       .data_size              = SSP_DATA_BITS_8,
+       .rx_lev_trig            = SSP_RX_4_OR_MORE_ELEM,
+       .tx_lev_trig            = SSP_TX_4_OR_MORE_EMPTY_LOC,
+       .clk_phase              = SSP_CLK_FIRST_EDGE,
+       .clk_pol                = SSP_CLK_POL_IDLE_LOW,
+       .ctrl_len               = SSP_BITS_8,
+       .wait_state             = SSP_MWIRE_WAIT_ZERO,
+       .duplex                 = SSP_MICROWIRE_CHANNEL_FULL_DUPLEX,
+       .cs_control             = phy3250_spi_cs_set,
+};
+
+static struct pl022_ssp_controller lpc32xx_ssp0_data = {
+       .bus_id                 = 0,
+       .num_chipselect         = 1,
+       .enable_dma             = 0,
+};
+
+static struct amba_device lpc32xx_ssp0_device = {
+       .dev                            = {
+               .coherent_dma_mask      = ~0,
+               .init_name              = "dev:ssp0",
+               .platform_data          = &lpc32xx_ssp0_data,
+       },
+       .res                            = {
+               .start                  = LPC32XX_SSP0_BASE,
+               .end                    = (LPC32XX_SSP0_BASE + SZ_4K - 1),
+               .flags                  = IORESOURCE_MEM,
+       },
+       .dma_mask                       = ~0,
+       .irq                            = {IRQ_LPC32XX_SSP0, NO_IRQ},
+};
+
+/* AT25 driver registration */
+static int __init phy3250_spi_board_register(void)
+{
+#if defined(CONFIG_SPI_SPIDEV) || defined(CONFIG_SPI_SPIDEV_MODULE)
+       static struct spi_board_info info[] = {
+               {
+                       .modalias = "spidev",
+                       .max_speed_hz = 5000000,
+                       .bus_num = 0,
+                       .chip_select = 0,
+                       .controller_data = &spi0_chip_info,
+               },
+       };
+
+#else
+       static struct spi_eeprom eeprom = {
+               .name = "at25256a",
+               .byte_len = 0x8000,
+               .page_size = 64,
+               .flags = EE_ADDR2,
+       };
+
+       static struct spi_board_info info[] = {
+               {
+                       .modalias = "at25",
+                       .max_speed_hz = 5000000,
+                       .bus_num = 0,
+                       .chip_select = 0,
+                       .platform_data = &eeprom,
+                       .controller_data = &spi0_chip_info,
+               },
+       };
+#endif
+       return spi_register_board_info(info, ARRAY_SIZE(info));
+}
+arch_initcall(phy3250_spi_board_register);
+
+static struct i2c_board_info __initdata phy3250_i2c_board_info[] = {
+       {
+               I2C_BOARD_INFO("pcf8563", 0x51),
+       },
+};
+
+static struct gpio_led phy_leds[] = {
+       {
+               .name                   = "led0",
+               .gpio                   = LED_GPIO,
+               .active_low             = 1,
+               .default_trigger        = "heartbeat",
+       },
+};
+
+static struct gpio_led_platform_data led_data = {
+       .leds = phy_leds,
+       .num_leds = ARRAY_SIZE(phy_leds),
+};
+
+static struct platform_device lpc32xx_gpio_led_device = {
+       .name                   = "leds-gpio",
+       .id                     = -1,
+       .dev.platform_data      = &led_data,
+};
+
+static struct platform_device *phy3250_devs[] __initdata = {
+       &lpc32xx_i2c0_device,
+       &lpc32xx_i2c1_device,
+       &lpc32xx_i2c2_device,
+       &lpc32xx_watchdog_device,
+       &lpc32xx_gpio_led_device,
+};
+
+static struct amba_device *amba_devs[] __initdata = {
+       &lpc32xx_clcd_device,
+       &lpc32xx_ssp0_device,
+};
+
+/*
+ * Board specific functions
+ */
+static void __init phy3250_board_init(void)
+{
+       u32 tmp;
+       int i;
+
+       lpc32xx_gpio_init();
+
+       /* Register GPIOs used on this board */
+       if (gpio_request(SPI0_CS_GPIO, "spi0 cs"))
+               printk(KERN_ERR "Error requesting gpio %u",
+                       SPI0_CS_GPIO);
+       else if (gpio_direction_output(SPI0_CS_GPIO, 1))
+               printk(KERN_ERR "Error setting gpio %u to output",
+                       SPI0_CS_GPIO);
+
+       /* Setup network interface for RMII mode */
+       tmp = __raw_readl(LPC32XX_CLKPWR_MACCLK_CTRL);
+       tmp &= ~LPC32XX_CLKPWR_MACCTRL_PINS_MSK;
+       tmp |= LPC32XX_CLKPWR_MACCTRL_USE_RMII_PINS;
+       __raw_writel(tmp, LPC32XX_CLKPWR_MACCLK_CTRL);
+
+       /* Setup SLC NAND controller muxing */
+       __raw_writel(LPC32XX_CLKPWR_NANDCLK_SEL_SLC,
+               LPC32XX_CLKPWR_NAND_CLK_CTRL);
+
+       /* Setup LCD muxing to RGB565 */
+       tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL) &
+               ~(LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_MSK |
+               LPC32XX_CLKPWR_LCDCTRL_PSCALE_MSK);
+       tmp |= LPC32XX_CLKPWR_LCDCTRL_LCDTYPE_TFT16;
+       __raw_writel(tmp, LPC32XX_CLKPWR_LCDCLK_CTRL);
+
+       /* Set up I2C pull levels */
+       tmp = __raw_readl(LPC32XX_CLKPWR_I2C_CLK_CTRL);
+       tmp |= LPC32XX_CLKPWR_I2CCLK_USBI2CHI_DRIVE |
+               LPC32XX_CLKPWR_I2CCLK_I2C2HI_DRIVE;
+       __raw_writel(tmp, LPC32XX_CLKPWR_I2C_CLK_CTRL);
+
+       /* Disable IrDA pulsing support on UART6 */
+       tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
+       tmp |= LPC32XX_UART_UART6_IRDAMOD_BYPASS;
+       __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
+
+       /* Enable DMA for I2S1 channel */
+       tmp = __raw_readl(LPC32XX_CLKPWR_I2S_CLK_CTRL);
+       tmp = LPC32XX_CLKPWR_I2SCTRL_I2S1_USE_DMA;
+       __raw_writel(tmp, LPC32XX_CLKPWR_I2S_CLK_CTRL);
+
+       lpc32xx_serial_init();
+
+       /*
+        * AMBA peripheral clocks need to be enabled prior to AMBA device
+        * detection or a data fault will occur, so enable the clocks
+        * here. However, we don't want to enable them if the peripheral
+        * isn't included in the image
+        */
+#ifdef CONFIG_FB_ARMCLCD
+       tmp = __raw_readl(LPC32XX_CLKPWR_LCDCLK_CTRL);
+       __raw_writel((tmp | LPC32XX_CLKPWR_LCDCTRL_CLK_EN),
+               LPC32XX_CLKPWR_LCDCLK_CTRL);
+#endif
+#ifdef CONFIG_SPI_PL022
+       tmp = __raw_readl(LPC32XX_CLKPWR_SSP_CLK_CTRL);
+       __raw_writel((tmp | LPC32XX_CLKPWR_SSPCTRL_SSPCLK0_EN),
+               LPC32XX_CLKPWR_SSP_CLK_CTRL);
+#endif
+
+       platform_add_devices(phy3250_devs, ARRAY_SIZE(phy3250_devs));
+       for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
+               struct amba_device *d = amba_devs[i];
+               amba_device_register(d, &iomem_resource);
+       }
+
+       /* Test clock needed for UDA1380 initial init */
+       __raw_writel(LPC32XX_CLKPWR_TESTCLK2_SEL_MOSC |
+               LPC32XX_CLKPWR_TESTCLK_TESTCLK2_EN,
+               LPC32XX_CLKPWR_TEST_CLK_SEL);
+
+       i2c_register_board_info(0, phy3250_i2c_board_info,
+               ARRAY_SIZE(phy3250_i2c_board_info));
+}
+
+static int __init lpc32xx_display_uid(void)
+{
+       u32 uid[4];
+
+       lpc32xx_get_uid(uid);
+
+       printk(KERN_INFO "LPC32XX unique ID: %08x%08x%08x%08x\n",
+               uid[3], uid[2], uid[1], uid[0]);
+
+       return 1;
+}
+arch_initcall(lpc32xx_display_uid);
+
+MACHINE_START(PHY3250, "Phytec 3250 board with the LPC3250 Microcontroller")
+       /* Maintainer: Kevin Wells, NXP Semiconductors */
+       .phys_io        = LPC32XX_UART5_BASE,
+       .io_pg_offst    = ((IO_ADDRESS(LPC32XX_UART5_BASE))>>18) & 0xfffc,
+       .boot_params    = 0x80000100,
+       .map_io         = lpc32xx_map_io,
+       .init_irq       = lpc32xx_init_irq,
+       .timer          = &lpc32xx_timer,
+       .init_machine   = phy3250_board_init,
+MACHINE_END
diff --git a/arch/arm/mach-lpc32xx/pm.c b/arch/arm/mach-lpc32xx/pm.c
new file mode 100644 (file)
index 0000000..a6e2aed
--- /dev/null
@@ -0,0 +1,146 @@
+/*
+ * arch/arm/mach-lpc32xx/pm.c
+ *
+ * Original authors: Vitaly Wool, Dmitry Chigirev <source@mvista.com>
+ * Modified by Kevin Wells <kevin.wells@nxp.com>
+ *
+ * 2005 (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+
+/*
+ * LPC32XX CPU and system power management
+ *
+ * The LCP32XX has three CPU modes for controlling system power: run,
+ * direct-run, and halt modes. When switching between halt and run modes,
+ * the CPU transistions through direct-run mode. For Linux, direct-run
+ * mode is not used in normal operation. Halt mode is used when the
+ * system is fully suspended.
+ *
+ * Run mode:
+ * The ARM CPU clock (HCLK_PLL), HCLK bus clock, and PCLK bus clocks are
+ * derived from the HCLK PLL. The HCLK and PCLK bus rates are divided from
+ * the HCLK_PLL rate. Linux runs in this mode.
+ *
+ * Direct-run mode:
+ * The ARM CPU clock, HCLK bus clock, and PCLK bus clocks are driven from
+ * SYSCLK. SYSCLK is usually around 13MHz, but may vary based on SYSCLK
+ * source or the frequency of the main oscillator. In this mode, the
+ * HCLK_PLL can be safely enabled, changed, or disabled.
+ *
+ * Halt mode:
+ * SYSCLK is gated off and the CPU and system clocks are halted.
+ * Peripherals based on the 32KHz oscillator clock (ie, RTC, touch,
+ * key scanner, etc.) still operate if enabled. In this state, an enabled
+ * system event (ie, GPIO state change, RTC match, key press, etc.) will
+ * wake the system up back into direct-run mode.
+ *
+ * DRAM refresh
+ * DRAM clocking and refresh are slightly different for systems with DDR
+ * DRAM or regular SDRAM devices. If SDRAM is used in the system, the
+ * SDRAM will still be accessible in direct-run mode. In DDR based systems,
+ * a transistion to direct-run mode will stop all DDR accesses (no clocks).
+ * Because of this, the code to switch power modes and the code to enter
+ * and exit DRAM self-refresh modes must not be executed in DRAM. A small
+ * section of IRAM is used instead for this.
+ *
+ * Suspend is handled with the following logic:
+ *  Backup a small area of IRAM used for the suspend code
+ *  Copy suspend code to IRAM
+ *  Transfer control to code in IRAM
+ *  Places DRAMs in self-refresh mode
+ *  Enter direct-run mode
+ *  Save state of HCLK_PLL PLL
+ *  Disable HCLK_PLL PLL
+ *  Enter halt mode - CPU and buses will stop
+ *  System enters direct-run mode when an enabled event occurs
+ *  HCLK PLL state is restored
+ *  Run mode is entered
+ *  DRAMS are placed back into normal mode
+ *  Code execution returns from IRAM
+ *  IRAM code are used for suspend is restored
+ *  Suspend mode is exited
+ */
+
+#include <linux/suspend.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+
+#include <asm/cacheflush.h>
+
+#include <mach/hardware.h>
+#include <mach/platform.h>
+#include "common.h"
+#include "clock.h"
+
+#define TEMP_IRAM_AREA  IO_ADDRESS(LPC32XX_IRAM_BASE)
+
+/*
+ * Both STANDBY and MEM suspend states are handled the same with no
+ * loss of CPU or memory state
+ */
+static int lpc32xx_pm_enter(suspend_state_t state)
+{
+       int (*lpc32xx_suspend_ptr) (void);
+       void *iram_swap_area;
+
+       /* Allocate some space for temporary IRAM storage */
+       iram_swap_area = kmalloc(lpc32xx_sys_suspend_sz, GFP_KERNEL);
+       if (!iram_swap_area) {
+               printk(KERN_ERR
+                      "PM Suspend: cannot allocate memory to save portion "
+                       "of SRAM\n");
+               return -ENOMEM;
+       }
+
+       /* Backup a small area of IRAM used for the suspend code */
+       memcpy(iram_swap_area, (void *) TEMP_IRAM_AREA,
+               lpc32xx_sys_suspend_sz);
+
+       /*
+        * Copy code to suspend system into IRAM. The suspend code
+        * needs to run from IRAM as DRAM may no longer be available
+        * when the PLL is stopped.
+        */
+       memcpy((void *) TEMP_IRAM_AREA, &lpc32xx_sys_suspend,
+               lpc32xx_sys_suspend_sz);
+       flush_icache_range((unsigned long)TEMP_IRAM_AREA,
+               (unsigned long)(TEMP_IRAM_AREA) + lpc32xx_sys_suspend_sz);
+
+       /* Transfer to suspend code in IRAM */
+       lpc32xx_suspend_ptr = (void *) TEMP_IRAM_AREA;
+       flush_cache_all();
+       (void) lpc32xx_suspend_ptr();
+
+       /* Restore original IRAM contents */
+       memcpy((void *) TEMP_IRAM_AREA, iram_swap_area,
+               lpc32xx_sys_suspend_sz);
+
+       kfree(iram_swap_area);
+
+       return 0;
+}
+
+static struct platform_suspend_ops lpc32xx_pm_ops = {
+       .valid  = suspend_valid_only_mem,
+       .enter  = lpc32xx_pm_enter,
+};
+
+#define EMC_DYN_MEM_CTRL_OFS 0x20
+#define EMC_SRMMC           (1 << 3)
+#define EMC_CTRL_REG io_p2v(LPC32XX_EMC_BASE + EMC_DYN_MEM_CTRL_OFS)
+static int __init lpc32xx_pm_init(void)
+{
+       /*
+        * Setup SDRAM self-refresh clock to automatically disable o
+        * start of self-refresh. This only needs to be done once.
+        */
+       __raw_writel(__raw_readl(EMC_CTRL_REG) | EMC_SRMMC, EMC_CTRL_REG);
+
+       suspend_set_ops(&lpc32xx_pm_ops);
+
+       return 0;
+}
+arch_initcall(lpc32xx_pm_init);
diff --git a/arch/arm/mach-lpc32xx/serial.c b/arch/arm/mach-lpc32xx/serial.c
new file mode 100644 (file)
index 0000000..429cfdb
--- /dev/null
@@ -0,0 +1,190 @@
+/*
+ * arch/arm/mach-lpc32xx/serial.c
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2010 NXP Semiconductors
+ *
+ * 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.
+ */
+
+#include <linux/kernel.h>
+#include <linux/types.h>
+#include <linux/serial.h>
+#include <linux/serial_core.h>
+#include <linux/serial_reg.h>
+#include <linux/serial_8250.h>
+#include <linux/clk.h>
+#include <linux/io.h>
+
+#include <mach/hardware.h>
+#include <mach/platform.h>
+#include "common.h"
+
+#define LPC32XX_SUART_FIFO_SIZE        64
+
+/* Standard 8250/16550 compatible serial ports */
+static struct plat_serial8250_port serial_std_platform_data[] = {
+#ifdef CONFIG_ARCH_LPC32XX_UART5_SELECT
+       {
+               .membase        = io_p2v(LPC32XX_UART5_BASE),
+               .mapbase        = LPC32XX_UART5_BASE,
+               .irq            = IRQ_LPC32XX_UART_IIR5,
+               .uartclk        = LPC32XX_MAIN_OSC_FREQ,
+               .regshift       = 2,
+               .iotype         = UPIO_MEM32,
+               .flags          = UPF_BOOT_AUTOCONF | UPF_BUGGY_UART |
+                                       UPF_SKIP_TEST,
+       },
+#endif
+#ifdef CONFIG_ARCH_LPC32XX_UART3_SELECT
+       {
+               .membase        = io_p2v(LPC32XX_UART3_BASE),
+               .mapbase        = LPC32XX_UART3_BASE,
+               .irq            = IRQ_LPC32XX_UART_IIR3,
+               .uartclk        = LPC32XX_MAIN_OSC_FREQ,
+               .regshift       = 2,
+               .iotype         = UPIO_MEM32,
+               .flags          = UPF_BOOT_AUTOCONF | UPF_BUGGY_UART |
+                                       UPF_SKIP_TEST,
+       },
+#endif
+#ifdef CONFIG_ARCH_LPC32XX_UART4_SELECT
+       {
+               .membase        = io_p2v(LPC32XX_UART4_BASE),
+               .mapbase        = LPC32XX_UART4_BASE,
+               .irq            = IRQ_LPC32XX_UART_IIR4,
+               .uartclk        = LPC32XX_MAIN_OSC_FREQ,
+               .regshift       = 2,
+               .iotype         = UPIO_MEM32,
+               .flags          = UPF_BOOT_AUTOCONF | UPF_BUGGY_UART |
+                                       UPF_SKIP_TEST,
+       },
+#endif
+#ifdef CONFIG_ARCH_LPC32XX_UART6_SELECT
+       {
+               .membase        = io_p2v(LPC32XX_UART6_BASE),
+               .mapbase        = LPC32XX_UART6_BASE,
+               .irq            = IRQ_LPC32XX_UART_IIR6,
+               .uartclk        = LPC32XX_MAIN_OSC_FREQ,
+               .regshift       = 2,
+               .iotype         = UPIO_MEM32,
+               .flags          = UPF_BOOT_AUTOCONF | UPF_BUGGY_UART |
+                                       UPF_SKIP_TEST,
+       },
+#endif
+       { },
+};
+
+struct uartinit {
+       char *uart_ck_name;
+       u32 ck_mode_mask;
+       void __iomem *pdiv_clk_reg;
+};
+
+static struct uartinit uartinit_data[] __initdata = {
+#ifdef CONFIG_ARCH_LPC32XX_UART5_SELECT
+       {
+               .uart_ck_name = "uart5_ck",
+               .ck_mode_mask =
+                       LPC32XX_UART_CLKMODE_LOAD(LPC32XX_UART_CLKMODE_ON, 5),
+               .pdiv_clk_reg = LPC32XX_CLKPWR_UART5_CLK_CTRL,
+       },
+#endif
+#ifdef CONFIG_ARCH_LPC32XX_UART3_SELECT
+       {
+               .uart_ck_name = "uart3_ck",
+               .ck_mode_mask =
+                       LPC32XX_UART_CLKMODE_LOAD(LPC32XX_UART_CLKMODE_ON, 3),
+               .pdiv_clk_reg = LPC32XX_CLKPWR_UART3_CLK_CTRL,
+       },
+#endif
+#ifdef CONFIG_ARCH_LPC32XX_UART4_SELECT
+       {
+               .uart_ck_name = "uart4_ck",
+               .ck_mode_mask =
+                       LPC32XX_UART_CLKMODE_LOAD(LPC32XX_UART_CLKMODE_ON, 4),
+               .pdiv_clk_reg = LPC32XX_CLKPWR_UART4_CLK_CTRL,
+       },
+#endif
+#ifdef CONFIG_ARCH_LPC32XX_UART6_SELECT
+       {
+               .uart_ck_name = "uart6_ck",
+               .ck_mode_mask =
+                       LPC32XX_UART_CLKMODE_LOAD(LPC32XX_UART_CLKMODE_ON, 6),
+               .pdiv_clk_reg = LPC32XX_CLKPWR_UART6_CLK_CTRL,
+       },
+#endif
+};
+
+static struct platform_device serial_std_platform_device = {
+       .name                   = "serial8250",
+       .id                     = 0,
+       .dev                    = {
+               .platform_data  = serial_std_platform_data,
+       },
+};
+
+static struct platform_device *lpc32xx_serial_devs[] __initdata = {
+       &serial_std_platform_device,
+};
+
+void __init lpc32xx_serial_init(void)
+{
+       u32 tmp, clkmodes = 0;
+       struct clk *clk;
+       unsigned int puart;
+       int i, j;
+
+       /* UART clocks are off, let clock driver manage them */
+       __raw_writel(0, LPC32XX_CLKPWR_UART_CLK_CTRL);
+
+       for (i = 0; i < ARRAY_SIZE(uartinit_data); i++) {
+               clk = clk_get(NULL, uartinit_data[i].uart_ck_name);
+               if (!IS_ERR(clk)) {
+                       clk_enable(clk);
+                       serial_std_platform_data[i].uartclk =
+                               clk_get_rate(clk);
+               }
+
+               /* Fall back on main osc rate if clock rate return fails */
+               if (serial_std_platform_data[i].uartclk == 0)
+                       serial_std_platform_data[i].uartclk =
+                               LPC32XX_MAIN_OSC_FREQ;
+
+               /* Setup UART clock modes for all UARTs, disable autoclock */
+               clkmodes |= uartinit_data[i].ck_mode_mask;
+
+               /* pre-UART clock divider set to 1 */
+               __raw_writel(0x0101, uartinit_data[i].pdiv_clk_reg);
+       }
+
+       /* This needs to be done after all UART clocks are setup */
+       __raw_writel(clkmodes, LPC32XX_UARTCTL_CLKMODE);
+       for (i = 0; i < ARRAY_SIZE(uartinit_data) - 1; i++) {
+               /* Force a flush of the RX FIFOs to work around a HW bug */
+               puart = serial_std_platform_data[i].mapbase;
+               __raw_writel(0xC1, LPC32XX_UART_IIR_FCR(puart));
+               __raw_writel(0x00, LPC32XX_UART_DLL_FIFO(puart));
+               j = LPC32XX_SUART_FIFO_SIZE;
+               while (j--)
+                       tmp = __raw_readl(LPC32XX_UART_DLL_FIFO(puart));
+               __raw_writel(0, LPC32XX_UART_IIR_FCR(puart));
+       }
+
+       /* Disable UART5->USB transparent mode or USB won't work */
+       tmp = __raw_readl(LPC32XX_UARTCTL_CTRL);
+       tmp &= ~LPC32XX_UART_U5_ROUTE_TO_USB;
+       __raw_writel(tmp, LPC32XX_UARTCTL_CTRL);
+
+       platform_add_devices(lpc32xx_serial_devs,
+               ARRAY_SIZE(lpc32xx_serial_devs));
+}
diff --git a/arch/arm/mach-lpc32xx/suspend.S b/arch/arm/mach-lpc32xx/suspend.S
new file mode 100644 (file)
index 0000000..374f9f0
--- /dev/null
@@ -0,0 +1,151 @@
+/*
+ * arch/arm/mach-lpc32xx/suspend.S
+ *
+ * Original authors: Dmitry Chigirev, Vitaly Wool <source@mvista.com>
+ * Modified by Kevin Wells <kevin.wells@nxp.com>
+ *
+ * 2005 (c) MontaVista Software, Inc. This file is licensed under
+ * the terms of the GNU General Public License version 2. This program
+ * is licensed "as is" without any warranty of any kind, whether express
+ * or implied.
+ */
+#include <linux/linkage.h>
+#include <asm/assembler.h>
+#include <mach/platform.h>
+#include <mach/hardware.h>
+
+/* Using named register defines makes the code easier to follow */
+#define WORK1_REG                      r0
+#define WORK2_REG                      r1
+#define SAVED_HCLK_DIV_REG             r2
+#define SAVED_HCLK_PLL_REG             r3
+#define SAVED_DRAM_CLKCTRL_REG         r4
+#define SAVED_PWR_CTRL_REG             r5
+#define CLKPWRBASE_REG                 r6
+#define EMCBASE_REG                    r7
+
+#define LPC32XX_EMC_STATUS_OFFS                0x04
+#define LPC32XX_EMC_STATUS_BUSY                0x1
+#define LPC32XX_EMC_STATUS_SELF_RFSH   0x4
+
+#define LPC32XX_CLKPWR_PWR_CTRL_OFFS   0x44
+#define LPC32XX_CLKPWR_HCLK_DIV_OFFS   0x40
+#define LPC32XX_CLKPWR_HCLKPLL_CTRL_OFFS 0x58
+
+#define CLKPWR_PCLK_DIV_MASK           0xFFFFFE7F
+
+       .text
+
+ENTRY(lpc32xx_sys_suspend)
+       @ Save a copy of the used registers in IRAM, r0 is corrupted
+       adr     r0, tmp_stack_end
+       stmfd   r0!, {r3 - r7, sp, lr}
+
+       @ Load a few common register addresses
+       adr     WORK1_REG, reg_bases
+       ldr     CLKPWRBASE_REG, [WORK1_REG, #0]
+       ldr     EMCBASE_REG, [WORK1_REG, #4]
+
+       ldr     SAVED_PWR_CTRL_REG, [CLKPWRBASE_REG,\
+               #LPC32XX_CLKPWR_PWR_CTRL_OFFS]
+       orr     WORK1_REG, SAVED_PWR_CTRL_REG, #LPC32XX_CLKPWR_SDRAM_SELF_RFSH
+
+       @ Wait for SDRAM busy status to go busy and then idle
+       @ This guarantees a small windows where DRAM isn't busy
+1:
+       ldr     WORK2_REG, [EMCBASE_REG, #LPC32XX_EMC_STATUS_OFFS]
+       and     WORK2_REG, WORK2_REG, #LPC32XX_EMC_STATUS_BUSY
+       cmp     WORK2_REG, #LPC32XX_EMC_STATUS_BUSY
+       bne     1b @ Branch while idle
+2:
+       ldr     WORK2_REG, [EMCBASE_REG, #LPC32XX_EMC_STATUS_OFFS]
+       and     WORK2_REG, WORK2_REG, #LPC32XX_EMC_STATUS_BUSY
+       cmp     WORK2_REG, #LPC32XX_EMC_STATUS_BUSY
+       beq     2b @ Branch until idle
+
+       @ Setup self-refresh with support for manual exit of
+       @ self-refresh mode
+       str     WORK1_REG, [CLKPWRBASE_REG, #LPC32XX_CLKPWR_PWR_CTRL_OFFS]
+       orr     WORK2_REG, WORK1_REG, #LPC32XX_CLKPWR_UPD_SDRAM_SELF_RFSH
+       str     WORK2_REG, [CLKPWRBASE_REG, #LPC32XX_CLKPWR_PWR_CTRL_OFFS]
+       str     WORK1_REG, [CLKPWRBASE_REG, #LPC32XX_CLKPWR_PWR_CTRL_OFFS]
+
+       @ Wait for self-refresh acknowledge, clocks to the DRAM device
+       @ will automatically stop on start of self-refresh
+3:
+       ldr     WORK2_REG, [EMCBASE_REG, #LPC32XX_EMC_STATUS_OFFS]
+       and     WORK2_REG, WORK2_REG, #LPC32XX_EMC_STATUS_SELF_RFSH
+       cmp     WORK2_REG, #LPC32XX_EMC_STATUS_SELF_RFSH
+       bne     3b @ Branch until self-refresh mode starts
+
+       @ Enter direct-run mode from run mode
+       bic     WORK1_REG, WORK1_REG, #LPC32XX_CLKPWR_SELECT_RUN_MODE
+       str     WORK1_REG, [CLKPWRBASE_REG, #LPC32XX_CLKPWR_PWR_CTRL_OFFS]
+
+       @ Safe disable of DRAM clock in EMC block, prevents DDR sync
+       @ issues on restart
+       ldr     SAVED_HCLK_DIV_REG, [CLKPWRBASE_REG,\
+               #LPC32XX_CLKPWR_HCLK_DIV_OFFS]
+       and     WORK2_REG, SAVED_HCLK_DIV_REG, #CLKPWR_PCLK_DIV_MASK
+       str     WORK2_REG, [CLKPWRBASE_REG, #LPC32XX_CLKPWR_HCLK_DIV_OFFS]
+
+       @ Save HCLK PLL state and disable HCLK PLL
+       ldr     SAVED_HCLK_PLL_REG, [CLKPWRBASE_REG,\
+               #LPC32XX_CLKPWR_HCLKPLL_CTRL_OFFS]
+       bic     WORK2_REG, SAVED_HCLK_PLL_REG, #LPC32XX_CLKPWR_HCLKPLL_POWER_UP
+       str     WORK2_REG, [CLKPWRBASE_REG, #LPC32XX_CLKPWR_HCLKPLL_CTRL_OFFS]
+
+       @ Enter stop mode until an enabled event occurs
+       orr     WORK1_REG, WORK1_REG, #LPC32XX_CLKPWR_STOP_MODE_CTRL
+       str     WORK1_REG, [CLKPWRBASE_REG, #LPC32XX_CLKPWR_PWR_CTRL_OFFS]
+       .rept 9
+       nop
+       .endr
+
+       @ Clear stop status
+       bic     WORK1_REG, WORK1_REG, #LPC32XX_CLKPWR_STOP_MODE_CTRL
+
+       @ Restore original HCLK PLL value and wait for PLL lock
+       str     SAVED_HCLK_PLL_REG, [CLKPWRBASE_REG,\
+               #LPC32XX_CLKPWR_HCLKPLL_CTRL_OFFS]
+4:
+       ldr     WORK2_REG, [CLKPWRBASE_REG, #LPC32XX_CLKPWR_HCLKPLL_CTRL_OFFS]
+       and     WORK2_REG, WORK2_REG, #LPC32XX_CLKPWR_HCLKPLL_PLL_STS
+       bne     4b
+
+       @ Re-enter run mode with self-refresh flag cleared, but no DRAM
+       @ update yet. DRAM is still in self-refresh
+       str     SAVED_PWR_CTRL_REG, [CLKPWRBASE_REG,\
+               #LPC32XX_CLKPWR_PWR_CTRL_OFFS]
+
+       @ Restore original DRAM clock mode to restore DRAM clocks
+       str     SAVED_HCLK_DIV_REG, [CLKPWRBASE_REG,\
+               #LPC32XX_CLKPWR_HCLK_DIV_OFFS]
+
+       @ Clear self-refresh mode
+       orr     WORK1_REG, SAVED_PWR_CTRL_REG,\
+               #LPC32XX_CLKPWR_UPD_SDRAM_SELF_RFSH
+       str     WORK1_REG, [CLKPWRBASE_REG, #LPC32XX_CLKPWR_PWR_CTRL_OFFS]
+       str     SAVED_PWR_CTRL_REG, [CLKPWRBASE_REG,\
+               #LPC32XX_CLKPWR_PWR_CTRL_OFFS]
+
+       @ Wait for EMC to clear self-refresh mode
+5:
+       ldr     WORK2_REG, [EMCBASE_REG, #LPC32XX_EMC_STATUS_OFFS]
+       and     WORK2_REG, WORK2_REG, #LPC32XX_EMC_STATUS_SELF_RFSH
+       bne     5b @ Branch until self-refresh has exited
+
+       @ restore regs and return
+       adr     r0, tmp_stack
+       ldmfd   r0!, {r3 - r7, sp, pc}
+
+reg_bases:
+       .long   IO_ADDRESS(LPC32XX_CLK_PM_BASE)
+       .long   IO_ADDRESS(LPC32XX_EMC_BASE)
+
+tmp_stack:
+       .long   0, 0, 0, 0, 0, 0, 0
+tmp_stack_end:
+
+ENTRY(lpc32xx_sys_suspend_sz)
+       .word   . - lpc32xx_sys_suspend
diff --git a/arch/arm/mach-lpc32xx/timer.c b/arch/arm/mach-lpc32xx/timer.c
new file mode 100644 (file)
index 0000000..630dd4a
--- /dev/null
@@ -0,0 +1,182 @@
+/*
+ * arch/arm/mach-lpc32xx/timer.c
+ *
+ * Author: Kevin Wells <kevin.wells@nxp.com>
+ *
+ * Copyright (C) 2009 - 2010 NXP Semiconductors
+ * Copyright (C) 2009 Fontys University of Applied Sciences, Eindhoven
+ *                    Ed Schouten <e.schouten@fontys.nl>
+ *                    Laurens Timmermans <l.timmermans@fontys.nl>
+ *
+ * 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.
+ */
+
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/time.h>
+#include <linux/err.h>
+#include <linux/clockchips.h>
+
+#include <asm/mach/time.h>
+
+#include <mach/hardware.h>
+#include <mach/platform.h>
+#include "common.h"
+
+static cycle_t lpc32xx_clksrc_read(struct clocksource *cs)
+{
+       return (cycle_t)__raw_readl(LCP32XX_TIMER_TC(LPC32XX_TIMER1_BASE));
+}
+
+static struct clocksource lpc32xx_clksrc = {
+       .name   = "lpc32xx_clksrc",
+       .shift  = 24,
+       .rating = 300,
+       .read   = lpc32xx_clksrc_read,
+       .mask   = CLOCKSOURCE_MASK(32),
+       .flags  = CLOCK_SOURCE_IS_CONTINUOUS,
+};
+
+static int lpc32xx_clkevt_next_event(unsigned long delta,
+    struct clock_event_device *dev)
+{
+       __raw_writel(LCP32XX_TIMER_CNTR_TCR_RESET,
+               LCP32XX_TIMER_TCR(LPC32XX_TIMER0_BASE));
+       __raw_writel(delta, LCP32XX_TIMER_PR(LPC32XX_TIMER0_BASE));
+       __raw_writel(LCP32XX_TIMER_CNTR_TCR_EN,
+               LCP32XX_TIMER_TCR(LPC32XX_TIMER0_BASE));
+
+       return 0;
+}
+
+static void lpc32xx_clkevt_mode(enum clock_event_mode mode,
+    struct clock_event_device *dev)
+{
+       switch (mode) {
+       case CLOCK_EVT_MODE_PERIODIC:
+               WARN_ON(1);
+               break;
+
+       case CLOCK_EVT_MODE_ONESHOT:
+       case CLOCK_EVT_MODE_SHUTDOWN:
+               /*
+                * Disable the timer. When using oneshot, we must also
+                * disable the timer to wait for the first call to
+                * set_next_event().
+                */
+               __raw_writel(0, LCP32XX_TIMER_TCR(LPC32XX_TIMER0_BASE));
+               break;
+
+       case CLOCK_EVT_MODE_UNUSED:
+       case CLOCK_EVT_MODE_RESUME:
+               break;
+       }
+}
+
+static struct clock_event_device lpc32xx_clkevt = {
+       .name           = "lpc32xx_clkevt",
+       .features       = CLOCK_EVT_FEAT_ONESHOT,
+       .shift          = 32,
+       .rating         = 300,
+       .set_next_event = lpc32xx_clkevt_next_event,
+       .set_mode       = lpc32xx_clkevt_mode,
+};
+
+static irqreturn_t lpc32xx_timer_interrupt(int irq, void *dev_id)
+{
+       struct clock_event_device *evt = &lpc32xx_clkevt;
+
+       /* Clear match */
+       __raw_writel(LCP32XX_TIMER_CNTR_MTCH_BIT(0),
+               LCP32XX_TIMER_IR(LPC32XX_TIMER0_BASE));
+
+       evt->event_handler(evt);
+
+       return IRQ_HANDLED;
+}
+
+static struct irqaction lpc32xx_timer_irq = {
+       .name           = "LPC32XX Timer Tick",
+       .flags          = IRQF_DISABLED | IRQF_TIMER | IRQF_IRQPOLL,
+       .handler        = lpc32xx_timer_interrupt,
+};
+
+/*
+ * The clock management driver isn't initialized at this point, so the
+ * clocks need to be enabled here manually and then tagged as used in
+ * the clock driver initialization
+ */
+static void __init lpc32xx_timer_init(void)
+{
+       u32 clkrate, pllreg;
+
+       /* Enable timer clock */
+       __raw_writel(LPC32XX_CLKPWR_TMRPWMCLK_TIMER0_EN |
+               LPC32XX_CLKPWR_TMRPWMCLK_TIMER1_EN,
+               LPC32XX_CLKPWR_TIMERS_PWMS_CLK_CTRL_1);
+
+       /*
+        * The clock driver isn't initialized at this point. So determine if
+        * the SYSCLK is driven from the PLL397 or main oscillator and then use
+        * it to compute the PLL frequency and the PCLK divider to get the base
+        * timer rates. This rate is needed to compute the tick rate.
+        */
+       if (clk_is_sysclk_mainosc() != 0)
+               clkrate = LPC32XX_MAIN_OSC_FREQ;
+       else
+               clkrate = 397 * LPC32XX_CLOCK_OSC_FREQ;
+
+       /* Get ARM HCLKPLL register and convert it into a frequency */
+       pllreg = __raw_readl(LPC32XX_CLKPWR_HCLKPLL_CTRL) & 0x1FFFF;
+       clkrate = clk_get_pllrate_from_reg(clkrate, pllreg);
+
+       /* Get PCLK divider and divide ARM PLL clock by it to get timer rate */
+       clkrate = clkrate / clk_get_pclk_div();
+
+       /* Initial timer setup */
+       __raw_writel(0, LCP32XX_TIMER_TCR(LPC32XX_TIMER0_BASE));
+       __raw_writel(LCP32XX_TIMER_CNTR_MTCH_BIT(0),
+               LCP32XX_TIMER_IR(LPC32XX_TIMER0_BASE));
+       __raw_writel(1, LCP32XX_TIMER_MR0(LPC32XX_TIMER0_BASE));
+       __raw_writel(LCP32XX_TIMER_CNTR_MCR_MTCH(0) |
+               LCP32XX_TIMER_CNTR_MCR_STOP(0) |
+               LCP32XX_TIMER_CNTR_MCR_RESET(0),
+               LCP32XX_TIMER_MCR(LPC32XX_TIMER0_BASE));
+
+       /* Setup tick interrupt */
+       setup_irq(IRQ_LPC32XX_TIMER0, &lpc32xx_timer_irq);
+
+       /* Setup the clockevent structure. */
+       lpc32xx_clkevt.mult = div_sc(clkrate, NSEC_PER_SEC,
+               lpc32xx_clkevt.shift);
+       lpc32xx_clkevt.max_delta_ns = clockevent_delta2ns(-1,
+               &lpc32xx_clkevt);
+       lpc32xx_clkevt.min_delta_ns = clockevent_delta2ns(1,
+               &lpc32xx_clkevt) + 1;
+       lpc32xx_clkevt.cpumask = cpumask_of(0);
+       clockevents_register_device(&lpc32xx_clkevt);
+
+       /* Use timer1 as clock source. */
+       __raw_writel(LCP32XX_TIMER_CNTR_TCR_RESET,
+               LCP32XX_TIMER_TCR(LPC32XX_TIMER1_BASE));
+       __raw_writel(0, LCP32XX_TIMER_PR(LPC32XX_TIMER1_BASE));
+       __raw_writel(0, LCP32XX_TIMER_MCR(LPC32XX_TIMER1_BASE));
+       __raw_writel(LCP32XX_TIMER_CNTR_TCR_EN,
+               LCP32XX_TIMER_TCR(LPC32XX_TIMER1_BASE));
+       lpc32xx_clksrc.mult = clocksource_hz2mult(clkrate,
+               lpc32xx_clksrc.shift);
+       clocksource_register(&lpc32xx_clksrc);
+}
+
+struct sys_timer lpc32xx_timer = {
+       .init           = &lpc32xx_timer_init,
+};
+
index 66677f0acaed287fb5bde8b48f054334af195703..7ff8020d4d2422f0f509e7bb8aec2631dca60f72 100644 (file)
@@ -15,7 +15,7 @@ obj-$(CONFIG_ARCH_QSD8X50) += sirc.o
 obj-$(CONFIG_MSM_SMD) += smd.o smd_debug.o
 obj-$(CONFIG_MSM_SMD) += last_radio_log.o
 
-obj-$(CONFIG_MACH_TROUT) += board-trout.o devices-msm7x00.o
+obj-$(CONFIG_MACH_TROUT) += board-trout.o board-trout-gpio.o devices-msm7x00.o
 obj-$(CONFIG_MACH_HALIBUT) += board-halibut.o devices-msm7x00.o
 obj-$(CONFIG_ARCH_MSM7X30) += board-msm7x30.o devices-msm7x30.o
 obj-$(CONFIG_ARCH_QSD8X50) += board-qsd8x50.o devices-qsd8x50.o
diff --git a/arch/arm/mach-msm/board-trout-gpio.c b/arch/arm/mach-msm/board-trout-gpio.c
new file mode 100644 (file)
index 0000000..523d213
--- /dev/null
@@ -0,0 +1,112 @@
+/*
+ * linux/arch/arm/mach-msm/gpio.c
+ *
+ * Copyright (C) 2005 HP Labs
+ * Copyright (C) 2008 Google, Inc.
+ * Copyright (C) 2009 Pavel Machek <pavel@ucw.cz>
+ *
+ * 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 <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/irq.h>
+#include <linux/gpio.h>
+
+#include "board-trout.h"
+
+struct msm_gpio_chip {
+       struct gpio_chip        chip;
+       void __iomem            *reg;   /* Base of register bank */
+       u8                      shadow;
+};
+
+#define to_msm_gpio_chip(c) container_of(c, struct msm_gpio_chip, chip)
+
+static int msm_gpiolib_get(struct gpio_chip *chip, unsigned offset)
+{
+       struct msm_gpio_chip *msm_gpio = to_msm_gpio_chip(chip);
+       unsigned mask = 1 << offset;
+
+       return !!(readb(msm_gpio->reg) & mask);
+}
+
+static void msm_gpiolib_set(struct gpio_chip *chip, unsigned offset, int val)
+{
+       struct msm_gpio_chip *msm_gpio = to_msm_gpio_chip(chip);
+       unsigned mask = 1 << offset;
+
+       if (val)
+               msm_gpio->shadow |= mask;
+       else
+               msm_gpio->shadow &= ~mask;
+
+       writeb(msm_gpio->shadow, msm_gpio->reg);
+}
+
+static int msm_gpiolib_direction_input(struct gpio_chip *chip,
+                                       unsigned offset)
+{
+       msm_gpiolib_set(chip, offset, 0);
+       return 0;
+}
+
+static int msm_gpiolib_direction_output(struct gpio_chip *chip,
+                                        unsigned offset, int val)
+{
+       msm_gpiolib_set(chip, offset, val);
+       return 0;
+}
+
+#define TROUT_GPIO_BANK(name, reg_num, base_gpio, shadow_val)          \
+       {                                                               \
+               .chip = {                                               \
+                       .label            = name,                       \
+                       .direction_input  = msm_gpiolib_direction_input,\
+                       .direction_output = msm_gpiolib_direction_output, \
+                       .get              = msm_gpiolib_get,            \
+                       .set              = msm_gpiolib_set,            \
+                       .base             = base_gpio,                  \
+                       .ngpio            = 8,                          \
+               },                                                      \
+               .reg = (void *) reg_num + TROUT_CPLD_BASE,              \
+               .shadow = shadow_val,                                   \
+       }
+
+static struct msm_gpio_chip msm_gpio_banks[] = {
+#if defined(CONFIG_MSM_DEBUG_UART1)
+       /* H2W pins <-> UART1 */
+       TROUT_GPIO_BANK("MISC2", 0x00,   TROUT_GPIO_MISC2_BASE, 0x40),
+#else
+       /* H2W pins <-> UART3, Bluetooth <-> UART1 */
+       TROUT_GPIO_BANK("MISC2", 0x00,   TROUT_GPIO_MISC2_BASE, 0x80),
+#endif
+       /* I2C pull */
+       TROUT_GPIO_BANK("MISC3", 0x02,   TROUT_GPIO_MISC3_BASE, 0x04),
+       TROUT_GPIO_BANK("MISC4", 0x04,   TROUT_GPIO_MISC4_BASE, 0),
+       /* mmdi 32k en */
+       TROUT_GPIO_BANK("MISC5", 0x06,   TROUT_GPIO_MISC5_BASE, 0x04),
+       TROUT_GPIO_BANK("INT2", 0x08,    TROUT_GPIO_INT2_BASE,  0),
+       TROUT_GPIO_BANK("MISC1", 0x0a,   TROUT_GPIO_MISC1_BASE, 0),
+       TROUT_GPIO_BANK("VIRTUAL", 0x12, TROUT_GPIO_VIRTUAL_BASE, 0),
+};
+
+/*
+ * Called from the processor-specific init to enable GPIO pin support.
+ */
+int __init trout_init_gpio(void)
+{
+       int i;
+
+       for (i = 0; i < ARRAY_SIZE(msm_gpio_banks); i++)
+               gpiochip_add(&msm_gpio_banks[i].chip);
+
+       return 0;
+}
+
+postcore_initcall(trout_init_gpio);
+
index dca5a5f062dce229fe98b9e00fe5f18e5ff40620..e69a1502e4e8dc80cac9dd620497b5adddd0e6d4 100644 (file)
@@ -50,7 +50,6 @@ static void __init trout_fixup(struct machine_desc *desc, struct tag *tags,
 {
        mi->nr_banks = 1;
        mi->bank[0].start = PHYS_OFFSET;
-       mi->bank[0].node = PHYS_TO_NID(PHYS_OFFSET);
        mi->bank[0].size = (101*1024*1024);
 }
 
index 4f345a5a0a61c7a0cd223a996e07b8650cddd52a..651851c3e1dd14d21ef24c497667dbe2f5d5828d 100644 (file)
@@ -1,5 +1,162 @@
+/* linux/arch/arm/mach-msm/board-trout.h
+** Author: Brian Swetland <swetland@google.com>
+*/
+#ifndef __ARCH_ARM_MACH_MSM_BOARD_TROUT_H
+#define __ARCH_ARM_MACH_MSM_BOARD_TROUT_H
+
+#include <mach/board.h>
+
+#define MSM_SMI_BASE           0x00000000
+#define MSM_SMI_SIZE           0x00800000
+
+#define MSM_EBI_BASE           0x10000000
+#define MSM_EBI_SIZE           0x06e00000
+
+#define MSM_PMEM_GPU0_BASE     0x00000000
+#define MSM_PMEM_GPU0_SIZE     0x00700000
+
+#define MSM_PMEM_MDP_BASE      0x02000000
+#define MSM_PMEM_MDP_SIZE      0x00800000
+
+#define MSM_PMEM_ADSP_BASE      0x02800000
+#define MSM_PMEM_ADSP_SIZE     0x00800000
+
+#define MSM_PMEM_CAMERA_BASE   0x03000000
+#define MSM_PMEM_CAMERA_SIZE   0x00800000
+
+#define MSM_FB_BASE            0x03800000
+#define MSM_FB_SIZE            0x00100000
+
+#define MSM_LINUX_BASE         MSM_EBI_BASE
+#define MSM_LINUX_SIZE         0x06500000
+
+#define MSM_PMEM_GPU1_SIZE     0x800000
+#define MSM_PMEM_GPU1_BASE     (MSM_RAM_CONSOLE_BASE - MSM_PMEM_GPU1_SIZE)
+
+#define MSM_RAM_CONSOLE_BASE   (MSM_EBI_BASE + 0x6d00000)
+#define MSM_RAM_CONSOLE_SIZE   (128 * SZ_1K)
+
+#if (MSM_FB_BASE + MSM_FB_SIZE) >= (MSM_PMEM_GPU1_BASE)
+#error invalid memory map
+#endif
+
+#define DECLARE_MSM_IOMAP
+#include <mach/msm_iomap.h>
+
+#define TROUT_4_BALL_UP_0     1
+#define TROUT_4_BALL_LEFT_0   18
+#define TROUT_4_BALL_DOWN_0   57
+#define TROUT_4_BALL_RIGHT_0  91
+
+#define TROUT_5_BALL_UP_0     94
+#define TROUT_5_BALL_LEFT_0   18
+#define TROUT_5_BALL_DOWN_0   90
+#define TROUT_5_BALL_RIGHT_0  19
+
+#define TROUT_POWER_KEY     20
+
+#define TROUT_4_TP_LS_EN    19
+#define TROUT_5_TP_LS_EN    1
 
 #define TROUT_CPLD_BASE   0xE8100000
 #define TROUT_CPLD_START  0x98000000
 #define TROUT_CPLD_SIZE   SZ_4K
 
+#define TROUT_GPIO_CABLE_IN1           (83)
+#define TROUT_GPIO_CABLE_IN2           (49)
+
+#define TROUT_GPIO_START (128)
+
+#define TROUT_GPIO_INT_MASK0_REG            (0x0c)
+#define TROUT_GPIO_INT_STAT0_REG            (0x0e)
+#define TROUT_GPIO_INT_MASK1_REG            (0x14)
+#define TROUT_GPIO_INT_STAT1_REG            (0x10)
+
+#define TROUT_GPIO_HAPTIC_PWM               (28)
+#define TROUT_GPIO_PS_HOLD                  (25)
+
+#define TROUT_GPIO_MISC2_BASE               (TROUT_GPIO_START + 0x00)
+#define TROUT_GPIO_MISC3_BASE               (TROUT_GPIO_START + 0x08)
+#define TROUT_GPIO_MISC4_BASE               (TROUT_GPIO_START + 0x10)
+#define TROUT_GPIO_MISC5_BASE               (TROUT_GPIO_START + 0x18)
+#define TROUT_GPIO_INT2_BASE                (TROUT_GPIO_START + 0x20)
+#define TROUT_GPIO_MISC1_BASE               (TROUT_GPIO_START + 0x28)
+#define TROUT_GPIO_VIRTUAL_BASE             (TROUT_GPIO_START + 0x30)
+#define TROUT_GPIO_INT5_BASE                (TROUT_GPIO_START + 0x48)
+
+#define TROUT_GPIO_CHARGER_EN               (TROUT_GPIO_MISC2_BASE + 0)
+#define TROUT_GPIO_ISET                     (TROUT_GPIO_MISC2_BASE + 1)
+#define TROUT_GPIO_H2W_DAT_DIR              (TROUT_GPIO_MISC2_BASE + 2)
+#define TROUT_GPIO_H2W_CLK_DIR              (TROUT_GPIO_MISC2_BASE + 3)
+#define TROUT_GPIO_H2W_DAT_GPO              (TROUT_GPIO_MISC2_BASE + 4)
+#define TROUT_GPIO_H2W_CLK_GPO              (TROUT_GPIO_MISC2_BASE + 5)
+#define TROUT_GPIO_H2W_SEL0                 (TROUT_GPIO_MISC2_BASE + 6)
+#define TROUT_GPIO_H2W_SEL1                 (TROUT_GPIO_MISC2_BASE + 7)
+
+#define TROUT_GPIO_SPOTLIGHT_EN             (TROUT_GPIO_MISC3_BASE + 0)
+#define TROUT_GPIO_FLASH_EN                 (TROUT_GPIO_MISC3_BASE + 1)
+#define TROUT_GPIO_I2C_PULL                 (TROUT_GPIO_MISC3_BASE + 2)
+#define TROUT_GPIO_TP_I2C_PULL              (TROUT_GPIO_MISC3_BASE + 3)
+#define TROUT_GPIO_TP_EN                    (TROUT_GPIO_MISC3_BASE + 4)
+#define TROUT_GPIO_JOG_EN                   (TROUT_GPIO_MISC3_BASE + 5)
+#define TROUT_GPIO_UI_LED_EN                (TROUT_GPIO_MISC3_BASE + 6)
+#define TROUT_GPIO_QTKEY_LED_EN             (TROUT_GPIO_MISC3_BASE + 7)
+
+#define TROUT_GPIO_VCM_PWDN                 (TROUT_GPIO_MISC4_BASE + 0)
+#define TROUT_GPIO_USB_H2W_SW               (TROUT_GPIO_MISC4_BASE + 1)
+#define TROUT_GPIO_COMPASS_RST_N            (TROUT_GPIO_MISC4_BASE + 2)
+#define TROUT_GPIO_HAPTIC_EN_UP             (TROUT_GPIO_MISC4_BASE + 3)
+#define TROUT_GPIO_HAPTIC_EN_MAIN           (TROUT_GPIO_MISC4_BASE + 4)
+#define TROUT_GPIO_USB_PHY_RST_N            (TROUT_GPIO_MISC4_BASE + 5)
+#define TROUT_GPIO_WIFI_PA_RESETX           (TROUT_GPIO_MISC4_BASE + 6)
+#define TROUT_GPIO_WIFI_EN                  (TROUT_GPIO_MISC4_BASE + 7)
+
+#define TROUT_GPIO_BT_32K_EN                (TROUT_GPIO_MISC5_BASE + 0)
+#define TROUT_GPIO_MAC_32K_EN               (TROUT_GPIO_MISC5_BASE + 1)
+#define TROUT_GPIO_MDDI_32K_EN              (TROUT_GPIO_MISC5_BASE + 2)
+#define TROUT_GPIO_COMPASS_32K_EN           (TROUT_GPIO_MISC5_BASE + 3)
+
+#define TROUT_GPIO_NAVI_ACT_N               (TROUT_GPIO_INT2_BASE + 0)
+#define TROUT_GPIO_COMPASS_IRQ              (TROUT_GPIO_INT2_BASE + 1)
+#define TROUT_GPIO_SLIDING_DET              (TROUT_GPIO_INT2_BASE + 2)
+#define TROUT_GPIO_AUD_HSMIC_DET_N          (TROUT_GPIO_INT2_BASE + 3)
+#define TROUT_GPIO_SD_DOOR_N                (TROUT_GPIO_INT2_BASE + 4)
+#define TROUT_GPIO_CAM_BTN_STEP1_N          (TROUT_GPIO_INT2_BASE + 5)
+#define TROUT_GPIO_CAM_BTN_STEP2_N          (TROUT_GPIO_INT2_BASE + 6)
+#define TROUT_GPIO_TP_ATT_N                 (TROUT_GPIO_INT2_BASE + 7)
+#define TROUT_GPIO_BANK0_FIRST_INT_SOURCE   (TROUT_GPIO_NAVI_ACT_N)
+#define TROUT_GPIO_BANK0_LAST_INT_SOURCE    (TROUT_GPIO_TP_ATT_N)
+
+#define TROUT_GPIO_H2W_DAT_GPI              (TROUT_GPIO_MISC1_BASE + 0)
+#define TROUT_GPIO_H2W_CLK_GPI              (TROUT_GPIO_MISC1_BASE + 1)
+#define TROUT_GPIO_CPLD128_VER_0            (TROUT_GPIO_MISC1_BASE + 4)
+#define TROUT_GPIO_CPLD128_VER_1            (TROUT_GPIO_MISC1_BASE + 5)
+#define TROUT_GPIO_CPLD128_VER_2            (TROUT_GPIO_MISC1_BASE + 6)
+#define TROUT_GPIO_CPLD128_VER_3            (TROUT_GPIO_MISC1_BASE + 7)
+
+#define TROUT_GPIO_SDMC_CD_N                (TROUT_GPIO_VIRTUAL_BASE + 0)
+#define TROUT_GPIO_END                      (TROUT_GPIO_SDMC_CD_N)
+#define TROUT_GPIO_BANK1_FIRST_INT_SOURCE   (TROUT_GPIO_SDMC_CD_N)
+#define TROUT_GPIO_BANK1_LAST_INT_SOURCE    (TROUT_GPIO_SDMC_CD_N)
+
+#define TROUT_GPIO_VIRTUAL_TO_REAL_OFFSET \
+       (TROUT_GPIO_INT5_BASE - TROUT_GPIO_VIRTUAL_BASE)
+
+#define TROUT_INT_START (NR_MSM_IRQS + NR_GPIO_IRQS)
+#define TROUT_INT_BANK0_COUNT (8)
+#define TROUT_INT_BANK1_START (TROUT_INT_START + TROUT_INT_BANK0_COUNT)
+#define TROUT_INT_BANK1_COUNT (1)
+#define TROUT_INT_END (TROUT_INT_START + TROUT_INT_BANK0_COUNT + \
+                       TROUT_INT_BANK1_COUNT - 1)
+#define TROUT_GPIO_TO_INT(n) (((n) <= TROUT_GPIO_BANK0_LAST_INT_SOURCE) ? \
+       (TROUT_INT_START - TROUT_GPIO_BANK0_FIRST_INT_SOURCE + (n)) : \
+       (TROUT_INT_BANK1_START - TROUT_GPIO_BANK1_FIRST_INT_SOURCE + (n)))
+
+#define TROUT_INT_TO_BANK(n) ((n - TROUT_INT_START) / TROUT_INT_BANK0_COUNT)
+#define TROUT_INT_TO_MASK(n) (1U << ((n - TROUT_INT_START) & 7))
+#define TROUT_BANK_TO_MASK_REG(bank) \
+       (bank ? TROUT_GPIO_INT_MASK1_REG : TROUT_GPIO_INT_MASK0_REG)
+#define TROUT_BANK_TO_STAT_REG(bank) \
+       (bank ? TROUT_GPIO_INT_STAT1_REG : TROUT_GPIO_INT_STAT0_REG)
+
+#endif /* GUARD */
index 262b441b4374a94dd71e90cc9ed1ce1d3b230d90..83e47c0d5c2e451de5f459653053684beb786ee8 100644 (file)
 #ifndef __ASM_ARCH_MSM_GPIO_H
 #define __ASM_ARCH_MSM_GPIO_H
 
+#include <asm-generic/gpio.h>
+
+#define gpio_get_value  __gpio_get_value
+#define gpio_set_value  __gpio_set_value
+#define gpio_cansleep   __gpio_cansleep
+#define gpio_to_irq     __gpio_to_irq
+
 /**
  * struct msm_gpio - GPIO pin description
  * @gpio_cfg - configuration bitmap, as per gpio_tlmm_config()
diff --git a/arch/arm/mach-mx1/Kconfig b/arch/arm/mach-mx1/Kconfig
deleted file mode 100644 (file)
index eb7660f..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-if ARCH_MX1
-
-comment "MX1 platforms:"
-
-config MACH_MXLADS
-       bool
-
-config ARCH_MX1ADS
-       bool "MX1ADS platform"
-       select MACH_MXLADS
-       help
-         Say Y here if you are using Motorola MX1ADS/MXLADS boards
-
-config MACH_SCB9328
-       bool "Synertronixx scb9328"
-       help
-         Say Y here if you are using a Synertronixx scb9328 board
-
-endif
diff --git a/arch/arm/mach-mx1/Makefile b/arch/arm/mach-mx1/Makefile
deleted file mode 100644 (file)
index fc2ddf8..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-#
-# Makefile for the linux kernel.
-#
-
-# Object file lists.
-
-EXTRA_CFLAGS += -DIMX_NEEDS_DEPRECATED_SYMBOLS
-obj-y                  += generic.o clock.o devices.o
-
-# Support for CMOS sensor interface
-obj-$(CONFIG_MX1_VIDEO)        += ksym_mx1.o mx1_camera_fiq.o
-
-# Specific board support
-obj-$(CONFIG_ARCH_MX1ADS) += mach-mx1ads.o
-obj-$(CONFIG_MACH_SCB9328) += mach-scb9328.o
diff --git a/arch/arm/mach-mx1/Makefile.boot b/arch/arm/mach-mx1/Makefile.boot
deleted file mode 100644 (file)
index 8ed1492..0000000
+++ /dev/null
@@ -1,4 +0,0 @@
-   zreladdr-y  := 0x08008000
-params_phys-y  := 0x08000100
-initrd_phys-y  := 0x08800000
-
diff --git a/arch/arm/mach-mx1/crm_regs.h b/arch/arm/mach-mx1/crm_regs.h
deleted file mode 100644 (file)
index 22e866f..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2004-2007 Freescale Semiconductor, Inc. All Rights Reserved.
- * Copyright (c) 2008 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
- *
- * This file may be distributed under the terms of the GNU General
- * Public License, version 2.
- */
-
-#ifndef __ARCH_ARM_MACH_MX1_CRM_REGS_H__
-#define __ARCH_ARM_MACH_MX1_CRM_REGS_H__
-
-#define CCM_BASE       IO_ADDRESS(CCM_BASE_ADDR)
-#define SCM_BASE       IO_ADDRESS(SCM_BASE_ADDR)
-
-/* CCM register addresses */
-#define CCM_CSCR       (CCM_BASE + 0x0)
-#define CCM_MPCTL0     (CCM_BASE + 0x4)
-#define CCM_MPCTL1     (CCM_BASE + 0x8)
-#define CCM_SPCTL0     (CCM_BASE + 0xC)
-#define CCM_SPCTL1     (CCM_BASE + 0x10)
-#define CCM_PCDR       (CCM_BASE + 0x20)
-
-#define CCM_CSCR_CLKO_OFFSET   29
-#define CCM_CSCR_CLKO_MASK     (0x7 << 29)
-#define CCM_CSCR_USB_OFFSET    26
-#define CCM_CSCR_USB_MASK      (0x7 << 26)
-#define CCM_CSCR_SPLL_RESTART  (1 << 22)
-#define CCM_CSCR_MPLL_RESTART  (1 << 21)
-#define CCM_CSCR_OSC_EN_SHIFT  17
-#define CCM_CSCR_SYSTEM_SEL    (1 << 16)
-#define CCM_CSCR_BCLK_OFFSET   10
-#define CCM_CSCR_BCLK_MASK     (0xF << 10)
-#define CCM_CSCR_PRESC         (1 << 15)
-#define CCM_CSCR_SPEN          (1 << 1)
-#define CCM_CSCR_MPEN          (1 << 0)
-
-#define CCM_PCDR_PCLK3_OFFSET  16
-#define CCM_PCDR_PCLK3_MASK    (0x7F << 16)
-#define CCM_PCDR_PCLK2_OFFSET  4
-#define CCM_PCDR_PCLK2_MASK    (0xF << 4)
-#define CCM_PCDR_PCLK1_OFFSET  0
-#define CCM_PCDR_PCLK1_MASK    0xF
-
-/* SCM register addresses */
-#define SCM_SIDR       (SCM_BASE + 0x0)
-#define SCM_FMCR       (SCM_BASE + 0x4)
-#define SCM_GPCR       (SCM_BASE + 0x8)
-#define SCM_GCCR       (SCM_BASE + 0xC)
-
-#define SCM_GCCR_DMA_CLK_EN_OFFSET     3
-#define SCM_GCCR_CSI_CLK_EN_OFFSET     2
-#define SCM_GCCR_MMA_CLK_EN_OFFSET     1
-#define SCM_GCCR_USBD_CLK_EN_OFFSET    0
-
-#endif /* __ARCH_ARM_MACH_MX2_CRM_REGS_H__ */
diff --git a/arch/arm/mach-mx1/devices.c b/arch/arm/mach-mx1/devices.c
deleted file mode 100644 (file)
index b6be29d..0000000
+++ /dev/null
@@ -1,242 +0,0 @@
-/*
- * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
- * Copyright 2008 Sascha Hauer, kernel@pengutronix.de
- * Copyright (c) 2008 Paulius Zaleckas <paulius.zaleckas@teltonika.lt>
- * Copyright (c) 2008 Darius Augulis <darius.augulis@teltonika.lt>
- *
- * 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., 51 Franklin Street, Fifth Floor,
- * Boston, MA  02110-1301, USA.
- */
-
-#include <linux/kernel.h>
-#include <linux/init.h>
-#include <linux/platform_device.h>
-#include <linux/gpio.h>
-#include <mach/irqs.h>
-#include <mach/hardware.h>
-
-#include "devices.h"
-
-static struct resource imx_csi_resources[] = {
-       {
-               .start  = 0x00224000,
-               .end    = 0x00224010,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = CSI_INT,
-               .end    = CSI_INT,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-static u64 imx_csi_dmamask = 0xffffffffUL;
-
-struct platform_device imx_csi_device = {
-       .name           = "mx1-camera",
-       .id             = 0, /* This is used to put cameras on this interface */
-       .dev            = {
-               .dma_mask = &imx_csi_dmamask,
-               .coherent_dma_mask = 0xffffffff,
-       },
-       .resource       = imx_csi_resources,
-       .num_resources  = ARRAY_SIZE(imx_csi_resources),
-};
-
-static struct resource imx_i2c_resources[] = {
-       {
-               .start  = 0x00217000,
-               .end    = 0x00217010,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = I2C_INT,
-               .end    = I2C_INT,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device imx_i2c_device = {
-       .name           = "imx-i2c",
-       .id             = 0,
-       .resource       = imx_i2c_resources,
-       .num_resources  = ARRAY_SIZE(imx_i2c_resources),
-};
-
-static struct resource imx_uart1_resources[] = {
-       {
-               .start  = UART1_BASE_ADDR,
-               .end    = UART1_BASE_ADDR + 0xD0,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = UART1_MINT_RX,
-               .end    = UART1_MINT_RX,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = UART1_MINT_TX,
-               .end    = UART1_MINT_TX,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = UART1_MINT_RTS,
-               .end    = UART1_MINT_RTS,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device imx_uart1_device = {
-       .name           = "imx-uart",
-       .id             = 0,
-       .num_resources  = ARRAY_SIZE(imx_uart1_resources),
-       .resource       = imx_uart1_resources,
-};
-
-static struct resource imx_uart2_resources[] = {
-       {
-               .start  = UART2_BASE_ADDR,
-               .end    = UART2_BASE_ADDR + 0xD0,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = UART2_MINT_RX,
-               .end    = UART2_MINT_RX,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = UART2_MINT_TX,
-               .end    = UART2_MINT_TX,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = UART2_MINT_RTS,
-               .end    = UART2_MINT_RTS,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device imx_uart2_device = {
-       .name           = "imx-uart",
-       .id             = 1,
-       .num_resources  = ARRAY_SIZE(imx_uart2_resources),
-       .resource       = imx_uart2_resources,
-};
-
-static struct resource imx_rtc_resources[] = {
-       {
-               .start  = 0x00204000,
-               .end    = 0x00204024,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = RTC_INT,
-               .end    = RTC_INT,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = RTC_SAMINT,
-               .end    = RTC_SAMINT,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device imx_rtc_device = {
-       .name           = "rtc-imx",
-       .id             = 0,
-       .resource       = imx_rtc_resources,
-       .num_resources  = ARRAY_SIZE(imx_rtc_resources),
-};
-
-static struct resource imx_wdt_resources[] = {
-       {
-               .start  = 0x00201000,
-               .end    = 0x00201008,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = WDT_INT,
-               .end    = WDT_INT,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device imx_wdt_device = {
-       .name           = "imx-wdt",
-       .id             = 0,
-       .resource       = imx_wdt_resources,
-       .num_resources  = ARRAY_SIZE(imx_wdt_resources),
-};
-
-static struct resource imx_usb_resources[] = {
-       {
-               .start  = 0x00212000,
-               .end    = 0x00212148,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = USBD_INT0,
-               .end    = USBD_INT0,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = USBD_INT1,
-               .end    = USBD_INT1,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = USBD_INT2,
-               .end    = USBD_INT2,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = USBD_INT3,
-               .end    = USBD_INT3,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = USBD_INT4,
-               .end    = USBD_INT4,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = USBD_INT5,
-               .end    = USBD_INT5,
-               .flags  = IORESOURCE_IRQ,
-       }, {
-               .start  = USBD_INT6,
-               .end    = USBD_INT6,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device imx_usb_device = {
-       .name           = "imx_udc",
-       .id             = 0,
-       .num_resources  = ARRAY_SIZE(imx_usb_resources),
-       .resource       = imx_usb_resources,
-};
-
-/* GPIO port description */
-static struct mxc_gpio_port imx_gpio_ports[] = {
-       {
-               .chip.label = "gpio-0",
-               .base = (void __iomem *)IO_ADDRESS(GPIO_BASE_ADDR),
-               .irq = GPIO_INT_PORTA,
-               .virtual_irq_start = MXC_GPIO_IRQ_START,
-       }, {
-               .chip.label = "gpio-1",
-               .base = (void __iomem *)IO_ADDRESS(GPIO_BASE_ADDR + 0x100),
-               .irq = GPIO_INT_PORTB,
-               .virtual_irq_start = MXC_GPIO_IRQ_START + 32,
-       }, {
-               .chip.label = "gpio-2",
-               .base = (void __iomem *)IO_ADDRESS(GPIO_BASE_ADDR + 0x200),
-               .irq = GPIO_INT_PORTC,
-               .virtual_irq_start = MXC_GPIO_IRQ_START + 64,
-       }, {
-               .chip.label = "gpio-3",
-               .base = (void __iomem *)IO_ADDRESS(GPIO_BASE_ADDR + 0x300),
-               .irq = GPIO_INT_PORTD,
-               .virtual_irq_start = MXC_GPIO_IRQ_START + 96,
-       }
-};
-
-int __init mxc_register_gpios(void)
-{
-       return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
-}
diff --git a/arch/arm/mach-mx1/devices.h b/arch/arm/mach-mx1/devices.h
deleted file mode 100644 (file)
index 0da5d7c..0000000
+++ /dev/null
@@ -1,7 +0,0 @@
-extern struct platform_device imx_csi_device;
-extern struct platform_device imx_i2c_device;
-extern struct platform_device imx_uart1_device;
-extern struct platform_device imx_uart2_device;
-extern struct platform_device imx_rtc_device;
-extern struct platform_device imx_wdt_device;
-extern struct platform_device imx_usb_device;
diff --git a/arch/arm/mach-mx2/serial.c b/arch/arm/mach-mx2/serial.c
deleted file mode 100644 (file)
index 1c0c835..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Copyright 2006-2007 Freescale Semiconductor, Inc. All Rights Reserved.
- * Copyright 2008 Juergen Beisert, kernel@pengutronix.de
- *
- * 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., 51 Franklin Street, Fifth Floor, Boston,
- * MA 02110-1301, USA.
- */
-
-#include <linux/module.h>
-#include <linux/platform_device.h>
-#include <linux/serial.h>
-#include <mach/hardware.h>
-#include <mach/imx-uart.h>
-#include "devices.h"
-
-static struct resource uart0[] = {
-       {
-               .start = MX2x_UART1_BASE_ADDR,
-               .end = MX2x_UART1_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MX2x_INT_UART1,
-               .end = MX2x_INT_UART1,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device0 = {
-       .name = "imx-uart",
-       .id = 0,
-       .resource = uart0,
-       .num_resources = ARRAY_SIZE(uart0),
-};
-
-static struct resource uart1[] = {
-       {
-               .start = MX2x_UART2_BASE_ADDR,
-               .end = MX2x_UART2_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MX2x_INT_UART2,
-               .end = MX2x_INT_UART2,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device1 = {
-       .name = "imx-uart",
-       .id = 1,
-       .resource = uart1,
-       .num_resources = ARRAY_SIZE(uart1),
-};
-
-static struct resource uart2[] = {
-       {
-               .start = MX2x_UART3_BASE_ADDR,
-               .end = MX2x_UART3_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MX2x_INT_UART3,
-               .end = MX2x_INT_UART3,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device2 = {
-       .name = "imx-uart",
-       .id = 2,
-       .resource = uart2,
-       .num_resources = ARRAY_SIZE(uart2),
-};
-
-static struct resource uart3[] = {
-       {
-               .start = MX2x_UART4_BASE_ADDR,
-               .end = MX2x_UART4_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MX2x_INT_UART4,
-               .end = MX2x_INT_UART4,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device3 = {
-       .name = "imx-uart",
-       .id = 3,
-       .resource = uart3,
-       .num_resources = ARRAY_SIZE(uart3),
-};
-
-#ifdef CONFIG_MACH_MX27
-static struct resource uart4[] = {
-       {
-               .start = MX27_UART5_BASE_ADDR,
-               .end = MX27_UART5_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MX27_INT_UART5,
-               .end = MX27_INT_UART5,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device4 = {
-       .name = "imx-uart",
-       .id = 4,
-       .resource = uart4,
-       .num_resources = ARRAY_SIZE(uart4),
-};
-
-static struct resource uart5[] = {
-       {
-               .start = MX27_UART6_BASE_ADDR,
-               .end = MX27_UART6_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MX27_INT_UART6,
-               .end = MX27_INT_UART6,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device5 = {
-       .name = "imx-uart",
-       .id = 5,
-       .resource = uart5,
-       .num_resources = ARRAY_SIZE(uart5),
-};
-#endif
index 54d217314ee9a3b57030af0f26f747d4d834e828..c71a7bc19284bf64b14f939f3094bfc501631240 100644 (file)
@@ -4,5 +4,28 @@ comment "MX25 platforms:"
 
 config MACH_MX25_3DS
        bool "Support MX25PDK (3DS) Platform"
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
+
+config MACH_EUKREA_CPUIMX25
+       bool "Support Eukrea CPUIMX25 Platform"
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
+       select MXC_ULPI if USB_ULPI
+
+choice
+       prompt "Baseboard"
+       depends on MACH_EUKREA_CPUIMX25
+       default MACH_EUKREA_MBIMXSD25_BASEBOARD
+
+config MACH_EUKREA_MBIMXSD25_BASEBOARD
+       prompt "Eukrea MBIMXSD development board"
+       bool
+       help
+         This adds board specific devices that can be found on Eukrea's
+         MBIMXSD evaluation board.
+
+endchoice
 
 endif
index 10cebc5ced8c0a0e15748fd7027effbee446d3f2..d9e46ce00a4ec747d92a47041ed98bebdeb3aa34 100644 (file)
@@ -1,3 +1,5 @@
 obj-y                          := mm.o devices.o
 obj-$(CONFIG_ARCH_MX25)                += clock.o
-obj-$(CONFIG_MACH_MX25_3DS)    += mach-mx25pdk.o
+obj-$(CONFIG_MACH_MX25_3DS)    += mach-mx25_3ds.o
+obj-$(CONFIG_MACH_EUKREA_CPUIMX25)             += mach-cpuimx25.o
+obj-$(CONFIG_MACH_EUKREA_MBIMXSD25_BASEBOARD)  += eukrea_mbimxsd-baseboard.o
index 155014993b13cc18d7724ca5d3d03604c7a103e1..40c7cc41cee372c906e3339f5da50f9e709f36df 100644 (file)
@@ -109,6 +109,16 @@ static unsigned long get_rate_uart(struct clk *clk)
        return get_rate_per(15);
 }
 
+static unsigned long get_rate_ssi2(struct clk *clk)
+{
+       return get_rate_per(14);
+}
+
+static unsigned long get_rate_ssi1(struct clk *clk)
+{
+       return get_rate_per(13);
+}
+
 static unsigned long get_rate_i2c(struct clk *clk)
 {
        return get_rate_per(6);
@@ -129,9 +139,17 @@ static unsigned long get_rate_lcdc(struct clk *clk)
        return get_rate_per(7);
 }
 
+static unsigned long get_rate_csi(struct clk *clk)
+{
+       return get_rate_per(0);
+}
+
 static unsigned long get_rate_otg(struct clk *clk)
 {
-       return 48000000; /* FIXME */
+       unsigned long cctl = readl(CRM_BASE + CCM_CCTL);
+       unsigned long rate = get_rate_upll();
+
+       return (cctl & (1 << 23)) ? 0 : rate / ((0x3F & (cctl >> 16)) + 1);
 }
 
 static int clk_cgcr_enable(struct clk *clk)
@@ -166,14 +184,40 @@ static void clk_cgcr_disable(struct clk *clk)
                .secondary      = s,                    \
        }
 
+/*
+ * Note: the following IPG clock gating bits are wrongly marked "Reserved" in
+ * the i.MX25 Reference Manual Rev 1, table 15-13. The information below is
+ * taken from the Freescale released BSP.
+ *
+ * bit reg     offset  clock
+ *
+ * 0   CGCR1   0       AUDMUX
+ * 12  CGCR1   12      ESAI
+ * 16  CGCR1   16      GPIO1
+ * 17  CGCR1   17      GPIO2
+ * 18  CGCR1   18      GPIO3
+ * 23  CGCR1   23      I2C1
+ * 24  CGCR1   24      I2C2
+ * 25  CGCR1   25      I2C3
+ * 27  CGCR1   27      IOMUXC
+ * 28  CGCR1   28      KPP
+ * 30  CGCR1   30      OWIRE
+ * 36  CGCR2   4       RTIC
+ * 51  CGCR2   19      WDOG
+ */
+
 DEFINE_CLOCK(gpt_clk,    0, CCM_CGCR0,  5, get_rate_gpt, NULL, NULL);
 DEFINE_CLOCK(uart_per_clk, 0, CCM_CGCR0, 15, get_rate_uart, NULL, NULL);
+DEFINE_CLOCK(ssi1_per_clk, 0, CCM_CGCR0, 13, get_rate_ipg, NULL, NULL);
+DEFINE_CLOCK(ssi2_per_clk, 0, CCM_CGCR0, 14, get_rate_ipg, NULL, NULL);
 DEFINE_CLOCK(cspi1_clk,  0, CCM_CGCR1,  5, get_rate_ipg, NULL, NULL);
 DEFINE_CLOCK(cspi2_clk,  0, CCM_CGCR1,  6, get_rate_ipg, NULL, NULL);
 DEFINE_CLOCK(cspi3_clk,  0, CCM_CGCR1,  7, get_rate_ipg, NULL, NULL);
 DEFINE_CLOCK(fec_ahb_clk, 0, CCM_CGCR0, 23, NULL,       NULL, NULL);
 DEFINE_CLOCK(lcdc_ahb_clk, 0, CCM_CGCR0, 24, NULL,      NULL, NULL);
 DEFINE_CLOCK(lcdc_per_clk, 0, CCM_CGCR0,  7, NULL,      NULL, &lcdc_ahb_clk);
+DEFINE_CLOCK(csi_ahb_clk, 0, CCM_CGCR0, 18, get_rate_csi, NULL, NULL);
+DEFINE_CLOCK(csi_per_clk, 0, CCM_CGCR0, 0, get_rate_csi, NULL, &csi_ahb_clk);
 DEFINE_CLOCK(uart1_clk,  0, CCM_CGCR2, 14, get_rate_uart, NULL, &uart_per_clk);
 DEFINE_CLOCK(uart2_clk,  0, CCM_CGCR2, 15, get_rate_uart, NULL, &uart_per_clk);
 DEFINE_CLOCK(uart3_clk,  0, CCM_CGCR2, 16, get_rate_uart, NULL, &uart_per_clk);
@@ -191,6 +235,13 @@ DEFINE_CLOCK(i2c_clk,       0, CCM_CGCR0,  6, get_rate_i2c, NULL, NULL);
 DEFINE_CLOCK(fec_clk,   0, CCM_CGCR1, 15, get_rate_ipg, NULL, &fec_ahb_clk);
 DEFINE_CLOCK(dryice_clk, 0, CCM_CGCR1,  8, get_rate_ipg, NULL, NULL);
 DEFINE_CLOCK(lcdc_clk,  0, CCM_CGCR1, 29, get_rate_lcdc, NULL, &lcdc_per_clk);
+DEFINE_CLOCK(wdt_clk,    0, CCM_CGCR2, 19, get_rate_ipg, NULL,  NULL);
+DEFINE_CLOCK(ssi1_clk,  0, CCM_CGCR2, 11, get_rate_ssi1, NULL, &ssi1_per_clk);
+DEFINE_CLOCK(ssi2_clk,  1, CCM_CGCR2, 12, get_rate_ssi2, NULL, &ssi2_per_clk);
+DEFINE_CLOCK(audmux_clk, 0, CCM_CGCR1, 0, NULL, NULL, NULL);
+DEFINE_CLOCK(csi_clk,    0, CCM_CGCR1,  4, get_rate_csi, NULL,  &csi_per_clk);
+DEFINE_CLOCK(can1_clk,  0, CCM_CGCR1,  2, get_rate_ipg, NULL, NULL);
+DEFINE_CLOCK(can2_clk,  0, CCM_CGCR1,  3, get_rate_ipg, NULL, NULL);
 
 #define _REGISTER_CLOCK(d, n, c)       \
        {                               \
@@ -217,7 +268,7 @@ static struct clk_lookup lookups[] = {
        _REGISTER_CLOCK("mxc_pwm.1", NULL, pwm2_clk)
        _REGISTER_CLOCK("mxc_pwm.2", NULL, pwm3_clk)
        _REGISTER_CLOCK("mxc_pwm.3", NULL, pwm4_clk)
-       _REGISTER_CLOCK("mxc-keypad", NULL, kpp_clk)
+       _REGISTER_CLOCK("imx-keypad", NULL, kpp_clk)
        _REGISTER_CLOCK("mx25-adc", NULL, tsc_clk)
        _REGISTER_CLOCK("imx-i2c.0", NULL, i2c_clk)
        _REGISTER_CLOCK("imx-i2c.1", NULL, i2c_clk)
@@ -225,6 +276,13 @@ static struct clk_lookup lookups[] = {
        _REGISTER_CLOCK("fec.0", NULL, fec_clk)
        _REGISTER_CLOCK("imxdi_rtc.0", NULL, dryice_clk)
        _REGISTER_CLOCK("imx-fb.0", NULL, lcdc_clk)
+       _REGISTER_CLOCK("imx-wdt.0", NULL, wdt_clk)
+       _REGISTER_CLOCK("imx-ssi.0", NULL, ssi1_clk)
+       _REGISTER_CLOCK("imx-ssi.1", NULL, ssi2_clk)
+       _REGISTER_CLOCK("mx2-camera.0", NULL, csi_clk)
+       _REGISTER_CLOCK(NULL, "audmux", audmux_clk)
+       _REGISTER_CLOCK("flexcan.0", NULL, can1_clk)
+       _REGISTER_CLOCK("flexcan.1", NULL, can2_clk)
 };
 
 int __init mx25_clocks_init(void)
@@ -238,9 +296,13 @@ int __init mx25_clocks_init(void)
        __raw_writel((1 << 19), CRM_BASE + CCM_CGCR0);
        __raw_writel((0xf << 16) | (3 << 26), CRM_BASE + CCM_CGCR1);
        __raw_writel((1 << 5), CRM_BASE + CCM_CGCR2);
+#if defined(CONFIG_DEBUG_LL) && !defined(CONFIG_DEBUG_ICEDCC)
+       clk_enable(&uart1_clk);
+#endif
 
-       /* Clock source for lcdc is upll */
-       __raw_writel(__raw_readl(CRM_BASE+0x64) | (1 << 7), CRM_BASE + 0x64);
+       /* Clock source for lcdc and csi is upll */
+       __raw_writel(__raw_readl(CRM_BASE+0x64) | (1 << 7) | (1 << 0),
+                       CRM_BASE + 0x64);
 
        mxc_timer_init(&gpt_clk, MX25_IO_ADDRESS(MX25_GPT1_BASE_ADDR), 54);
 
diff --git a/arch/arm/mach-mx25/devices-imx25.h b/arch/arm/mach-mx25/devices-imx25.h
new file mode 100644 (file)
index 0000000..d86a7c3
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <mach/mx25.h>
+#include <mach/devices-common.h>
+
+#define imx25_add_flexcan0(pdata)      \
+       imx_add_flexcan(0, MX25_CAN1_BASE_ADDR, SZ_16K, MX25_INT_CAN1, pdata)
+#define imx25_add_flexcan1(pdata)      \
+       imx_add_flexcan(1, MX25_CAN2_BASE_ADDR, SZ_16K, MX25_INT_CAN2, pdata)
+
+#define imx25_add_imx_i2c0(pdata)      \
+       imx_add_imx_i2c(0, MX25_I2C1_BASE_ADDR, SZ_16K, MX25_INT_I2C1, pdata)
+#define imx25_add_imx_i2c1(pdata)      \
+       imx_add_imx_i2c(1, MX25_I2C2_BASE_ADDR, SZ_16K, MX25_INT_I2C2, pdata)
+#define imx25_add_imx_i2c2(pdata)      \
+       imx_add_imx_i2c(2, MX25_I2C3_BASE_ADDR, SZ_16K, MX25_INT_I2C3, pdata)
+
+#define imx25_add_imx_uart0(pdata)     \
+       imx_add_imx_uart_1irq(0, MX25_UART1_BASE_ADDR, SZ_16K, MX25_INT_UART1, pdata)
+#define imx25_add_imx_uart1(pdata)     \
+       imx_add_imx_uart_1irq(1, MX25_UART2_BASE_ADDR, SZ_16K, MX25_INT_UART2, pdata)
+#define imx25_add_imx_uart2(pdata)     \
+       imx_add_imx_uart_1irq(2, MX25_UART3_BASE_ADDR, SZ_16K, MX25_INT_UART3, pdata)
+#define imx25_add_imx_uart3(pdata)     \
+       imx_add_imx_uart_1irq(3, MX25_UART4_BASE_ADDR, SZ_16K, MX25_INT_UART4, pdata)
+#define imx25_add_imx_uart4(pdata)     \
+       imx_add_imx_uart_1irq(4, MX25_UART5_BASE_ADDR, SZ_16K, MX25_INT_UART5, pdata)
+
+#define imx25_add_mxc_nand(pdata)      \
+       imx_add_mxc_nand_v21(MX25_NFC_BASE_ADDR, MX25_INT_NANDFC, pdata)
+
+#define imx25_add_spi_imx0(pdata)      \
+       imx_add_spi_imx(0, MX25_CSPI1_BASE_ADDR, SZ_16K, MX25_INT_CSPI1, pdata)
+#define imx25_add_spi_imx1(pdata)      \
+       imx_add_spi_imx(1, MX25_CSPI2_BASE_ADDR, SZ_16K, MX25_INT_CSPI2, pdata)
+#define imx25_add_spi_imx2(pdata)      \
+       imx_add_spi_imx(2, MX25_CSPI3_BASE_ADDR, SZ_16K, MX25_INT_CSPI3, pdata)
index 3a405fa400eb064a6a8e612027709b7601cb4d34..3468eb15b2367fd1a4c197bf76d3b59af4b3372a 100644 (file)
 #include <mach/mx25.h>
 #include <mach/irqs.h>
 
-static struct resource uart0[] = {
-       {
-               .start = 0x43f90000,
-               .end = 0x43f93fff,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = 45,
-               .end = 45,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device0 = {
-       .name = "imx-uart",
-       .id = 0,
-       .resource = uart0,
-       .num_resources = ARRAY_SIZE(uart0),
-};
-
-static struct resource uart1[] = {
-       {
-               .start = 0x43f94000,
-               .end = 0x43f97fff,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = 32,
-               .end = 32,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device1 = {
-       .name = "imx-uart",
-       .id = 1,
-       .resource = uart1,
-       .num_resources = ARRAY_SIZE(uart1),
-};
-
-static struct resource uart2[] = {
-       {
-               .start = 0x5000c000,
-               .end = 0x5000ffff,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = 18,
-               .end = 18,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device2 = {
-       .name = "imx-uart",
-       .id = 2,
-       .resource = uart2,
-       .num_resources = ARRAY_SIZE(uart2),
-};
-
-static struct resource uart3[] = {
-       {
-               .start = 0x50008000,
-               .end = 0x5000bfff,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = 5,
-               .end = 5,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device3 = {
-       .name = "imx-uart",
-       .id = 3,
-       .resource = uart3,
-       .num_resources = ARRAY_SIZE(uart3),
-};
-
-static struct resource uart4[] = {
-       {
-               .start = 0x5002c000,
-               .end = 0x5002ffff,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = 40,
-               .end = 40,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device4 = {
-       .name = "imx-uart",
-       .id = 4,
-       .resource = uart4,
-       .num_resources = ARRAY_SIZE(uart4),
-};
-
-#define MX25_OTG_BASE_ADDR 0x53FF4000
-
 static u64 otg_dmamask = DMA_BIT_MASK(32);
 
 static struct resource mxc_otg_resources[] = {
@@ -181,63 +84,6 @@ struct platform_device mxc_usbh2 = {
        .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
 };
 
-static struct resource mxc_spi_resources0[] = {
-       {
-              .start = 0x43fa4000,
-              .end = 0x43fa7fff,
-              .flags = IORESOURCE_MEM,
-       }, {
-              .start = 14,
-              .end = 14,
-              .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_spi_device0 = {
-       .name = "spi_imx",
-       .id = 0,
-       .num_resources = ARRAY_SIZE(mxc_spi_resources0),
-       .resource = mxc_spi_resources0,
-};
-
-static struct resource mxc_spi_resources1[] = {
-       {
-              .start = 0x50010000,
-              .end = 0x50013fff,
-              .flags = IORESOURCE_MEM,
-       }, {
-              .start = 13,
-              .end = 13,
-              .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_spi_device1 = {
-       .name = "spi_imx",
-       .id = 1,
-       .num_resources = ARRAY_SIZE(mxc_spi_resources1),
-       .resource = mxc_spi_resources1,
-};
-
-static struct resource mxc_spi_resources2[] = {
-       {
-              .start = 0x50004000,
-              .end = 0x50007fff,
-              .flags = IORESOURCE_MEM,
-       }, {
-              .start = 0,
-              .end = 0,
-              .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_spi_device2 = {
-       .name = "spi_imx",
-       .id = 2,
-       .num_resources = ARRAY_SIZE(mxc_spi_resources2),
-       .resource = mxc_spi_resources2,
-};
-
 static struct resource mxc_pwm_resources0[] = {
        {
                .start  = 0x53fe0000,
@@ -333,63 +179,6 @@ struct platform_device mxc_pwm_device3 = {
        .resource = mxc_pwm_resources3,
 };
 
-static struct resource mxc_i2c_1_resources[] = {
-       {
-               .start  = 0x43f80000,
-               .end    = 0x43f83fff,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = 3,
-               .end    = 3,
-               .flags  = IORESOURCE_IRQ,
-       }
-};
-
-struct platform_device mxc_i2c_device0 = {
-       .name = "imx-i2c",
-       .id = 0,
-       .num_resources = ARRAY_SIZE(mxc_i2c_1_resources),
-       .resource = mxc_i2c_1_resources,
-};
-
-static struct resource mxc_i2c_2_resources[] = {
-       {
-               .start  = 0x43f98000,
-               .end    = 0x43f9bfff,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = 4,
-               .end    = 4,
-               .flags  = IORESOURCE_IRQ,
-       }
-};
-
-struct platform_device mxc_i2c_device1 = {
-       .name = "imx-i2c",
-       .id = 1,
-       .num_resources = ARRAY_SIZE(mxc_i2c_2_resources),
-       .resource = mxc_i2c_2_resources,
-};
-
-static struct resource mxc_i2c_3_resources[] = {
-       {
-               .start  = 0x43f84000,
-               .end    = 0x43f87fff,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = 10,
-               .end    = 10,
-               .flags  = IORESOURCE_IRQ,
-       }
-};
-
-struct platform_device mxc_i2c_device2 = {
-       .name = "imx-i2c",
-       .id = 2,
-       .num_resources = ARRAY_SIZE(mxc_i2c_3_resources),
-       .resource = mxc_i2c_3_resources,
-};
-
 static struct mxc_gpio_port imx_gpio_ports[] = {
        {
                .chip.label = "gpio-0",
@@ -414,7 +203,7 @@ static struct mxc_gpio_port imx_gpio_ports[] = {
        }
 };
 
-int __init mxc_register_gpios(void)
+int __init imx25_register_gpios(void)
 {
        return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
 }
@@ -439,26 +228,6 @@ struct platform_device mx25_fec_device = {
        .resource       = mx25_fec_resources,
 };
 
-static struct resource mxc_nand_resources[] = {
-       {
-               .start  = MX25_NFC_BASE_ADDR,
-               .end    = MX25_NFC_BASE_ADDR + 0x1fff,
-               .flags  = IORESOURCE_MEM,
-       },
-       {
-               .start  = MX25_INT_NANDFC,
-               .end    = MX25_INT_NANDFC,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_nand_device = {
-       .name           = "mxc_nand",
-       .id             = 0,
-       .num_resources  = ARRAY_SIZE(mxc_nand_resources),
-       .resource       = mxc_nand_resources,
-};
-
 static struct resource mx25_rtc_resources[] = {
        {
                .start  = MX25_DRYICE_BASE_ADDR,
@@ -515,3 +284,83 @@ struct platform_device mxc_wdt = {
        .num_resources = ARRAY_SIZE(mxc_wdt_resources),
        .resource = mxc_wdt_resources,
 };
+
+static struct resource mx25_kpp_resources[] = {
+       {
+               .start  = MX25_KPP_BASE_ADDR,
+               .end    = MX25_KPP_BASE_ADDR + 0xf,
+               .flags  = IORESOURCE_MEM,
+       },
+       {
+               .start  = MX25_INT_KPP,
+               .end    = MX25_INT_KPP,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device mx25_kpp_device = {
+       .name   = "imx-keypad",
+       .id     = -1,
+       .num_resources  = ARRAY_SIZE(mx25_kpp_resources),
+       .resource       = mx25_kpp_resources,
+};
+
+static struct resource imx_ssi_resources0[] = {
+       {
+               .start  = MX25_SSI1_BASE_ADDR,
+               .end    = MX25_SSI1_BASE_ADDR + 0x3fff,
+               .flags  = IORESOURCE_MEM,
+       }, {
+               .start  = MX25_INT_SSI1,
+               .end    = MX25_INT_SSI1,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct resource imx_ssi_resources1[] = {
+       {
+               .start  = MX25_SSI2_BASE_ADDR,
+               .end    = MX25_SSI2_BASE_ADDR + 0x3fff,
+               .flags  = IORESOURCE_MEM
+       }, {
+               .start  = MX25_INT_SSI2,
+               .end    = MX25_INT_SSI2,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device imx_ssi_device0 = {
+       .name = "imx-ssi",
+       .id = 0,
+       .num_resources = ARRAY_SIZE(imx_ssi_resources0),
+       .resource = imx_ssi_resources0,
+};
+
+struct platform_device imx_ssi_device1 = {
+       .name = "imx-ssi",
+       .id = 1,
+       .num_resources = ARRAY_SIZE(imx_ssi_resources1),
+       .resource = imx_ssi_resources1,
+};
+
+static struct resource mx25_csi_resources[] = {
+       {
+               .start  = MX25_CSI_BASE_ADDR,
+               .end    = MX25_CSI_BASE_ADDR + 0xfff,
+               .flags  = IORESOURCE_MEM,
+       },
+       {
+               .start  = MX25_INT_CSI,
+               .flags  = IORESOURCE_IRQ
+       },
+};
+
+struct platform_device mx25_csi_device = {
+       .name   = "mx2-camera",
+       .id     = 0,
+       .num_resources  = ARRAY_SIZE(mx25_csi_resources),
+       .resource       = mx25_csi_resources,
+       .dev            = {
+               .coherent_dma_mask = 0xffffffff,
+       },
+};
index cee12c0a0be68e5988fcc8f914c94705dfe92beb..4aceb68e35a77003e11505dfb3eca338006263fb 100644 (file)
@@ -1,24 +1,16 @@
-extern struct platform_device mxc_uart_device0;
-extern struct platform_device mxc_uart_device1;
-extern struct platform_device mxc_uart_device2;
-extern struct platform_device mxc_uart_device3;
-extern struct platform_device mxc_uart_device4;
 extern struct platform_device mxc_otg;
 extern struct platform_device otg_udc_device;
 extern struct platform_device mxc_usbh2;
-extern struct platform_device mxc_spi_device0;
-extern struct platform_device mxc_spi_device1;
-extern struct platform_device mxc_spi_device2;
 extern struct platform_device mxc_pwm_device0;
 extern struct platform_device mxc_pwm_device1;
 extern struct platform_device mxc_pwm_device2;
 extern struct platform_device mxc_pwm_device3;
 extern struct platform_device mxc_keypad_device;
-extern struct platform_device mxc_i2c_device0;
-extern struct platform_device mxc_i2c_device1;
-extern struct platform_device mxc_i2c_device2;
 extern struct platform_device mx25_fec_device;
-extern struct platform_device mxc_nand_device;
 extern struct platform_device mx25_rtc_device;
 extern struct platform_device mx25_fb_device;
 extern struct platform_device mxc_wdt;
+extern struct platform_device mx25_kpp_device;
+extern struct platform_device imx_ssi_device0;
+extern struct platform_device imx_ssi_device1;
+extern struct platform_device mx25_csi_device;
diff --git a/arch/arm/mach-mx25/eukrea_mbimxsd-baseboard.c b/arch/arm/mach-mx25/eukrea_mbimxsd-baseboard.c
new file mode 100644 (file)
index 0000000..91931dc
--- /dev/null
@@ -0,0 +1,260 @@
+/*
+ * Copyright (C) 2010 Eric Benard - eric@eukrea.com
+ *
+ * Based on pcm970-baseboard.c which is :
+ * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/gpio.h>
+#include <linux/leds.h>
+#include <linux/platform_device.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <video/platform_lcd.h>
+
+#include <mach/hardware.h>
+#include <mach/iomux-mx25.h>
+#include <mach/common.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <mach/mx25.h>
+#include <mach/imx-uart.h>
+#include <mach/imxfb.h>
+#include <mach/ssi.h>
+#include <mach/audmux.h>
+
+#include "devices-imx25.h"
+#include "devices.h"
+
+static struct pad_desc eukrea_mbimxsd_pads[] = {
+       /* LCD */
+       MX25_PAD_LD0__LD0,
+       MX25_PAD_LD1__LD1,
+       MX25_PAD_LD2__LD2,
+       MX25_PAD_LD3__LD3,
+       MX25_PAD_LD4__LD4,
+       MX25_PAD_LD5__LD5,
+       MX25_PAD_LD6__LD6,
+       MX25_PAD_LD7__LD7,
+       MX25_PAD_LD8__LD8,
+       MX25_PAD_LD9__LD9,
+       MX25_PAD_LD10__LD10,
+       MX25_PAD_LD11__LD11,
+       MX25_PAD_LD12__LD12,
+       MX25_PAD_LD13__LD13,
+       MX25_PAD_LD14__LD14,
+       MX25_PAD_LD15__LD15,
+       MX25_PAD_GPIO_E__LD16,
+       MX25_PAD_GPIO_F__LD17,
+       MX25_PAD_HSYNC__HSYNC,
+       MX25_PAD_VSYNC__VSYNC,
+       MX25_PAD_LSCLK__LSCLK,
+       MX25_PAD_OE_ACD__OE_ACD,
+       MX25_PAD_CONTRAST__CONTRAST,
+       /* LCD_PWR */
+       MX25_PAD_PWM__GPIO_1_26,
+       /* LED */
+       MX25_PAD_POWER_FAIL__GPIO_3_19,
+       /* SWITCH */
+       MX25_PAD_VSTBY_ACK__GPIO_3_18,
+       /* UART2 */
+       MX25_PAD_UART2_RTS__UART2_RTS,
+       MX25_PAD_UART2_CTS__UART2_CTS,
+       MX25_PAD_UART2_TXD__UART2_TXD,
+       MX25_PAD_UART2_RXD__UART2_RXD,
+       /* SD1 */
+       MX25_PAD_SD1_CMD__SD1_CMD,
+       MX25_PAD_SD1_CLK__SD1_CLK,
+       MX25_PAD_SD1_DATA0__SD1_DATA0,
+       MX25_PAD_SD1_DATA1__SD1_DATA1,
+       MX25_PAD_SD1_DATA2__SD1_DATA2,
+       MX25_PAD_SD1_DATA3__SD1_DATA3,
+       /* SD1 CD */
+       MX25_PAD_DE_B__GPIO_2_20,
+       /* I2S */
+       MX25_PAD_KPP_COL3__AUD5_TXFS,
+       MX25_PAD_KPP_COL2__AUD5_TXC,
+       MX25_PAD_KPP_COL1__AUD5_RXD,
+       MX25_PAD_KPP_COL0__AUD5_TXD,
+};
+
+#define GPIO_LED1      83
+#define GPIO_SWITCH1   82
+#define GPIO_SD1CD     52
+#define GPIO_LCDPWR    26
+
+static struct imx_fb_videomode eukrea_mximxsd_modes[] = {
+       {
+               .mode   = {
+                       .name           = "CMO-QVGA",
+                       .refresh        = 60,
+                       .xres           = 320,
+                       .yres           = 240,
+                       .pixclock       = KHZ2PICOS(6500),
+                       .left_margin    = 30,
+                       .right_margin   = 38,
+                       .upper_margin   = 20,
+                       .lower_margin   = 3,
+                       .hsync_len      = 15,
+                       .vsync_len      = 4,
+               },
+               .bpp    = 16,
+               .pcr    = 0xCAD08B80,
+       },
+};
+
+static struct imx_fb_platform_data eukrea_mximxsd_fb_pdata = {
+       .mode           = eukrea_mximxsd_modes,
+       .num_modes      = ARRAY_SIZE(eukrea_mximxsd_modes),
+       .pwmr           = 0x00A903FF,
+       .lscr1          = 0x00120300,
+       .dmacr          = 0x00040060,
+};
+
+static void eukrea_mbimxsd_lcd_power_set(struct plat_lcd_data *pd,
+                                  unsigned int power)
+{
+       if (power)
+               gpio_direction_output(GPIO_LCDPWR, 1);
+       else
+               gpio_direction_output(GPIO_LCDPWR, 0);
+}
+
+static struct plat_lcd_data eukrea_mbimxsd_lcd_power_data = {
+       .set_power              = eukrea_mbimxsd_lcd_power_set,
+};
+
+static struct platform_device eukrea_mbimxsd_lcd_powerdev = {
+       .name                   = "platform-lcd",
+       .dev.platform_data      = &eukrea_mbimxsd_lcd_power_data,
+};
+
+static struct gpio_led eukrea_mbimxsd_leds[] = {
+       {
+               .name                   = "led1",
+               .default_trigger        = "heartbeat",
+               .active_low             = 1,
+               .gpio                   = GPIO_LED1,
+       },
+};
+
+static struct gpio_led_platform_data eukrea_mbimxsd_led_info = {
+       .leds           = eukrea_mbimxsd_leds,
+       .num_leds       = ARRAY_SIZE(eukrea_mbimxsd_leds),
+};
+
+static struct platform_device eukrea_mbimxsd_leds_gpio = {
+       .name   = "leds-gpio",
+       .id     = -1,
+       .dev    = {
+               .platform_data  = &eukrea_mbimxsd_led_info,
+       },
+};
+
+static struct gpio_keys_button eukrea_mbimxsd_gpio_buttons[] = {
+       {
+               .gpio           = GPIO_SWITCH1,
+               .code           = BTN_0,
+               .desc           = "BP1",
+               .active_low     = 1,
+               .wakeup         = 1,
+       },
+};
+
+static struct gpio_keys_platform_data eukrea_mbimxsd_button_data = {
+       .buttons        = eukrea_mbimxsd_gpio_buttons,
+       .nbuttons       = ARRAY_SIZE(eukrea_mbimxsd_gpio_buttons),
+};
+
+static struct platform_device eukrea_mbimxsd_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &eukrea_mbimxsd_button_data,
+       }
+};
+
+static struct platform_device *platform_devices[] __initdata = {
+       &eukrea_mbimxsd_leds_gpio,
+       &eukrea_mbimxsd_button_device,
+       &eukrea_mbimxsd_lcd_powerdev,
+};
+
+static const struct imxuart_platform_data uart_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
+};
+
+static struct i2c_board_info eukrea_mbimxsd_i2c_devices[] = {
+       {
+               I2C_BOARD_INFO("tlv320aic23", 0x1a),
+       },
+};
+
+struct imx_ssi_platform_data eukrea_mbimxsd_ssi_pdata = {
+       .flags = IMX_SSI_SYN | IMX_SSI_NET | IMX_SSI_USE_I2S_SLAVE,
+};
+
+/*
+ * system init for baseboard usage. Will be called by cpuimx25 init.
+ *
+ * Add platform devices present on this baseboard and init
+ * them from CPU side as far as required to use them later on
+ */
+void __init eukrea_mbimxsd_baseboard_init(void)
+{
+       if (mxc_iomux_v3_setup_multiple_pads(eukrea_mbimxsd_pads,
+                       ARRAY_SIZE(eukrea_mbimxsd_pads)))
+               printk(KERN_ERR "error setting mbimxsd pads !\n");
+
+#if defined(CONFIG_SND_SOC_EUKREA_TLV320)
+       /* SSI unit master I2S codec connected to SSI_AUD5*/
+       mxc_audmux_v2_configure_port(0,
+                       MXC_AUDMUX_V2_PTCR_SYN |
+                       MXC_AUDMUX_V2_PTCR_TFSDIR |
+                       MXC_AUDMUX_V2_PTCR_TFSEL(4) |
+                       MXC_AUDMUX_V2_PTCR_TCLKDIR |
+                       MXC_AUDMUX_V2_PTCR_TCSEL(4),
+                       MXC_AUDMUX_V2_PDCR_RXDSEL(4)
+       );
+       mxc_audmux_v2_configure_port(4,
+                       MXC_AUDMUX_V2_PTCR_SYN,
+                       MXC_AUDMUX_V2_PDCR_RXDSEL(0)
+       );
+#endif
+
+       imx25_add_imx_uart1(&uart_pdata);
+       mxc_register_device(&mx25_fb_device, &eukrea_mximxsd_fb_pdata);
+       mxc_register_device(&imx_ssi_device0, &eukrea_mbimxsd_ssi_pdata);
+
+       gpio_request(GPIO_LED1, "LED1");
+       gpio_direction_output(GPIO_LED1, 1);
+       gpio_free(GPIO_LED1);
+
+       gpio_request(GPIO_SWITCH1, "SWITCH1");
+       gpio_direction_input(GPIO_SWITCH1);
+       gpio_free(GPIO_SWITCH1);
+
+       gpio_request(GPIO_LCDPWR, "LCDPWR");
+       gpio_direction_output(GPIO_LCDPWR, 1);
+       gpio_free(GPIO_SWITCH1);
+
+       i2c_register_board_info(0, eukrea_mbimxsd_i2c_devices,
+                               ARRAY_SIZE(eukrea_mbimxsd_i2c_devices));
+
+       platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
+}
diff --git a/arch/arm/mach-mx25/mach-cpuimx25.c b/arch/arm/mach-mx25/mach-cpuimx25.c
new file mode 100644 (file)
index 0000000..56b2e26
--- /dev/null
@@ -0,0 +1,173 @@
+/*
+ * Copyright 2009 Sascha Hauer, <kernel@pengutronix.de>
+ * Copyright 2010 Eric Bénard - Eukréa Electromatique, <eric@eukrea.com>
+ *
+ * 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., 51 Franklin Street, Fifth Floor,
+ * Boston, MA  02110-1301, USA.
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+#include <linux/delay.h>
+#include <linux/clk.h>
+#include <linux/irq.h>
+#include <linux/gpio.h>
+#include <linux/fec.h>
+#include <linux/platform_device.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/ulpi.h>
+#include <linux/fsl_devices.h>
+
+#include <mach/eukrea-baseboards.h>
+#include <mach/hardware.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+#include <asm/memory.h>
+#include <asm/mach/map.h>
+#include <mach/common.h>
+#include <mach/mx25.h>
+#include <mach/mxc_nand.h>
+#include <mach/imxfb.h>
+#include <mach/mxc_ehci.h>
+#include <mach/ulpi.h>
+#include <mach/iomux-mx25.h>
+
+#include "devices-imx25.h"
+#include "devices.h"
+
+static const struct imxuart_platform_data uart_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
+};
+
+static struct pad_desc eukrea_cpuimx25_pads[] = {
+       /* FEC - RMII */
+       MX25_PAD_FEC_MDC__FEC_MDC,
+       MX25_PAD_FEC_MDIO__FEC_MDIO,
+       MX25_PAD_FEC_TDATA0__FEC_TDATA0,
+       MX25_PAD_FEC_TDATA1__FEC_TDATA1,
+       MX25_PAD_FEC_TX_EN__FEC_TX_EN,
+       MX25_PAD_FEC_RDATA0__FEC_RDATA0,
+       MX25_PAD_FEC_RDATA1__FEC_RDATA1,
+       MX25_PAD_FEC_RX_DV__FEC_RX_DV,
+       MX25_PAD_FEC_TX_CLK__FEC_TX_CLK,
+       /* I2C1 */
+       MX25_PAD_I2C1_CLK__I2C1_CLK,
+       MX25_PAD_I2C1_DAT__I2C1_DAT,
+};
+
+static struct fec_platform_data mx25_fec_pdata = {
+       .phy    = PHY_INTERFACE_MODE_RMII,
+};
+
+static const struct mxc_nand_platform_data
+eukrea_cpuimx25_nand_board_info __initconst = {
+       .width          = 1,
+       .hw_ecc         = 1,
+       .flash_bbt      = 1,
+};
+
+static const struct imxi2c_platform_data
+eukrea_cpuimx25_i2c0_data __initconst = {
+       .bitrate = 100000,
+};
+
+static struct i2c_board_info eukrea_cpuimx25_i2c_devices[] = {
+       {
+               I2C_BOARD_INFO("pcf8563", 0x51),
+       },
+};
+
+static struct mxc_usbh_platform_data otg_pdata = {
+       .portsc = MXC_EHCI_MODE_UTMI,
+       .flags  = MXC_EHCI_INTERFACE_DIFF_UNI,
+};
+
+static struct mxc_usbh_platform_data usbh2_pdata = {
+       .portsc = MXC_EHCI_MODE_SERIAL,
+       .flags  = MXC_EHCI_INTERFACE_SINGLE_UNI | MXC_EHCI_INTERNAL_PHY |
+                 MXC_EHCI_IPPUE_DOWN,
+};
+
+static struct fsl_usb2_platform_data otg_device_pdata = {
+       .operating_mode = FSL_USB2_DR_DEVICE,
+       .phy_mode       = FSL_USB2_PHY_UTMI,
+};
+
+static int otg_mode_host;
+
+static int __init eukrea_cpuimx25_otg_mode(char *options)
+{
+       if (!strcmp(options, "host"))
+               otg_mode_host = 1;
+       else if (!strcmp(options, "device"))
+               otg_mode_host = 0;
+       else
+               pr_info("otg_mode neither \"host\" nor \"device\". "
+                       "Defaulting to device\n");
+       return 0;
+}
+__setup("otg_mode=", eukrea_cpuimx25_otg_mode);
+
+static void __init eukrea_cpuimx25_init(void)
+{
+       if (mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx25_pads,
+                       ARRAY_SIZE(eukrea_cpuimx25_pads)))
+               printk(KERN_ERR "error setting cpuimx25 pads !\n");
+
+       imx25_add_imx_uart0(&uart_pdata);
+       imx25_add_mxc_nand(&eukrea_cpuimx25_nand_board_info);
+       mxc_register_device(&mx25_rtc_device, NULL);
+       mxc_register_device(&mx25_fec_device, &mx25_fec_pdata);
+
+       i2c_register_board_info(0, eukrea_cpuimx25_i2c_devices,
+                               ARRAY_SIZE(eukrea_cpuimx25_i2c_devices));
+       imx25_add_imx_i2c0(&eukrea_cpuimx25_i2c0_data);
+
+#if defined(CONFIG_USB_ULPI)
+       if (otg_mode_host) {
+               otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
+                               USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
+
+               mxc_register_device(&mxc_otg, &otg_pdata);
+       }
+       mxc_register_device(&mxc_usbh2, &usbh2_pdata);
+#endif
+       if (!otg_mode_host)
+               mxc_register_device(&otg_udc_device, &otg_device_pdata);
+
+#ifdef CONFIG_MACH_EUKREA_MBIMXSD_BASEBOARD
+       eukrea_mbimxsd_baseboard_init();
+#endif
+}
+
+static void __init eukrea_cpuimx25_timer_init(void)
+{
+       mx25_clocks_init();
+}
+
+static struct sys_timer eukrea_cpuimx25_timer = {
+       .init   = eukrea_cpuimx25_timer_init,
+};
+
+MACHINE_START(EUKREA_CPUIMX25, "Eukrea CPUIMX25")
+       /* Maintainer: Eukrea Electromatique */
+       .phys_io        = MX25_AIPS1_BASE_ADDR,
+       .io_pg_offst    = ((MX25_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
+       .boot_params    = MX25_PHYS_OFFSET + 0x100,
+       .map_io         = mx25_map_io,
+       .init_irq       = mx25_init_irq,
+       .init_machine   = eukrea_cpuimx25_init,
+       .timer          = &eukrea_cpuimx25_timer,
+MACHINE_END
similarity index 76%
rename from arch/arm/mach-mx25/mach-mx25pdk.c
rename to arch/arm/mach-mx25/mach-mx25_3ds.c
index 83d74109e7d837fb8e53f4c803652e4bae4cae4d..62bc21f11a714aa46df5e439d4965f340d59460a 100644 (file)
  * Boston, MA  02110-1301, USA.
  */
 
+/*
+ * This machine is known as:
+ *  - i.MX25 3-Stack Development System
+ *  - i.MX25 Platform Development Kit (i.MX25 PDK)
+ */
+
 #include <linux/types.h>
 #include <linux/init.h>
 #include <linux/delay.h>
@@ -24,6 +30,7 @@
 #include <linux/gpio.h>
 #include <linux/fec.h>
 #include <linux/platform_device.h>
+#include <linux/input/matrix_keypad.h>
 
 #include <mach/hardware.h>
 #include <asm/mach-types.h>
 #include <asm/memory.h>
 #include <asm/mach/map.h>
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/mx25.h>
-#include <mach/mxc_nand.h>
 #include <mach/imxfb.h>
-#include "devices.h"
 #include <mach/iomux-mx25.h>
 
-static struct imxuart_platform_data uart_pdata = {
+#include "devices-imx25.h"
+#include "devices.h"
+
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -80,6 +87,16 @@ static struct pad_desc mx25pdk_pads[] = {
        MX25_PAD_LSCLK__LSCLK,
        MX25_PAD_OE_ACD__OE_ACD,
        MX25_PAD_CONTRAST__CONTRAST,
+
+       /* Keypad */
+       MX25_PAD_KPP_ROW0__KPP_ROW0,
+       MX25_PAD_KPP_ROW1__KPP_ROW1,
+       MX25_PAD_KPP_ROW2__KPP_ROW2,
+       MX25_PAD_KPP_ROW3__KPP_ROW3,
+       MX25_PAD_KPP_COL0__KPP_COL0,
+       MX25_PAD_KPP_COL1__KPP_COL1,
+       MX25_PAD_KPP_COL2__KPP_COL2,
+       MX25_PAD_KPP_COL3__KPP_COL3,
 };
 
 static struct fec_platform_data mx25_fec_pdata = {
@@ -103,7 +120,8 @@ static void __init mx25pdk_fec_reset(void)
        gpio_set_value(FEC_RESET_B_GPIO, 1);
 }
 
-static struct mxc_nand_platform_data mx25pdk_nand_board_info = {
+static const struct mxc_nand_platform_data
+mx25pdk_nand_board_info __initconst = {
        .width          = 1,
        .hw_ecc         = 1,
        .flash_bbt      = 1,
@@ -137,19 +155,45 @@ static struct imx_fb_platform_data mx25pdk_fb_pdata = {
        .dmacr          = 0x00020010,
 };
 
+static const uint32_t mx25pdk_keymap[] = {
+       KEY(0, 0, KEY_UP),
+       KEY(0, 1, KEY_DOWN),
+       KEY(0, 2, KEY_VOLUMEDOWN),
+       KEY(0, 3, KEY_HOME),
+       KEY(1, 0, KEY_RIGHT),
+       KEY(1, 1, KEY_LEFT),
+       KEY(1, 2, KEY_ENTER),
+       KEY(1, 3, KEY_VOLUMEUP),
+       KEY(2, 0, KEY_F6),
+       KEY(2, 1, KEY_F8),
+       KEY(2, 2, KEY_F9),
+       KEY(2, 3, KEY_F10),
+       KEY(3, 0, KEY_F1),
+       KEY(3, 1, KEY_F2),
+       KEY(3, 2, KEY_F3),
+       KEY(3, 3, KEY_POWER),
+};
+
+static struct matrix_keymap_data mx25pdk_keymap_data = {
+       .keymap         = mx25pdk_keymap,
+       .keymap_size    = ARRAY_SIZE(mx25pdk_keymap),
+};
+
 static void __init mx25pdk_init(void)
 {
        mxc_iomux_v3_setup_multiple_pads(mx25pdk_pads,
                        ARRAY_SIZE(mx25pdk_pads));
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       imx25_add_imx_uart0(&uart_pdata);
        mxc_register_device(&mxc_usbh2, NULL);
-       mxc_register_device(&mxc_nand_device, &mx25pdk_nand_board_info);
+       imx25_add_mxc_nand(&mx25pdk_nand_board_info);
        mxc_register_device(&mx25_rtc_device, NULL);
        mxc_register_device(&mx25_fb_device, &mx25pdk_fb_pdata);
+       mxc_register_device(&mxc_wdt, NULL);
 
        mx25pdk_fec_reset();
        mxc_register_device(&mx25_fec_device, &mx25_fec_pdata);
+       mxc_register_device(&mx25_kpp_device, &mx25pdk_keymap_data);
 }
 
 static void __init mx25pdk_timer_init(void)
index a7e587ff3e9ebc5b0821f4a506548b7bd7e1b817..bb677111fb0f11cca20f5ff143cf397412b92587 100644 (file)
  * 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
  */
 
 #include <linux/mm.h>
@@ -69,8 +65,11 @@ void __init mx25_map_io(void)
        iotable_init(mxc_io_desc, ARRAY_SIZE(mxc_io_desc));
 }
 
+int imx25_register_gpios(void);
+
 void __init mx25_init_irq(void)
 {
        mxc_init_irq((void __iomem *)MX25_AVIC_BASE_ADDR_VIRT);
+       imx25_register_gpios();
 }
 
index 344753fdf25ef47ac6856ff5058f9cc8a193120a..85beece802aab702a71331f63fd6ff7065adb7bb 100644 (file)
@@ -15,6 +15,8 @@ comment "MX3 platforms:"
 config MACH_MX31ADS
        bool "Support MX31ADS platforms"
        select ARCH_MX31
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
        default y
        help
          Include support for MX31ADS platform. This includes specific
@@ -34,6 +36,9 @@ config MACH_MX31ADS_WM1133_EV1
 config MACH_PCM037
        bool "Support Phytec pcm037 (i.MX31) platforms"
        select ARCH_MX31
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
        select MXC_ULPI if USB_ULPI
        help
          Include support for Phytec pcm037 platform. This includes
@@ -42,6 +47,7 @@ config MACH_PCM037
 config MACH_PCM037_EET
        bool "Support pcm037 EET board extensions"
        depends on MACH_PCM037
+       select IMX_HAVE_PLATFORM_SPI_IMX
        help
          Add support for PCM037 EET baseboard extensions. If you are using the
          OLED display with EET, use "video=mx3fb:CMEL-OLED" kernel
@@ -51,6 +57,9 @@ config MACH_MX31LITE
        bool "Support MX31 LITEKIT (LogicPD)"
        select ARCH_MX31
        select MXC_ULPI if USB_ULPI
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
+       select IMX_HAVE_PLATFORM_SPI_IMX
        help
          Include support for MX31 LITEKIT platform. This includes specific
          configurations for the board and its peripherals.
@@ -58,6 +67,10 @@ config MACH_MX31LITE
 config MACH_MX31_3DS
        bool "Support MX31PDK (3DS)"
        select ARCH_MX31
+       select MXC_DEBUG_BOARD
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
+       select IMX_HAVE_PLATFORM_SPI_IMX
        help
          Include support for MX31PDK (3DS) platform. This includes specific
          configurations for the board and its peripherals.
@@ -74,6 +87,9 @@ config MACH_MX31_3DS_MXC_NAND_USE_BBT
 config MACH_MX31MOBOARD
        bool "Support mx31moboard platforms (EPFL Mobots group)"
        select ARCH_MX31
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_SPI_IMX
        select MXC_ULPI if USB_ULPI
        help
          Include support for mx31moboard platform. This includes specific
@@ -82,6 +98,8 @@ config MACH_MX31MOBOARD
 config MACH_MX31LILLY
        bool "Support MX31 LILLY-1131 platforms (INCO startec)"
        select ARCH_MX31
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_SPI_IMX
        select MXC_ULPI if USB_ULPI
        help
          Include support for mx31 based LILLY1131 modules. This includes
@@ -90,6 +108,7 @@ config MACH_MX31LILLY
 config MACH_QONG
        bool "Support Dave/DENX QongEVB-LITE platform"
        select ARCH_MX31
+       select IMX_HAVE_PLATFORM_IMX_UART
        help
          Include support for Dave/DENX QongEVB-LITE platform. This includes
          specific configurations for the board and its peripherals.
@@ -97,6 +116,10 @@ config MACH_QONG
 config MACH_PCM043
        bool "Support Phytec pcm043 (i.MX35) platforms"
        select ARCH_MX35
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
+       select IMX_HAVE_PLATFORM_FLEXCAN
        select MXC_ULPI if USB_ULPI
        help
          Include support for Phytec pcm043 platform. This includes
@@ -105,6 +128,9 @@ config MACH_PCM043
 config MACH_ARMADILLO5X0
        bool "Support Atmark Armadillo-500 Development Base Board"
        select ARCH_MX31
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_MXC_NAND
        select MXC_ULPI if USB_ULPI
        help
          Include support for Atmark Armadillo-500 platform. This includes
@@ -113,6 +139,7 @@ config MACH_ARMADILLO5X0
 config MACH_MX35_3DS
        bool "Support MX35PDK platform"
        select ARCH_MX35
+       select IMX_HAVE_PLATFORM_IMX_UART
        default n
        help
          Include support for MX35PDK platform. This includes specific
@@ -121,8 +148,34 @@ config MACH_MX35_3DS
 config MACH_KZM_ARM11_01
        bool "Support KZM-ARM11-01(Kyoto Microcomputer)"
        select ARCH_MX31
+       select IMX_HAVE_PLATFORM_IMX_UART
        help
          Include support for KZM-ARM11-01. This includes specific
          configurations for the board and its peripherals.
 
+config MACH_EUKREA_CPUIMX35
+       bool "Support Eukrea CPUIMX35 Platform"
+       select ARCH_MX35
+       select IMX_HAVE_PLATFORM_IMX_UART
+       select IMX_HAVE_PLATFORM_IMX_I2C
+       select IMX_HAVE_PLATFORM_MXC_NAND
+       select MXC_ULPI if USB_ULPI
+       help
+         Include support for Eukrea CPUIMX35 platform. This includes
+         specific configurations for the board and its peripherals.
+
+choice
+       prompt "Baseboard"
+       depends on MACH_EUKREA_CPUIMX35
+       default MACH_EUKREA_MBIMXSD35_BASEBOARD
+
+config MACH_EUKREA_MBIMXSD35_BASEBOARD
+       prompt "Eukrea MBIMXSD development board"
+       bool
+       help
+         This adds board specific devices that can be found on Eukrea's
+         MBIMXSD evaluation board.
+
+endchoice
+
 endif
index 5d650fda5d5d3f0653c0cedc287068d98eb0a476..2bd7beceb99182879a7100d14e6d54dd5cdac6a2 100644 (file)
@@ -22,5 +22,7 @@ obj-$(CONFIG_MACH_MX31MOBOARD)        += mach-mx31moboard.o mx31moboard-devboard.o \
 obj-$(CONFIG_MACH_QONG)                += mach-qong.o
 obj-$(CONFIG_MACH_PCM043)      += mach-pcm043.o
 obj-$(CONFIG_MACH_ARMADILLO5X0) += mach-armadillo5x0.o
-obj-$(CONFIG_MACH_MX35_3DS)    += mach-mx35pdk.o
+obj-$(CONFIG_MACH_MX35_3DS)    += mach-mx35_3ds.o
 obj-$(CONFIG_MACH_KZM_ARM11_01)        += mach-kzm_arm11_01.o
+obj-$(CONFIG_MACH_EUKREA_CPUIMX35)     += mach-cpuimx35.o
+obj-$(CONFIG_MACH_EUKREA_MBIMXSD35_BASEBOARD)  += eukrea_mbimxsd-baseboard.o
index 9f3e943e22326cf0b0f8024194414de457a66356..d3af0fdf8475f7ef0d67b3afbb080df739c36431 100644 (file)
@@ -359,7 +359,7 @@ DEFINE_CLOCK(i2c1_clk,   0, CCM_CGR1, 10, get_rate_ipg_per, NULL);
 DEFINE_CLOCK(i2c2_clk,   1, CCM_CGR1, 12, get_rate_ipg_per, NULL);
 DEFINE_CLOCK(i2c3_clk,   2, CCM_CGR1, 14, get_rate_ipg_per, NULL);
 DEFINE_CLOCK(iomuxc_clk, 0, CCM_CGR1, 16, NULL, NULL);
-DEFINE_CLOCK(ipu_clk,    0, CCM_CGR1, 18, NULL, NULL);
+DEFINE_CLOCK(ipu_clk,    0, CCM_CGR1, 18, get_rate_ahb, NULL);
 DEFINE_CLOCK(kpp_clk,    0, CCM_CGR1, 20, get_rate_ipg, NULL);
 DEFINE_CLOCK(mlb_clk,    0, CCM_CGR1, 22, get_rate_ahb, NULL);
 DEFINE_CLOCK(mshc_clk,   0, CCM_CGR1, 24, get_rate_mshc, NULL);
@@ -428,8 +428,8 @@ static struct clk nfc_clk = {
 static struct clk_lookup lookups[] = {
        _REGISTER_CLOCK(NULL, "asrc", asrc_clk)
        _REGISTER_CLOCK(NULL, "ata", ata_clk)
-       _REGISTER_CLOCK(NULL, "can", can1_clk)
-       _REGISTER_CLOCK(NULL, "can", can2_clk)
+       _REGISTER_CLOCK("flexcan.0", NULL, can1_clk)
+       _REGISTER_CLOCK("flexcan.1", NULL, can2_clk)
        _REGISTER_CLOCK("spi_imx.0", NULL, cspi1_clk)
        _REGISTER_CLOCK("spi_imx.1", NULL, cspi2_clk)
        _REGISTER_CLOCK(NULL, "ect", ect_clk)
diff --git a/arch/arm/mach-mx3/devices-imx31.h b/arch/arm/mach-mx3/devices-imx31.h
new file mode 100644 (file)
index 0000000..3b1a44a
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * Copyright (C) 2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <mach/mx31.h>
+#include <mach/devices-common.h>
+
+#define imx31_add_imx_i2c0(pdata)      \
+       imx_add_imx_i2c(0, MX31_I2C1_BASE_ADDR, SZ_4K, MX31_INT_I2C1, pdata)
+#define imx31_add_imx_i2c1(pdata)      \
+       imx_add_imx_i2c(1, MX31_I2C2_BASE_ADDR, SZ_4K, MX31_INT_I2C2, pdata)
+#define imx31_add_imx_i2c2(pdata)      \
+       imx_add_imx_i2c(2, MX31_I2C3_BASE_ADDR, SZ_4K, MX31_INT_I2C3, pdata)
+
+#define imx31_add_imx_uart0(pdata)     \
+       imx_add_imx_uart_1irq(0, MX31_UART1_BASE_ADDR, SZ_16K, MX31_INT_UART1, pdata)
+#define imx31_add_imx_uart1(pdata)     \
+       imx_add_imx_uart_1irq(1, MX31_UART2_BASE_ADDR, SZ_16K, MX31_INT_UART2, pdata)
+#define imx31_add_imx_uart2(pdata)     \
+       imx_add_imx_uart_1irq(2, MX31_UART3_BASE_ADDR, SZ_16K, MX31_INT_UART3, pdata)
+#define imx31_add_imx_uart3(pdata)     \
+       imx_add_imx_uart_1irq(3, MX31_UART4_BASE_ADDR, SZ_16K, MX31_INT_UART4, pdata)
+#define imx31_add_imx_uart4(pdata)     \
+       imx_add_imx_uart_1irq(4, MX31_UART5_BASE_ADDR, SZ_16K, MX31_INT_UART5, pdata)
+
+#define imx31_add_mxc_nand(pdata)      \
+       imx_add_mxc_nand_v1(MX31_NFC_BASE_ADDR, MX31_INT_NANDFC, pdata)
+
+#define imx31_add_spi_imx0(pdata)      \
+       imx_add_spi_imx(0, MX31_CSPI1_BASE_ADDR, SZ_4K, MX31_INT_CSPI1, pdata)
+#define imx31_add_spi_imx1(pdata)      \
+       imx_add_spi_imx(1, MX31_CSPI2_BASE_ADDR, SZ_4K, MX31_INT_CSPI2, pdata)
+#define imx31_add_spi_imx2(pdata)      \
+       imx_add_spi_imx(2, MX31_CSPI3_BASE_ADDR, SZ_4K, MX31_INT_CSPI3, pdata)
diff --git a/arch/arm/mach-mx3/devices-imx35.h b/arch/arm/mach-mx3/devices-imx35.h
new file mode 100644 (file)
index 0000000..f6a431a
--- /dev/null
@@ -0,0 +1,37 @@
+/*
+ * Copyright (C) 2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <mach/mx35.h>
+#include <mach/devices-common.h>
+
+#define imx35_add_flexcan0(pdata)      \
+       imx_add_flexcan(0, MX35_CAN1_BASE_ADDR, SZ_16K, MX35_INT_CAN1, pdata)
+#define imx35_add_flexcan1(pdata)      \
+       imx_add_flexcan(1, MX35_CAN2_BASE_ADDR, SZ_16K, MX35_INT_CAN2, pdata)
+
+#define imx35_add_imx_i2c0(pdata)      \
+       imx_add_imx_i2c(0, MX35_I2C1_BASE_ADDR, SZ_4K, MX35_INT_I2C1, pdata)
+#define imx35_add_imx_i2c1(pdata)      \
+       imx_add_imx_i2c(1, MX35_I2C2_BASE_ADDR, SZ_4K, MX35_INT_I2C2, pdata)
+#define imx35_add_imx_i2c2(pdata)      \
+       imx_add_imx_i2c(2, MX35_I2C3_BASE_ADDR, SZ_4K, MX35_INT_I2C3, pdata)
+
+#define imx35_add_imx_uart0(pdata)     \
+       imx_add_imx_uart_1irq(0, MX35_UART1_BASE_ADDR, SZ_16K, MX35_INT_UART1, pdata)
+#define imx35_add_imx_uart1(pdata)     \
+       imx_add_imx_uart_1irq(1, MX35_UART2_BASE_ADDR, SZ_16K, MX35_INT_UART2, pdata)
+#define imx35_add_imx_uart2(pdata)     \
+       imx_add_imx_uart_1irq(2, MX35_UART3_BASE_ADDR, SZ_16K, MX35_INT_UART3, pdata)
+
+#define imx35_add_mxc_nand(pdata)      \
+       imx_add_mxc_nand_v21(MX35_NFC_BASE_ADDR, MX35_INT_NANDFC, pdata)
+
+#define imx35_add_spi_imx0(pdata)      \
+       imx_add_spi_imx(0, MX35_CSPI1_BASE_ADDR, SZ_4K, MX35_INT_CSPI1, pdata)
+#define imx35_add_spi_imx1(pdata)      \
+       imx_add_spi_imx(1, MX35_CSPI2_BASE_ADDR, SZ_4K, MX35_INT_CSPI2, pdata)
index db7acd6e910160cc230736ff3eb441eff255f2d0..a4fd1a26fc91982d200d76c7a152eb5c62610a7b 100644 (file)
 #include <mach/hardware.h>
 #include <mach/irqs.h>
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/mx3_camera.h>
 
 #include "devices.h"
 
-static struct resource uart0[] = {
-       {
-               .start = UART1_BASE_ADDR,
-               .end = UART1_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_UART1,
-               .end = MXC_INT_UART1,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device0 = {
-       .name = "imx-uart",
-       .id = 0,
-       .resource = uart0,
-       .num_resources = ARRAY_SIZE(uart0),
-};
-
-static struct resource uart1[] = {
-       {
-               .start = UART2_BASE_ADDR,
-               .end = UART2_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_UART2,
-               .end = MXC_INT_UART2,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device1 = {
-       .name = "imx-uart",
-       .id = 1,
-       .resource = uart1,
-       .num_resources = ARRAY_SIZE(uart1),
-};
-
-static struct resource uart2[] = {
-       {
-               .start = UART3_BASE_ADDR,
-               .end = UART3_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_UART3,
-               .end = MXC_INT_UART3,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device2 = {
-       .name = "imx-uart",
-       .id = 2,
-       .resource = uart2,
-       .num_resources = ARRAY_SIZE(uart2),
-};
-
-#ifdef CONFIG_ARCH_MX31
-static struct resource uart3[] = {
-       {
-               .start = UART4_BASE_ADDR,
-               .end = UART4_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_UART4,
-               .end = MXC_INT_UART4,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device3 = {
-       .name = "imx-uart",
-       .id = 3,
-       .resource = uart3,
-       .num_resources = ARRAY_SIZE(uart3),
-};
-
-static struct resource uart4[] = {
-       {
-               .start = UART5_BASE_ADDR,
-               .end = UART5_BASE_ADDR + 0x0B5,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_UART5,
-               .end = MXC_INT_UART5,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_uart_device4 = {
-       .name = "imx-uart",
-       .id = 4,
-       .resource = uart4,
-       .num_resources = ARRAY_SIZE(uart4),
-};
-#endif /* CONFIG_ARCH_MX31 */
-
 /* GPIO port description */
 static struct mxc_gpio_port imx_gpio_ports[] = {
        {
@@ -147,7 +49,7 @@ static struct mxc_gpio_port imx_gpio_ports[] = {
        }
 };
 
-int __init mxc_register_gpios(void)
+int __init imx3x_register_gpios(void)
 {
        return mxc_gpio_init(imx_gpio_ports, ARRAY_SIZE(imx_gpio_ports));
 }
@@ -167,82 +69,6 @@ struct platform_device mxc_w1_master_device = {
        .resource = mxc_w1_master_resources,
 };
 
-static struct resource mxc_nand_resources[] = {
-       {
-               .start  = 0, /* runtime dependent */
-               .end    = 0,
-               .flags  = IORESOURCE_MEM,
-       }, {
-               .start  = MXC_INT_NANDFC,
-               .end    = MXC_INT_NANDFC,
-               .flags  = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_nand_device = {
-       .name = "mxc_nand",
-       .id = 0,
-       .num_resources = ARRAY_SIZE(mxc_nand_resources),
-       .resource = mxc_nand_resources,
-};
-
-static struct resource mxc_i2c0_resources[] = {
-       {
-               .start = I2C_BASE_ADDR,
-               .end = I2C_BASE_ADDR + SZ_4K - 1,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_I2C,
-               .end = MXC_INT_I2C,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_i2c_device0 = {
-       .name = "imx-i2c",
-       .id = 0,
-       .num_resources = ARRAY_SIZE(mxc_i2c0_resources),
-       .resource = mxc_i2c0_resources,
-};
-
-static struct resource mxc_i2c1_resources[] = {
-       {
-               .start = I2C2_BASE_ADDR,
-               .end = I2C2_BASE_ADDR + SZ_4K - 1,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_I2C2,
-               .end = MXC_INT_I2C2,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_i2c_device1 = {
-       .name = "imx-i2c",
-       .id = 1,
-       .num_resources = ARRAY_SIZE(mxc_i2c1_resources),
-       .resource = mxc_i2c1_resources,
-};
-
-static struct resource mxc_i2c2_resources[] = {
-       {
-               .start = I2C3_BASE_ADDR,
-               .end = I2C3_BASE_ADDR + SZ_4K - 1,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_I2C3,
-               .end = MXC_INT_I2C3,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_i2c_device2 = {
-       .name = "imx-i2c",
-       .id = 2,
-       .num_resources = ARRAY_SIZE(mxc_i2c2_resources),
-       .resource = mxc_i2c2_resources,
-};
-
 #ifdef CONFIG_ARCH_MX31
 static struct resource mxcsdhc0_resources[] = {
        {
@@ -455,68 +281,7 @@ struct platform_device mxc_usbh2 = {
        .num_resources = ARRAY_SIZE(mxc_usbh2_resources),
 };
 
-/*
- * SPI master controller
- * 3 channels
- */
-static struct resource mxc_spi_0_resources[] = {
-       {
-              .start = CSPI1_BASE_ADDR,
-              .end = CSPI1_BASE_ADDR + SZ_4K - 1,
-              .flags = IORESOURCE_MEM,
-       }, {
-              .start = MXC_INT_CSPI1,
-              .end = MXC_INT_CSPI1,
-              .flags = IORESOURCE_IRQ,
-       },
-};
-
-static struct resource mxc_spi_1_resources[] = {
-       {
-               .start = CSPI2_BASE_ADDR,
-               .end = CSPI2_BASE_ADDR + SZ_4K - 1,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_CSPI2,
-               .end = MXC_INT_CSPI2,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-static struct resource mxc_spi_2_resources[] = {
-       {
-               .start = CSPI3_BASE_ADDR,
-               .end = CSPI3_BASE_ADDR + SZ_4K - 1,
-               .flags = IORESOURCE_MEM,
-       }, {
-               .start = MXC_INT_CSPI3,
-               .end = MXC_INT_CSPI3,
-               .flags = IORESOURCE_IRQ,
-       },
-};
-
-struct platform_device mxc_spi_device0 = {
-       .name = "spi_imx",
-       .id = 0,
-       .num_resources = ARRAY_SIZE(mxc_spi_0_resources),
-       .resource = mxc_spi_0_resources,
-};
-
-struct platform_device mxc_spi_device1 = {
-       .name = "spi_imx",
-       .id = 1,
-       .num_resources = ARRAY_SIZE(mxc_spi_1_resources),
-       .resource = mxc_spi_1_resources,
-};
-
-struct platform_device mxc_spi_device2 = {
-       .name = "spi_imx",
-       .id = 2,
-       .num_resources = ARRAY_SIZE(mxc_spi_2_resources),
-       .resource = mxc_spi_2_resources,
-};
-
-#ifdef CONFIG_ARCH_MX35
+#if defined(CONFIG_ARCH_MX35)
 static struct resource mxc_fec_resources[] = {
        {
                .start  = MXC_FEC_BASE_ADDR,
@@ -628,16 +393,15 @@ struct platform_device imx_kpp_device = {
 
 static int __init mx3_devices_init(void)
 {
+#if defined(CONFIG_ARCH_MX31)
        if (cpu_is_mx31()) {
-               mxc_nand_resources[0].start = MX31_NFC_BASE_ADDR;
-               mxc_nand_resources[0].end = MX31_NFC_BASE_ADDR + 0xfff;
                imx_wdt_resources[0].start = MX31_WDOG_BASE_ADDR;
                imx_wdt_resources[0].end = MX31_WDOG_BASE_ADDR + 0x3fff;
                mxc_register_device(&mxc_rnga_device, NULL);
        }
+#endif
+#if defined(CONFIG_ARCH_MX35)
        if (cpu_is_mx35()) {
-               mxc_nand_resources[0].start = MX35_NFC_BASE_ADDR;
-               mxc_nand_resources[0].end = MX35_NFC_BASE_ADDR + 0x1fff;
                otg_resources[0].start = MX35_OTG_BASE_ADDR;
                otg_resources[0].end = MX35_OTG_BASE_ADDR + 0x1ff;
                otg_resources[1].start = MXC_INT_USBOTG;
@@ -653,6 +417,7 @@ static int __init mx3_devices_init(void)
                imx_wdt_resources[0].start = MX35_WDOG_BASE_ADDR;
                imx_wdt_resources[0].end = MX35_WDOG_BASE_ADDR + 0x3fff;
        }
+#endif
 
        return 0;
 }
index 2c3c8646a29ef701c3872483ddf44901332b4858..e5535234839f5e1ae8159d0513e8bf9c0952d7c7 100644 (file)
@@ -1,14 +1,4 @@
-
-extern struct platform_device mxc_uart_device0;
-extern struct platform_device mxc_uart_device1;
-extern struct platform_device mxc_uart_device2;
-extern struct platform_device mxc_uart_device3;
-extern struct platform_device mxc_uart_device4;
 extern struct platform_device mxc_w1_master_device;
-extern struct platform_device mxc_nand_device;
-extern struct platform_device mxc_i2c_device0;
-extern struct platform_device mxc_i2c_device1;
-extern struct platform_device mxc_i2c_device2;
 extern struct platform_device mx3_ipu;
 extern struct platform_device mx3_fb;
 extern struct platform_device mx3_camera;
@@ -20,9 +10,6 @@ extern struct platform_device mxc_otg_host;
 extern struct platform_device mxc_usbh1;
 extern struct platform_device mxc_usbh2;
 extern struct platform_device mxc_rnga_device;
-extern struct platform_device mxc_spi_device0;
-extern struct platform_device mxc_spi_device1;
-extern struct platform_device mxc_spi_device2;
 extern struct platform_device imx_ssi_device0;
 extern struct platform_device imx_ssi_device1;
 extern struct platform_device imx_ssi_device1;
diff --git a/arch/arm/mach-mx3/eukrea_mbimxsd-baseboard.c b/arch/arm/mach-mx3/eukrea_mbimxsd-baseboard.c
new file mode 100644 (file)
index 0000000..1dc5004
--- /dev/null
@@ -0,0 +1,263 @@
+/*
+ * Copyright (C) 2010 Eric Benard - eric@eukrea.com
+ *
+ * Based on pcm970-baseboard.c which is :
+ * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
+ *
+ * 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., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+
+#include <linux/gpio.h>
+#include <linux/interrupt.h>
+#include <linux/leds.h>
+#include <linux/platform_device.h>
+#include <linux/gpio_keys.h>
+#include <linux/input.h>
+#include <video/platform_lcd.h>
+#include <linux/i2c.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+#include <asm/mach/map.h>
+
+#include <mach/hardware.h>
+#include <mach/common.h>
+#include <mach/imx-uart.h>
+#include <mach/iomux-mx35.h>
+#include <mach/ipu.h>
+#include <mach/mx3fb.h>
+#include <mach/audmux.h>
+#include <mach/ssi.h>
+
+#include "devices-imx35.h"
+#include "devices.h"
+
+static const struct fb_videomode fb_modedb[] = {
+       {
+               .name           = "CMO_QVGA",
+               .refresh        = 60,
+               .xres           = 320,
+               .yres           = 240,
+               .pixclock       = KHZ2PICOS(6500),
+               .left_margin    = 68,
+               .right_margin   = 20,
+               .upper_margin   = 15,
+               .lower_margin   = 4,
+               .hsync_len      = 30,
+               .vsync_len      = 3,
+               .sync           = 0,
+               .vmode          = FB_VMODE_NONINTERLACED,
+               .flag           = 0,
+       },
+};
+
+static struct ipu_platform_data mx3_ipu_data = {
+       .irq_base = MXC_IPU_IRQ_START,
+};
+
+static struct mx3fb_platform_data mx3fb_pdata = {
+       .dma_dev        = &mx3_ipu.dev,
+       .name           = "CMO_QVGA",
+       .mode           = fb_modedb,
+       .num_modes      = ARRAY_SIZE(fb_modedb),
+};
+
+static struct pad_desc eukrea_mbimxsd_pads[] = {
+       /* LCD */
+       MX35_PAD_LD0__IPU_DISPB_DAT_0,
+       MX35_PAD_LD1__IPU_DISPB_DAT_1,
+       MX35_PAD_LD2__IPU_DISPB_DAT_2,
+       MX35_PAD_LD3__IPU_DISPB_DAT_3,
+       MX35_PAD_LD4__IPU_DISPB_DAT_4,
+       MX35_PAD_LD5__IPU_DISPB_DAT_5,
+       MX35_PAD_LD6__IPU_DISPB_DAT_6,
+       MX35_PAD_LD7__IPU_DISPB_DAT_7,
+       MX35_PAD_LD8__IPU_DISPB_DAT_8,
+       MX35_PAD_LD9__IPU_DISPB_DAT_9,
+       MX35_PAD_LD10__IPU_DISPB_DAT_10,
+       MX35_PAD_LD11__IPU_DISPB_DAT_11,
+       MX35_PAD_LD12__IPU_DISPB_DAT_12,
+       MX35_PAD_LD13__IPU_DISPB_DAT_13,
+       MX35_PAD_LD14__IPU_DISPB_DAT_14,
+       MX35_PAD_LD15__IPU_DISPB_DAT_15,
+       MX35_PAD_LD16__IPU_DISPB_DAT_16,
+       MX35_PAD_LD17__IPU_DISPB_DAT_17,
+       MX35_PAD_D3_HSYNC__IPU_DISPB_D3_HSYNC,
+       MX35_PAD_D3_FPSHIFT__IPU_DISPB_D3_CLK,
+       MX35_PAD_D3_DRDY__IPU_DISPB_D3_DRDY,
+       MX35_PAD_D3_VSYNC__IPU_DISPB_D3_VSYNC,
+       /* Backlight */
+       MX35_PAD_CONTRAST__IPU_DISPB_CONTR,
+       /* LCD_PWR */
+       MX35_PAD_D3_CLS__GPIO1_4,
+       /* LED */
+       MX35_PAD_LD23__GPIO3_29,
+       /* SWITCH */
+       MX35_PAD_LD19__GPIO3_25,
+       /* UART2 */
+       MX35_PAD_CTS2__UART2_CTS,
+       MX35_PAD_RTS2__UART2_RTS,
+       MX35_PAD_TXD2__UART2_TXD_MUX,
+       MX35_PAD_RXD2__UART2_RXD_MUX,
+       /* I2S */
+       MX35_PAD_STXFS4__AUDMUX_AUD4_TXFS,
+       MX35_PAD_STXD4__AUDMUX_AUD4_TXD,
+       MX35_PAD_SRXD4__AUDMUX_AUD4_RXD,
+       MX35_PAD_SCK4__AUDMUX_AUD4_TXC,
+};
+
+#define GPIO_LED1      (2 * 32 + 29)
+#define GPIO_SWITCH1   (2 * 32 + 25)
+#define GPIO_LCDPWR    (4)
+
+static void eukrea_mbimxsd_lcd_power_set(struct plat_lcd_data *pd,
+                                  unsigned int power)
+{
+       if (power)
+               gpio_direction_output(GPIO_LCDPWR, 1);
+       else
+               gpio_direction_output(GPIO_LCDPWR, 0);
+}
+
+static struct plat_lcd_data eukrea_mbimxsd_lcd_power_data = {
+       .set_power              = eukrea_mbimxsd_lcd_power_set,
+};
+
+static struct platform_device eukrea_mbimxsd_lcd_powerdev = {
+       .name                   = "platform-lcd",
+       .dev.platform_data      = &eukrea_mbimxsd_lcd_power_data,
+};
+
+static struct gpio_led eukrea_mbimxsd_leds[] = {
+       {
+               .name                   = "led1",
+               .default_trigger        = "heartbeat",
+               .active_low             = 1,
+               .gpio                   = GPIO_LED1,
+       },
+};
+
+static struct gpio_led_platform_data eukrea_mbimxsd_led_info = {
+       .leds           = eukrea_mbimxsd_leds,
+       .num_leds       = ARRAY_SIZE(eukrea_mbimxsd_leds),
+};
+
+static struct platform_device eukrea_mbimxsd_leds_gpio = {
+       .name   = "leds-gpio",
+       .id     = -1,
+       .dev    = {
+               .platform_data  = &eukrea_mbimxsd_led_info,
+       },
+};
+
+static struct gpio_keys_button eukrea_mbimxsd_gpio_buttons[] = {
+       {
+               .gpio           = GPIO_SWITCH1,
+               .code           = BTN_0,
+               .desc           = "BP1",
+               .active_low     = 1,
+               .wakeup         = 1,
+       },
+};
+
+static struct gpio_keys_platform_data eukrea_mbimxsd_button_data = {
+       .buttons        = eukrea_mbimxsd_gpio_buttons,
+       .nbuttons       = ARRAY_SIZE(eukrea_mbimxsd_gpio_buttons),
+};
+
+static struct platform_device eukrea_mbimxsd_button_device = {
+       .name           = "gpio-keys",
+       .id             = -1,
+       .num_resources  = 0,
+       .dev            = {
+               .platform_data  = &eukrea_mbimxsd_button_data,
+       }
+};
+
+static struct platform_device *platform_devices[] __initdata = {
+       &eukrea_mbimxsd_leds_gpio,
+       &eukrea_mbimxsd_button_device,
+       &eukrea_mbimxsd_lcd_powerdev,
+};
+
+static const struct imxuart_platform_data uart_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
+};
+
+static struct i2c_board_info eukrea_mbimxsd_i2c_devices[] = {
+       {
+               I2C_BOARD_INFO("tlv320aic23", 0x1a),
+       },
+};
+
+struct imx_ssi_platform_data eukrea_mbimxsd_ssi_pdata = {
+       .flags = IMX_SSI_SYN | IMX_SSI_NET | IMX_SSI_USE_I2S_SLAVE,
+};
+
+/*
+ * system init for baseboard usage. Will be called by cpuimx35 init.
+ *
+ * Add platform devices present on this baseboard and init
+ * them from CPU side as far as required to use them later on
+ */
+void __init eukrea_mbimxsd_baseboard_init(void)
+{
+       if (mxc_iomux_v3_setup_multiple_pads(eukrea_mbimxsd_pads,
+                       ARRAY_SIZE(eukrea_mbimxsd_pads)))
+               printk(KERN_ERR "error setting mbimxsd pads !\n");
+
+#if defined(CONFIG_SND_SOC_EUKREA_TLV320)
+       /* SSI unit master I2S codec connected to SSI_AUD4 */
+       mxc_audmux_v2_configure_port(0,
+                       MXC_AUDMUX_V2_PTCR_SYN |
+                       MXC_AUDMUX_V2_PTCR_TFSDIR |
+                       MXC_AUDMUX_V2_PTCR_TFSEL(3) |
+                       MXC_AUDMUX_V2_PTCR_TCLKDIR |
+                       MXC_AUDMUX_V2_PTCR_TCSEL(3),
+                       MXC_AUDMUX_V2_PDCR_RXDSEL(3)
+       );
+       mxc_audmux_v2_configure_port(3,
+                       MXC_AUDMUX_V2_PTCR_SYN,
+                       MXC_AUDMUX_V2_PDCR_RXDSEL(0)
+       );
+#endif
+
+       imx35_add_imx_uart1(&uart_pdata);
+       mxc_register_device(&mx3_ipu, &mx3_ipu_data);
+       mxc_register_device(&mx3_fb, &mx3fb_pdata);
+
+       mxc_register_device(&imx_ssi_device0, &eukrea_mbimxsd_ssi_pdata);
+
+       gpio_request(GPIO_LED1, "LED1");
+       gpio_direction_output(GPIO_LED1, 1);
+       gpio_free(GPIO_LED1);
+
+       gpio_request(GPIO_SWITCH1, "SWITCH1");
+       gpio_direction_input(GPIO_SWITCH1);
+       gpio_free(GPIO_SWITCH1);
+
+       gpio_request(GPIO_LCDPWR, "LCDPWR");
+       gpio_direction_output(GPIO_LCDPWR, 1);
+       gpio_free(GPIO_SWITCH1);
+
+       i2c_register_board_info(0, eukrea_mbimxsd_i2c_devices,
+                               ARRAY_SIZE(eukrea_mbimxsd_i2c_devices));
+
+       platform_add_devices(platform_devices, ARRAY_SIZE(platform_devices));
+}
index 5f72ec91af2d62c97acbdff70fbccd4988c292b5..96aadcadb4ff094b1b5eeaaebc502b68cd87a370 100644 (file)
 #include <asm/mach/map.h>
 
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
-#include <mach/board-armadillo5x0.h>
 #include <mach/mmc.h>
 #include <mach/ipu.h>
 #include <mach/mx3fb.h>
-#include <mach/mxc_nand.h>
 #include <mach/mxc_ehci.h>
 #include <mach/ulpi.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 #include "crm_regs.h"
 
@@ -301,7 +299,8 @@ static struct platform_device armadillo5x0_button_device = {
 /*
  * NAND Flash
  */
-static struct mxc_nand_platform_data armadillo5x0_nand_flash_pdata = {
+static const struct mxc_nand_platform_data
+armadillo5x0_nand_board_info __initconst = {
        .width          = 1,
        .hw_ecc         = 1,
 };
@@ -493,13 +492,12 @@ static struct platform_device armadillo5x0_smc911x_device = {
 };
 
 /* UART device data */
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
 static struct platform_device *devices[] __initdata = {
        &armadillo5x0_smc911x_device,
-       &mxc_i2c_device1,
        &armadillo5x0_button_device,
 };
 
@@ -512,10 +510,11 @@ static void __init armadillo5x0_init(void)
                        ARRAY_SIZE(armadillo5x0_pins), "armadillo5x0");
 
        platform_add_devices(devices, ARRAY_SIZE(devices));
+       imx31_add_imx_i2c1(NULL);
 
        /* Register UART */
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
-       mxc_register_device(&mxc_uart_device1, &uart_pdata);
+       imx31_add_imx_uart0(&uart_pdata);
+       imx31_add_imx_uart1(&uart_pdata);
 
        /* SMSC9118 IRQ pin */
        gpio_direction_input(MX31_PIN_GPIO1_0);
@@ -532,7 +531,7 @@ static void __init armadillo5x0_init(void)
                            &armadillo5x0_nor_flash_pdata);
 
        /* Register NAND Flash */
-       mxc_register_device(&mxc_nand_device, &armadillo5x0_nand_flash_pdata);
+       imx31_add_mxc_nand(&armadillo5x0_nand_board_info);
 
        /* set NAND page size to 2k if not configured via boot mode pins */
        __raw_writel(__raw_readl(MXC_CCM_RCSR) | (1 << 30), MXC_CCM_RCSR);
diff --git a/arch/arm/mach-mx3/mach-cpuimx35.c b/arch/arm/mach-mx3/mach-cpuimx35.c
new file mode 100644 (file)
index 0000000..63f970f
--- /dev/null
@@ -0,0 +1,227 @@
+/*
+ * Copyright (C) 2010 Eric Benard - eric@eukrea.com
+ * Copyright (C) 2009 Sascha Hauer, Pengutronix
+ *
+ * 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
+ */
+
+#include <linux/types.h>
+#include <linux/init.h>
+
+#include <linux/platform_device.h>
+#include <linux/mtd/physmap.h>
+#include <linux/memory.h>
+#include <linux/gpio.h>
+#include <linux/interrupt.h>
+#include <linux/delay.h>
+#include <linux/i2c.h>
+#include <linux/i2c/tsc2007.h>
+#include <linux/usb/otg.h>
+#include <linux/usb/ulpi.h>
+#include <linux/fsl_devices.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+#include <asm/mach/map.h>
+
+#include <mach/eukrea-baseboards.h>
+#include <mach/hardware.h>
+#include <mach/common.h>
+#include <mach/iomux-mx35.h>
+#include <mach/mxc_nand.h>
+#include <mach/mxc_ehci.h>
+#include <mach/ulpi.h>
+
+#include "devices-imx35.h"
+#include "devices.h"
+
+static const struct imxuart_platform_data uart_pdata __initconst = {
+       .flags = IMXUART_HAVE_RTSCTS,
+};
+
+static const struct imxi2c_platform_data
+eukrea_cpuimx35_i2c0_data __initconst = {
+       .bitrate = 50000,
+};
+
+#define TSC2007_IRQGPIO                (2 * 32 + 2)
+static int ts_get_pendown_state(void)
+{
+       int val = 0;
+       gpio_free(TSC2007_IRQGPIO);
+       gpio_request(TSC2007_IRQGPIO, NULL);
+       gpio_direction_input(TSC2007_IRQGPIO);
+
+       val = gpio_get_value(TSC2007_IRQGPIO);
+
+       gpio_free(TSC2007_IRQGPIO);
+       gpio_request(TSC2007_IRQGPIO, NULL);
+
+       return val ? 0 : 1;
+}
+
+static int ts_init(void)
+{
+       gpio_request(TSC2007_IRQGPIO, NULL);
+       return 0;
+}
+
+static struct tsc2007_platform_data tsc2007_info = {
+       .model                  = 2007,
+       .x_plate_ohms           = 180,
+       .get_pendown_state      = ts_get_pendown_state,
+       .init_platform_hw       = ts_init,
+};
+
+static struct i2c_board_info eukrea_cpuimx35_i2c_devices[] = {
+       {
+               I2C_BOARD_INFO("pcf8563", 0x51),
+       }, {
+               I2C_BOARD_INFO("tsc2007", 0x48),
+               .type           = "tsc2007",
+               .platform_data  = &tsc2007_info,
+               .irq            = gpio_to_irq(TSC2007_IRQGPIO),
+       },
+};
+
+static struct platform_device *devices[] __initdata = {
+       &mxc_fec_device,
+       &imx_wdt_device0,
+};
+
+static struct pad_desc eukrea_cpuimx35_pads[] = {
+       /* UART1 */
+       MX35_PAD_CTS1__UART1_CTS,
+       MX35_PAD_RTS1__UART1_RTS,
+       MX35_PAD_TXD1__UART1_TXD_MUX,
+       MX35_PAD_RXD1__UART1_RXD_MUX,
+       /* FEC */
+       MX35_PAD_FEC_TX_CLK__FEC_TX_CLK,
+       MX35_PAD_FEC_RX_CLK__FEC_RX_CLK,
+       MX35_PAD_FEC_RX_DV__FEC_RX_DV,
+       MX35_PAD_FEC_COL__FEC_COL,
+       MX35_PAD_FEC_RDATA0__FEC_RDATA_0,
+       MX35_PAD_FEC_TDATA0__FEC_TDATA_0,
+       MX35_PAD_FEC_TX_EN__FEC_TX_EN,
+       MX35_PAD_FEC_MDC__FEC_MDC,
+       MX35_PAD_FEC_MDIO__FEC_MDIO,
+       MX35_PAD_FEC_TX_ERR__FEC_TX_ERR,
+       MX35_PAD_FEC_RX_ERR__FEC_RX_ERR,
+       MX35_PAD_FEC_CRS__FEC_CRS,
+       MX35_PAD_FEC_RDATA1__FEC_RDATA_1,
+       MX35_PAD_FEC_TDATA1__FEC_TDATA_1,
+       MX35_PAD_FEC_RDATA2__FEC_RDATA_2,
+       MX35_PAD_FEC_TDATA2__FEC_TDATA_2,
+       MX35_PAD_FEC_RDATA3__FEC_RDATA_3,
+       MX35_PAD_FEC_TDATA3__FEC_TDATA_3,
+       /* I2C1 */
+       MX35_PAD_I2C1_CLK__I2C1_SCL,
+       MX35_PAD_I2C1_DAT__I2C1_SDA,
+       /* TSC2007 IRQ */
+       MX35_PAD_ATA_DA2__GPIO3_2,
+};
+
+static const struct mxc_nand_platform_data
+eukrea_cpuimx35_nand_board_info __initconst = {
+       .width          = 1,
+       .hw_ecc         = 1,
+       .flash_bbt      = 1,
+};
+
+static struct mxc_usbh_platform_data otg_pdata = {
+       .portsc = MXC_EHCI_MODE_UTMI,
+       .flags  = MXC_EHCI_INTERFACE_DIFF_UNI,
+};
+
+static struct mxc_usbh_platform_data usbh1_pdata = {
+       .portsc = MXC_EHCI_MODE_SERIAL,
+       .flags  = MXC_EHCI_INTERFACE_SINGLE_UNI | MXC_EHCI_INTERNAL_PHY |
+                 MXC_EHCI_IPPUE_DOWN,
+};
+
+static struct fsl_usb2_platform_data otg_device_pdata = {
+       .operating_mode = FSL_USB2_DR_DEVICE,
+       .phy_mode       = FSL_USB2_PHY_UTMI,
+};
+
+static int otg_mode_host;
+
+static int __init eukrea_cpuimx35_otg_mode(char *options)
+{
+       if (!strcmp(options, "host"))
+               otg_mode_host = 1;
+       else if (!strcmp(options, "device"))
+               otg_mode_host = 0;
+       else
+               pr_info("otg_mode neither \"host\" nor \"device\". "
+                       "Defaulting to device\n");
+       return 0;
+}
+__setup("otg_mode=", eukrea_cpuimx35_otg_mode);
+
+/*
+ * Board specific initialization.
+ */
+static void __init mxc_board_init(void)
+{
+       mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx35_pads,
+                       ARRAY_SIZE(eukrea_cpuimx35_pads));
+
+       platform_add_devices(devices, ARRAY_SIZE(devices));
+
+       imx35_add_imx_uart0(&uart_pdata);
+       imx35_add_mxc_nand(&eukrea_cpuimx35_nand_board_info);
+
+       i2c_register_board_info(0, eukrea_cpuimx35_i2c_devices,
+                       ARRAY_SIZE(eukrea_cpuimx35_i2c_devices));
+       imx35_add_imx_i2c0(&eukrea_cpuimx35_i2c0_data);
+
+#if defined(CONFIG_USB_ULPI)
+       if (otg_mode_host) {
+               otg_pdata.otg = otg_ulpi_create(&mxc_ulpi_access_ops,
+                               USB_OTG_DRV_VBUS | USB_OTG_DRV_VBUS_EXT);
+
+               mxc_register_device(&mxc_otg_host, &otg_pdata);
+       }
+       mxc_register_device(&mxc_usbh1, &usbh1_pdata);
+#endif
+       if (!otg_mode_host)
+               mxc_register_device(&mxc_otg_udc_device, &otg_device_pdata);
+
+#ifdef CONFIG_MACH_EUKREA_MBIMXSD_BASEBOARD
+       eukrea_mbimxsd_baseboard_init();
+#endif
+}
+
+static void __init eukrea_cpuimx35_timer_init(void)
+{
+       mx35_clocks_init();
+}
+
+struct sys_timer eukrea_cpuimx35_timer = {
+       .init   = eukrea_cpuimx35_timer_init,
+};
+
+MACHINE_START(EUKREA_CPUIMX35, "Eukrea CPUIMX35")
+       /* Maintainer: Eukrea Electromatique */
+       .phys_io        = MX35_AIPS1_BASE_ADDR,
+       .io_pg_offst    = ((MX35_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
+       .boot_params    = MX3x_PHYS_OFFSET + 0x100,
+       .map_io         = mx35_map_io,
+       .init_irq       = mx35_init_irq,
+       .init_machine   = mxc_board_init,
+       .timer          = &eukrea_cpuimx35_timer,
+MACHINE_END
index f085d5d1a6de7c560d42fba0809b29d73a04a6e9..5b23e416d6c704c904385895f4bbf82dabfba56e 100644 (file)
  * 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
  */
 
 #include <linux/gpio.h>
 #include <asm/mach/map.h>
 #include <asm/mach/time.h>
 
-#include <mach/board-kzmarm11.h>
 #include <mach/clock.h>
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 #include <mach/memory.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 
 #define KZM_ARM11_IO_ADDRESS(x) (                                      \
        IMX_IO_ADDRESS(x, MX31_CS5) ?:                                  \
        MX31_IO_ADDRESS(x))
 
+/*
+ *  KZM-ARM11-01 Board Control Registers on FPGA
+ */
+#define KZM_ARM11_CTL1         (MX31_CS4_BASE_ADDR + 0x1000)
+#define KZM_ARM11_CTL2         (MX31_CS4_BASE_ADDR + 0x1001)
+#define KZM_ARM11_RSW1         (MX31_CS4_BASE_ADDR + 0x1002)
+#define KZM_ARM11_BACK_LIGHT   (MX31_CS4_BASE_ADDR + 0x1004)
+#define KZM_ARM11_FPGA_REV     (MX31_CS4_BASE_ADDR + 0x1008)
+#define KZM_ARM11_7SEG_LED     (MX31_CS4_BASE_ADDR + 0x1010)
+#define KZM_ARM11_LEDS         (MX31_CS4_BASE_ADDR + 0x1020)
+#define KZM_ARM11_DIPSW2       (MX31_CS4_BASE_ADDR + 0x1003)
+
+/*
+ * External UART for touch panel on FPGA
+ */
+#define KZM_ARM11_16550                (MX31_CS4_BASE_ADDR + 0x1050)
+
 #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
 /*
  * KZM-ARM11-01 has an external UART on FPGA
@@ -173,15 +185,14 @@ static inline int kzm_init_smsc9118(void)
 #endif
 
 #if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE)
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
 static void __init kzm_init_imx_uart(void)
 {
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
-
-       mxc_register_device(&mxc_uart_device1, &uart_pdata);
+       imx31_add_imx_uart0(&uart_pdata);
+       imx31_add_imx_uart1(&uart_pdata);
 }
 #else
 static inline void kzm_init_imx_uart(void)
index 58e57291b79d876fb6bdf04fe6da2020c36d9e1b..6fe69e124d30faa27d23a239ba903f0a76cb1c15 100644 (file)
  * 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
  */
 
 #include <linux/delay.h>
@@ -22,7 +18,6 @@
 #include <linux/clk.h>
 #include <linux/irq.h>
 #include <linux/gpio.h>
-#include <linux/smsc911x.h>
 #include <linux/platform_device.h>
 #include <linux/mfd/mc13783.h>
 #include <linux/spi/spi.h>
 #include <asm/memory.h>
 #include <asm/mach/map.h>
 #include <mach/common.h>
-#include <mach/board-mx31_3ds.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
-#include <mach/mxc_nand.h>
-#include <mach/spi.h>
+#include <mach/3ds_debugboard.h>
+
+#include "devices-imx31.h"
 #include "devices.h"
 
-/*!
- * @file mx31_3ds.c
- *
- * @brief This file contains the board-specific initialization routines.
- *
- * @ingroup System
+/* Definitions for components on the Debug board */
+
+/* Base address of CPLD controller on the Debug board */
+#define DEBUG_BASE_ADDRESS             CS5_IO_ADDRESS(MX3x_CS5_BASE_ADDR)
+
+/* LAN9217 ethernet base address */
+#define LAN9217_BASE_ADDR              MX3x_CS5_BASE_ADDR
+
+/* CPLD config and interrupt base address */
+#define CPLD_ADDR                      (DEBUG_BASE_ADDRESS + 0x20000)
+
+/* status, interrupt */
+#define CPLD_INT_STATUS_REG            (CPLD_ADDR + 0x10)
+#define CPLD_INT_MASK_REG              (CPLD_ADDR + 0x38)
+#define CPLD_INT_RESET_REG             (CPLD_ADDR + 0x20)
+/* magic word for debug CPLD */
+#define CPLD_MAGIC_NUMBER1_REG         (CPLD_ADDR + 0x40)
+#define CPLD_MAGIC_NUMBER2_REG         (CPLD_ADDR + 0x48)
+/* CPLD code version */
+#define CPLD_CODE_VER_REG              (CPLD_ADDR + 0x50)
+/* magic word for debug CPLD */
+#define CPLD_MAGIC_NUMBER3_REG         (CPLD_ADDR + 0x58)
+
+/* CPLD IRQ line for external uart, external ethernet etc */
+#define EXPIO_PARENT_INT       IOMUX_TO_IRQ(MX31_PIN_GPIO1_1)
+
+#define MXC_EXP_IO_BASE                (MXC_BOARD_IRQ_START)
+#define MXC_IRQ_TO_EXPIO(irq)  ((irq) - MXC_EXP_IO_BASE)
+
+#define EXPIO_INT_ENET         (MXC_EXP_IO_BASE + 0)
+
+#define MXC_MAX_EXP_IO_LINES   16
+
+/*
+ * This file contains the board-specific initialization routines.
  */
 
 static int mx31_3ds_pins[] = {
@@ -145,7 +168,7 @@ static int spi1_internal_chipselect[] = {
        MXC_SPI_CS(2),
 };
 
-static struct spi_imx_master spi1_pdata = {
+static const struct spi_imx_master spi1_pdata __initconst = {
        .chipselect     = spi1_internal_chipselect,
        .num_chipselect = ARRAY_SIZE(spi1_internal_chipselect),
 };
@@ -165,7 +188,8 @@ static struct spi_board_info mx31_3ds_spi_devs[] __initdata = {
 /*
  * NAND Flash
  */
-static struct mxc_nand_platform_data imx31_3ds_nand_flash_pdata = {
+static const struct mxc_nand_platform_data
+mx31_3ds_nand_board_info __initconst = {
        .width          = 1,
        .hw_ecc         = 1,
 #ifdef MACH_MX31_3DS_MXC_NAND_USE_BBT
@@ -182,8 +206,10 @@ static struct mxc_nand_platform_data imx31_3ds_nand_flash_pdata = {
 
 #define USBOTG_RST_B IOMUX_TO_GPIO(MX31_PIN_USB_PWR)
 
-static void mx31_3ds_usbotg_init(void)
+static int mx31_3ds_usbotg_init(void)
 {
+       int err;
+
        mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA0, USB_PAD_CFG);
        mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA1, USB_PAD_CFG);
        mxc_iomux_set_pad(MX31_PIN_USBOTG_DATA2, USB_PAD_CFG);
@@ -197,10 +223,25 @@ static void mx31_3ds_usbotg_init(void)
        mxc_iomux_set_pad(MX31_PIN_USBOTG_NXT, USB_PAD_CFG);
        mxc_iomux_set_pad(MX31_PIN_USBOTG_STP, USB_PAD_CFG);
 
-       gpio_request(USBOTG_RST_B, "otgusb-reset");
-       gpio_direction_output(USBOTG_RST_B, 0);
+       err = gpio_request(USBOTG_RST_B, "otgusb-reset");
+       if (err) {
+               pr_err("Failed to request the USB OTG reset gpio\n");
+               return err;
+       }
+
+       err = gpio_direction_output(USBOTG_RST_B, 0);
+       if (err) {
+               pr_err("Failed to drive the USB OTG reset gpio\n");
+               goto usbotg_free_reset;
+       }
+
        mdelay(1);
        gpio_set_value(USBOTG_RST_B, 1);
+       return 0;
+
+usbotg_free_reset:
+       gpio_free(USBOTG_RST_B);
+       return err;
 }
 
 static struct fsl_usb2_platform_data usbotg_pdata = {
@@ -208,178 +249,16 @@ static struct fsl_usb2_platform_data usbotg_pdata = {
        .phy_mode       = FSL_USB2_PHY_ULPI,
 };
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
-/*
- * Support for the SMSC9217 on the Debug board.
- */
-
-static struct smsc911x_platform_config smsc911x_config = {
-       .irq_polarity   = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
-       .irq_type       = SMSC911X_IRQ_TYPE_PUSH_PULL,
-       .flags          = SMSC911X_USE_16BIT | SMSC911X_FORCE_INTERNAL_PHY,
-       .phy_interface  = PHY_INTERFACE_MODE_MII,
-};
-
-static struct resource smsc911x_resources[] = {
-       {
-               .start          = LAN9217_BASE_ADDR,
-               .end            = LAN9217_BASE_ADDR + 0xff,
-               .flags          = IORESOURCE_MEM,
-       }, {
-               .start          = EXPIO_INT_ENET,
-               .end            = EXPIO_INT_ENET,
-               .flags          = IORESOURCE_IRQ,
-       },
-};
-
-static struct platform_device smsc911x_device = {
-       .name           = "smsc911x",
-       .id             = -1,
-       .num_resources  = ARRAY_SIZE(smsc911x_resources),
-       .resource       = smsc911x_resources,
-       .dev            = {
-               .platform_data = &smsc911x_config,
-       },
-};
-
-/*
- * Routines for the CPLD on the debug board. It contains a CPLD handling
- * LEDs, switches, interrupts for Ethernet.
- */
-
-static void mx31_3ds_expio_irq_handler(uint32_t irq, struct irq_desc *desc)
-{
-       uint32_t imr_val;
-       uint32_t int_valid;
-       uint32_t expio_irq;
-
-       imr_val = __raw_readw(CPLD_INT_MASK_REG);
-       int_valid = __raw_readw(CPLD_INT_STATUS_REG) & ~imr_val;
-
-       expio_irq = MXC_EXP_IO_BASE;
-       for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
-               if ((int_valid & 1) == 0)
-                       continue;
-               generic_handle_irq(expio_irq);
-       }
-}
-
-/*
- * Disable an expio pin's interrupt by setting the bit in the imr.
- * @param irq           an expio virtual irq number
- */
-static void expio_mask_irq(uint32_t irq)
-{
-       uint16_t reg;
-       uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
-
-       /* mask the interrupt */
-       reg = __raw_readw(CPLD_INT_MASK_REG);
-       reg |= 1 << expio;
-       __raw_writew(reg, CPLD_INT_MASK_REG);
-}
-
-/*
- * Acknowledge an expanded io pin's interrupt by clearing the bit in the isr.
- * @param irq           an expanded io virtual irq number
- */
-static void expio_ack_irq(uint32_t irq)
-{
-       uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
-
-       /* clear the interrupt status */
-       __raw_writew(1 << expio, CPLD_INT_RESET_REG);
-       __raw_writew(0, CPLD_INT_RESET_REG);
-       /* mask the interrupt */
-       expio_mask_irq(irq);
-}
-
-/*
- * Enable a expio pin's interrupt by clearing the bit in the imr.
- * @param irq           a expio virtual irq number
- */
-static void expio_unmask_irq(uint32_t irq)
-{
-       uint16_t reg;
-       uint32_t expio = MXC_IRQ_TO_EXPIO(irq);
-
-       /* unmask the interrupt */
-       reg = __raw_readw(CPLD_INT_MASK_REG);
-       reg &= ~(1 << expio);
-       __raw_writew(reg, CPLD_INT_MASK_REG);
-}
-
-static struct irq_chip expio_irq_chip = {
-       .ack = expio_ack_irq,
-       .mask = expio_mask_irq,
-       .unmask = expio_unmask_irq,
-};
-
-static int __init mx31_3ds_init_expio(void)
-{
-       int i;
-       int ret;
-
-       /* Check if there's a debug board connected */
-       if ((__raw_readw(CPLD_MAGIC_NUMBER1_REG) != 0xAAAA) ||
-           (__raw_readw(CPLD_MAGIC_NUMBER2_REG) != 0x5555) ||
-           (__raw_readw(CPLD_MAGIC_NUMBER3_REG) != 0xCAFE)) {
-               /* No Debug board found */
-               return -ENODEV;
-       }
-
-       pr_info("i.MX31 3DS Debug board detected, rev = 0x%04X\n",
-               __raw_readw(CPLD_CODE_VER_REG));
-
-       /*
-        * Configure INT line as GPIO input
-        */
-       ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1), "sms9217-irq");
-       if (ret)
-               pr_warning("could not get LAN irq gpio\n");
-       else
-               gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_1));
-
-       /* Disable the interrupts and clear the status */
-       __raw_writew(0, CPLD_INT_MASK_REG);
-       __raw_writew(0xFFFF, CPLD_INT_RESET_REG);
-       __raw_writew(0, CPLD_INT_RESET_REG);
-       __raw_writew(0x1F, CPLD_INT_MASK_REG);
-       for (i = MXC_EXP_IO_BASE;
-            i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES);
-            i++) {
-               set_irq_chip(i, &expio_irq_chip);
-               set_irq_handler(i, handle_level_irq);
-               set_irq_flags(i, IRQF_VALID);
-       }
-       set_irq_type(EXPIO_PARENT_INT, IRQ_TYPE_LEVEL_LOW);
-       set_irq_chained_handler(EXPIO_PARENT_INT, mx31_3ds_expio_irq_handler);
-
-       return 0;
-}
-
-/*
- * This structure defines the MX31 memory map.
- */
-static struct map_desc mx31_3ds_io_desc[] __initdata = {
-       {
-               .virtual = MX31_CS5_BASE_ADDR_VIRT,
-               .pfn = __phys_to_pfn(MX31_CS5_BASE_ADDR),
-               .length = MX31_CS5_SIZE,
-               .type = MT_DEVICE,
-       },
-};
-
 /*
  * Set up static virtual mappings.
  */
 static void __init mx31_3ds_map_io(void)
 {
        mx31_map_io();
-       iotable_init(mx31_3ds_io_desc, ARRAY_SIZE(mx31_3ds_io_desc));
 }
 
 /*!
@@ -390,10 +269,10 @@ static void __init mxc_board_init(void)
        mxc_iomux_setup_multiple_pins(mx31_3ds_pins, ARRAY_SIZE(mx31_3ds_pins),
                                      "mx31_3ds");
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
-       mxc_register_device(&mxc_nand_device, &imx31_3ds_nand_flash_pdata);
+       imx31_add_imx_uart0(&uart_pdata);
+       imx31_add_mxc_nand(&mx31_3ds_nand_board_info);
 
-       mxc_register_device(&mxc_spi_device1, &spi1_pdata);
+       imx31_add_spi_imx0(&spi1_pdata);
        spi_register_board_info(mx31_3ds_spi_devs,
                                                ARRAY_SIZE(mx31_3ds_spi_devs));
 
@@ -402,8 +281,9 @@ static void __init mxc_board_init(void)
        mx31_3ds_usbotg_init();
        mxc_register_device(&mxc_otg_udc_device, &usbotg_pdata);
 
-       if (!mx31_3ds_init_expio())
-               platform_device_register(&smsc911x_device);
+       if (!mxc_expio_init(CS5_BASE_ADDR, EXPIO_PARENT_INT))
+               printk(KERN_WARNING "Init of the debugboard failed, all "
+                                   "devices on the board are unusable.\n");
 }
 
 static void __init mx31_3ds_timer_init(void)
index b3d1a1895c20f4f2eab29d99e832c09fbc096373..94b3e7c4240408451aa08446c9b991ad179be699 100644 (file)
  * 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
  */
 
 #include <linux/types.h>
@@ -33,8 +29,6 @@
 #include <asm/memory.h>
 #include <asm/mach/map.h>
 #include <mach/common.h>
-#include <mach/board-mx31ads.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 
 #ifdef CONFIG_MACH_MX31ADS_WM1133_EV1
 #include <linux/mfd/wm8350/pmic.h>
 #endif
 
+#include "devices-imx31.h"
 #include "devices.h"
 
-/*!
- * @file mx31ads.c
- *
- * @brief This file contains the board-specific initialization routines.
- *
- * @ingroup System
+/* Base address of PBC controller */
+#define PBC_BASE_ADDRESS        MX31_CS4_BASE_ADDR_VIRT
+/* Offsets for the PBC Controller register */
+
+/* PBC Board interrupt status register */
+#define PBC_INTSTATUS           0x000016
+
+/* PBC Board interrupt current status register */
+#define PBC_INTCURR_STATUS      0x000018
+
+/* PBC Interrupt mask register set address */
+#define PBC_INTMASK_SET         0x00001A
+
+/* PBC Interrupt mask register clear address */
+#define PBC_INTMASK_CLEAR       0x00001C
+
+/* External UART A */
+#define PBC_SC16C652_UARTA      0x010000
+
+/* External UART B */
+#define PBC_SC16C652_UARTB      0x010010
+
+#define PBC_INTSTATUS_REG      (PBC_INTSTATUS + PBC_BASE_ADDRESS)
+#define PBC_INTMASK_SET_REG    (PBC_INTMASK_SET + PBC_BASE_ADDRESS)
+#define PBC_INTMASK_CLEAR_REG  (PBC_INTMASK_CLEAR + PBC_BASE_ADDRESS)
+#define EXPIO_PARENT_INT       IOMUX_TO_IRQ(MX31_PIN_GPIO1_4)
+
+#define MXC_EXP_IO_BASE                (MXC_BOARD_IRQ_START)
+#define MXC_IRQ_TO_EXPIO(irq)  ((irq) - MXC_EXP_IO_BASE)
+
+#define EXPIO_INT_XUART_INTA   (MXC_EXP_IO_BASE + 10)
+#define EXPIO_INT_XUART_INTB   (MXC_EXP_IO_BASE + 11)
+
+#define MXC_MAX_EXP_IO_LINES   16
+/*
+ * This file contains the board-specific initialization routines.
  */
 
 #if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
@@ -98,7 +123,7 @@ static inline int mxc_init_extuart(void)
 #endif
 
 #if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE)
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -112,7 +137,7 @@ static unsigned int uart_pins[] = {
 static inline void mxc_init_imx_uart(void)
 {
        mxc_iomux_setup_multiple_pins(uart_pins, ARRAY_SIZE(uart_pins), "uart-0");
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       imx31_add_imx_uart0(&uart_pdata);
 }
 #else /* !SERIAL_IMX */
 static inline void mxc_init_imx_uart(void)
@@ -475,7 +500,7 @@ static void mxc_init_i2c(void)
        mxc_iomux_mode(IOMUX_MODE(MX31_PIN_CSPI2_MOSI, IOMUX_CONFIG_ALT1));
        mxc_iomux_mode(IOMUX_MODE(MX31_PIN_CSPI2_MISO, IOMUX_CONFIG_ALT1));
 
-       mxc_register_device(&mxc_i2c_device1, NULL);
+       imx31_add_imx_i2c1(NULL);
 }
 #else
 static void mxc_init_i2c(void)
index b2c7f512070fe450b710db83da53ce439a2a2bd4..8f66f65e80e2079a3dae7e70ddb2a530960d8f98 100644 (file)
  * 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
  */
 
 #include <linux/types.h>
 #include <mach/common.h>
 #include <mach/iomux-mx3.h>
 #include <mach/board-mx31lilly.h>
-#include <mach/spi.h>
 #include <mach/mxc_ehci.h>
 #include <mach/ulpi.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 
 /*
@@ -269,12 +265,12 @@ static int spi_internal_chipselect[] = {
        MXC_SPI_CS(2),
 };
 
-static struct spi_imx_master spi0_pdata = {
+static const struct spi_imx_master spi0_pdata __initconst = {
        .chipselect = spi_internal_chipselect,
        .num_chipselect = ARRAY_SIZE(spi_internal_chipselect),
 };
 
-static struct spi_imx_master spi1_pdata = {
+static const struct spi_imx_master spi1_pdata __initconst = {
        .chipselect = spi_internal_chipselect,
        .num_chipselect = ARRAY_SIZE(spi_internal_chipselect),
 };
@@ -289,6 +285,7 @@ static struct spi_board_info mc13783_dev __initdata = {
        .bus_num        = 1,
        .chip_select    = 0,
        .platform_data  = &mc13783_pdata,
+       .irq            = IOMUX_TO_IRQ(MX31_PIN_GPIO1_3),
 };
 
 static struct platform_device *devices[] __initdata = {
@@ -331,8 +328,8 @@ static void __init mx31lilly_board_init(void)
        mxc_iomux_alloc_pin(MX31_PIN_CSPI2_SS1__SS1, "SPI2_SS1");
        mxc_iomux_alloc_pin(MX31_PIN_CSPI2_SS2__SS2, "SPI2_SS2");
 
-       mxc_register_device(&mxc_spi_device0, &spi0_pdata);
-       mxc_register_device(&mxc_spi_device1, &spi1_pdata);
+       imx31_add_spi_imx0(&spi0_pdata);
+       imx31_add_spi_imx1(&spi1_pdata);
        spi_register_board_info(&mc13783_dev, 1);
 
        platform_add_devices(devices, ARRAY_SIZE(devices));
index 2b6d1140087740dbc72c157f47770620432a9575..da236c497d2ae38f2d6f01ca765df1957e1be8a1 100644 (file)
  * 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
  */
 
 #include <linux/types.h>
 #include <mach/hardware.h>
 #include <mach/common.h>
 #include <mach/board-mx31lite.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 #include <mach/irqs.h>
-#include <mach/mxc_nand.h>
-#include <mach/spi.h>
 #include <mach/mxc_ehci.h>
 #include <mach/ulpi.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 
 /*
@@ -69,7 +63,8 @@ static unsigned int mx31lite_pins[] = {
        MX31_PIN_CSPI2_SS2__SS2,
 };
 
-static struct mxc_nand_platform_data mx31lite_nand_board_info = {
+static const struct mxc_nand_platform_data
+mx31lite_nand_board_info __initconst  = {
        .width = 1,
        .hw_ecc = 1,
 };
@@ -112,7 +107,7 @@ static int spi_internal_chipselect[] = {
        MXC_SPI_CS(0),
 };
 
-static struct spi_imx_master spi1_pdata = {
+static const struct spi_imx_master spi1_pdata __initconst = {
        .chipselect     = spi_internal_chipselect,
        .num_chipselect = ARRAY_SIZE(spi_internal_chipselect),
 };
@@ -253,9 +248,9 @@ static void __init mxc_board_init(void)
 
        /* NOR and NAND flash */
        platform_device_register(&physmap_flash_device);
-       mxc_register_device(&mxc_nand_device, &mx31lite_nand_board_info);
+       imx31_add_mxc_nand(&mx31lite_nand_board_info);
 
-       mxc_register_device(&mxc_spi_device1, &spi1_pdata);
+       imx31_add_spi_imx1(&spi1_pdata);
        spi_register_board_info(&mc13783_spi_dev, 1);
 
 #if defined(CONFIG_USB_ULPI)
index 62b5e40165dfea0692b06c97865f2094d053439d..67776bc61c336cc09dfd2c31f7408a20875e79e9 100644 (file)
  * 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
  */
 
 #include <linux/delay.h>
 #include <mach/board-mx31moboard.h>
 #include <mach/common.h>
 #include <mach/hardware.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 #include <mach/ipu.h>
-#include <mach/i2c.h>
 #include <mach/mmc.h>
 #include <mach/mxc_ehci.h>
 #include <mach/mx3_camera.h>
 #include <mach/spi.h>
 #include <mach/ulpi.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 
 static unsigned int moboard_pins[] = {
@@ -130,24 +125,36 @@ static struct platform_device mx31moboard_flash = {
 
 static int moboard_uart0_init(struct platform_device *pdev)
 {
-       gpio_request(IOMUX_TO_GPIO(MX31_PIN_CTS1), "uart0-cts-hack");
-       gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_CTS1), 0);
-       return 0;
+       int ret = gpio_request(IOMUX_TO_GPIO(MX31_PIN_CTS1), "uart0-cts-hack");
+       if (ret)
+               return ret;
+
+       ret = gpio_direction_output(IOMUX_TO_GPIO(MX31_PIN_CTS1), 0);
+       if (ret)
+               gpio_free(IOMUX_TO_GPIO(MX31_PIN_CTS1));
+
+       return ret;
+}
+
+static void moboard_uart0_exit(struct platform_device *pdev)
+{
+       gpio_free(IOMUX_TO_GPIO(MX31_PIN_CTS1));
 }
 
-static struct imxuart_platform_data uart0_pdata = {
+static const struct imxuart_platform_data uart0_pdata __initconst = {
        .init = moboard_uart0_init,
+       .exit = moboard_uart0_exit,
 };
 
-static struct imxuart_platform_data uart4_pdata = {
+static const struct imxuart_platform_data uart4_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
-static struct imxi2c_platform_data moboard_i2c0_pdata = {
+static const struct imxi2c_platform_data moboard_i2c0_data __initconst = {
        .bitrate = 400000,
 };
 
-static struct imxi2c_platform_data moboard_i2c1_pdata = {
+static const struct imxi2c_platform_data moboard_i2c1_data __initconst = {
        .bitrate = 100000,
 };
 
@@ -156,7 +163,7 @@ static int moboard_spi1_cs[] = {
        MXC_SPI_CS(2),
 };
 
-static struct spi_imx_master moboard_spi1_master = {
+static const struct spi_imx_master moboard_spi1_pdata __initconst = {
        .chipselect     = moboard_spi1_cs,
        .num_chipselect = ARRAY_SIZE(moboard_spi1_cs),
 };
@@ -286,7 +293,7 @@ static int moboard_spi2_cs[] = {
        MXC_SPI_CS(1),
 };
 
-static struct spi_imx_master moboard_spi2_master = {
+static const struct spi_imx_master moboard_spi2_pdata __initconst = {
        .chipselect     = moboard_spi2_cs,
        .num_chipselect = ARRAY_SIZE(moboard_spi2_cs),
 };
@@ -499,15 +506,14 @@ static void __init mxc_board_init(void)
 
        platform_add_devices(devices, ARRAY_SIZE(devices));
 
-       mxc_register_device(&mxc_uart_device0, &uart0_pdata);
-
-       mxc_register_device(&mxc_uart_device4, &uart4_pdata);
+       imx31_add_imx_uart0(&uart0_pdata);
+       imx31_add_imx_uart4(&uart4_pdata);
 
-       mxc_register_device(&mxc_i2c_device0, &moboard_i2c0_pdata);
-       mxc_register_device(&mxc_i2c_device1, &moboard_i2c1_pdata);
+       imx31_add_imx_i2c0(&moboard_i2c0_data);
+       imx31_add_imx_i2c1(&moboard_i2c1_data);
 
-       mxc_register_device(&mxc_spi_device1, &moboard_spi1_master);
-       mxc_register_device(&mxc_spi_device2, &moboard_spi2_master);
+       imx31_add_spi_imx1(&moboard_spi1_pdata);
+       imx31_add_spi_imx2(&moboard_spi2_pdata);
 
        gpio_request(IOMUX_TO_GPIO(MX31_PIN_GPIO1_3), "pmic-irq");
        gpio_direction_input(IOMUX_TO_GPIO(MX31_PIN_GPIO1_3));
similarity index 89%
rename from arch/arm/mach-mx3/mach-mx35pdk.c
rename to arch/arm/mach-mx3/mach-mx35_3ds.c
index bcac84d4dca4b71681626388cd2659edf0b10406..1c30d7212f17901a6703cb33d687ddab926ad3cd 100644 (file)
  * 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
+ */
+
+/*
+ * This machine is known as:
+ *  - i.MX35 3-Stack Development System
+ *  - i.MX35 Platform Development Kit (i.MX35 PDK)
  */
 
 #include <linux/types.h>
 
 #include <mach/hardware.h>
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx35.h>
 
+#include "devices-imx35.h"
 #include "devices.h"
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -90,7 +92,7 @@ static void __init mxc_board_init(void)
 
        platform_add_devices(devices, ARRAY_SIZE(devices));
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       imx35_add_imx_uart0(&uart_pdata);
 
        mxc_register_device(&mxc_otg_udc_device, &usb_pdata);
 }
index cce41066238338d4c09284835227b0dcd33deca4..8a292dd1a7146311394a90540af4811a60df804f 100644 (file)
  * 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
  */
 
 #include <linux/types.h>
 #include <asm/mach/arch.h>
 #include <asm/mach/time.h>
 #include <asm/mach/map.h>
-#include <mach/board-pcm037.h>
 #include <mach/common.h>
 #include <mach/hardware.h>
-#include <mach/i2c.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 #include <mach/ipu.h>
 #include <mach/mmc.h>
 #include <mach/mx3_camera.h>
 #include <mach/mx3fb.h>
-#include <mach/mxc_nand.h>
 #include <mach/mxc_ehci.h>
 #include <mach/ulpi.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 #include "pcm037.h"
 
@@ -225,7 +218,7 @@ static struct platform_device pcm037_flash = {
        .num_resources = 1,
 };
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -279,16 +272,17 @@ static struct platform_device pcm037_sram_device = {
        .resource = &pcm038_sram_resource,
 };
 
-static struct mxc_nand_platform_data pcm037_nand_board_info = {
+static const struct mxc_nand_platform_data
+pcm037_nand_board_info __initconst = {
        .width = 1,
        .hw_ecc = 1,
 };
 
-static struct imxi2c_platform_data pcm037_i2c_1_data = {
+static const struct imxi2c_platform_data pcm037_i2c1_data __initconst = {
        .bitrate = 100000,
 };
 
-static struct imxi2c_platform_data pcm037_i2c_2_data = {
+static const struct imxi2c_platform_data pcm037_i2c2_data __initconst = {
        .bitrate = 20000,
 };
 
@@ -545,6 +539,7 @@ static struct platform_device pcm970_sja1000 = {
        .num_resources = ARRAY_SIZE(pcm970_sja1000_resources),
 };
 
+#if defined(CONFIG_USB_ULPI)
 static struct mxc_usbh_platform_data otg_pdata = {
        .portsc = MXC_EHCI_MODE_ULPI,
        .flags  = MXC_EHCI_INTERFACE_DIFF_UNI,
@@ -554,6 +549,7 @@ static struct mxc_usbh_platform_data usbh2_pdata = {
        .portsc = MXC_EHCI_MODE_ULPI,
        .flags  = MXC_EHCI_INTERFACE_DIFF_UNI,
 };
+#endif
 
 static struct fsl_usb2_platform_data otg_device_pdata = {
        .operating_mode = FSL_USB2_DR_DEVICE,
@@ -581,7 +577,6 @@ __setup("otg_mode=", pcm037_otg_mode);
 static void __init mxc_board_init(void)
 {
        int ret;
-       u32 tmp;
 
        mxc_iomux_set_gpr(MUX_PGP_UH2, 1);
 
@@ -614,9 +609,10 @@ static void __init mxc_board_init(void)
 
        platform_add_devices(devices, ARRAY_SIZE(devices));
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
-       mxc_register_device(&mxc_uart_device1, &uart_pdata);
-       mxc_register_device(&mxc_uart_device2, &uart_pdata);
+       imx31_add_imx_uart0(&uart_pdata);
+       /* XXX: should't this have .flags = 0 (i.e. no RTSCTS) on PCM037_EET? */
+       imx31_add_imx_uart1(&uart_pdata);
+       imx31_add_imx_uart2(&uart_pdata);
 
        mxc_register_device(&mxc_w1_master_device, NULL);
 
@@ -634,10 +630,10 @@ static void __init mxc_board_init(void)
        i2c_register_board_info(1, pcm037_i2c_devices,
                        ARRAY_SIZE(pcm037_i2c_devices));
 
-       mxc_register_device(&mxc_i2c_device1, &pcm037_i2c_1_data);
-       mxc_register_device(&mxc_i2c_device2, &pcm037_i2c_2_data);
+       imx31_add_imx_i2c1(&pcm037_i2c1_data);
+       imx31_add_imx_i2c2(&pcm037_i2c2_data);
 
-       mxc_register_device(&mxc_nand_device, &pcm037_nand_board_info);
+       imx31_add_mxc_nand(&pcm037_nand_board_info);
        mxc_register_device(&mxcsdhc_device0, &sdhc_pdata);
        mxc_register_device(&mx3_ipu, &mx3_ipu_data);
        mxc_register_device(&mx3_fb, &mx3fb_pdata);
index 8d386000fc40d1f9c161ae1e121ec5a6466cba1e..c8b98218efeec9d32882333faa52c41458ce2f37 100644 (file)
@@ -13,9 +13,6 @@
 #include <linux/spi/spi.h>
 
 #include <mach/common.h>
-#if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
-#include <mach/spi.h>
-#endif
 #include <mach/iomux-mx3.h>
 
 #include <asm/mach-types.h>
@@ -64,7 +61,7 @@ static struct spi_board_info pcm037_spi_dev[] = {
 #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
 static int pcm037_spi1_cs[] = {MXC_SPI_CS(1), IOMUX_TO_GPIO(MX31_PIN_KEY_COL7)};
 
-struct spi_imx_master pcm037_spi1_master = {
+static const struct spi_imx_master pcm037_spi1_pdata __initconst = {
        .chipselect = pcm037_spi1_cs,
        .num_chipselect = ARRAY_SIZE(pcm037_spi1_cs),
 };
@@ -184,7 +181,7 @@ static int eet_init_devices(void)
        /* SPI */
        spi_register_board_info(pcm037_spi_dev, ARRAY_SIZE(pcm037_spi_dev));
 #if defined(CONFIG_SPI_IMX) || defined(CONFIG_SPI_IMX_MODULE)
-       mxc_register_device(&mxc_spi_device0, &pcm037_spi1_master);
+       imx35_add_spi_imx0(&pcm037_spi1_pdata);
 #endif
 
        platform_device_register(&pcm037_gpio_keys_device);
index 78d9185a9d4ba7f46937f47ffe893935e897b4bb..47f5311b301a18170fa30c86de22cd0d2b64495b 100644 (file)
  * 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
  */
 
 #include <linux/types.h>
 
 #include <mach/hardware.h>
 #include <mach/common.h>
-#include <mach/imx-uart.h>
-#if defined CONFIG_I2C_IMX || defined CONFIG_I2C_IMX_MODULE
-#include <mach/i2c.h>
-#endif
 #include <mach/iomux-mx35.h>
 #include <mach/ipu.h>
 #include <mach/mx3fb.h>
-#include <mach/mxc_nand.h>
 #include <mach/mxc_ehci.h>
 #include <mach/ulpi.h>
 #include <mach/audmux.h>
 #include <mach/ssi.h>
 
+#include "devices-imx35.h"
 #include "devices.h"
 
 static const struct fb_videomode fb_modedb[] = {
@@ -122,12 +114,12 @@ static struct platform_device pcm043_flash = {
        .num_resources = 1,
 };
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
 #if defined CONFIG_I2C_IMX || defined CONFIG_I2C_IMX_MODULE
-static struct imxi2c_platform_data pcm043_i2c_1_data = {
+static const struct imxi2c_platform_data pcm043_i2c0_data __initconst = {
        .bitrate = 50000,
 };
 
@@ -222,6 +214,9 @@ static struct pad_desc pcm043_pads[] = {
        MX35_PAD_STXD4__AUDMUX_AUD4_TXD,
        MX35_PAD_SRXD4__AUDMUX_AUD4_RXD,
        MX35_PAD_SCK4__AUDMUX_AUD4_TXC,
+       /* CAN2 */
+       MX35_PAD_TX5_RX0__CAN2_TXCAN,
+       MX35_PAD_TX4_RX1__CAN2_RXCAN,
 };
 
 #define AC97_GPIO_TXFS (1 * 32 + 31)
@@ -304,11 +299,13 @@ static struct imx_ssi_platform_data pcm043_ssi_pdata = {
        .flags = IMX_SSI_USE_AC97,
 };
 
-static struct mxc_nand_platform_data pcm037_nand_board_info = {
+static const struct mxc_nand_platform_data
+pcm037_nand_board_info __initconst = {
        .width = 1,
        .hw_ecc = 1,
 };
 
+#if defined(CONFIG_USB_ULPI)
 static struct mxc_usbh_platform_data otg_pdata = {
        .portsc = MXC_EHCI_MODE_UTMI,
        .flags  = MXC_EHCI_INTERFACE_DIFF_UNI,
@@ -319,6 +316,7 @@ static struct mxc_usbh_platform_data usbh1_pdata = {
        .flags  = MXC_EHCI_INTERFACE_SINGLE_UNI | MXC_EHCI_INTERNAL_PHY |
                  MXC_EHCI_IPPUE_DOWN,
 };
+#endif
 
 static struct fsl_usb2_platform_data otg_device_pdata = {
        .operating_mode = FSL_USB2_DR_DEVICE,
@@ -361,17 +359,17 @@ static void __init mxc_board_init(void)
 
        platform_add_devices(devices, ARRAY_SIZE(devices));
 
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
-       mxc_register_device(&mxc_nand_device, &pcm037_nand_board_info);
+       imx35_add_imx_uart0(&uart_pdata);
+       imx35_add_mxc_nand(&pcm037_nand_board_info);
        mxc_register_device(&imx_ssi_device0, &pcm043_ssi_pdata);
 
-       mxc_register_device(&mxc_uart_device1, &uart_pdata);
+       imx35_add_imx_uart1(&uart_pdata);
 
 #if defined CONFIG_I2C_IMX || defined CONFIG_I2C_IMX_MODULE
        i2c_register_board_info(0, pcm043_i2c_devices,
                        ARRAY_SIZE(pcm043_i2c_devices));
 
-       mxc_register_device(&mxc_i2c_device0, &pcm043_i2c_1_data);
+       imx35_add_imx_i2c0(&pcm043_i2c0_data);
 #endif
 
        mxc_register_device(&mx3_ipu, &mx3_ipu_data);
@@ -390,6 +388,7 @@ static void __init mxc_board_init(void)
        if (!otg_mode_host)
                mxc_register_device(&mxc_otg_udc_device, &otg_device_pdata);
 
+       imx35_add_flexcan1(NULL);
 }
 
 static void __init pcm043_timer_init(void)
index e5b5b8323a1793aad3115e4694a8e9bd149155f5..d44ac70222a592246e643b31f8572fcdaf846544 100644 (file)
  * 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
  */
 
 #include <linux/types.h>
@@ -34,9 +30,9 @@
 #include <mach/common.h>
 #include <asm/page.h>
 #include <asm/setup.h>
-#include <mach/board-qong.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
+
+#include "devices-imx31.h"
 #include "devices.h"
 
 /* FPGA defines */
@@ -62,7 +58,7 @@
  * This file contains the board-specific initialization routines.
  */
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -73,11 +69,11 @@ static int uart_pins[] = {
        MX31_PIN_RXD1__RXD1
 };
 
-static inline void mxc_init_imx_uart(void)
+static inline void __init mxc_init_imx_uart(void)
 {
        mxc_iomux_setup_multiple_pins(uart_pins, ARRAY_SIZE(uart_pins),
                        "uart-0");
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       imx31_add_imx_uart0(&uart_pdata);
 }
 
 static struct resource dnet_resources[] = {
@@ -116,7 +112,7 @@ static struct physmap_flash_data qong_flash_data = {
 
 static struct resource qong_flash_resource = {
        .start = MX31_CS0_BASE_ADDR,
-       .end = MX31_CS0_BASE_ADDR + QONG_NOR_SIZE - 1,
+       .end = MX31_CS0_BASE_ADDR + SZ_128M - 1,
        .flags = IORESOURCE_MEM,
 };
 
index 6858a4f9806cd69f3f0ffe95641d87d342cdd899..20e48c0195c4f8533c7d43113f0ce3965c0ef143 100644 (file)
  * 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
  */
 
 #include <linux/mm.h>
@@ -97,9 +93,12 @@ void __init mx35_map_io(void)
 }
 #endif
 
+int imx3x_register_gpios(void);
+
 void __init mx31_init_irq(void)
 {
        mxc_init_irq(IO_ADDRESS(AVIC_BASE_ADDR));
+       imx3x_register_gpios();
 }
 
 void __init mx35_init_irq(void)
index 7aebd74a12e8c075b3d5dadde345e9c4fea91752..827fd3c802012d7135fbca269456dbf12968d5d1 100644 (file)
  * 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
  */
 
 #include <linux/kernel.h>
 
 #include <mach/hardware.h>
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 #include <mach/board-mx31lilly.h>
 #include <mach/mmc.h>
 #include <mach/mx3fb.h>
 #include <mach/ipu.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 
 /*
@@ -96,7 +92,7 @@ static unsigned int lilly_db_board_pins[] __initdata = {
 };
 
 /* UART */
-static struct imxuart_platform_data uart_pdata __initdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -217,9 +213,9 @@ void __init mx31lilly_db_init(void)
        mxc_iomux_setup_multiple_pins(lilly_db_board_pins,
                                        ARRAY_SIZE(lilly_db_board_pins),
                                        "development board pins");
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
-       mxc_register_device(&mxc_uart_device1, &uart_pdata);
-       mxc_register_device(&mxc_uart_device2, &uart_pdata);
+       imx31_add_imx_uart0(&uart_pdata);
+       imx31_add_imx_uart1(&uart_pdata);
+       imx31_add_imx_uart2(&uart_pdata);
        mxc_register_device(&mxcsdhc_device0, &mmc_pdata);
        mx31lilly_init_fb();
 }
index 5f05bfbec38054187324565e3d421a3da01110c9..7b0e74e275ba77110cf73e3173b20ec438796fdc 100644 (file)
  * 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
  */
 
 #include <linux/kernel.h>
 
 #include <mach/hardware.h>
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 #include <mach/board-mx31lite.h>
 #include <mach/mmc.h>
-#include <mach/spi.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 
 /*
@@ -76,7 +71,7 @@ static unsigned int litekit_db_board_pins[] __initdata = {
 };
 
 /* UART */
-static struct imxuart_platform_data uart_pdata __initdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -161,7 +156,7 @@ static int spi_internal_chipselect[] = {
        MXC_SPI_CS(2),
 };
 
-static struct spi_imx_master spi0_pdata = {
+static const struct spi_imx_master spi0_pdata __initconst = {
        .chipselect     = spi_internal_chipselect,
        .num_chipselect = ARRAY_SIZE(spi_internal_chipselect),
 };
@@ -201,9 +196,9 @@ void __init mx31lite_db_init(void)
        mxc_iomux_setup_multiple_pins(litekit_db_board_pins,
                                        ARRAY_SIZE(litekit_db_board_pins),
                                        "development board pins");
-       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       imx31_add_imx_uart0(&uart_pdata);
        mxc_register_device(&mxcsdhc_device0, &mmc_pdata);
-       mxc_register_device(&mxc_spi_device0, &spi0_pdata);
+       imx31_add_spi_imx0(&spi0_pdata);
        platform_device_register(&litekit_led_device);
        mxc_register_device(&imx_wdt_device0, NULL);
        mxc_register_device(&imx_rtc_device0, NULL);
index 582299cb2c08be52c6d0cbd9f8c010d123fca33e..fc395a7a8599e78bf2c2096c523e50a0d0fb28aa 100644 (file)
  * 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
  */
 
 #include <linux/gpio.h>
 #include <linux/usb/otg.h>
 
 #include <mach/common.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 #include <mach/hardware.h>
 #include <mach/mmc.h>
 #include <mach/mxc_ehci.h>
 #include <mach/ulpi.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 
 static unsigned int devboard_pins[] = {
@@ -56,7 +52,7 @@ static unsigned int devboard_pins[] = {
        MX31_PIN_RI_DCE1__GPIO2_10, MX31_PIN_DCD_DCE1__GPIO2_11,
 };
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -230,7 +226,7 @@ void __init mx31moboard_devboard_init(void)
        mxc_iomux_setup_multiple_pins(devboard_pins, ARRAY_SIZE(devboard_pins),
                "devboard");
 
-       mxc_register_device(&mxc_uart_device1, &uart_pdata);
+       imx31_add_imx_uart1(&uart_pdata);
 
        mxc_register_device(&mxcsdhc_device1, &sdhc2_pdata);
 
index 4930f8c27e661fd5c8612c0369d7e79779f1cf7d..0551eb39d97eec32f7694538838eae418940da80 100644 (file)
  * 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
  */
 
 #include <linux/delay.h>
index 293eea6d9d97cbd9ffb5cdcbed1409ab685e6a31..40c3e7564cb61c43d77cbd1b01793262e6552eca 100644 (file)
  * 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
  */
 
 #include <linux/delay.h>
@@ -30,7 +26,6 @@
 
 #include <mach/common.h>
 #include <mach/hardware.h>
-#include <mach/imx-uart.h>
 #include <mach/iomux-mx3.h>
 #include <mach/board-mx31moboard.h>
 #include <mach/mxc_ehci.h>
@@ -38,6 +33,7 @@
 
 #include <media/soc_camera.h>
 
+#include "devices-imx31.h"
 #include "devices.h"
 
 static unsigned int smartbot_pins[] = {
@@ -59,7 +55,7 @@ static unsigned int smartbot_pins[] = {
        MX31_PIN_RI_DCE1__GPIO2_10, MX31_PIN_DCD_DCE1__GPIO2_11,
 };
 
-static struct imxuart_platform_data uart_pdata = {
+static const struct imxuart_platform_data uart_pdata __initconst = {
        .flags = IMXUART_HAVE_RTSCTS,
 };
 
@@ -183,8 +179,7 @@ void __init mx31moboard_smartbot_init(int board)
        mxc_iomux_setup_multiple_pins(smartbot_pins, ARRAY_SIZE(smartbot_pins),
                "smartbot");
 
-       mxc_register_device(&mxc_uart_device1, &uart_pdata);
-
+       imx31_add_imx_uart1(&uart_pdata);
 
        switch (board) {
        case MX31SMARTBOT:
index 1576d51e676c913cad7c5e4c6f5cfc379d7d336f..0848db5dd364dd5bb5b90ae03f3accf6eeb711aa 100644 (file)
@@ -15,4 +15,31 @@ config MACH_MX51_BABBAGE
          u-boot. This includes specific configurations for the board and its
          peripherals.
 
+config MACH_MX51_3DS
+       bool "Support MX51PDK (3DS)"
+       select MXC_DEBUG_BOARD
+       help
+         Include support for MX51PDK (3DS) platform. This includes specific
+         configurations for the board and its peripherals.
+
+config MACH_EUKREA_CPUIMX51
+       bool "Support Eukrea CPUIMX51 module"
+       help
+         Include support for Eukrea CPUIMX51 platform. This includes
+         specific configurations for the module and its peripherals.
+
+choice
+       prompt "Baseboard"
+       depends on MACH_EUKREA_CPUIMX51
+       default MACH_EUKREA_MBIMX51_BASEBOARD
+
+config MACH_EUKREA_MBIMX51_BASEBOARD
+       prompt "Eukrea MBIMX51 development board"
+       bool
+       help
+         This adds board specific devices that can be found on Eukrea's
+         MBIMX51 evaluation board.
+
+endchoice
+
 endif
index bf23f869ef511817f38be14ec7dcf48b3f82263c..86c66e7f52f3dc0855509587703e6972de2c483e 100644 (file)
@@ -6,4 +6,6 @@
 obj-y   := cpu.o mm.o clock-mx51.o devices.o
 
 obj-$(CONFIG_MACH_MX51_BABBAGE) += board-mx51_babbage.o
-
+obj-$(CONFIG_MACH_MX51_3DS) += board-mx51_3ds.o
+obj-$(CONFIG_MACH_EUKREA_CPUIMX51) += board-cpuimx51.o
+obj-$(CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD) += eukrea_mbimx51-baseboard.o
diff --git a/arch/arm/mach-mx5/board-cpuimx51.c b/arch/arm/mach-mx5/board-cpuimx51.c
new file mode 100644 (file)
index 0000000..623607a
--- /dev/null
@@ -0,0 +1,293 @@
+/*
+ *
+ * Copyright (C) 2010 Eric Bénard <eric@eukrea.com>
+ *
+ * based on board-mx51_babbage.c which is
+ * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright (C) 2009-2010 Amit Kucheria <amit.kucheria@canonical.com>
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/serial_8250.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/fsl_devices.h>
+
+#include <mach/eukrea-baseboards.h>
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/imx-uart.h>
+#include <mach/iomux-mx51.h>
+#include <mach/i2c.h>
+#include <mach/mxc_ehci.h>
+
+#include <asm/irq.h>
+#include <asm/setup.h>
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+
+#include "devices.h"
+
+#define CPUIMX51_USBH1_STP     (0*32 + 27)
+#define CPUIMX51_QUARTA_GPIO   (2*32 + 28)
+#define CPUIMX51_QUARTB_GPIO   (2*32 + 25)
+#define CPUIMX51_QUARTC_GPIO   (2*32 + 26)
+#define CPUIMX51_QUARTD_GPIO   (2*32 + 27)
+#define CPUIMX51_QUARTA_IRQ    (MXC_INTERNAL_IRQS + CPUIMX51_QUARTA_GPIO)
+#define CPUIMX51_QUARTB_IRQ    (MXC_INTERNAL_IRQS + CPUIMX51_QUARTB_GPIO)
+#define CPUIMX51_QUARTC_IRQ    (MXC_INTERNAL_IRQS + CPUIMX51_QUARTC_GPIO)
+#define CPUIMX51_QUARTD_IRQ    (MXC_INTERNAL_IRQS + CPUIMX51_QUARTD_GPIO)
+#define CPUIMX51_QUART_XTAL    14745600
+#define CPUIMX51_QUART_REGSHIFT        17
+
+/* USB_CTRL_1 */
+#define MX51_USB_CTRL_1_OFFSET         0x10
+#define MX51_USB_CTRL_UH1_EXT_CLK_EN   (1 << 25)
+
+#define        MX51_USB_PLLDIV_12_MHZ          0x00
+#define        MX51_USB_PLL_DIV_19_2_MHZ       0x01
+#define        MX51_USB_PLL_DIV_24_MHZ         0x02
+
+#if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
+static struct plat_serial8250_port serial_platform_data[] = {
+       {
+               .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x400000),
+               .irq = CPUIMX51_QUARTA_IRQ,
+               .irqflags = IRQF_TRIGGER_HIGH,
+               .uartclk = CPUIMX51_QUART_XTAL,
+               .regshift = CPUIMX51_QUART_REGSHIFT,
+               .iotype = UPIO_MEM,
+               .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
+       }, {
+               .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x800000),
+               .irq = CPUIMX51_QUARTB_IRQ,
+               .irqflags = IRQF_TRIGGER_HIGH,
+               .uartclk = CPUIMX51_QUART_XTAL,
+               .regshift = CPUIMX51_QUART_REGSHIFT,
+               .iotype = UPIO_MEM,
+               .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
+       }, {
+               .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x1000000),
+               .irq = CPUIMX51_QUARTC_IRQ,
+               .irqflags = IRQF_TRIGGER_HIGH,
+               .uartclk = CPUIMX51_QUART_XTAL,
+               .regshift = CPUIMX51_QUART_REGSHIFT,
+               .iotype = UPIO_MEM,
+               .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
+       }, {
+               .mapbase = (unsigned long)(MX51_CS1_BASE_ADDR + 0x2000000),
+               .irq = CPUIMX51_QUARTD_IRQ,
+               .irqflags = IRQF_TRIGGER_HIGH,
+               .uartclk = CPUIMX51_QUART_XTAL,
+               .regshift = CPUIMX51_QUART_REGSHIFT,
+               .iotype = UPIO_MEM,
+               .flags = UPF_BOOT_AUTOCONF | UPF_SKIP_TEST | UPF_IOREMAP,
+       }, {
+       }
+};
+
+static struct platform_device serial_device = {
+       .name = "serial8250",
+       .id = 0,
+       .dev = {
+               .platform_data = serial_platform_data,
+       },
+};
+#endif
+
+static struct platform_device *devices[] __initdata = {
+       &mxc_fec_device,
+#if defined(CONFIG_SERIAL_8250) || defined(CONFIG_SERIAL_8250_MODULE)
+       &serial_device,
+#endif
+};
+
+static struct pad_desc eukrea_cpuimx51_pads[] = {
+       /* UART1 */
+       MX51_PAD_UART1_RXD__UART1_RXD,
+       MX51_PAD_UART1_TXD__UART1_TXD,
+       MX51_PAD_UART1_RTS__UART1_RTS,
+       MX51_PAD_UART1_CTS__UART1_CTS,
+
+       /* I2C2 */
+       MX51_PAD_GPIO_1_2__I2C2_SCL,
+       MX51_PAD_GPIO_1_3__I2C2_SDA,
+       MX51_PAD_NANDF_D10__GPIO_3_30,
+
+       /* QUART IRQ */
+       MX51_PAD_NANDF_D15__GPIO_3_25,
+       MX51_PAD_NANDF_D14__GPIO_3_26,
+       MX51_PAD_NANDF_D13__GPIO_3_27,
+       MX51_PAD_NANDF_D12__GPIO_3_28,
+
+       /* USB HOST1 */
+       MX51_PAD_USBH1_CLK__USBH1_CLK,
+       MX51_PAD_USBH1_DIR__USBH1_DIR,
+       MX51_PAD_USBH1_NXT__USBH1_NXT,
+       MX51_PAD_USBH1_DATA0__USBH1_DATA0,
+       MX51_PAD_USBH1_DATA1__USBH1_DATA1,
+       MX51_PAD_USBH1_DATA2__USBH1_DATA2,
+       MX51_PAD_USBH1_DATA3__USBH1_DATA3,
+       MX51_PAD_USBH1_DATA4__USBH1_DATA4,
+       MX51_PAD_USBH1_DATA5__USBH1_DATA5,
+       MX51_PAD_USBH1_DATA6__USBH1_DATA6,
+       MX51_PAD_USBH1_DATA7__USBH1_DATA7,
+       MX51_PAD_USBH1_STP__USBH1_STP,
+};
+
+static struct imxuart_platform_data uart_pdata = {
+       .flags = IMXUART_HAVE_RTSCTS,
+};
+
+static struct imxi2c_platform_data eukrea_cpuimx51_i2c_data = {
+       .bitrate = 100000,
+};
+
+static struct i2c_board_info eukrea_cpuimx51_i2c_devices[] = {
+       {
+               I2C_BOARD_INFO("pcf8563", 0x51),
+       },
+};
+
+/* This function is board specific as the bit mask for the plldiv will also
+be different for other Freescale SoCs, thus a common bitmask is not
+possible and cannot get place in /plat-mxc/ehci.c.*/
+static int initialize_otg_port(struct platform_device *pdev)
+{
+       u32 v;
+       void __iomem *usb_base;
+       void __iomem *usbother_base;
+
+       usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
+       usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
+
+       /* Set the PHY clock to 19.2MHz */
+       v = __raw_readl(usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
+       v &= ~MX5_USB_UTMI_PHYCTRL1_PLLDIV_MASK;
+       v |= MX51_USB_PLL_DIV_19_2_MHZ;
+       __raw_writel(v, usbother_base + MXC_USB_PHY_CTR_FUNC2_OFFSET);
+       iounmap(usb_base);
+       return 0;
+}
+
+static int initialize_usbh1_port(struct platform_device *pdev)
+{
+       u32 v;
+       void __iomem *usb_base;
+       void __iomem *usbother_base;
+
+       usb_base = ioremap(MX51_OTG_BASE_ADDR, SZ_4K);
+       usbother_base = usb_base + MX5_USBOTHER_REGS_OFFSET;
+
+       /* The clock for the USBH1 ULPI port will come externally from the PHY. */
+       v = __raw_readl(usbother_base + MX51_USB_CTRL_1_OFFSET);
+       __raw_writel(v | MX51_USB_CTRL_UH1_EXT_CLK_EN, usbother_base + MX51_USB_CTRL_1_OFFSET);
+       iounmap(usb_base);
+       return 0;
+}
+
+static struct mxc_usbh_platform_data dr_utmi_config = {
+       .init           = initialize_otg_port,
+       .portsc = MXC_EHCI_UTMI_16BIT,
+       .flags  = MXC_EHCI_INTERNAL_PHY,
+};
+
+static struct fsl_usb2_platform_data usb_pdata = {
+       .operating_mode = FSL_USB2_DR_DEVICE,
+       .phy_mode       = FSL_USB2_PHY_UTMI_WIDE,
+};
+
+static struct mxc_usbh_platform_data usbh1_config = {
+       .init           = initialize_usbh1_port,
+       .portsc = MXC_EHCI_MODE_ULPI,
+       .flags  = (MXC_EHCI_POWER_PINS_ENABLED | MXC_EHCI_ITC_NO_THRESHOLD),
+};
+
+static int otg_mode_host;
+
+static int __init eukrea_cpuimx51_otg_mode(char *options)
+{
+       if (!strcmp(options, "host"))
+               otg_mode_host = 1;
+       else if (!strcmp(options, "device"))
+               otg_mode_host = 0;
+       else
+               pr_info("otg_mode neither \"host\" nor \"device\". "
+                       "Defaulting to device\n");
+       return 0;
+}
+__setup("otg_mode=", eukrea_cpuimx51_otg_mode);
+
+/*
+ * Board specific initialization.
+ */
+static void __init eukrea_cpuimx51_init(void)
+{
+       mxc_iomux_v3_setup_multiple_pads(eukrea_cpuimx51_pads,
+                                       ARRAY_SIZE(eukrea_cpuimx51_pads));
+
+       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       gpio_request(CPUIMX51_QUARTA_GPIO, "quarta_irq");
+       gpio_direction_input(CPUIMX51_QUARTA_GPIO);
+       gpio_free(CPUIMX51_QUARTA_GPIO);
+       gpio_request(CPUIMX51_QUARTB_GPIO, "quartb_irq");
+       gpio_direction_input(CPUIMX51_QUARTB_GPIO);
+       gpio_free(CPUIMX51_QUARTB_GPIO);
+       gpio_request(CPUIMX51_QUARTC_GPIO, "quartc_irq");
+       gpio_direction_input(CPUIMX51_QUARTC_GPIO);
+       gpio_free(CPUIMX51_QUARTC_GPIO);
+       gpio_request(CPUIMX51_QUARTD_GPIO, "quartd_irq");
+       gpio_direction_input(CPUIMX51_QUARTD_GPIO);
+       gpio_free(CPUIMX51_QUARTD_GPIO);
+
+       platform_add_devices(devices, ARRAY_SIZE(devices));
+
+       mxc_register_device(&mxc_i2c_device1, &eukrea_cpuimx51_i2c_data);
+       i2c_register_board_info(1, eukrea_cpuimx51_i2c_devices,
+                               ARRAY_SIZE(eukrea_cpuimx51_i2c_devices));
+
+       if (otg_mode_host)
+               mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
+       else {
+               initialize_otg_port(NULL);
+               mxc_register_device(&mxc_usbdr_udc_device, &usb_pdata);
+       }
+       mxc_register_device(&mxc_usbh1_device, &usbh1_config);
+
+#ifdef CONFIG_MACH_EUKREA_MBIMX51_BASEBOARD
+       eukrea_mbimx51_baseboard_init();
+#endif
+}
+
+static void __init eukrea_cpuimx51_timer_init(void)
+{
+       mx51_clocks_init(32768, 24000000, 22579200, 0);
+}
+
+static struct sys_timer mxc_timer = {
+       .init   = eukrea_cpuimx51_timer_init,
+};
+
+MACHINE_START(EUKREA_CPUIMX51, "Eukrea CPUIMX51 Module")
+       /* Maintainer: Eric Bénard <eric@eukrea.com> */
+       .phys_io = MX51_AIPS1_BASE_ADDR,
+       .io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
+       .boot_params = PHYS_OFFSET + 0x100,
+       .map_io = mx51_map_io,
+       .init_irq = mx51_init_irq,
+       .init_machine = eukrea_cpuimx51_init,
+       .timer = &mxc_timer,
+MACHINE_END
diff --git a/arch/arm/mach-mx5/board-mx51_3ds.c b/arch/arm/mach-mx5/board-mx51_3ds.c
new file mode 100644 (file)
index 0000000..f95c2fd
--- /dev/null
@@ -0,0 +1,164 @@
+/*
+ * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright (C) 2010 Jason Wang <jason77.wang@gmail.com>
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/irq.h>
+#include <linux/platform_device.h>
+#include <linux/input/matrix_keypad.h>
+
+#include <asm/mach-types.h>
+#include <asm/mach/arch.h>
+#include <asm/mach/time.h>
+
+#include <mach/hardware.h>
+#include <mach/common.h>
+#include <mach/iomux-mx51.h>
+#include <mach/imx-uart.h>
+#include <mach/3ds_debugboard.h>
+
+#include "devices.h"
+
+#define EXPIO_PARENT_INT       (MXC_INTERNAL_IRQS + GPIO_PORTA + 6)
+
+static struct pad_desc mx51_3ds_pads[] = {
+       /* UART1 */
+       MX51_PAD_UART1_RXD__UART1_RXD,
+       MX51_PAD_UART1_TXD__UART1_TXD,
+       MX51_PAD_UART1_RTS__UART1_RTS,
+       MX51_PAD_UART1_CTS__UART1_CTS,
+
+       /* UART2 */
+       MX51_PAD_UART2_RXD__UART2_RXD,
+       MX51_PAD_UART2_TXD__UART2_TXD,
+       MX51_PAD_EIM_D25__UART2_CTS,
+       MX51_PAD_EIM_D26__UART2_RTS,
+
+       /* UART3 */
+       MX51_PAD_UART3_RXD__UART3_RXD,
+       MX51_PAD_UART3_TXD__UART3_TXD,
+       MX51_PAD_EIM_D24__UART3_CTS,
+       MX51_PAD_EIM_D27__UART3_RTS,
+
+       /* CPLD PARENT IRQ PIN */
+       MX51_PAD_GPIO_1_6__GPIO_1_6,
+
+       /* KPP */
+       MX51_PAD_KEY_ROW0__KEY_ROW0,
+       MX51_PAD_KEY_ROW1__KEY_ROW1,
+       MX51_PAD_KEY_ROW2__KEY_ROW2,
+       MX51_PAD_KEY_ROW3__KEY_ROW3,
+       MX51_PAD_KEY_COL0__KEY_COL0,
+       MX51_PAD_KEY_COL1__KEY_COL1,
+       MX51_PAD_KEY_COL2__KEY_COL2,
+       MX51_PAD_KEY_COL3__KEY_COL3,
+       MX51_PAD_KEY_COL4__KEY_COL4,
+       MX51_PAD_KEY_COL5__KEY_COL5,
+};
+
+/* Serial ports */
+#if defined(CONFIG_SERIAL_IMX) || defined(CONFIG_SERIAL_IMX_MODULE)
+static struct imxuart_platform_data uart_pdata = {
+       .flags = IMXUART_HAVE_RTSCTS,
+};
+
+static inline void mxc_init_imx_uart(void)
+{
+       mxc_register_device(&mxc_uart_device0, &uart_pdata);
+       mxc_register_device(&mxc_uart_device1, &uart_pdata);
+       mxc_register_device(&mxc_uart_device2, &uart_pdata);
+}
+#else /* !SERIAL_IMX */
+static inline void mxc_init_imx_uart(void)
+{
+}
+#endif /* SERIAL_IMX */
+
+#if defined(CONFIG_KEYBOARD_IMX) || defined(CONFIG_KEYBOARD_IMX_MODULE)
+static int mx51_3ds_board_keymap[] = {
+       KEY(0, 0, KEY_1),
+       KEY(0, 1, KEY_2),
+       KEY(0, 2, KEY_3),
+       KEY(0, 3, KEY_F1),
+       KEY(0, 4, KEY_UP),
+       KEY(0, 5, KEY_F2),
+
+       KEY(1, 0, KEY_4),
+       KEY(1, 1, KEY_5),
+       KEY(1, 2, KEY_6),
+       KEY(1, 3, KEY_LEFT),
+       KEY(1, 4, KEY_SELECT),
+       KEY(1, 5, KEY_RIGHT),
+
+       KEY(2, 0, KEY_7),
+       KEY(2, 1, KEY_8),
+       KEY(2, 2, KEY_9),
+       KEY(2, 3, KEY_F3),
+       KEY(2, 4, KEY_DOWN),
+       KEY(2, 5, KEY_F4),
+
+       KEY(3, 0, KEY_0),
+       KEY(3, 1, KEY_OK),
+       KEY(3, 2, KEY_ESC),
+       KEY(3, 3, KEY_ENTER),
+       KEY(3, 4, KEY_MENU),
+       KEY(3, 5, KEY_BACK)
+};
+
+static struct matrix_keymap_data mx51_3ds_map_data = {
+       .keymap         = mx51_3ds_board_keymap,
+       .keymap_size    = ARRAY_SIZE(mx51_3ds_board_keymap),
+};
+
+static void mxc_init_keypad(void)
+{
+       mxc_register_device(&mxc_keypad_device, &mx51_3ds_map_data);
+}
+#else
+static inline void mxc_init_keypad(void)
+{
+}
+#endif
+
+/*
+ * Board specific initialization.
+ */
+static void __init mxc_board_init(void)
+{
+       mxc_iomux_v3_setup_multiple_pads(mx51_3ds_pads,
+                                       ARRAY_SIZE(mx51_3ds_pads));
+       mxc_init_imx_uart();
+
+       if (mxc_expio_init(MX51_CS5_BASE_ADDR, EXPIO_PARENT_INT))
+               printk(KERN_WARNING "Init of the debugboard failed, all "
+                                   "devices on the board are unusable.\n");
+
+       mxc_init_keypad();
+}
+
+static void __init mx51_3ds_timer_init(void)
+{
+       mx51_clocks_init(32768, 24000000, 22579200, 0);
+}
+
+static struct sys_timer mxc_timer = {
+       .init   = mx51_3ds_timer_init,
+};
+
+MACHINE_START(MX51_3DS, "Freescale MX51 3-Stack Board")
+       /* Maintainer: Freescale Semiconductor, Inc. */
+       .phys_io = MX51_AIPS1_BASE_ADDR,
+       .io_pg_offst = ((MX51_AIPS1_BASE_ADDR_VIRT) >> 18) & 0xfffc,
+       .boot_params = PHYS_OFFSET + 0x100,
+       .map_io = mx51_map_io,
+       .init_irq = mx51_init_irq,
+       .init_machine = mxc_board_init,
+       .timer = &mxc_timer,
+MACHINE_END
index ed885f9d7b73d51e0c19e4ba1c227e95f6dbb09e..6e384d92e625d107279c14228964553525aa6c53 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <linux/init.h>
 #include <linux/platform_device.h>
+#include <linux/i2c.h>
 #include <linux/gpio.h>
 #include <linux/delay.h>
 #include <linux/io.h>
@@ -21,6 +22,7 @@
 #include <mach/hardware.h>
 #include <mach/imx-uart.h>
 #include <mach/iomux-mx51.h>
+#include <mach/i2c.h>
 #include <mach/mxc_ehci.h>
 
 #include <asm/irq.h>
@@ -64,6 +66,18 @@ static struct pad_desc mx51babbage_pads[] = {
        MX51_PAD_EIM_D27__UART3_RTS,
        MX51_PAD_EIM_D24__UART3_CTS,
 
+       /* I2C1 */
+       MX51_PAD_EIM_D16__I2C1_SDA,
+       MX51_PAD_EIM_D19__I2C1_SCL,
+
+       /* I2C2 */
+       MX51_PAD_KEY_COL4__I2C2_SCL,
+       MX51_PAD_KEY_COL5__I2C2_SDA,
+
+       /* HSI2C */
+       MX51_PAD_I2C1_CLK__HSI2C_CLK,
+       MX51_PAD_I2C1_DAT__HSI2C_DAT,
+
        /* USB HOST1 */
        MX51_PAD_USBH1_CLK__USBH1_CLK,
        MX51_PAD_USBH1_DIR__USBH1_DIR,
@@ -78,7 +92,7 @@ static struct pad_desc mx51babbage_pads[] = {
        MX51_PAD_USBH1_DATA7__USBH1_DATA7,
 
        /* USB HUB reset line*/
-       MX51_PAD_GPIO_1_7__GPIO1_7,
+       MX51_PAD_GPIO_1_7__GPIO_1_7,
 };
 
 /* Serial ports */
@@ -99,6 +113,14 @@ static inline void mxc_init_imx_uart(void)
 }
 #endif /* SERIAL_IMX */
 
+static struct imxi2c_platform_data babbage_i2c_data = {
+       .bitrate = 100000,
+};
+
+static struct imxi2c_platform_data babbage_hsi2c_data = {
+       .bitrate = 400000,
+};
+
 static int gpio_usbh1_active(void)
 {
        struct pad_desc usbh1stp_gpio = MX51_PAD_USBH1_STP__GPIO_1_27;
@@ -230,6 +252,10 @@ static void __init mxc_board_init(void)
        mxc_init_imx_uart();
        platform_add_devices(devices, ARRAY_SIZE(devices));
 
+       mxc_register_device(&mxc_i2c_device0, &babbage_i2c_data);
+       mxc_register_device(&mxc_i2c_device1, &babbage_i2c_data);
+       mxc_register_device(&mxc_hsi2c_device, &babbage_hsi2c_data);
+
        if (otg_mode_host)
                mxc_register_device(&mxc_usbdr_host_device, &dr_utmi_config);
        else {
index d9f612d3370e8849bea8bfb568bc3d0c4f3839ec..6af69def357f92d2f177d19d8fc7bce330ff5666 100644 (file)
@@ -758,6 +758,10 @@ static struct clk gpt_32k_clk = {
        .parent = &ckil_clk,
 };
 
+static struct clk kpp_clk = {
+       .id = 0,
+};
+
 #define DEFINE_CLOCK(name, i, er, es, gr, sr, p, s)    \
        static struct clk name = {                      \
                .id             = i,                    \
@@ -798,6 +802,14 @@ DEFINE_CLOCK(gpt_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG9_OFFSET,
 DEFINE_CLOCK(gpt_ipg_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG10_OFFSET,
        NULL,  NULL, &ipg_clk, NULL);
 
+/* I2C */
+DEFINE_CLOCK(i2c1_clk, 0, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG9_OFFSET,
+       NULL, NULL, &ipg_clk, NULL);
+DEFINE_CLOCK(i2c2_clk, 1, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG10_OFFSET,
+       NULL, NULL, &ipg_clk, NULL);
+DEFINE_CLOCK(hsi2c_clk, 0, MXC_CCM_CCGR1, MXC_CCM_CCGRx_CG11_OFFSET,
+       NULL, NULL, &ipg_clk, NULL);
+
 /* FEC */
 DEFINE_CLOCK(fec_clk, 0, MXC_CCM_CCGR2, MXC_CCM_CCGRx_CG12_OFFSET,
        NULL,  NULL, &ipg_clk, NULL);
@@ -815,12 +827,16 @@ static struct clk_lookup lookups[] = {
        _REGISTER_CLOCK("imx-uart.2", NULL, uart3_clk)
        _REGISTER_CLOCK(NULL, "gpt", gpt_clk)
        _REGISTER_CLOCK("fec.0", NULL, fec_clk)
+       _REGISTER_CLOCK("imx-i2c.0", NULL, i2c1_clk)
+       _REGISTER_CLOCK("imx-i2c.1", NULL, i2c2_clk)
+       _REGISTER_CLOCK("imx-i2c.2", NULL, hsi2c_clk)
        _REGISTER_CLOCK("mxc-ehci.0", "usb", usboh3_clk)
        _REGISTER_CLOCK("mxc-ehci.0", "usb_ahb", ahb_clk)
        _REGISTER_CLOCK("mxc-ehci.1", "usb", usboh3_clk)
        _REGISTER_CLOCK("mxc-ehci.1", "usb_ahb", ahb_clk)
        _REGISTER_CLOCK("fsl-usb2-udc", "usb", usboh3_clk)
        _REGISTER_CLOCK("fsl-usb2-udc", "usb_ahb", ahb_clk)
+       _REGISTER_CLOCK("imx-keypad.0", NULL, kpp_clk)
 };
 
 static void clk_tree_init(void)
index 7130449aacdcff6671cea5fe794a418916bdac34..1920ff4963b211376822d2021d4e4bded6b268f1 100644 (file)
@@ -93,6 +93,64 @@ struct platform_device mxc_fec_device = {
        .resource = mxc_fec_resources,
 };
 
+static struct resource mxc_i2c0_resources[] = {
+       {
+               .start = MX51_I2C1_BASE_ADDR,
+               .end = MX51_I2C1_BASE_ADDR + SZ_4K - 1,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MX51_MXC_INT_I2C1,
+               .end = MX51_MXC_INT_I2C1,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device mxc_i2c_device0 = {
+       .name = "imx-i2c",
+       .id = 0,
+       .num_resources = ARRAY_SIZE(mxc_i2c0_resources),
+       .resource = mxc_i2c0_resources,
+};
+
+static struct resource mxc_i2c1_resources[] = {
+       {
+               .start = MX51_I2C2_BASE_ADDR,
+               .end = MX51_I2C2_BASE_ADDR + SZ_4K - 1,
+               .flags = IORESOURCE_MEM,
+       }, {
+               .start = MX51_MXC_INT_I2C2,
+               .end = MX51_MXC_INT_I2C2,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device mxc_i2c_device1 = {
+       .name = "imx-i2c",
+       .id = 1,
+       .num_resources = ARRAY_SIZE(mxc_i2c1_resources),
+       .resource = mxc_i2c1_resources,
+};
+
+static struct resource mxc_hsi2c_resources[] = {
+       {
+               .start = MX51_HSI2C_DMA_BASE_ADDR,
+               .end = MX51_HSI2C_DMA_BASE_ADDR + SZ_16K - 1,
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start = MX51_MXC_INT_HS_I2C,
+               .end = MX51_MXC_INT_HS_I2C,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+struct platform_device mxc_hsi2c_device = {
+       .name = "imx-i2c",
+       .id = 2,
+       .num_resources = ARRAY_SIZE(mxc_hsi2c_resources),
+       .resource = mxc_hsi2c_resources
+};
+
 static u64 usb_dma_mask = DMA_BIT_MASK(32);
 
 static struct resource usbotg_resources[] = {
@@ -168,34 +226,57 @@ struct platform_device mxc_wdt = {
        .resource = mxc_wdt_resources,
 };
 
+static struct resource mxc_kpp_resources[] = {
+       {
+               .start = MX51_MXC_INT_KPP,
+               .end = MX51_MXC_INT_KPP,
+               .flags = IORESOURCE_IRQ,
+       } , {
+               .start = MX51_KPP_BASE_ADDR,
+               .end = MX51_KPP_BASE_ADDR + 0x8 - 1,
+               .flags = IORESOURCE_MEM,
+       },
+};
+
+struct platform_device mxc_keypad_device = {
+       .name = "imx-keypad",
+       .id = 0,
+       .num_resources = ARRAY_SIZE(mxc_kpp_resources),
+       .resource = mxc_kpp_resources,
+};
+
 static struct mxc_gpio_port mxc_gpio_ports[] = {
        {
                .chip.label = "gpio-0",
                .base = MX51_IO_ADDRESS(MX51_GPIO1_BASE_ADDR),
                .irq = MX51_MXC_INT_GPIO1_LOW,
+               .irq_high = MX51_MXC_INT_GPIO1_HIGH,
                .virtual_irq_start = MXC_GPIO_IRQ_START
        },
        {
                .chip.label = "gpio-1",
                .base = MX51_IO_ADDRESS(MX51_GPIO2_BASE_ADDR),
                .irq = MX51_MXC_INT_GPIO2_LOW,
+               .irq_high = MX51_MXC_INT_GPIO2_HIGH,
                .virtual_irq_start = MXC_GPIO_IRQ_START + 32 * 1
        },
        {
                .chip.label = "gpio-2",
                .base = MX51_IO_ADDRESS(MX51_GPIO3_BASE_ADDR),
                .irq = MX51_MXC_INT_GPIO3_LOW,
+               .irq_high = MX51_MXC_INT_GPIO3_HIGH,
                .virtual_irq_start = MXC_GPIO_IRQ_START + 32 * 2
        },
        {
                .chip.label = "gpio-3",
                .base = MX51_IO_ADDRESS(MX51_GPIO4_BASE_ADDR),
                .irq = MX51_MXC_INT_GPIO4_LOW,
+               .irq_high = MX51_MXC_INT_GPIO4_HIGH,
                .virtual_irq_start = MXC_GPIO_IRQ_START + 32 * 3
        },
 };
 
-int __init mxc_register_gpios(void)
+int __init imx51_register_gpios(void)
 {
        return mxc_gpio_init(mxc_gpio_ports, ARRAY_SIZE(mxc_gpio_ports));
 }
index c879ae71cd5b03e2995b3cee1d45f550d857ca47..e509cfaad1d466b4209fd36a5b01d9b4464a3d1a 100644 (file)
@@ -6,3 +6,7 @@ extern struct platform_device mxc_usbdr_host_device;
 extern struct platform_device mxc_usbh1_device;
 extern struct platform_device mxc_usbdr_udc_device;
 extern struct platform_device mxc_wdt;
+extern struct platform_device mxc_i2c_device0;
+extern struct platform_device mxc_i2c_device1;
+extern struct platform_device mxc_hsi2c_device;
+extern struct platform_device mxc_keypad_device;
diff --git a/arch/arm/mach-mx5/eukrea_mbimx51-baseboard.c b/arch/arm/mach-mx5/eukrea_mbimx51-baseboard.c
new file mode 100644 (file)
index 0000000..ffa93d1
--- /dev/null
@@ -0,0 +1,200 @@
+/*
+ *
+ * Copyright (C) 2010 Eric Bénard <eric@eukrea.com>
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/serial_8250.h>
+#include <linux/i2c.h>
+#include <linux/gpio.h>
+#include <linux/io.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/fsl_devices.h>
+#include <linux/i2c/tsc2007.h>
+#include <linux/leds.h>
+#include <linux/input/matrix_keypad.h>
+
+#include <mach/common.h>
+#include <mach/hardware.h>
+#include <mach/imx-uart.h>
+#include <mach/iomux-mx51.h>
+
+#include <asm/mach/arch.h>
+
+#include "devices.h"
+
+#define MBIMX51_TSC2007_GPIO   (2*32 + 30)
+#define MBIMX51_TSC2007_IRQ    (MXC_INTERNAL_IRQS + MBIMX51_TSC2007_GPIO)
+#define MBIMX51_LED0           (2*32 + 5)
+#define MBIMX51_LED1           (2*32 + 6)
+#define MBIMX51_LED2           (2*32 + 7)
+#define MBIMX51_LED3           (2*32 + 8)
+
+static struct gpio_led mbimx51_leds[] = {
+       {
+               .name                   = "led0",
+               .default_trigger        = "heartbeat",
+               .active_low             = 1,
+               .gpio                   = MBIMX51_LED0,
+       },
+       {
+               .name                   = "led1",
+               .default_trigger        = "nand-disk",
+               .active_low             = 1,
+               .gpio                   = MBIMX51_LED1,
+       },
+       {
+               .name                   = "led2",
+               .default_trigger        = "mmc0",
+               .active_low             = 1,
+               .gpio                   = MBIMX51_LED2,
+       },
+       {
+               .name                   = "led3",
+               .default_trigger        = "default-on",
+               .active_low             = 1,
+               .gpio                   = MBIMX51_LED3,
+       },
+};
+
+static struct gpio_led_platform_data mbimx51_leds_info = {
+       .leds           = mbimx51_leds,
+       .num_leds       = ARRAY_SIZE(mbimx51_leds),
+};
+
+static struct platform_device mbimx51_leds_gpio = {
+       .name   = "leds-gpio",
+       .id     = -1,
+       .dev    = {
+               .platform_data  = &mbimx51_leds_info,
+       },
+};
+
+static struct platform_device *devices[] __initdata = {
+       &mbimx51_leds_gpio,
+};
+
+static struct pad_desc mbimx51_pads[] = {
+       /* UART2 */
+       MX51_PAD_UART2_RXD__UART2_RXD,
+       MX51_PAD_UART2_TXD__UART2_TXD,
+
+       /* UART3 */
+       MX51_PAD_UART3_RXD__UART3_RXD,
+       MX51_PAD_UART3_TXD__UART3_TXD,
+       MX51_PAD_KEY_COL4__UART3_RTS,
+       MX51_PAD_KEY_COL5__UART3_CTS,
+
+       /* TSC2007 IRQ */
+       MX51_PAD_NANDF_D10__GPIO_3_30,
+
+       /* LEDS */
+       MX51_PAD_DISPB2_SER_DIN__GPIO_3_5,
+       MX51_PAD_DISPB2_SER_DIO__GPIO_3_6,
+       MX51_PAD_DISPB2_SER_CLK__GPIO_3_7,
+       MX51_PAD_DISPB2_SER_RS__GPIO_3_8,
+
+       /* KPP */
+       MX51_PAD_KEY_ROW0__KEY_ROW0,
+       MX51_PAD_KEY_ROW1__KEY_ROW1,
+       MX51_PAD_KEY_ROW2__KEY_ROW2,
+       MX51_PAD_KEY_ROW3__KEY_ROW3,
+       MX51_PAD_KEY_COL0__KEY_COL0,
+       MX51_PAD_KEY_COL1__KEY_COL1,
+       MX51_PAD_KEY_COL2__KEY_COL2,
+       MX51_PAD_KEY_COL3__KEY_COL3,
+};
+
+static struct imxuart_platform_data uart_pdata = {
+       .flags = IMXUART_HAVE_RTSCTS,
+};
+
+static int mbimx51_keymap[] = {
+       KEY(0, 0, KEY_1),
+       KEY(0, 1, KEY_2),
+       KEY(0, 2, KEY_3),
+       KEY(0, 3, KEY_UP),
+
+       KEY(1, 0, KEY_4),
+       KEY(1, 1, KEY_5),
+       KEY(1, 2, KEY_6),
+       KEY(1, 3, KEY_LEFT),
+
+       KEY(2, 0, KEY_7),
+       KEY(2, 1, KEY_8),
+       KEY(2, 2, KEY_9),
+       KEY(2, 3, KEY_RIGHT),
+
+       KEY(3, 0, KEY_0),
+       KEY(3, 1, KEY_DOWN),
+       KEY(3, 2, KEY_ESC),
+       KEY(3, 3, KEY_ENTER),
+};
+
+static struct matrix_keymap_data mbimx51_map_data = {
+       .keymap         = mbimx51_keymap,
+       .keymap_size    = ARRAY_SIZE(mbimx51_keymap),
+};
+
+static int tsc2007_get_pendown_state(void)
+{
+       return !gpio_get_value(MBIMX51_TSC2007_GPIO);
+}
+
+struct tsc2007_platform_data tsc2007_data = {
+       .model = 2007,
+       .x_plate_ohms = 180,
+       .get_pendown_state = tsc2007_get_pendown_state,
+};
+
+static struct i2c_board_info mbimx51_i2c_devices[] = {
+       {
+               I2C_BOARD_INFO("tsc2007", 0x48),
+               .irq  = MBIMX51_TSC2007_IRQ,
+               .platform_data = &tsc2007_data,
+       },
+};
+
+/*
+ * baseboard initialization.
+ */
+void __init eukrea_mbimx51_baseboard_init(void)
+{
+       mxc_iomux_v3_setup_multiple_pads(mbimx51_pads,
+                                       ARRAY_SIZE(mbimx51_pads));
+
+       mxc_register_device(&mxc_uart_device1, NULL);
+       mxc_register_device(&mxc_uart_device2, &uart_pdata);
+
+       gpio_request(MBIMX51_LED0, "LED0");
+       gpio_direction_output(MBIMX51_LED0, 1);
+       gpio_free(MBIMX51_LED0);
+       gpio_request(MBIMX51_LED1, "LED1");
+       gpio_direction_output(MBIMX51_LED1, 1);
+       gpio_free(MBIMX51_LED1);
+       gpio_request(MBIMX51_LED2, "LED2");
+       gpio_direction_output(MBIMX51_LED2, 1);
+       gpio_free(MBIMX51_LED2);
+       gpio_request(MBIMX51_LED3, "LED3");
+       gpio_direction_output(MBIMX51_LED3, 1);
+       gpio_free(MBIMX51_LED3);
+
+       platform_add_devices(devices, ARRAY_SIZE(devices));
+
+       mxc_register_device(&mxc_keypad_device, &mbimx51_map_data);
+
+       gpio_request(MBIMX51_TSC2007_GPIO, "tsc2007_irq");
+       gpio_direction_input(MBIMX51_TSC2007_GPIO);
+       set_irq_type(MBIMX51_TSC2007_IRQ, IRQF_TRIGGER_FALLING);
+       i2c_register_board_info(1, mbimx51_i2c_devices,
+                               ARRAY_SIZE(mbimx51_i2c_devices));
+}
index b7677ef80cc4388a4c414c4b7c8e1269137227a6..bc3f30db8d9a0f2df94debe9bf556000f58b0e91 100644 (file)
@@ -65,6 +65,8 @@ void __init mx51_map_io(void)
        iotable_init(mxc_io_desc, ARRAY_SIZE(mxc_io_desc));
 }
 
+int imx51_register_gpios(void);
+
 void __init mx51_init_irq(void)
 {
        unsigned long tzic_addr;
@@ -80,4 +82,5 @@ void __init mx51_init_irq(void)
                panic("unable to map TZIC interrupt controller\n");
 
        tzic_init_irq(tzic_virt);
+       imx51_register_gpios();
 }
index ce4f5905818982580bae7b24fca1a6ea0a67573d..b989baccd67507f76b5aa8dcc5fb7d6a2f67029f 100644 (file)
  * 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 _ARCH_ARM_MACH_MXC91231_CRM_REGS_H_
index 353bd977b393b3e87e21dd83c866776a69479d0b..027af4f0d18aed1a40c97f448f43daa2028efc32 100644 (file)
@@ -135,7 +135,7 @@ static struct mxc_gpio_port mxc_gpio_ports[] = {
        },
 };
 
-int __init mxc_register_gpios(void)
+int __init mxc91231_register_gpios(void)
 {
        return mxc_gpio_init(mxc_gpio_ports, ARRAY_SIZE(mxc_gpio_ports));
 }
index 6becda3ff331ddf4196dc8a6667cbd543decd07e..aeccfd755fee6a9af9307a31a766a31fd091f7d5 100644 (file)
  * 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
- *
  */
 
 #include <linux/mm.h>
@@ -88,7 +83,10 @@ void __init mxc91231_map_io(void)
        iotable_init(mxc_io_desc, ARRAY_SIZE(mxc_io_desc));
 }
 
+int mxc91231_register_gpios(void);
+
 void __init mxc91231_init_irq(void)
 {
+       mxc91231_register_gpios();
        mxc_init_irq(MXC91231_IO_ADDRESS(MXC91231_AVIC_BASE_ADDR));
 }
index f035f4185274160757e11d32377509defbdfb1b7..89f793adf77643093c9e465c35447553102ae295 100644 (file)
@@ -53,6 +53,10 @@ static struct clk clk_default;
        }
 
 static struct clk_lookup lookups[] = {
+       {
+               .con_id         = "apb_pclk",
+               .clk            = &clk_default,
+       },
        CLK(&clk_24, "mtu0"),
        CLK(&clk_24, "mtu1"),
        CLK(&clk_48, "uart0"),
index fdd1dd53fa9ceddcc5738687b36215d31c3b8ca0..0a9d61d2d2293f8b51c32eb82cd4bea5ada9e6d9 100644 (file)
@@ -301,6 +301,7 @@ MACHINE_START(AMS_DELTA, "Amstrad E3 (Delta)")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = ams_delta_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = ams_delta_init_irq,
        .init_machine   = ams_delta_init,
        .timer          = &omap_timer,
index 096f2ed102cbe5aa8fff6a3632022f999776c51d..059bac60b35ae7a3d5d5a59a7e481e549989ae2d 100644 (file)
@@ -378,6 +378,7 @@ MACHINE_START(OMAP_FSAMPLE, "OMAP730 F-Sample")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = omap_fsample_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_fsample_init_irq,
        .init_machine   = omap_fsample_init,
        .timer          = &omap_timer,
index e1195a3467b86106a60c258a429c664ca818569e..7a65684d2a15b52064a7afee5be0926b5d8e0ffd 100644 (file)
@@ -98,6 +98,7 @@ MACHINE_START(OMAP_GENERIC, "Generic OMAP1510/1610/1710")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = omap_generic_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_generic_init_irq,
        .init_machine   = omap_generic_init,
        .timer          = &omap_timer,
index d1100e4f65aca736c6113643c1310cff4bc2a9b4..68b2beda8b99c8ef9e5261e7a658d0968bb7d27b 100644 (file)
@@ -467,6 +467,7 @@ MACHINE_START(OMAP_H2, "TI-H2")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = h2_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = h2_init_irq,
        .init_machine   = h2_init,
        .timer          = &omap_timer,
index a53ab8297d25eb05185b433d310ab2dd415290bf..0b0825fe6751aea72a6ee39e490ab75bf087fd79 100644 (file)
@@ -437,6 +437,7 @@ MACHINE_START(OMAP_H3, "TI OMAP1710 H3 board")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = h3_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = h3_init_irq,
        .init_machine   = h3_init,
        .timer          = &omap_timer,
index 8e313b4b99a9d91145201f1d2e28a4a022a7f151..d70a4f0923f53278858692e2bf48637dbb495a4b 100644 (file)
@@ -304,6 +304,7 @@ MACHINE_START(HERALD, "HTC Herald")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = htcherald_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = htcherald_init_irq,
        .init_machine   = htcherald_init,
        .timer          = &omap_timer,
index 5d12fd35681b24041695fd3a324bb5a8f2d226bc..91064b37859a131e1d71250d941ebb4e3844237f 100644 (file)
@@ -463,6 +463,7 @@ MACHINE_START(OMAP_INNOVATOR, "TI-Innovator")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = innovator_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = innovator_init_irq,
        .init_machine   = innovator_init,
        .timer          = &omap_timer,
index 71e1a3fad0ead110b7947e555af8c652da261695..8c28b10f3dae75b091017600d03c2d1ed67eca07 100644 (file)
@@ -400,6 +400,7 @@ MACHINE_START(NOKIA770, "Nokia 770")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = omap_nokia770_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_nokia770_init_irq,
        .init_machine   = omap_nokia770_init,
        .timer          = &omap_timer,
index 80d862001def595ef2fada032e909a9bcd9aea01..e2a72af30890bbd54850257c3d82df1e5e38339f 100644 (file)
@@ -584,6 +584,7 @@ MACHINE_START(OMAP_OSK, "TI-OSK")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = osk_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = osk_init_irq,
        .init_machine   = osk_init,
        .timer          = &omap_timer,
index 569b4c9085cd8b952f91716ebe7e00984ebe7169..61a2321b97323d200db96f1e6e8ceb73794189ed 100644 (file)
@@ -373,6 +373,7 @@ MACHINE_START(OMAP_PALMTE, "OMAP310 based Palm Tungsten E")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = omap_palmte_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_palmte_init_irq,
        .init_machine   = omap_palmte_init,
        .timer          = &omap_timer,
index 6ad49a2cc1a03af4368628ddef06896786d6c3ae..21c01c6afcc1690faaa3cea3399b085b2e8efc9f 100644 (file)
@@ -321,6 +321,7 @@ MACHINE_START(OMAP_PALMTT, "OMAP1510 based Palm Tungsten|T")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = omap_palmtt_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_palmtt_init_irq,
        .init_machine   = omap_palmtt_init,
        .timer          = &omap_timer,
index 6641de9257efa047cbf02d94e37506675913c354..f324924515332e956e1eebbda1319b54f9a8a407 100644 (file)
@@ -338,10 +338,12 @@ omap_palmz71_map_io(void)
 }
 
 MACHINE_START(OMAP_PALMZ71, "OMAP310 based Palm Zire71")
-       .phys_io = 0xfff00000,
-       .io_pg_offst = ((0xfef00000) >> 18) & 0xfffc,
-       .boot_params = 0x10000100,.map_io = omap_palmz71_map_io,
-       .init_irq = omap_palmz71_init_irq,
-       .init_machine = omap_palmz71_init,
-       .timer = &omap_timer,
+       .phys_io        = 0xfff00000,
+       .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
+       .boot_params    = 0x10000100,
+       .map_io         = omap_palmz71_map_io,
+       .reserve        = omap_reserve,
+       .init_irq       = omap_palmz71_init_irq,
+       .init_machine   = omap_palmz71_init,
+       .timer          = &omap_timer,
 MACHINE_END
index e854d5741c8889daad675ae230bef5848bdcf6fa..8b5ab1fcc405820979ea0e70c2f7a86ed68c17bb 100644 (file)
@@ -339,6 +339,7 @@ MACHINE_START(OMAP_PERSEUS2, "OMAP730 Perseus2")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = omap_perseus2_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_perseus2_init_irq,
        .init_machine   = omap_perseus2_init,
        .timer          = &omap_timer,
index 2fb1e5f8e2ec5c637a992007123842bf7e48d2f3..995566b862bb739c04953e2d3ad94175b494570b 100644 (file)
@@ -423,7 +423,8 @@ MACHINE_START(SX1, "OMAP310 based Siemens SX1")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = omap_sx1_map_io,
-       .init_irq               = omap_sx1_init_irq,
+       .reserve        = omap_reserve,
+       .init_irq       = omap_sx1_init_irq,
        .init_machine   = omap_sx1_init,
        .timer          = &omap_timer,
 MACHINE_END
index 87b9436fe7c0c011972fd24b7da43716a5aad5fd..4c483dc1de5c4fa3ee22f2db095b1b4b4d273e31 100644 (file)
@@ -287,6 +287,7 @@ MACHINE_START(VOICEBLUE, "VoiceBlue OMAP5910")
        .io_pg_offst    = ((0xfef00000) >> 18) & 0xfffc,
        .boot_params    = 0x10000100,
        .map_io         = voiceblue_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = voiceblue_init_irq,
        .init_machine   = voiceblue_init,
        .timer          = &omap_timer,
index d9b8d82530ae165bf18ab272c49ff61a069ae298..0ce3fec2d257c2b6183a4b426608e56679ff556c 100644 (file)
@@ -22,7 +22,6 @@
 
 extern void omap_check_revision(void);
 extern void omap_sram_init(void);
-extern void omapfb_reserve_sdram(void);
 
 /*
  * The machine specific code may provide the extra mapping besides the
@@ -122,7 +121,6 @@ void __init omap1_map_common_io(void)
 #endif
 
        omap_sram_init();
-       omapfb_reserve_sdram();
 }
 
 /*
index a11a575745e44c5bcab1d1fd7cc202afeedd06ea..42f49f785c93811c8956192287159ed711a07115 100644 (file)
@@ -248,6 +248,7 @@ MACHINE_START(OMAP_2430SDP, "OMAP2430 sdp2430 board")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_2430sdp_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_2430sdp_init_irq,
        .init_machine   = omap_2430sdp_init,
        .timer          = &omap_timer,
index f474a80b886733582af7f3dba04929ce02cd561b..dd9c03171a19c3dd0d83c69a9109fb92c18c380c 100644 (file)
@@ -815,6 +815,7 @@ MACHINE_START(OMAP_3430SDP, "OMAP3430 3430SDP board")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_3430sdp_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_3430sdp_init_irq,
        .init_machine   = omap_3430sdp_init,
        .timer          = &omap_timer,
index 504d2bd222fe35ec02bb277f5f87d6af6f18e5e8..57290fb3fcd76d5171c1316b17c944f7df78c3d4 100644 (file)
@@ -108,6 +108,7 @@ MACHINE_START(OMAP_3630SDP, "OMAP 3630SDP board")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_sdp_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_sdp_init_irq,
        .init_machine   = omap_sdp_init,
        .timer          = &omap_timer,
index e4a5d66b83b8bbb5e8f1701bbba5a94f825b9703..4bb2c5d151ec9908164e5263ad7a903342e732f6 100644 (file)
@@ -402,6 +402,7 @@ MACHINE_START(OMAP_4430SDP, "OMAP4430 4430SDP board")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_4430sdp_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_4430sdp_init_irq,
        .init_machine   = omap_4430sdp_init,
        .timer          = &omap_timer,
index af383a8769432fd108bc48efedf5e893e93f60fe..7da92defcde04e0604125da51d320f548f91c82e 100644 (file)
@@ -472,6 +472,7 @@ MACHINE_START(OMAP3517EVM, "OMAP3517/AM3517 EVM")
        .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = am3517_evm_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = am3517_evm_init_irq,
        .init_machine   = am3517_evm_init,
        .timer          = &omap_timer,
index aa69fb999748af3698a6950f9549a59c8260f5a7..bd75642aee65d0828ebf7897806662c20b616c54 100644 (file)
@@ -346,6 +346,7 @@ MACHINE_START(OMAP_APOLLON, "OMAP24xx Apollon")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_apollon_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_apollon_init_irq,
        .init_machine   = omap_apollon_init,
        .timer          = &omap_timer,
index e679a2cc86c3061031923123c21e4189bf028e8a..bc4c3f807068ee76848370482587e6566aa2f482 100644 (file)
@@ -837,6 +837,7 @@ MACHINE_START(CM_T35, "Compulab CM-T35")
        .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = cm_t35_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = cm_t35_init_irq,
        .init_machine   = cm_t35_init,
        .timer          = &omap_timer,
index 77022b58881670fc38bf3c88840a4b925ae0ff03..922b7464807fb964193b5298d2f2f99d98f6e7fd 100644 (file)
@@ -825,6 +825,7 @@ MACHINE_START(DEVKIT8000, "OMAP3 Devkit8000")
        .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = devkit8000_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = devkit8000_init_irq,
        .init_machine   = devkit8000_init,
        .timer          = &omap_timer,
index 16cc06860670ed7cf22c4a6e1d991d6e76fe3b89..9242902d3a43ccf36670f89daee4a2a5677b11ef 100644 (file)
@@ -59,6 +59,7 @@ MACHINE_START(OMAP_GENERIC, "Generic OMAP24xx")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_generic_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_generic_init_irq,
        .init_machine   = omap_generic_init,
        .timer          = &omap_timer,
index 0665f2c8dc8e894a1e949baf2a273e7bef104159..16703fdb3515e73347bb1bb5c1c556295fbce223 100644 (file)
@@ -378,6 +378,7 @@ MACHINE_START(OMAP_H4, "OMAP2420 H4 board")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_h4_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_h4_init_irq,
        .init_machine   = omap_h4_init,
        .timer          = &omap_timer,
index d55c57b761a988e3bb62cc2adeb999709861db2c..759e39d1a702fdc9b84f12a70990e995154bc6d6 100644 (file)
@@ -543,6 +543,7 @@ MACHINE_START(IGEP0020, "IGEP v2 board")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = igep2_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = igep2_init_irq,
        .init_machine   = igep2_init,
        .timer          = &omap_timer,
index fefd7e6e97796a9ede0ce8076de96f9ee437fb9d..9cd2669113e49f548375b09260100e9da078cfd1 100644 (file)
@@ -417,6 +417,7 @@ MACHINE_START(OMAP_LDP, "OMAP LDP board")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_ldp_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_ldp_init_irq,
        .init_machine   = omap_ldp_init,
        .timer          = &omap_timer,
index 3ccc34ebdcc79c11e021b4c80e9fca550bfea037..2565ff08a2218963d1b0213b75127f764e37ea2b 100644 (file)
@@ -667,6 +667,7 @@ MACHINE_START(NOKIA_N800, "Nokia N800")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = n8x0_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = n8x0_init_irq,
        .init_machine   = n8x0_init_machine,
        .timer          = &omap_timer,
@@ -677,6 +678,7 @@ MACHINE_START(NOKIA_N810, "Nokia N810")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = n8x0_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = n8x0_init_irq,
        .init_machine   = n8x0_init_machine,
        .timer          = &omap_timer,
@@ -687,6 +689,7 @@ MACHINE_START(NOKIA_N810_WIMAX, "Nokia N810 WiMAX")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = n8x0_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = n8x0_init_irq,
        .init_machine   = n8x0_init_machine,
        .timer          = &omap_timer,
index 69b154cdc75dcaa2c46d0a33434cfc7c379fd1fc..0ab0c26db4dd063c99966612ca210c80ec6f3092 100644 (file)
@@ -519,6 +519,7 @@ MACHINE_START(OMAP3_BEAGLE, "OMAP3 Beagle Board")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap3_beagle_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap3_beagle_init_irq,
        .init_machine   = omap3_beagle_init,
        .timer          = &omap_timer,
index b952610138121862368aab2296ef30552bdc5528..a3d2e285e116111161939de0c8d2ec689cc5cb8f 100644 (file)
@@ -727,6 +727,7 @@ MACHINE_START(OMAP3EVM, "OMAP3 EVM")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap3_evm_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap3_evm_init_irq,
        .init_machine   = omap3_evm_init,
        .timer          = &omap_timer,
index db06dc910ba755c6988cc11155c3f047dff3c792..c0f4f12eba549458fefc82124dfd3938f9976efe 100644 (file)
@@ -601,6 +601,7 @@ MACHINE_START(OMAP3_PANDORA, "Pandora Handheld Console")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap3pandora_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap3pandora_init_irq,
        .init_machine   = omap3pandora_init,
        .timer          = &omap_timer,
index 2f5f8233dd5b8857bcfddb29d178f802fbd1271f..f05b867c585109392708a6bdb37f49392fbc775c 100644 (file)
@@ -571,6 +571,7 @@ MACHINE_START(TOUCHBOOK, "OMAP3 touchbook Board")
        .io_pg_offst    = ((0xd8000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap3_touchbook_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap3_touchbook_init_irq,
        .init_machine   = omap3_touchbook_init,
        .timer          = &omap_timer,
index 79ac41400c218039193ab8a3384805d74953797a..87acb2f198ecaedf274b18973f6ca1e99f037d96 100644 (file)
@@ -495,6 +495,7 @@ MACHINE_START(OVERO, "Gumstix Overo")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = overo_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = overo_init_irq,
        .init_machine   = overo_init,
        .timer          = &omap_timer,
index 1b86b5bb87a219bc89d3703131c2d70c28181d04..3bd956f9e19f5bb74588dd28fcae16aa047e55de 100644 (file)
@@ -154,6 +154,7 @@ MACHINE_START(NOKIA_RX51, "Nokia RX-51 board")
        .io_pg_offst    = ((0xfa000000) >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = rx51_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = rx51_init_irq,
        .init_machine   = rx51_init,
        .timer          = &omap_timer,
index 803ef14cbf2d64ca3218e56ce4e48572088fe67f..ffe188cb18e90185f306199bae2b6da0acb71a91 100644 (file)
@@ -95,6 +95,7 @@ MACHINE_START(OMAP_ZOOM2, "OMAP Zoom2 board")
        .io_pg_offst    = (ZOOM_UART_VIRT >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_zoom2_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_zoom2_init_irq,
        .init_machine   = omap_zoom2_init,
        .timer          = &omap_timer,
index 33147042485f5f505c7a0906f2b0d94e02a9f460..5b605eba3e7bcf449c9fa62020233e49b8f8ae8a 100644 (file)
@@ -77,6 +77,7 @@ MACHINE_START(OMAP_ZOOM3, "OMAP Zoom3 board")
        .io_pg_offst    = (ZOOM_UART_VIRT >> 18) & 0xfffc,
        .boot_params    = 0x80000100,
        .map_io         = omap_zoom_map_io,
+       .reserve        = omap_reserve,
        .init_irq       = omap_zoom_init_irq,
        .init_machine   = omap_zoom_init,
        .timer          = &omap_timer,
index 41b155acfca7cf2605202f78ffbe45a84ebf594a..d33744117ce2488067b50c739afd701623beb315 100644 (file)
@@ -3166,6 +3166,10 @@ static struct clk uart4_ick_am35xx = {
        .recalc         = &followparent_recalc,
 };
 
+static struct clk dummy_apb_pclk = {
+       .name           = "apb_pclk",
+       .ops            = &clkops_null,
+};
 
 /*
  * clkdev
@@ -3173,6 +3177,7 @@ static struct clk uart4_ick_am35xx = {
 
 /* XXX At some point we should rename this file to clock3xxx_data.c */
 static struct omap_clk omap3xxx_clks[] = {
+       CLK(NULL,       "apb_pclk",     &dummy_apb_pclk,        CK_3XXX),
        CLK(NULL,       "omap_32k_fck", &omap_32k_fck,  CK_3XXX),
        CLK(NULL,       "virt_12m_ck",  &virt_12m_ck,   CK_3XXX),
        CLK(NULL,       "virt_13m_ck",  &virt_13m_ck,   CK_3XXX),
index 3cfb425ea67e86585f66e1595b29e2c28b4d31ea..4e1f53d0b8801cfb799a626d80562d1df0378103 100644 (file)
@@ -33,7 +33,6 @@
 #include <plat/sdrc.h>
 #include <plat/gpmc.h>
 #include <plat/serial.h>
-#include <plat/vram.h>
 
 #include "clock2xxx.h"
 #include "clock3xxx.h"
@@ -241,8 +240,6 @@ static void __init _omap2_map_common_io(void)
 
        omap2_check_revision();
        omap_sram_init();
-       omapfb_reserve_sdram();
-       omap_vram_reserve_sdram();
 }
 
 #ifdef CONFIG_ARCH_OMAP2420
index 905719a677ae31b8be356f356b289569157ec48d..c897e03e413d05eb91c836d0472d9534f71633f7 100644 (file)
@@ -26,6 +26,7 @@ config MACH_KUROBOX_PRO
 config MACH_DNS323
        bool "D-Link DNS-323"
        select I2C_BOARDINFO
+       select PHYLIB
        help
          Say 'Y' here if you want your kernel to support the
          D-Link DNS-323 platform.
index fe0de1698edc95c9e4aedf78aac576d2fc9e69b8..a47100d46a4e88a9f3f41b4d1705ddc397cfe622 100644 (file)
@@ -3,6 +3,10 @@
  *
  * Copyright (C) 2007 Herbert Valerio Riedel <hvr@gnu.org>
  *
+ * Support for HW Rev C1:
+ *
+ * Copyright (C) 2010 Benjamin Herrenschmidt <benh@kernel.crashing.org>
+ *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU Lesser General Public License as
  * published by the Free Software Foundation; either version 2 of the
@@ -23,6 +27,8 @@
 #include <linux/input.h>
 #include <linux/i2c.h>
 #include <linux/ata_platform.h>
+#include <linux/phy.h>
+#include <linux/marvell_phy.h>
 #include <asm/mach-types.h>
 #include <asm/gpio.h>
 #include <asm/mach/arch.h>
@@ -31,6 +37,7 @@
 #include "common.h"
 #include "mpp.h"
 
+/* Rev A1 and B1 */
 #define DNS323_GPIO_LED_RIGHT_AMBER    1
 #define DNS323_GPIO_LED_LEFT_AMBER     2
 #define DNS323_GPIO_SYSTEM_UP          3
 #define DNS323_GPIO_KEY_POWER          9
 #define DNS323_GPIO_KEY_RESET          10
 
+/* Rev C1 */
+#define DNS323C_GPIO_KEY_POWER         1
+#define DNS323C_GPIO_POWER_OFF         2
+#define DNS323C_GPIO_LED_RIGHT_AMBER   8
+#define DNS323C_GPIO_LED_LEFT_AMBER    9
+#define DNS323C_GPIO_LED_POWER         17
+#define DNS323C_GPIO_FAN_BIT1          18
+#define DNS323C_GPIO_FAN_BIT0          19
+
+/* Exposed to userspace, do not change */
+enum {
+       DNS323_REV_A1,  /* 0 */
+       DNS323_REV_B1,  /* 1 */
+       DNS323_REV_C1,  /* 2 */
+};
+
+
 /****************************************************************************
  * PCI setup
  */
@@ -68,21 +92,12 @@ static struct hw_pci dns323_pci __initdata = {
        .map_irq        = dns323_pci_map_irq,
 };
 
-static int __init dns323_dev_id(void)
-{
-       u32 dev, rev;
-
-       orion5x_pcie_id(&dev, &rev);
-
-       return dev;
-}
-
 static int __init dns323_pci_init(void)
 {
-       /* The 5182 doesn't really use its PCI bus, and initialising PCI
+       /* Rev B1 and C1 doesn't really use its PCI bus, and initialising PCI
         * gets in the way of initialising the SATA controller.
         */
-       if (machine_is_dns323() && dns323_dev_id() != MV88F5182_DEV_ID)
+       if (machine_is_dns323() && system_rev == DNS323_REV_A1)
                pci_common_init(&dns323_pci);
 
        return 0;
@@ -221,7 +236,7 @@ static int __init dns323_read_mac_addr(void)
        }
 
        iounmap(mac_page);
-       printk("DNS323: Found ethernet MAC address: ");
+       printk("DNS-323: Found ethernet MAC address: ");
        for (i = 0; i < 6; i++)
                printk("%.2x%s", addr[i], (i < 5) ? ":" : ".\n");
 
@@ -259,12 +274,11 @@ static int dns323_gpio_blink_set(unsigned gpio, int state,
        return 0;
 }
 
-static struct gpio_led dns323_leds[] = {
+static struct gpio_led dns323ab_leds[] = {
        {
                .name = "power:blue",
                .gpio = DNS323_GPIO_LED_POWER2,
-               .default_trigger = "timer",
-               .active_low = 1,
+               .default_trigger = "default-on",
        }, {
                .name = "right:amber",
                .gpio = DNS323_GPIO_LED_RIGHT_AMBER,
@@ -276,9 +290,34 @@ static struct gpio_led dns323_leds[] = {
        },
 };
 
-static struct gpio_led_platform_data dns323_led_data = {
-       .num_leds       = ARRAY_SIZE(dns323_leds),
-       .leds           = dns323_leds,
+
+static struct gpio_led dns323c_leds[] = {
+       {
+               .name = "power:blue",
+               .gpio = DNS323C_GPIO_LED_POWER,
+               .default_trigger = "timer",
+               .active_low = 1,
+       }, {
+               .name = "right:amber",
+               .gpio = DNS323C_GPIO_LED_RIGHT_AMBER,
+               .active_low = 1,
+       }, {
+               .name = "left:amber",
+               .gpio = DNS323C_GPIO_LED_LEFT_AMBER,
+               .active_low = 1,
+       },
+};
+
+
+static struct gpio_led_platform_data dns323ab_led_data = {
+       .num_leds       = ARRAY_SIZE(dns323ab_leds),
+       .leds           = dns323ab_leds,
+       .gpio_blink_set = dns323_gpio_blink_set,
+};
+
+static struct gpio_led_platform_data dns323c_led_data = {
+       .num_leds       = ARRAY_SIZE(dns323c_leds),
+       .leds           = dns323c_leds,
        .gpio_blink_set = dns323_gpio_blink_set,
 };
 
@@ -286,7 +325,7 @@ static struct platform_device dns323_gpio_leds = {
        .name           = "leds-gpio",
        .id             = -1,
        .dev            = {
-               .platform_data  = &dns323_led_data,
+               .platform_data  = &dns323ab_led_data,
        },
 };
 
@@ -294,7 +333,7 @@ static struct platform_device dns323_gpio_leds = {
  * GPIO Attached Keys
  */
 
-static struct gpio_keys_button dns323_buttons[] = {
+static struct gpio_keys_button dns323ab_buttons[] = {
        {
                .code           = KEY_RESTART,
                .gpio           = DNS323_GPIO_KEY_RESET,
@@ -308,9 +347,23 @@ static struct gpio_keys_button dns323_buttons[] = {
        },
 };
 
-static struct gpio_keys_platform_data dns323_button_data = {
-       .buttons        = dns323_buttons,
-       .nbuttons       = ARRAY_SIZE(dns323_buttons),
+static struct gpio_keys_platform_data dns323ab_button_data = {
+       .buttons        = dns323ab_buttons,
+       .nbuttons       = ARRAY_SIZE(dns323ab_buttons),
+};
+
+static struct gpio_keys_button dns323c_buttons[] = {
+       {
+               .code           = KEY_POWER,
+               .gpio           = DNS323C_GPIO_KEY_POWER,
+               .desc           = "Power Button",
+               .active_low     = 1,
+       },
+};
+
+static struct gpio_keys_platform_data dns323c_button_data = {
+       .buttons        = dns323c_buttons,
+       .nbuttons       = ARRAY_SIZE(dns323c_buttons),
 };
 
 static struct platform_device dns323_button_device = {
@@ -318,7 +371,7 @@ static struct platform_device dns323_button_device = {
        .id             = -1,
        .num_resources  = 0,
        .dev            = {
-               .platform_data  = &dns323_button_data,
+               .platform_data  = &dns323ab_button_data,
        },
 };
 
@@ -332,7 +385,7 @@ static struct mv_sata_platform_data dns323_sata_data = {
 /****************************************************************************
  * General Setup
  */
-static struct orion5x_mpp_mode dns323_mv88f5181_mpp_modes[] __initdata = {
+static struct orion5x_mpp_mode dns323a_mpp_modes[] __initdata = {
        {  0, MPP_PCIE_RST_OUTn },
        {  1, MPP_GPIO },               /* right amber LED (sata ch0) */
        {  2, MPP_GPIO },               /* left amber LED (sata ch1) */
@@ -356,7 +409,7 @@ static struct orion5x_mpp_mode dns323_mv88f5181_mpp_modes[] __initdata = {
        { -1 },
 };
 
-static struct orion5x_mpp_mode dns323_mv88f5182_mpp_modes[] __initdata = {
+static struct orion5x_mpp_mode dns323b_mpp_modes[] __initdata = {
        {  0, MPP_UNUSED },
        {  1, MPP_GPIO },               /* right amber LED (sata ch0) */
        {  2, MPP_GPIO },               /* left amber LED (sata ch1) */
@@ -380,15 +433,57 @@ static struct orion5x_mpp_mode dns323_mv88f5182_mpp_modes[] __initdata = {
        { -1 },
 };
 
+static struct orion5x_mpp_mode dns323c_mpp_modes[] __initdata = {
+       {  0, MPP_GPIO },               /* ? input */
+       {  1, MPP_GPIO },               /* input power switch (0 = pressed) */
+       {  2, MPP_GPIO },               /* output power off */
+       {  3, MPP_UNUSED },             /* ? output */
+       {  4, MPP_UNUSED },             /* ? output */
+       {  5, MPP_UNUSED },             /* ? output */
+       {  6, MPP_UNUSED },             /* ? output */
+       {  7, MPP_UNUSED },             /* ? output */
+       {  8, MPP_GPIO },               /* i/o right amber LED */
+       {  9, MPP_GPIO },               /* i/o left amber LED */
+       { 10, MPP_GPIO },               /* input */
+       { 11, MPP_UNUSED },
+       { 12, MPP_SATA_LED },
+       { 13, MPP_SATA_LED },
+       { 14, MPP_SATA_LED },
+       { 15, MPP_SATA_LED },
+       { 16, MPP_UNUSED },
+       { 17, MPP_GPIO },               /* power button LED */
+       { 18, MPP_GPIO },               /* fan speed bit 0 */
+       { 19, MPP_GPIO },               /* fan speed bit 1 */
+       { -1 },
+};
+
+/* Rev C1 Fan speed notes:
+ *
+ * The fan is controlled by 2 GPIOs on this board. The settings
+ * of the bits is as follow:
+ *
+ *  GPIO 18    GPIO 19    Fan
+ *
+ *    0          0        stopped
+ *    0          1        low speed
+ *    1          0        high speed
+ *    1          1        don't do that (*)
+ *
+ * (*) I think the two bits control two feed-in resistors into a fixed
+ *     PWN circuit, setting both bits will basically go a 'bit' faster
+ *     than high speed, but d-link doesn't do it and you may get out of
+ *     HW spec so don't do it.
+ */
+
 /*
- * On the DNS-323 the following devices are attached via I2C:
+ * On the DNS-323 A1 and B1 the following devices are attached via I2C:
  *
  *  i2c addr | chip        | description
  *  0x3e     | GMT G760Af  | fan speed PWM controller
  *  0x48     | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
  *  0x68     | ST M41T80   | RTC w/ alarm
  */
-static struct i2c_board_info __initdata dns323_i2c_devices[] = {
+static struct i2c_board_info __initdata dns323ab_i2c_devices[] = {
        {
                I2C_BOARD_INFO("g760a", 0x3e),
        }, {
@@ -398,36 +493,140 @@ static struct i2c_board_info __initdata dns323_i2c_devices[] = {
        },
 };
 
+/*
+ * On the DNS-323 C1 the following devices are attached via I2C:
+ *
+ *  i2c addr | chip        | description
+ *  0x48     | GMT G751-2f | temp. sensor and therm. watchdog (LM75 compatible)
+ *  0x68     | ST M41T80   | RTC w/ alarm
+ */
+static struct i2c_board_info __initdata dns323c_i2c_devices[] = {
+       {
+               I2C_BOARD_INFO("lm75", 0x48),
+       }, {
+               I2C_BOARD_INFO("m41t80", 0x68),
+       },
+};
+
 /* DNS-323 rev. A specific power off method */
 static void dns323a_power_off(void)
 {
-       pr_info("%s: triggering power-off...\n", __func__);
+       pr_info("DNS-323: Triggering power-off...\n");
        gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
 }
 
 /* DNS-323 rev B specific power off method */
 static void dns323b_power_off(void)
 {
-       pr_info("%s: triggering power-off...\n", __func__);
+       pr_info("DNS-323: Triggering power-off...\n");
        /* Pin has to be changed to 1 and back to 0 to do actual power off. */
        gpio_set_value(DNS323_GPIO_POWER_OFF, 1);
        mdelay(100);
        gpio_set_value(DNS323_GPIO_POWER_OFF, 0);
 }
 
+/* DNS-323 rev. C specific power off method */
+static void dns323c_power_off(void)
+{
+       pr_info("DNS-323: Triggering power-off...\n");
+       gpio_set_value(DNS323C_GPIO_POWER_OFF, 1);
+}
+
+static int dns323c_phy_fixup(struct phy_device *phy)
+{
+       phy->dev_flags |= MARVELL_PHY_M1118_DNS323_LEDS;
+
+       return 0;
+}
+
+static int __init dns323_identify_rev(void)
+{
+       u32 dev, rev, i, reg;
+
+       pr_debug("DNS-323: Identifying board ... \n");
+
+       /* Rev A1 has a 5181 */
+       orion5x_pcie_id(&dev, &rev);
+       if (dev == MV88F5181_DEV_ID) {
+               pr_debug("DNS-323: 5181 found, board is A1\n");
+               return DNS323_REV_A1;
+       }
+       pr_debug("DNS-323: 5182 found, board is B1 or C1, checking PHY...\n");
+
+       /* Rev B1 and C1 both have 5182, let's poke at the eth PHY. This is
+        * a bit gross but we want to do that without links into the eth
+        * driver so let's poke at it directly. We default to rev B1 in
+        * case the accesses fail
+        */
+
+#define ETH_SMI_REG            (ORION5X_ETH_VIRT_BASE + 0x2000 + 0x004)
+#define  SMI_BUSY              0x10000000
+#define  SMI_READ_VALID                0x08000000
+#define  SMI_OPCODE_READ       0x04000000
+#define  SMI_OPCODE_WRITE      0x00000000
+
+       for (i = 0; i < 1000; i++) {
+               reg = readl(ETH_SMI_REG);
+               if (!(reg & SMI_BUSY))
+                       break;
+       }
+       if (i >= 1000) {
+               pr_warning("DNS-323: Timeout accessing PHY, assuming rev B1\n");
+               return DNS323_REV_B1;
+       }
+       writel((3 << 21)        /* phy ID reg */ |
+              (8 << 16)        /* phy addr */ |
+              SMI_OPCODE_READ, ETH_SMI_REG);
+       for (i = 0; i < 1000; i++) {
+               reg = readl(ETH_SMI_REG);
+               if (reg & SMI_READ_VALID)
+                       break;
+       }
+       if (i >= 1000) {
+               pr_warning("DNS-323: Timeout reading PHY, assuming rev B1\n");
+               return DNS323_REV_B1;
+       }
+       pr_debug("DNS-323: Ethernet PHY ID 0x%x\n", reg & 0xffff);
+
+       /* Note: the Marvell tools mask the ID with 0x3f0 before comparison
+        * but I don't see that making a difference here, at least with
+        * any known Marvell PHY ID
+        */
+       switch(reg & 0xfff0) {
+       case 0x0cc0: /* MV88E1111 */
+               return DNS323_REV_B1;
+       case 0x0e10: /* MV88E1118 */
+               return DNS323_REV_C1;
+       default:
+               pr_warning("DNS-323: Unknown PHY ID 0x%04x, assuming rev B1\n",
+                          reg & 0xffff);
+       }
+       return DNS323_REV_B1;
+}
+
 static void __init dns323_init(void)
 {
        /* Setup basic Orion functions. Need to be called early. */
        orion5x_init();
 
+       /* Identify revision */
+       system_rev = dns323_identify_rev();
+       pr_info("DNS-323: Identified HW revision %c1\n", 'A' + system_rev);
+
        /* Just to be tricky, the 5182 has a completely different
         * set of MPP modes to the 5181.
         */
-       if (dns323_dev_id() == MV88F5182_DEV_ID)
-               orion5x_mpp_conf(dns323_mv88f5182_mpp_modes);
-       else {
-               orion5x_mpp_conf(dns323_mv88f5181_mpp_modes);
+       switch(system_rev) {
+       case DNS323_REV_A1:
+               orion5x_mpp_conf(dns323a_mpp_modes);
                writel(0, MPP_DEV_CTRL);                /* DEV_D[31:16] */
+               break;
+       case DNS323_REV_B1:
+               orion5x_mpp_conf(dns323b_mpp_modes);
+               break;
+       case DNS323_REV_C1:
+               orion5x_mpp_conf(dns323c_mpp_modes);
+               break;
        }
 
        /* setup flash mapping
@@ -436,53 +635,96 @@ static void __init dns323_init(void)
        orion5x_setup_dev_boot_win(DNS323_NOR_BOOT_BASE, DNS323_NOR_BOOT_SIZE);
        platform_device_register(&dns323_nor_flash);
 
-       /* The 5181 power LED is active low and requires
-        * DNS323_GPIO_LED_POWER1 to also be low.
-        */
-       if (dns323_dev_id() == MV88F5181_DEV_ID) {
-               dns323_leds[0].active_low = 1;
-               gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable");
-               gpio_direction_output(DNS323_GPIO_LED_POWER1, 0);
+       /* Sort out LEDs, Buttons and i2c devices */
+       switch(system_rev) {
+       case DNS323_REV_A1:
+               /* The 5181 power LED is active low and requires
+                * DNS323_GPIO_LED_POWER1 to also be low.
+                */
+                dns323ab_leds[0].active_low = 1;
+                gpio_request(DNS323_GPIO_LED_POWER1, "Power Led Enable");
+                gpio_direction_output(DNS323_GPIO_LED_POWER1, 0);
+               /* Fall through */
+       case DNS323_REV_B1:
+               i2c_register_board_info(0, dns323ab_i2c_devices,
+                               ARRAY_SIZE(dns323ab_i2c_devices));
+               break;
+       case DNS323_REV_C1:
+               /* Hookup LEDs & Buttons */
+               dns323_gpio_leds.dev.platform_data = &dns323c_led_data;
+               dns323_button_device.dev.platform_data = &dns323c_button_data;
+
+               /* Hookup i2c devices and fan driver */
+               i2c_register_board_info(0, dns323c_i2c_devices,
+                               ARRAY_SIZE(dns323c_i2c_devices));
+               platform_device_register_simple("dns323c-fan", 0, NULL, 0);
+
+               /* Register fixup for the PHY LEDs */
+               phy_register_fixup_for_uid(MARVELL_PHY_ID_88E1118,
+                                          MARVELL_PHY_ID_MASK,
+                                          dns323c_phy_fixup);
        }
 
        platform_device_register(&dns323_gpio_leds);
-
        platform_device_register(&dns323_button_device);
 
-       i2c_register_board_info(0, dns323_i2c_devices,
-                               ARRAY_SIZE(dns323_i2c_devices));
-
        /*
         * Configure peripherals.
         */
        if (dns323_read_mac_addr() < 0)
-               printk("DNS323: Failed to read MAC address\n");
-
+               printk("DNS-323: Failed to read MAC address\n");
        orion5x_ehci0_init();
        orion5x_eth_init(&dns323_eth_data);
        orion5x_i2c_init();
        orion5x_uart0_init();
 
-       /* The 5182 has its SATA controller on-chip, and needs its own little
-        * init routine.
-        */
-       if (dns323_dev_id() == MV88F5182_DEV_ID)
+       /* Remaining GPIOs */
+       switch(system_rev) {
+       case DNS323_REV_A1:
+               /* Poweroff GPIO */
+               if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
+                   gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
+                       pr_err("DNS-323: failed to setup power-off GPIO\n");
+               pm_power_off = dns323a_power_off;
+               break;
+       case DNS323_REV_B1:
+               /* 5182 built-in SATA init */
                orion5x_sata_init(&dns323_sata_data);
 
-       /* The 5182 has flag to indicate the system is up. Without this flag
-        * set, power LED will flash and cannot be controlled via leds-gpio.
-        */
-       if (dns323_dev_id() == MV88F5182_DEV_ID)
-               gpio_set_value(DNS323_GPIO_SYSTEM_UP, 1);
-
-       /* Register dns323 specific power-off method */
-       if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
-           gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
-               pr_err("DNS323: failed to setup power-off GPIO\n");
-       if (dns323_dev_id() == MV88F5182_DEV_ID)
+               /* The DNS323 rev B1 has flag to indicate the system is up.
+                * Without this flag set, power LED will flash and cannot be
+                * controlled via leds-gpio.
+                */
+               if (gpio_request(DNS323_GPIO_SYSTEM_UP, "SYS_READY") == 0)
+                       gpio_direction_output(DNS323_GPIO_SYSTEM_UP, 1);
+
+               /* Poweroff GPIO */
+               if (gpio_request(DNS323_GPIO_POWER_OFF, "POWEROFF") != 0 ||
+                   gpio_direction_output(DNS323_GPIO_POWER_OFF, 0) != 0)
+                       pr_err("DNS-323: failed to setup power-off GPIO\n");
                pm_power_off = dns323b_power_off;
-       else
-               pm_power_off = dns323a_power_off;
+               break;
+       case DNS323_REV_C1:
+               /* 5182 built-in SATA init */
+               orion5x_sata_init(&dns323_sata_data);
+
+               /* Poweroff GPIO */
+               if (gpio_request(DNS323C_GPIO_POWER_OFF, "POWEROFF") != 0 ||
+                   gpio_direction_output(DNS323C_GPIO_POWER_OFF, 0) != 0)
+                       pr_err("DNS-323: failed to setup power-off GPIO\n");
+               pm_power_off = dns323c_power_off;
+
+               /* Now, -this- should theorically be done by the sata_mv driver
+                * once I figure out what's going on there. Maybe the behaviour
+                * of the LEDs should be somewhat passed via the platform_data.
+                * for now, just whack the register and make the LEDs happy
+                *
+                * Note: AFAIK, rev B1 needs the same treatement but I'll let
+                * somebody else test it.
+                */
+               writel(0x5, ORION5X_SATA_VIRT_BASE | 0x2c);
+               break;
+       }
 }
 
 /* Warning: D-Link uses a wrong mach-type (=526) in their bootloader */
index 60e734c104584c3765268b310c18e6df37b84937..a1d6e46ab0355fd5e6410ff4449bbcca28427d81 100644 (file)
@@ -25,6 +25,8 @@ static inline void arch_reset(char mode, const char *cmd)
         */
        orion5x_setbits(RSTOUTn_MASK, (1 << 2));
        orion5x_setbits(CPU_SOFT_RESET, 1);
+       mdelay(200);
+       orion5x_clrbits(CPU_SOFT_RESET, 1);
 }
 
 
index 161fc2d6120705b2f4737c5f1980b7631fd089a5..0f3130599770f2a7008d2de009ea09266620e708 100644 (file)
@@ -35,7 +35,7 @@ static int cmx2xx_it8152_irq_gpio;
  * This is really ugly and we need a better way of specifying
  * DMA-capable regions of memory.
  */
-void __init cmx2xx_pci_adjust_zones(int node, unsigned long *zone_size,
+void __init cmx2xx_pci_adjust_zones(unsigned long *zone_size,
        unsigned long *zhole_size)
 {
        unsigned int sz = SZ_64M >> PAGE_SHIFT;
@@ -46,7 +46,7 @@ void __init cmx2xx_pci_adjust_zones(int node, unsigned long *zone_size,
                /*
                 * Only adjust if > 64M on current system
                 */
-               if (node || (zone_size[0] <= sz))
+               if (zone_size[0] <= sz)
                        return;
 
                zone_size[1] = zone_size[0] - sz;
index 51ffa6afb67530e5cde74659319584ac52646593..461ba4080155414d6e64b8d0f61f4dcee49a24fa 100644 (file)
@@ -715,7 +715,6 @@ static void __init fixup_corgi(struct machine_desc *desc,
        sharpsl_save_param();
        mi->nr_banks=1;
        mi->bank[0].start = 0xa0000000;
-       mi->bank[0].node = 0;
        if (machine_is_corgi())
                mi->bank[0].size = (32*1024*1024);
        else
index 96ed13081639598335309b23b992751d27102ea5..a0ab3082a0009d31b3837f1234f6f4175cde6a8b 100644 (file)
@@ -34,7 +34,6 @@ void __init eseries_fixup(struct machine_desc *desc,
 {
        mi->nr_banks=1;
        mi->bank[0].start = 0xa0000000;
-       mi->bank[0].node = 0;
        if (machine_is_e800())
                mi->bank[0].size = (128*1024*1024);
        else
index 890fb90a672f5e957af6f9d75f78425f4d371fd5..c6305c5b8a72c1497ee05aee42d7795b07513c94 100644 (file)
@@ -26,8 +26,7 @@ extern unsigned int get_clk_frequency_khz(int info);
 
 #define SET_BANK(__nr,__start,__size) \
        mi->bank[__nr].start = (__start), \
-       mi->bank[__nr].size = (__size), \
-       mi->bank[__nr].node = (((unsigned)(__start) - PHYS_OFFSET) >> 27)
+       mi->bank[__nr].size = (__size)
 
 #define ARRAY_AND_SIZE(x)      (x), ARRAY_SIZE(x)
 
index f626730ee42e11a8071149677b43f55fb85666a7..92361a66b223d9f62243074d26ee534a131cba64 100644 (file)
  */
 #define PHYS_OFFSET    UL(0xa0000000)
 
-/*
- * The nodes are matched with the physical SDRAM banks as follows:
- *
- *     node 0:  0xa0000000-0xa3ffffff  -->  0xc0000000-0xc3ffffff
- *     node 1:  0xa4000000-0xa7ffffff  -->  0xc4000000-0xc7ffffff
- *     node 2:  0xa8000000-0xabffffff  -->  0xc8000000-0xcbffffff
- *     node 3:  0xac000000-0xafffffff  -->  0xcc000000-0xcfffffff
- *
- * This needs a node mem size of 26 bits.
- */
-#define NODE_MEM_SIZE_BITS     26
-
 #if !defined(__ASSEMBLY__) && defined(CONFIG_MACH_ARMCORE) && defined(CONFIG_PCI)
-void cmx2xx_pci_adjust_zones(int node, unsigned long *size,
-                            unsigned long *holes);
+void cmx2xx_pci_adjust_zones(unsigned long *size, unsigned long *holes);
 
-#define arch_adjust_zones(node, size, holes) \
-       cmx2xx_pci_adjust_zones(node, size, holes)
+#define arch_adjust_zones(size, holes) \
+       cmx2xx_pci_adjust_zones(size, holes)
 
 #define ISA_DMA_THRESHOLD      (PHYS_OFFSET + SZ_64M - 1)
 #define MAX_DMA_ADDRESS                (PAGE_OFFSET + SZ_64M)
index 5305a3993e694b77666920db5e1581a1abb503fc..5e92d84fe50d0805be94a07f583c40ee46f0e6c4 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/irq.h>
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
+#include <linux/memblock.h>
 #include <linux/pda_power.h>
 #include <linux/pwm_backlight.h>
 #include <linux/gpio.h>
@@ -396,6 +397,11 @@ static void __init palmt5_udc_init(void)
        }
 }
 
+static void __init palmt5_reserve(void)
+{
+       memblock_reserve(0xa0200000, 0x1000);
+}
+
 static void __init palmt5_init(void)
 {
        pxa2xx_mfp_config(ARRAY_AND_SIZE(palmt5_pin_config));
@@ -421,6 +427,7 @@ MACHINE_START(PALMT5, "Palm Tungsten|T5")
        .io_pg_offst    = (io_p2v(0x40000000) >> 18) & 0xfffc,
        .boot_params    = 0xa0000100,
        .map_io         = pxa_map_io,
+       .reserve        = palmt5_reserve,
        .init_irq       = pxa27x_init_irq,
        .timer          = &pxa_timer,
        .init_machine   = palmt5_init
index d8b4469607a1e1794a1775238bddd8c478e99e4a..3d0c9cc2a40648a049a3ccc81a34c5f03f4126de 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/irq.h>
 #include <linux/gpio_keys.h>
 #include <linux/input.h>
+#include <linux/memblock.h>
 #include <linux/pda_power.h>
 #include <linux/pwm_backlight.h>
 #include <linux/gpio.h>
@@ -633,6 +634,12 @@ static void __init treo_lcd_power_init(void)
        treo_lcd_screen.pxafb_lcd_power = treo_lcd_power;
 }
 
+static void __init treo_reserve(void)
+{
+       memblock_reserve(0xa0000000, 0x1000);
+       memblock_reserve(0xa2000000, 0x1000);
+}
+
 static void __init treo_init(void)
 {
        pxa_set_ffuart_info(NULL);
@@ -668,6 +675,7 @@ MACHINE_START(TREO680, "Palm Treo 680")
        .io_pg_offst    = io_p2v(0x40000000),
        .boot_params    = 0xa0000100,
        .map_io         = pxa_map_io,
+       .reserve        = treo_reserve,
        .init_irq       = pxa27x_init_irq,
        .timer          = &pxa_timer,
        .init_machine   = treo680_init,
@@ -691,6 +699,7 @@ MACHINE_START(CENTRO, "Palm Centro 685")
        .io_pg_offst    = io_p2v(0x40000000),
        .boot_params    = 0xa0000100,
        .map_io         = pxa_map_io,
+       .reserve        = treo_reserve,
        .init_irq       = pxa27x_init_irq,
        .timer          = &pxa_timer,
        .init_machine   = centro_init,
index f4abdaafdac4d5c552bd7aa72421b8f8bd97a263..bc2758b54446fc5cc38db451fc70a9ed77d0511a 100644 (file)
@@ -463,7 +463,6 @@ static void __init fixup_poodle(struct machine_desc *desc,
        sharpsl_save_param();
        mi->nr_banks=1;
        mi->bank[0].start = 0xa0000000;
-       mi->bank[0].node = 0;
        mi->bank[0].size = (32*1024*1024);
 }
 
index c1048a35f187e990984a83111110671241ff1f93..51756c723557e8c25eee690aa57e252a1aa08376 100644 (file)
@@ -847,7 +847,6 @@ static void __init fixup_spitz(struct machine_desc *desc,
        sharpsl_save_param();
        mi->nr_banks = 1;
        mi->bank[0].start = 0xa0000000;
-       mi->bank[0].node = 0;
        mi->bank[0].size = (64*1024*1024);
 }
 
index 7512b822c6cac0f1b0473a7ec029a66a45b33030..83cc3a18c2e9a0ded180a0b223f29167b3a290f7 100644 (file)
@@ -948,7 +948,6 @@ static void __init fixup_tosa(struct machine_desc *desc,
        sharpsl_save_param();
        mi->nr_banks=1;
        mi->bank[0].start = 0xa0000000;
-       mi->bank[0].node = 0;
        mi->bank[0].size = (64*1024*1024);
 }
 
index 02e9fdeb8faf26891bdf43cb5846ae717fb720ea..2fa38df284140e08099739d55305a93e7899ebe3 100644 (file)
@@ -61,12 +61,11 @@ void __iomem *gic_cpu_base_addr;
 /*
  * Adjust the zones if there are restrictions for DMA access.
  */
-void __init realview_adjust_zones(int node, unsigned long *size,
-                                 unsigned long *hole)
+void __init realview_adjust_zones(unsigned long *size, unsigned long *hole)
 {
        unsigned long dma_size = SZ_256M >> PAGE_SHIFT;
 
-       if (!machine_is_realview_pbx() || node || (size[0] <= dma_size))
+       if (!machine_is_realview_pbx() || size[0] <= dma_size)
                return;
 
        size[ZONE_NORMAL] = size[0] - dma_size;
@@ -232,6 +231,21 @@ static unsigned int realview_mmc_status(struct device *dev)
        struct amba_device *adev = container_of(dev, struct amba_device, dev);
        u32 mask;
 
+       if (machine_is_realview_pb1176()) {
+               static bool inserted = false;
+
+               /*
+                * The PB1176 does not have the status register,
+                * assume it is inserted at startup, then invert
+                * for each call so card insertion/removal will
+                * be detected anyway. This will not be called if
+                * GPIO on PL061 is active, which is the proper
+                * way to do this on the PB1176.
+                */
+               inserted = !inserted;
+               return inserted ? 0 : 1;
+       }
+
        if (adev->res.start == REALVIEW_MMCI0_BASE)
                mask = 1;
        else
@@ -300,8 +314,13 @@ static struct clk ref24_clk = {
        .rate   = 24000000,
 };
 
+static struct clk dummy_apb_pclk;
+
 static struct clk_lookup lookups[] = {
-       {       /* UART0 */
+       {       /* Bus clock */
+               .con_id         = "apb_pclk",
+               .clk            = &dummy_apb_pclk,
+       }, {    /* UART0 */
                .dev_id         = "dev:uart0",
                .clk            = &ref24_clk,
        }, {    /* UART1 */
@@ -313,6 +332,12 @@ static struct clk_lookup lookups[] = {
        }, {    /* UART3 */
                .dev_id         = "fpga:uart3",
                .clk            = &ref24_clk,
+       }, {    /* UART3 is on the dev chip in PB1176 */
+               .dev_id         = "dev:uart3",
+               .clk            = &ref24_clk,
+       }, {    /* UART4 only exists in PB1176 */
+               .dev_id         = "fpga:uart4",
+               .clk            = &ref24_clk,
        }, {    /* KMI0 */
                .dev_id         = "fpga:kmi0",
                .clk            = &ref24_clk,
@@ -322,12 +347,15 @@ static struct clk_lookup lookups[] = {
        }, {    /* MMC0 */
                .dev_id         = "fpga:mmc0",
                .clk            = &ref24_clk,
-       }, {    /* EB:CLCD */
+       }, {    /* CLCD is in the PB1176 and EB DevChip */
                .dev_id         = "dev:clcd",
                .clk            = &oscvco_clk,
        }, {    /* PB:CLCD */
                .dev_id         = "issp:clcd",
                .clk            = &oscvco_clk,
+       }, {    /* SSP */
+               .dev_id         = "dev:ssp0",
+               .clk            = &ref24_clk,
        }
 };
 
@@ -342,7 +370,7 @@ static int __init clk_init(void)
 
        return 0;
 }
-arch_initcall(clk_init);
+core_initcall(clk_init);
 
 /*
  * CLCD support.
index 2f5ccb298858def61458ed544fdac81383718982..002ab5d8c11c31705ce2f419b16a0fa9b23ccfa8 100644 (file)
@@ -26,6 +26,7 @@
 /*
  * Peripheral addresses
  */
+#define REALVIEW_PB1176_UART4_BASE             0x10009000 /* UART 4 */
 #define REALVIEW_PB1176_SCTL_BASE              0x10100000 /* System controller */
 #define REALVIEW_PB1176_SMC_BASE               0x10111000 /* SMC */
 #define REALVIEW_PB1176_DMC_BASE               0x10109000 /* DMC configuration */
index 830055bb86289860626fd5cbbfb08a3c64bfe04e..5c3c625e3e04f3b84db19f25a3c1c849f3833a5b 100644 (file)
@@ -40,6 +40,7 @@
 #define IRQ_DC1176_L2CC                (IRQ_DC1176_GIC_START + 13)
 #define IRQ_DC1176_RTC         (IRQ_DC1176_GIC_START + 14)
 #define IRQ_DC1176_CLCD                (IRQ_DC1176_GIC_START + 15)     /* CLCD controller */
+#define IRQ_DC1176_SSP         (IRQ_DC1176_GIC_START + 17)     /* SSP port */
 #define IRQ_DC1176_UART0       (IRQ_DC1176_GIC_START + 18)     /* UART 0 on development chip */
 #define IRQ_DC1176_UART1       (IRQ_DC1176_GIC_START + 19)     /* UART 1 on development chip */
 #define IRQ_DC1176_UART2       (IRQ_DC1176_GIC_START + 20)     /* UART 2 on development chip */
@@ -73,7 +74,6 @@
 #define IRQ_PB1176_RTC         (IRQ_PB1176_GIC_START + 25)     /* Real Time Clock */
 
 #define IRQ_PB1176_GPIO0       -1
-#define IRQ_PB1176_SSP         -1
 #define IRQ_PB1176_SCTL                -1
 
 #define NR_GIC_PB1176          2
index 2417bbcf97fd267ff236c09f31d71ef86ad2a047..5dafc157b276207f91837923cd2efd51762820cd 100644 (file)
 #endif
 
 #if !defined(__ASSEMBLY__) && defined(CONFIG_ZONE_DMA)
-extern void realview_adjust_zones(int node, unsigned long *size,
-                                 unsigned long *hole);
-#define arch_adjust_zones(node, size, hole) \
-       realview_adjust_zones(node, size, hole)
+extern void realview_adjust_zones(unsigned long *size, unsigned long *hole);
+#define arch_adjust_zones(size, hole) \
+       realview_adjust_zones(size, hole)
 
 #define ISA_DMA_THRESHOLD      (PHYS_OFFSET + SZ_256M - 1)
 #define MAX_DMA_ADDRESS                (PAGE_OFFSET + SZ_256M)
index 4425018fab828c864e662dfb4bfd5db369a76a15..991c1f8390e2a8eccfbbfae39ccab3768a7badbe 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/amba/mmci.h>
+#include <linux/amba/pl022.h>
 #include <linux/io.h>
 
 #include <mach/hardware.h>
@@ -129,6 +130,12 @@ static struct pl061_platform_data gpio2_plat_data = {
        .irq_base       = -1,
 };
 
+static struct pl022_ssp_controller ssp0_plat_data = {
+       .bus_id = 0,
+       .enable_dma = 0,
+       .num_chipselect = 1,
+};
+
 /*
  * RealView EB AMBA devices
  */
@@ -213,7 +220,7 @@ AMBA_DEVICE(sci0,  "dev:sci0",  SCI,      NULL);
 AMBA_DEVICE(uart0, "dev:uart0", EB_UART0, NULL);
 AMBA_DEVICE(uart1, "dev:uart1", EB_UART1, NULL);
 AMBA_DEVICE(uart2, "dev:uart2", EB_UART2, NULL);
-AMBA_DEVICE(ssp0,  "dev:ssp0",  EB_SSP,   NULL);
+AMBA_DEVICE(ssp0,  "dev:ssp0",  EB_SSP,   &ssp0_plat_data);
 
 static struct amba_device *amba_devs[] __initdata = {
        &dmac_device,
@@ -324,6 +331,26 @@ static struct platform_device pmu_device = {
        .resource               = pmu_resources,
 };
 
+static struct resource char_lcd_resources[] = {
+       {
+               .start = REALVIEW_CHAR_LCD_BASE,
+               .end   = (REALVIEW_CHAR_LCD_BASE + SZ_4K - 1),
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start  = IRQ_EB_CHARLCD,
+               .end    = IRQ_EB_CHARLCD,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device char_lcd_device = {
+       .name           =       "arm-charlcd",
+       .id             =       -1,
+       .num_resources  =       ARRAY_SIZE(char_lcd_resources),
+       .resource       =       char_lcd_resources,
+};
+
 static void __init gic_init_irq(void)
 {
        if (core_tile_eb11mp() || core_tile_a9mp()) {
@@ -442,6 +469,7 @@ static void __init realview_eb_init(void)
 
        realview_flash_register(&realview_eb_flash_resource, 1);
        platform_device_register(&realview_i2c_device);
+       platform_device_register(&char_lcd_device);
        eth_device_register();
        realview_usb_register(realview_eb_isp1761_resources);
 
index 099a1f125cf8f6c10b1720ccdcee7623ff5a73ad..d2be12eb829eb3b759be8a37bc8020df9f01d253 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/amba/mmci.h>
+#include <linux/amba/pl022.h>
 #include <linux/io.h>
 
 #include <mach/hardware.h>
@@ -123,6 +124,12 @@ static struct pl061_platform_data gpio2_plat_data = {
        .irq_base       = -1,
 };
 
+static struct pl022_ssp_controller ssp0_plat_data = {
+       .bus_id = 0,
+       .enable_dma = 0,
+       .num_chipselect = 1,
+};
+
 /*
  * RealView PB1176 AMBA devices
  */
@@ -144,8 +151,6 @@ static struct pl061_platform_data gpio2_plat_data = {
 #define MPMC_DMA       { 0, 0 }
 #define PB1176_CLCD_IRQ        { IRQ_DC1176_CLCD, NO_IRQ }
 #define PB1176_CLCD_DMA        { 0, 0 }
-#define DMAC_IRQ       { IRQ_PB1176_DMAC, NO_IRQ }
-#define DMAC_DMA       { 0, 0 }
 #define SCTL_IRQ       { NO_IRQ, NO_IRQ }
 #define SCTL_DMA       { 0, 0 }
 #define PB1176_WATCHDOG_IRQ    { IRQ_DC1176_WATCHDOG, NO_IRQ }
@@ -166,7 +171,9 @@ static struct pl061_platform_data gpio2_plat_data = {
 #define PB1176_UART2_DMA       { 11, 10 }
 #define PB1176_UART3_IRQ       { IRQ_DC1176_UART3, NO_IRQ }
 #define PB1176_UART3_DMA       { 0x86, 0x87 }
-#define PB1176_SSP_IRQ         { IRQ_PB1176_SSP, NO_IRQ }
+#define PB1176_UART4_IRQ       { IRQ_PB1176_UART4, NO_IRQ }
+#define PB1176_UART4_DMA       { 0, 0 }
+#define PB1176_SSP_IRQ         { IRQ_DC1176_SSP, NO_IRQ }
 #define PB1176_SSP_DMA         { 9, 8 }
 
 /* FPGA Primecells */
@@ -174,7 +181,7 @@ AMBA_DEVICE(aaci,   "fpga:aaci",    AACI,           NULL);
 AMBA_DEVICE(mmc0,      "fpga:mmc0",    MMCI0,          &realview_mmc0_plat_data);
 AMBA_DEVICE(kmi0,      "fpga:kmi0",    KMI0,           NULL);
 AMBA_DEVICE(kmi1,      "fpga:kmi1",    KMI1,           NULL);
-AMBA_DEVICE(uart3,     "fpga:uart3",   PB1176_UART3,   NULL);
+AMBA_DEVICE(uart4,     "fpga:uart4",   PB1176_UART4,   NULL);
 
 /* DevChip Primecells */
 AMBA_DEVICE(smc,       "dev:smc",      PB1176_SMC,     NULL);
@@ -188,18 +195,16 @@ AMBA_DEVICE(sci0, "dev:sci0",     SCI,            NULL);
 AMBA_DEVICE(uart0,     "dev:uart0",    PB1176_UART0,   NULL);
 AMBA_DEVICE(uart1,     "dev:uart1",    PB1176_UART1,   NULL);
 AMBA_DEVICE(uart2,     "dev:uart2",    PB1176_UART2,   NULL);
-AMBA_DEVICE(ssp0,      "dev:ssp0",     PB1176_SSP,     NULL);
-
-/* Primecells on the NEC ISSP chip */
-AMBA_DEVICE(clcd,      "issp:clcd",    PB1176_CLCD,    &clcd_plat_data);
-//AMBA_DEVICE(dmac,    "issp:dmac",    PB1176_DMAC,    NULL);
+AMBA_DEVICE(uart3,     "dev:uart3",    PB1176_UART3,   NULL);
+AMBA_DEVICE(ssp0,      "dev:ssp0",     PB1176_SSP,     &ssp0_plat_data);
+AMBA_DEVICE(clcd,      "dev:clcd",     PB1176_CLCD,    &clcd_plat_data);
 
 static struct amba_device *amba_devs[] __initdata = {
-//     &dmac_device,
        &uart0_device,
        &uart1_device,
        &uart2_device,
        &uart3_device,
+       &uart4_device,
        &smc_device,
        &clcd_device,
        &sctl_device,
@@ -276,6 +281,26 @@ static struct platform_device pmu_device = {
        .resource               = &pmu_resource,
 };
 
+static struct resource char_lcd_resources[] = {
+       {
+               .start = REALVIEW_CHAR_LCD_BASE,
+               .end   = (REALVIEW_CHAR_LCD_BASE + SZ_4K - 1),
+               .flags = IORESOURCE_MEM,
+       },
+       {
+               .start  = IRQ_PB1176_CHARLCD,
+               .end    = IRQ_PB1176_CHARLCD,
+               .flags  = IORESOURCE_IRQ,
+       },
+};
+
+static struct platform_device char_lcd_device = {
+       .name           =       "arm-charlcd",
+       .id             =       -1,
+       .num_resources  =       ARRAY_SIZE(char_lcd_resources),
+       .resource       =       char_lcd_resources,
+};
+
 static void __init gic_init_irq(void)
 {
        /* ARM1176 DevChip GIC, primary */
@@ -338,6 +363,7 @@ static void __init realview_pb1176_init(void)
        platform_device_register(&realview_i2c_device);
        realview_usb_register(realview_pb1176_isp1761_resources);
        platform_device_register(&pmu_device);
+       platform_device_register(&char_lcd_device);
 
        for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
                struct amba_device *d = amba_devs[i];
index 0e07a5ccb75f56de33bec477f242d93d88bca448..d591bc00b86ec74147b0ff0b8c7bb85e99d52041 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/amba/mmci.h>
+#include <linux/amba/pl022.h>
 #include <linux/io.h>
 
 #include <mach/hardware.h>
@@ -124,6 +125,12 @@ static struct pl061_platform_data gpio2_plat_data = {
        .irq_base       = -1,
 };
 
+static struct pl022_ssp_controller ssp0_plat_data = {
+       .bus_id = 0,
+       .enable_dma = 0,
+       .num_chipselect = 1,
+};
+
 /*
  * RealView PB11MPCore AMBA devices
  */
@@ -190,7 +197,7 @@ AMBA_DEVICE(sci0,   "dev:sci0",     SCI,            NULL);
 AMBA_DEVICE(uart0,     "dev:uart0",    PB11MP_UART0,   NULL);
 AMBA_DEVICE(uart1,     "dev:uart1",    PB11MP_UART1,   NULL);
 AMBA_DEVICE(uart2,     "dev:uart2",    PB11MP_UART2,   NULL);
-AMBA_DEVICE(ssp0,      "dev:ssp0",     PB11MP_SSP,     NULL);
+AMBA_DEVICE(ssp0,      "dev:ssp0",     PB11MP_SSP,     &ssp0_plat_data);
 
 /* Primecells on the NEC ISSP chip */
 AMBA_DEVICE(clcd,      "issp:clcd",    PB11MP_CLCD,    &clcd_plat_data);
index ac2f06f1ca500e9bd26603b21ba6c6badf046e11..6c37621217bc916fba02af26a8d3163c4b1d4aec 100644 (file)
@@ -25,6 +25,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/amba/mmci.h>
+#include <linux/amba/pl022.h>
 #include <linux/io.h>
 
 #include <asm/irq.h>
@@ -114,6 +115,12 @@ static struct pl061_platform_data gpio2_plat_data = {
        .irq_base       = -1,
 };
 
+static struct pl022_ssp_controller ssp0_plat_data = {
+       .bus_id = 0,
+       .enable_dma = 0,
+       .num_chipselect = 1,
+};
+
 /*
  * RealView PBA8Core AMBA devices
  */
@@ -180,7 +187,7 @@ AMBA_DEVICE(sci0,   "dev:sci0",     SCI,            NULL);
 AMBA_DEVICE(uart0,     "dev:uart0",    PBA8_UART0,     NULL);
 AMBA_DEVICE(uart1,     "dev:uart1",    PBA8_UART1,     NULL);
 AMBA_DEVICE(uart2,     "dev:uart2",    PBA8_UART2,     NULL);
-AMBA_DEVICE(ssp0,      "dev:ssp0",     PBA8_SSP,       NULL);
+AMBA_DEVICE(ssp0,      "dev:ssp0",     PBA8_SSP,       &ssp0_plat_data);
 
 /* Primecells on the NEC ISSP chip */
 AMBA_DEVICE(clcd,      "issp:clcd",    PBA8_CLCD,      &clcd_plat_data);
index 08fd683adc4ced929eb255fd8da2e3b733850a87..9428eff0b116addda238d99d492cbe9d80c6b8a5 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/amba/bus.h>
 #include <linux/amba/pl061.h>
 #include <linux/amba/mmci.h>
+#include <linux/amba/pl022.h>
 #include <linux/io.h>
 
 #include <asm/irq.h>
@@ -136,6 +137,12 @@ static struct pl061_platform_data gpio2_plat_data = {
        .irq_base       = -1,
 };
 
+static struct pl022_ssp_controller ssp0_plat_data = {
+       .bus_id = 0,
+       .enable_dma = 0,
+       .num_chipselect = 1,
+};
+
 /*
  * RealView PBXCore AMBA devices
  */
@@ -202,7 +209,7 @@ AMBA_DEVICE(sci0,   "dev:sci0",     SCI,            NULL);
 AMBA_DEVICE(uart0,     "dev:uart0",    PBX_UART0,      NULL);
 AMBA_DEVICE(uart1,     "dev:uart1",    PBX_UART1,      NULL);
 AMBA_DEVICE(uart2,     "dev:uart2",    PBX_UART2,      NULL);
-AMBA_DEVICE(ssp0,      "dev:ssp0",     PBX_SSP,        NULL);
+AMBA_DEVICE(ssp0,      "dev:ssp0",     PBX_SSP,        &ssp0_plat_data);
 
 /* Primecells on the NEC ISSP chip */
 AMBA_DEVICE(clcd,      "issp:clcd",    PBX_CLCD,       &clcd_plat_data);
index 779b45b3f80fdca1f6815782eef8b8dfa81b4841..3ba3bab139d0917ce45feaeb079573428f8a2af2 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/types.h>
 #include <linux/interrupt.h>
 #include <linux/list.h>
+#include <linux/memblock.h>
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/sysdev.h>
@@ -304,6 +305,13 @@ static void __init h1940_map_io(void)
        s3c_pm_init();
 }
 
+/* H1940 and RX3715 need to reserve this for suspend */
+static void __init h1940_reserve(void)
+{
+       memblock_reserve(0x30003000, 0x1000);
+       memblock_reserve(0x30081000, 0x1000);
+}
+
 static void __init h1940_init_irq(void)
 {
        s3c24xx_init_irq();
@@ -346,6 +354,7 @@ MACHINE_START(H1940, "IPAQ-H1940")
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
        .map_io         = h1940_map_io,
+       .reserve        = h1940_reserve,
        .init_irq       = h1940_init_irq,
        .init_machine   = h1940_init,
        .timer          = &s3c24xx_timer,
index ba93a356a83998a2b6e0ab2dfc83be7945321345..054c9f92232aa676dad11c0b86359ad21ef47fa6 100644 (file)
@@ -119,7 +119,6 @@ static void __init smdk2413_fixup(struct machine_desc *desc,
                mi->nr_banks=1;
                mi->bank[0].start = 0x30000000;
                mi->bank[0].size = SZ_64M;
-               mi->bank[0].node = 0;
        }
 }
 
index 3ca9265b699716f518d6d5b9e28f4e6f3c9e3d53..f291ac25d31252a8882bc632434a2c03f71e0361 100644 (file)
@@ -137,7 +137,6 @@ static void __init vstms_fixup(struct machine_desc *desc,
                mi->nr_banks=1;
                mi->bank[0].start = 0x30000000;
                mi->bank[0].size = SZ_64M;
-               mi->bank[0].node = 0;
        }
 }
 
index 8603b577a24b7673703db6992e2a4e3d7549e8c6..142d1f92117651e60fdad7e55fcc52997e430962 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/types.h>
 #include <linux/interrupt.h>
 #include <linux/list.h>
+#include <linux/memblock.h>
 #include <linux/delay.h>
 #include <linux/timer.h>
 #include <linux/init.h>
@@ -570,12 +571,20 @@ static void __init rx1950_init_machine(void)
        platform_add_devices(rx1950_devices, ARRAY_SIZE(rx1950_devices));
 }
 
+/* H1940 and RX3715 need to reserve this for suspend */
+static void __init rx1950_reserve(void)
+{
+       memblock_reserve(0x30003000, 0x1000);
+       memblock_reserve(0x30081000, 0x1000);
+}
+
 MACHINE_START(RX1950, "HP iPAQ RX1950")
     /* Maintainers: Vasily Khoruzhick */
     .phys_io = S3C2410_PA_UART,
        .io_pg_offst = (((u32) S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params = S3C2410_SDRAM_PA + 0x100,
        .map_io = rx1950_map_io,
+       .reserve        = rx1950_reserve,
        .init_irq = s3c24xx_init_irq,
        .init_machine = rx1950_init_machine,
        .timer = &s3c24xx_timer,
index d2946de3f3659d3e2588cc980a727973b9716062..6bb44f75a9ce65094a35c1bdad78775c1c655eee 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/types.h>
 #include <linux/interrupt.h>
 #include <linux/list.h>
+#include <linux/memblock.h>
 #include <linux/timer.h>
 #include <linux/init.h>
 #include <linux/tty.h>
@@ -191,6 +192,13 @@ static void __init rx3715_map_io(void)
        s3c24xx_init_uarts(rx3715_uartcfgs, ARRAY_SIZE(rx3715_uartcfgs));
 }
 
+/* H1940 and RX3715 need to reserve this for suspend */
+static void __init rx3715_reserve(void)
+{
+       memblock_reserve(0x30003000, 0x1000);
+       memblock_reserve(0x30081000, 0x1000);
+}
+
 static void __init rx3715_init_irq(void)
 {
        s3c24xx_init_irq();
@@ -214,6 +222,7 @@ MACHINE_START(RX3715, "IPAQ-RX3715")
        .io_pg_offst    = (((u32)S3C24XX_VA_UART) >> 18) & 0xfffc,
        .boot_params    = S3C2410_SDRAM_PA + 0x100,
        .map_io         = rx3715_map_io,
+       .reserve        = rx3715_reserve,
        .init_irq       = rx3715_init_irq,
        .init_machine   = rx3715_init_machine,
        .timer          = &s3c24xx_timer,
index ec03f187c52bcef3e1cf28145b373016b7e66e2d..b7a9a601c2d1e18a407c6110976812e35ebf93a3 100644 (file)
@@ -13,8 +13,7 @@ extern void __init sa1100_init_gpio(void);
 
 #define SET_BANK(__nr,__start,__size) \
        mi->bank[__nr].start = (__start), \
-       mi->bank[__nr].size = (__size), \
-       mi->bank[__nr].node = (((unsigned)(__start) - PHYS_OFFSET) >> 27)
+       mi->bank[__nr].size = (__size)
 
 extern void (*sa1100fb_backlight_power)(int on);
 extern void (*sa1100fb_lcd_power)(int on);
index d5277f9bee77d8dc7a98b2acb60d494e5fcc9df1..128a1dfa96b9b4ae9f64286f5b11df60c2297d79 100644 (file)
 #ifndef __ASSEMBLY__
 
 #ifdef CONFIG_SA1111
-void sa1111_adjust_zones(int node, unsigned long *size, unsigned long *holes);
+void sa1111_adjust_zones(unsigned long *size, unsigned long *holes);
 
-#define arch_adjust_zones(node, size, holes) \
-       sa1111_adjust_zones(node, size, holes)
+#define arch_adjust_zones(size, holes) \
+       sa1111_adjust_zones(size, holes)
 
 #define ISA_DMA_THRESHOLD      (PHYS_OFFSET + SZ_1M - 1)
 #define MAX_DMA_ADDRESS                (PAGE_OFFSET + SZ_1M)
index 3053e5b7f1685290eccc1c44a9b011c030ffd741..d9c4812f1c316c69ab650a44cd513948410320ce 100644 (file)
@@ -19,9 +19,8 @@
 
 #ifndef __ASSEMBLY__
 
-static inline void __arch_adjust_zones(int node, unsigned long *zone_size, unsigned long *zhole_size) 
+static inline void __arch_adjust_zones(unsigned long *zone_size, unsigned long *zhole_size)
 {
-  if (node != 0) return;
   /* Only the first 4 MB (=1024 Pages) are usable for DMA */
   /* See dev / -> .properties in OpenFirmware. */
   zone_size[1] = zone_size[0] - 1024;
@@ -30,8 +29,8 @@ static inline void __arch_adjust_zones(int node, unsigned long *zone_size, unsig
   zhole_size[0] = 0;
 }
 
-#define arch_adjust_zones(node, size, holes) \
-       __arch_adjust_zones(node, size, holes)
+#define arch_adjust_zones(size, holes) \
+       __arch_adjust_zones(size, holes)
 
 #define ISA_DMA_THRESHOLD      (PHYS_OFFSET + SZ_4M - 1)
 #define MAX_DMA_ADDRESS                (PAGE_OFFSET + SZ_4M)
index f2b88c5fe142841e718928a0bd787dc6185032c3..4c704b4e8b340c9a6482e2c3ec87da15029c67a8 100644 (file)
@@ -70,6 +70,18 @@ endmenu
 
 menu "Timer and clock configuration"
 
+config SHMOBILE_TIMER_HZ
+       int "Kernel HZ (jiffies per second)"
+       range 32 1024
+       default "128"
+       help
+         Allows the configuration of the timer frequency. It is customary
+         to have the timer interrupt run at 1000 Hz or 100 Hz, but in the
+         case of low timer frequencies other values may be more suitable.
+         SH-Mobile systems using a 32768 Hz RCLK for clock events may want
+         to select a HZ value such as 128 that can evenly divide RCLK.
+         A HZ value that does not divide evenly may cause timer drift.
+
 config SH_TIMER_CMT
        bool "CMT timer driver"
        default y
index 5179b72e1ee3d04186f2cfba7d675778853735ae..132256bb8c817b1b5ab9aa08cd1af7875b22ca00 100644 (file)
@@ -2,7 +2,6 @@
 #define __ASM_MACH_IRQS_H
 
 #define NR_IRQS         512
-#define NR_IRQS_LEGACY  8
 
 #define evt2irq(evt)           (((evt) >> 5) - 16)
 #define irq2evt(irq)           (((irq) + 16) << 5)
index 39f6ccf22294d1e8a9c27f90a771a3c0090fa2d5..18febf92f20a10bfe38df87fc75d6c7f23dd9d83 100644 (file)
@@ -341,8 +341,11 @@ static struct clk gpio_clk = {
        .recalc = &follow_parent,
 };
 
+static struct clk dummy_apb_pclk;
+
 /* array of all spear 3xx clock lookups */
 static struct clk_lookup spear_clk_lookups[] = {
+       { .con_id = "apb_pclk", .clk = &dummy_apb_pclk},
        /* root clks */
        { .con_id = "osc_32k_clk",      .clk = &osc_32k_clk},
        { .con_id = "osc_24m_clk",      .clk = &osc_24m_clk},
index 13e27c769685018bb82b75b745ca45c56bf6d5d9..36ff056b73219f5b07339ab627558a64eb96adae 100644 (file)
@@ -428,8 +428,11 @@ static struct clk gpio2_clk = {
        .recalc = &follow_parent,
 };
 
+static struct clk dummy_apb_pclk;
+
 /* array of all spear 6xx clock lookups */
 static struct clk_lookup spear_clk_lookups[] = {
+       { .con_id = "apb_pclk", .clk = &dummy_apb_pclk},
        /* root clks */
        { .con_id = "osc_32k_clk",      .clk = &osc_32k_clk},
        { .con_id = "osc_30m_clk",      .clk = &osc_30m_clk},
index 5af71d5ba6656c648fc724a36b66e6d419389a1d..5d12d547789e3f17ee993c9df7d8e1056486045b 100644 (file)
@@ -1212,6 +1212,8 @@ static struct clk ppm_clk = {
 };
 #endif
 
+static struct clk dummy_apb_pclk;
+
 #define DEF_LOOKUP(devid, clkref)              \
        {                                       \
        .dev_id = devid,                        \
@@ -1223,6 +1225,10 @@ static struct clk ppm_clk = {
  * look up through clockdevice.
  */
 static struct clk_lookup lookups[] = {
+       {
+               .con_id = "apb_pclk",
+               .clk = &dummy_apb_pclk,
+       },
        /* Connected directly to the AMBA bus */
        DEF_LOOKUP("amba",      &amba_clk),
        DEF_LOOKUP("cpu",       &cpu_clk),
index ab000df7fc0337c7f75ef31deb9bef182ac172f0..bf134bcc129d612cde5362a6971a08360a42b582 100644 (file)
            (CONFIG_MACH_U300_ACCESS_MEM_SIZE & 1))*1024*1024 + 0x100)
 #endif
 
-/*
- * TCM memory whereabouts
- */
-#define ITCM_OFFSET    0xffff2000
-#define ITCM_END       0xffff3fff
-#define DTCM_OFFSET    0xffff4000
-#define DTCM_END       0xffff5fff
-
 /*
  * We enable a real big DMA buffer if need be.
  */
index d2a0b8847a18061e36576f5dec89bc567745d473..bfcda9820888b6083fd10779b63fe89580f76036 100644 (file)
@@ -14,6 +14,7 @@
 #include <linux/sched.h>
 #include <linux/interrupt.h>
 #include <linux/ioport.h>
+#include <linux/memblock.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
 #include <mach/hardware.h>
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 
+static void __init u300_reserve(void)
+{
+       /*
+        * U300 - This platform family can share physical memory
+        * between two ARM cpus, one running Linux and the other
+        * running another OS.
+        */
+#ifdef CONFIG_MACH_U300_SINGLE_RAM
+#if ((CONFIG_MACH_U300_ACCESS_MEM_SIZE & 1) == 1) && \
+       CONFIG_MACH_U300_2MB_ALIGNMENT_FIX
+        memblock_reserve(PHYS_OFFSET, 0x00100000);
+#endif
+#endif
+}
+
 static void __init u300_init_machine(void)
 {
        u300_init_devices();
@@ -49,6 +65,7 @@ MACHINE_START(U300, MACH_U300_STRING)
        .io_pg_offst    = ((U300_AHB_PER_VIRT_BASE) >> 18) & 0xfffc,
        .boot_params    = BOOT_PARAMS_OFFSET,
        .map_io         = u300_map_io,
+       .reserve        = u300_reserve,
        .init_irq       = u300_init_irq,
        .timer          = &u300_timer,
        .init_machine   = u300_init_machine,
index bb8d7b771817b774a7ff3406e87d46552cf8391c..0e8fd135a57dee1d56afb200208d62bf7d756fa8 100644 (file)
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/gpio.h>
 #include <linux/amba/bus.h>
 #include <linux/amba/pl022.h>
 #include <linux/spi/spi.h>
+#include <linux/mfd/ab8500.h>
 
 #include <asm/mach-types.h>
 #include <asm/mach/arch.h>
 
+#include <plat/pincfg.h>
 #include <plat/i2c.h>
 
 #include <mach/hardware.h>
 #include <mach/setup.h>
 #include <mach/devices.h>
 
+#include "pins-db8500.h"
+
+static pin_cfg_t mop500_pins[] = {
+       /* SSP0 */
+       GPIO143_SSP0_CLK,
+       GPIO144_SSP0_FRM,
+       GPIO145_SSP0_RXD,
+       GPIO146_SSP0_TXD,
+
+       /* I2C */
+       GPIO147_I2C0_SCL,
+       GPIO148_I2C0_SDA,
+       GPIO16_I2C1_SCL,
+       GPIO17_I2C1_SDA,
+       GPIO10_I2C2_SDA,
+       GPIO11_I2C2_SCL,
+       GPIO229_I2C3_SDA,
+       GPIO230_I2C3_SCL,
+};
+
 static void ab4500_spi_cs_control(u32 command)
 {
        /* set the FRM signal, which is CS  - TODO */
@@ -48,15 +71,20 @@ struct pl022_config_chip ab4500_chip_info = {
        .cs_control = ab4500_spi_cs_control,
 };
 
+static struct ab8500_platform_data ab8500_platdata = {
+       .irq_base       = MOP500_AB8500_IRQ_BASE,
+};
+
 static struct spi_board_info u8500_spi_devices[] = {
        {
                .modalias = "ab8500",
                .controller_data = &ab4500_chip_info,
+               .platform_data = &ab8500_platdata,
                .max_speed_hz = 12000000,
                .bus_num = 0,
                .chip_select = 0,
                .mode = SPI_MODE_0,
-               .irq = IRQ_AB4500,
+               .irq = IRQ_DB8500_AB8500,
        },
 };
 
@@ -118,6 +146,10 @@ static void __init u8500_init_machine(void)
 {
        int i;
 
+       u8500_init_devices();
+
+       nmk_config_pins(mop500_pins, ARRAY_SIZE(mop500_pins));
+
        u8500_i2c0_device.dev.platform_data = &u8500_i2c0_data;
        ux500_i2c1_device.dev.platform_data = &u8500_i2c1_data;
        ux500_i2c2_device.dev.platform_data = &u8500_i2c2_data;
@@ -133,8 +165,6 @@ static void __init u8500_init_machine(void)
 
        spi_register_board_info(u8500_spi_devices,
                        ARRAY_SIZE(u8500_spi_devices));
-
-       u8500_init_devices();
 }
 
 MACHINE_START(U8500, "ST-Ericsson MOP500 platform")
index 0a1318fc8e2bd6c29774bcf1ab8cc48f6a5cfa0c..d8ab7f184fe439ec2492079a063def04c5e3c690 100644 (file)
@@ -453,7 +453,11 @@ static DEFINE_PRCC_CLK_CUSTOM(7, mtu0_ed, 2, -1, NULL, clk_mtu_get_rate, 0);
 static DEFINE_PRCC_CLK(7, wdg_ed,      1, -1, NULL);
 static DEFINE_PRCC_CLK(7, cfgreg_ed,   0, -1, NULL);
 
+static struct clk clk_dummy_apb_pclk;
+
 static struct clk_lookup u8500_common_clks[] = {
+       CLK(dummy_apb_pclk, NULL,       "apb_pclk"),
+
        /* Peripheral Cluster #1 */
        CLK(gpio0,      "gpio.0",       NULL),
        CLK(gpio0,      "gpio.1",       NULL),
index 8229034219432ad1f2090fe99b5da7723992ac22..654fca944e6554cd65eb77fff9c9563a96e58173 100644 (file)
@@ -65,7 +65,7 @@ struct amba_device u8500_ssp0_device = {
                .end   = U8500_SSP0_BASE + SZ_4K - 1,
                .flags = IORESOURCE_MEM,
        },
-       .irq = {IRQ_SSP0, NO_IRQ },
+       .irq = {IRQ_DB8500_SSP0, NO_IRQ },
        /* ST-Ericsson modified id */
        .periphid = SSP_PER_ID,
 };
@@ -77,8 +77,8 @@ static struct resource u8500_i2c0_resources[] = {
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
-               .start  = IRQ_I2C0,
-               .end    = IRQ_I2C0,
+               .start  = IRQ_DB8500_I2C0,
+               .end    = IRQ_DB8500_I2C0,
                .flags  = IORESOURCE_IRQ,
        }
 };
@@ -97,8 +97,8 @@ static struct resource u8500_i2c4_resources[] = {
                .flags  = IORESOURCE_MEM,
        },
        [1] = {
-               .start  = IRQ_I2C4,
-               .end    = IRQ_I2C4,
+               .start  = IRQ_DB8500_I2C4,
+               .end    = IRQ_DB8500_I2C4,
                .flags  = IORESOURCE_IRQ,
        }
 };
@@ -130,8 +130,8 @@ static struct resource dma40_resources[] = {
                .name = "lcla",
        },
        [3] = {
-               .start = IRQ_DMA,
-               .end = IRQ_DMA,
+               .start = IRQ_DB8500_DMA,
+               .end   = IRQ_DB8500_DMA,
                .flags = IORESOURCE_IRQ}
 };
 
diff --git a/arch/arm/mach-ux500/include/mach/irqs-board-mop500.h b/arch/arm/mach-ux500/include/mach/irqs-board-mop500.h
new file mode 100644 (file)
index 0000000..cca4f70
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com>
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#ifndef __MACH_IRQS_BOARD_MOP500_H
+#define __MACH_IRQS_BOARD_MOP500_H
+
+#define AB8500_NR_IRQS                 104
+
+#define MOP500_AB8500_IRQ_BASE         IRQ_BOARD_START
+#define MOP500_AB8500_IRQ_END          (MOP500_AB8500_IRQ_BASE \
+                                        + AB8500_NR_IRQS)
+#define MOP500_IRQ_END                 MOP500_AB8500_IRQ_END
+
+#if MOP500_IRQ_END > IRQ_BOARD_END
+#undef IRQ_BOARD_END
+#define IRQ_BOARD_END  MOP500_IRQ_END
+#endif
+
+#endif
diff --git a/arch/arm/mach-ux500/include/mach/irqs-db5500.h b/arch/arm/mach-ux500/include/mach/irqs-db5500.h
new file mode 100644 (file)
index 0000000..6fbfe5e
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com>
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#ifndef __MACH_IRQS_DB5500_H
+#define __MACH_IRQS_DB5500_H
+
+#define IRQ_DB5500_MTU0                        (IRQ_SHPI_START + 4)
+#define IRQ_DB5500_SPI2                        (IRQ_SHPI_START + 6)
+#define IRQ_DB5500_PMU0                        (IRQ_SHPI_START + 7)
+#define IRQ_DB5500_SPI0                        (IRQ_SHPI_START + 8)
+#define IRQ_DB5500_RTT                 (IRQ_SHPI_START + 9)
+#define IRQ_DB5500_PKA                 (IRQ_SHPI_START + 10)
+#define IRQ_DB5500_UART0               (IRQ_SHPI_START + 11)
+#define IRQ_DB5500_I2C3                        (IRQ_SHPI_START + 12)
+#define IRQ_DB5500_L2CC                        (IRQ_SHPI_START + 13)
+#define IRQ_DB5500_MSP0                        (IRQ_SHPI_START + 14)
+#define IRQ_DB5500_CRYP1               (IRQ_SHPI_START + 15)
+#define IRQ_DB5500_PMU1                        (IRQ_SHPI_START + 16)
+#define IRQ_DB5500_MTU1                        (IRQ_SHPI_START + 17)
+#define IRQ_DB5500_RTC                 (IRQ_SHPI_START + 18)
+#define IRQ_DB5500_UART1               (IRQ_SHPI_START + 19)
+#define IRQ_DB5500_USB_WAKEUP          (IRQ_SHPI_START + 20)
+#define IRQ_DB5500_I2C0                        (IRQ_SHPI_START + 21)
+#define IRQ_DB5500_I2C1                        (IRQ_SHPI_START + 22)
+#define IRQ_DB5500_USBOTG              (IRQ_SHPI_START + 23)
+#define IRQ_DB5500_DMA_SECURE          (IRQ_SHPI_START + 24)
+#define IRQ_DB5500_DMA                 (IRQ_SHPI_START + 25)
+#define IRQ_DB5500_UART2               (IRQ_SHPI_START + 26)
+#define IRQ_DB5500_ICN_PMU1            (IRQ_SHPI_START + 27)
+#define IRQ_DB5500_ICN_PMU2            (IRQ_SHPI_START + 28)
+#define IRQ_DB5500_UART3               (IRQ_SHPI_START + 29)
+#define IRQ_DB5500_SPI3                        (IRQ_SHPI_START + 30)
+#define IRQ_DB5500_SDMMC4              (IRQ_SHPI_START + 31)
+#define IRQ_DB5500_IRRC                        (IRQ_SHPI_START + 33)
+#define IRQ_DB5500_IRDA_FT             (IRQ_SHPI_START + 34)
+#define IRQ_DB5500_IRDA_SD             (IRQ_SHPI_START + 35)
+#define IRQ_DB5500_IRDA_FI             (IRQ_SHPI_START + 36)
+#define IRQ_DB5500_IRDA_FD             (IRQ_SHPI_START + 37)
+#define IRQ_DB5500_FSMC_CODEREADY      (IRQ_SHPI_START + 38)
+#define IRQ_DB5500_FSMC_NANDWAIT       (IRQ_SHPI_START + 39)
+#define IRQ_DB5500_AB5500              (IRQ_SHPI_START + 40)
+#define IRQ_DB5500_SDMMC2              (IRQ_SHPI_START + 41)
+#define IRQ_DB5500_SIA                 (IRQ_SHPI_START + 42)
+#define IRQ_DB5500_SIA2                        (IRQ_SHPI_START + 43)
+#define IRQ_DB5500_HVA                 (IRQ_SHPI_START + 44)
+#define IRQ_DB5500_HVA2                        (IRQ_SHPI_START + 45)
+#define IRQ_DB5500_PRCMU0              (IRQ_SHPI_START + 46)
+#define IRQ_DB5500_PRCMU1              (IRQ_SHPI_START + 47)
+#define IRQ_DB5500_DISP                        (IRQ_SHPI_START + 48)
+#define IRQ_DB5500_SDMMC1              (IRQ_SHPI_START + 50)
+#define IRQ_DB5500_MSP1                        (IRQ_SHPI_START + 52)
+#define IRQ_DB5500_KBD                 (IRQ_SHPI_START + 53)
+#define IRQ_DB5500_I2C2                        (IRQ_SHPI_START + 55)
+#define IRQ_DB5500_B2R2                        (IRQ_SHPI_START + 56)
+#define IRQ_DB5500_CRYP0               (IRQ_SHPI_START + 57)
+#define IRQ_DB5500_SDMMC3              (IRQ_SHPI_START + 59)
+#define IRQ_DB5500_SDMMC0              (IRQ_SHPI_START + 60)
+#define IRQ_DB5500_HSEM                        (IRQ_SHPI_START + 61)
+#define IRQ_DB5500_SBAG                        (IRQ_SHPI_START + 63)
+#define IRQ_DB5500_SPI1                        (IRQ_SHPI_START + 96)
+#define IRQ_DB5500_MSP2                        (IRQ_SHPI_START + 98)
+#define IRQ_DB5500_SRPTIMER            (IRQ_SHPI_START + 101)
+#define IRQ_DB5500_CTI0                        (IRQ_SHPI_START + 108)
+#define IRQ_DB5500_CTI1                        (IRQ_SHPI_START + 109)
+#define IRQ_DB5500_ICN_ERR             (IRQ_SHPI_START + 110)
+#define IRQ_DB5500_MALI_PPMMU          (IRQ_SHPI_START + 112)
+#define IRQ_DB5500_MALI_PP             (IRQ_SHPI_START + 113)
+#define IRQ_DB5500_MALI_GPMMU          (IRQ_SHPI_START + 114)
+#define IRQ_DB5500_MALI_GP             (IRQ_SHPI_START + 115)
+#define IRQ_DB5500_MALI                        (IRQ_SHPI_START + 116)
+#define IRQ_DB5500_PRCMU_SEM           (IRQ_SHPI_START + 118)
+#define IRQ_DB5500_GPIO0               (IRQ_SHPI_START + 119)
+#define IRQ_DB5500_GPIO1               (IRQ_SHPI_START + 120)
+#define IRQ_DB5500_GPIO2               (IRQ_SHPI_START + 121)
+#define IRQ_DB5500_GPIO3               (IRQ_SHPI_START + 122)
+#define IRQ_DB5500_GPIO4               (IRQ_SHPI_START + 123)
+#define IRQ_DB5500_GPIO5               (IRQ_SHPI_START + 124)
+#define IRQ_DB5500_GPIO6               (IRQ_SHPI_START + 125)
+#define IRQ_DB5500_GPIO7               (IRQ_SHPI_START + 126)
+
+#endif
diff --git a/arch/arm/mach-ux500/include/mach/irqs-db8500.h b/arch/arm/mach-ux500/include/mach/irqs-db8500.h
new file mode 100644 (file)
index 0000000..8b5d9f0
--- /dev/null
@@ -0,0 +1,96 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com>
+ * License terms: GNU General Public License (GPL) version 2
+ */
+
+#ifndef __MACH_IRQS_DB8500_H
+#define __MACH_IRQS_DB8500_H
+
+#define IRQ_DB8500_MTU0                        (IRQ_SHPI_START + 4)
+#define IRQ_DB8500_SPI2                        (IRQ_SHPI_START + 6)
+#define IRQ_DB8500_PMU                 (IRQ_SHPI_START + 7)
+#define IRQ_DB8500_SPI0                        (IRQ_SHPI_START + 8)
+#define IRQ_DB8500_RTT                 (IRQ_SHPI_START + 9)
+#define IRQ_DB8500_PKA                 (IRQ_SHPI_START + 10)
+#define IRQ_DB8500_UART0               (IRQ_SHPI_START + 11)
+#define IRQ_DB8500_I2C3                        (IRQ_SHPI_START + 12)
+#define IRQ_DB8500_L2CC                        (IRQ_SHPI_START + 13)
+#define IRQ_DB8500_SSP0                        (IRQ_SHPI_START + 14)
+#define IRQ_DB8500_CRYP1               (IRQ_SHPI_START + 15)
+#define IRQ_DB8500_MSP1_RX             (IRQ_SHPI_START + 16)
+#define IRQ_DB8500_MTU1                        (IRQ_SHPI_START + 17)
+#define IRQ_DB8500_RTC                 (IRQ_SHPI_START + 18)
+#define IRQ_DB8500_UART1               (IRQ_SHPI_START + 19)
+#define IRQ_DB8500_USB_WAKEUP          (IRQ_SHPI_START + 20)
+#define IRQ_DB8500_I2C0                        (IRQ_SHPI_START + 21)
+#define IRQ_DB8500_I2C1                        (IRQ_SHPI_START + 22)
+#define IRQ_DB8500_USBOTG              (IRQ_SHPI_START + 23)
+#define IRQ_DB8500_DMA_SECURE          (IRQ_SHPI_START + 24)
+#define IRQ_DB8500_DMA                 (IRQ_SHPI_START + 25)
+#define IRQ_DB8500_UART2               (IRQ_SHPI_START + 26)
+#define IRQ_DB8500_ICN_PMU1            (IRQ_SHPI_START + 27)
+#define IRQ_DB8500_ICN_PMU2            (IRQ_SHPI_START + 28)
+#define IRQ_DB8500_HSIR_EXCEP          (IRQ_SHPI_START + 29)
+#define IRQ_DB8500_MSP0                        (IRQ_SHPI_START + 31)
+#define IRQ_DB8500_HSIR_CH0_OVRRUN     (IRQ_SHPI_START + 32)
+#define IRQ_DB8500_HSIR_CH1_OVRRUN     (IRQ_SHPI_START + 33)
+#define IRQ_DB8500_HSIR_CH2_OVRRUN     (IRQ_SHPI_START + 34)
+#define IRQ_DB8500_HSIR_CH3_OVRRUN     (IRQ_SHPI_START + 35)
+#define IRQ_DB8500_HSIR_CH4_OVRRUN     (IRQ_SHPI_START + 36)
+#define IRQ_DB8500_HSIR_CH5_OVRRUN     (IRQ_SHPI_START + 37)
+#define IRQ_DB8500_HSIR_CH6_OVRRUN     (IRQ_SHPI_START + 38)
+#define IRQ_DB8500_HSIR_CH7_OVRRUN     (IRQ_SHPI_START + 39)
+#define IRQ_DB8500_AB8500              (IRQ_SHPI_START + 40)
+#define IRQ_DB8500_SDMMC2              (IRQ_SHPI_START + 41)
+#define IRQ_DB8500_SIA                 (IRQ_SHPI_START + 42)
+#define IRQ_DB8500_SIA2                        (IRQ_SHPI_START + 43)
+#define IRQ_DB8500_SVA                 (IRQ_SHPI_START + 44)
+#define IRQ_DB8500_SVA2                        (IRQ_SHPI_START + 45)
+#define IRQ_DB8500_PRCMU0              (IRQ_SHPI_START + 46)
+#define IRQ_DB8500_PRCMU1              (IRQ_SHPI_START + 47)
+#define IRQ_DB8500_DISP                        (IRQ_SHPI_START + 48)
+#define IRQ_DB8500_SPI3                        (IRQ_SHPI_START + 49)
+#define IRQ_DB8500_SDMMC1              (IRQ_SHPI_START + 50)
+#define IRQ_DB8500_I2C4                        (IRQ_SHPI_START + 51)
+#define IRQ_DB8500_SSP1                        (IRQ_SHPI_START + 52)
+#define IRQ_DB8500_SKE                 (IRQ_SHPI_START + 53)
+#define IRQ_DB8500_KB                  (IRQ_SHPI_START + 54)
+#define IRQ_DB8500_I2C2                        (IRQ_SHPI_START + 55)
+#define IRQ_DB8500_B2R2                        (IRQ_SHPI_START + 56)
+#define IRQ_DB8500_CRYP0               (IRQ_SHPI_START + 57)
+#define IRQ_DB8500_SDMMC3              (IRQ_SHPI_START + 59)
+#define IRQ_DB8500_SDMMC0              (IRQ_SHPI_START + 60)
+#define IRQ_DB8500_HSEM                        (IRQ_SHPI_START + 61)
+#define IRQ_DB8500_MSP1                        (IRQ_SHPI_START + 62)
+#define IRQ_DB8500_SBAG                        (IRQ_SHPI_START + 63)
+#define IRQ_DB8500_SPI1                        (IRQ_SHPI_START + 96)
+#define IRQ_DB8500_SRPTIMER            (IRQ_SHPI_START + 97)
+#define IRQ_DB8500_MSP2                        (IRQ_SHPI_START + 98)
+#define IRQ_DB8500_SDMMC4              (IRQ_SHPI_START + 99)
+#define IRQ_DB8500_SDMMC5              (IRQ_SHPI_START + 100)
+#define IRQ_DB8500_HSIRD0              (IRQ_SHPI_START + 104)
+#define IRQ_DB8500_HSIRD1              (IRQ_SHPI_START + 105)
+#define IRQ_DB8500_HSITD0              (IRQ_SHPI_START + 106)
+#define IRQ_DB8500_HSITD1              (IRQ_SHPI_START + 107)
+#define IRQ_DB8500_CTI0                        (IRQ_SHPI_START + 108)
+#define IRQ_DB8500_CTI1                        (IRQ_SHPI_START + 109)
+#define IRQ_DB8500_ICN_ERR             (IRQ_SHPI_START + 110)
+#define IRQ_DB8500_MALI_PPMMU          (IRQ_SHPI_START + 112)
+#define IRQ_DB8500_MALI_PP             (IRQ_SHPI_START + 113)
+#define IRQ_DB8500_MALI_GPMMU          (IRQ_SHPI_START + 114)
+#define IRQ_DB8500_MALI_GP             (IRQ_SHPI_START + 115)
+#define IRQ_DB8500_MALI                        (IRQ_SHPI_START + 116)
+#define IRQ_DB8500_PRCMU_SEM           (IRQ_SHPI_START + 118)
+#define IRQ_DB8500_GPIO0               (IRQ_SHPI_START + 119)
+#define IRQ_DB8500_GPIO1               (IRQ_SHPI_START + 120)
+#define IRQ_DB8500_GPIO2               (IRQ_SHPI_START + 121)
+#define IRQ_DB8500_GPIO3               (IRQ_SHPI_START + 122)
+#define IRQ_DB8500_GPIO4               (IRQ_SHPI_START + 123)
+#define IRQ_DB8500_GPIO5               (IRQ_SHPI_START + 124)
+#define IRQ_DB8500_GPIO6               (IRQ_SHPI_START + 125)
+#define IRQ_DB8500_GPIO7               (IRQ_SHPI_START + 126)
+#define IRQ_DB8500_GPIO8               (IRQ_SHPI_START + 127)
+
+#endif
index 7970684b1d0983841bd74e623daf93412fd8797e..10385bdc2b7760506af333077fd1fd34fe5972fc 100644 (file)
@@ -10,7 +10,8 @@
 #ifndef ASM_ARCH_IRQS_H
 #define ASM_ARCH_IRQS_H
 
-#include <mach/hardware.h>
+#include <mach/irqs-db5500.h>
+#include <mach/irqs-db8500.h>
 
 #define IRQ_LOCALTIMER                  29
 #define IRQ_LOCALWDOG                   30
 /* There are 128 shared peripheral interrupts assigned to
  * INTID[160:32]. The first 32 interrupts are reserved.
  */
-#define U8500_SOC_NR_IRQS              161
+#define DBX500_NR_INTERNAL_IRQS                161
 
 /* After chip-specific IRQ numbers we have the GPIO ones */
 #define NOMADIK_NR_GPIO                        288
-#define NOMADIK_GPIO_TO_IRQ(gpio)      ((gpio) + U8500_SOC_NR_IRQS)
-#define NOMADIK_IRQ_TO_GPIO(irq)       ((irq) - U8500_SOC_NR_IRQS)
-#define NR_IRQS                                NOMADIK_GPIO_TO_IRQ(NOMADIK_NR_GPIO)
+#define NOMADIK_GPIO_TO_IRQ(gpio)      ((gpio) + DBX500_NR_INTERNAL_IRQS)
+#define NOMADIK_IRQ_TO_GPIO(irq)       ((irq) - DBX500_NR_INTERNAL_IRQS)
+#define IRQ_BOARD_START                        NOMADIK_GPIO_TO_IRQ(NOMADIK_NR_GPIO)
 
-#endif /*ASM_ARCH_IRQS_H*/
+/* This will be overridden by board-specific irq headers */
+#define IRQ_BOARD_END                  IRQ_BOARD_START
+
+#ifdef CONFIG_MACH_U8500_MOP
+#include <mach/irqs-board-mop500.h>
+#endif
+
+#define NR_IRQS                                IRQ_BOARD_END
+
+#endif /* ASM_ARCH_IRQS_H */
diff --git a/arch/arm/mach-ux500/pins-db8500.h b/arch/arm/mach-ux500/pins-db8500.h
new file mode 100644 (file)
index 0000000..9055d5d
--- /dev/null
@@ -0,0 +1,742 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * License terms: GNU General Public License, version 2
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com>
+ */
+
+#ifndef __MACH_PINS_DB8500_H
+#define __MACH_PINS_DB8500_H
+
+/*
+ * TODO: Eventually encode all non-board specific pull up/down configuration
+ * here.
+ */
+
+#define GPIO0_GPIO             PIN_CFG(0, GPIO)
+#define GPIO0_U0_CTSn          PIN_CFG(0, ALT_A)
+#define GPIO0_TRIG_OUT         PIN_CFG(0, ALT_B)
+#define GPIO0_IP_TDO           PIN_CFG(0, ALT_C)
+
+#define GPIO1_GPIO             PIN_CFG(1, GPIO)
+#define GPIO1_U0_RTSn          PIN_CFG(1, ALT_A)
+#define GPIO1_TRIG_IN          PIN_CFG(1, ALT_B)
+#define GPIO1_IP_TDI           PIN_CFG(1, ALT_C)
+
+#define GPIO2_GPIO             PIN_CFG(2, GPIO)
+#define GPIO2_U0_RXD           PIN_CFG(2, ALT_A)
+#define GPIO2_NONE             PIN_CFG(2, ALT_B)
+#define GPIO2_IP_TMS           PIN_CFG(2, ALT_C)
+
+#define GPIO3_GPIO             PIN_CFG(3, GPIO)
+#define GPIO3_U0_TXD           PIN_CFG(3, ALT_A)
+#define GPIO3_NONE             PIN_CFG(3, ALT_B)
+#define GPIO3_IP_TCK           PIN_CFG(3, ALT_C)
+
+#define GPIO4_GPIO             PIN_CFG(4, GPIO)
+#define GPIO4_U1_RXD           PIN_CFG(4, ALT_A)
+#define GPIO4_I2C4_SCL         PIN_CFG_PULL(4, ALT_B, UP)
+#define GPIO4_IP_TRSTn         PIN_CFG(4, ALT_C)
+
+#define GPIO5_GPIO             PIN_CFG(5, GPIO)
+#define GPIO5_U1_TXD           PIN_CFG(5, ALT_A)
+#define GPIO5_I2C4_SDA         PIN_CFG_PULL(5, ALT_B, UP)
+#define GPIO5_IP_GPIO6         PIN_CFG(5, ALT_C)
+
+#define GPIO6_GPIO             PIN_CFG(6, GPIO)
+#define GPIO6_U1_CTSn          PIN_CFG(6, ALT_A)
+#define GPIO6_I2C1_SCL         PIN_CFG_PULL(6, ALT_B, UP)
+#define GPIO6_IP_GPIO0         PIN_CFG(6, ALT_C)
+
+#define GPIO7_GPIO             PIN_CFG(7, GPIO)
+#define GPIO7_U1_RTSn          PIN_CFG(7, ALT_A)
+#define GPIO7_I2C1_SDA         PIN_CFG_PULL(7, ALT_B, UP)
+#define GPIO7_IP_GPIO1         PIN_CFG(7, ALT_C)
+
+#define GPIO8_GPIO             PIN_CFG(8, GPIO)
+#define GPIO8_IPI2C_SDA                PIN_CFG_PULL(8, ALT_A, UP)
+#define GPIO8_I2C2_SDA         PIN_CFG_PULL(8, ALT_B, UP)
+
+#define GPIO9_GPIO             PIN_CFG(9, GPIO)
+#define GPIO9_IPI2C_SCL                PIN_CFG_PULL(9, ALT_A, UP)
+#define GPIO9_I2C2_SCL         PIN_CFG_PULL(9, ALT_B, UP)
+
+#define GPIO10_GPIO            PIN_CFG(10, GPIO)
+#define GPIO10_IPI2C_SDA       PIN_CFG_PULL(10, ALT_A, UP)
+#define GPIO10_I2C2_SDA                PIN_CFG_PULL(10, ALT_B, UP)
+#define GPIO10_IP_GPIO3                PIN_CFG(10, ALT_C)
+
+#define GPIO11_GPIO            PIN_CFG(11, GPIO)
+#define GPIO11_IPI2C_SCL       PIN_CFG_PULL(11, ALT_A, UP)
+#define GPIO11_I2C2_SCL                PIN_CFG_PULL(11, ALT_B, UP)
+#define GPIO11_IP_GPIO2                PIN_CFG(11, ALT_C)
+
+#define GPIO12_GPIO            PIN_CFG(12, GPIO)
+#define GPIO12_MSP0_TXD                PIN_CFG(12, ALT_A)
+#define GPIO12_MSP0_RXD                PIN_CFG(12, ALT_B)
+
+#define GPIO13_GPIO            PIN_CFG(13, GPIO)
+#define GPIO13_MSP0_TFS                PIN_CFG(13, ALT_A)
+
+#define GPIO14_GPIO            PIN_CFG(14, GPIO)
+#define GPIO14_MSP0_TCK                PIN_CFG(14, ALT_A)
+
+#define GPIO15_GPIO            PIN_CFG(15, GPIO)
+#define GPIO15_MSP0_RXD                PIN_CFG(15, ALT_A)
+#define GPIO15_MSP0_TXD                PIN_CFG(15, ALT_B)
+
+#define GPIO16_GPIO            PIN_CFG(16, GPIO)
+#define GPIO16_MSP0_RFS                PIN_CFG(16, ALT_A)
+#define GPIO16_I2C1_SCL                PIN_CFG_PULL(16, ALT_B, UP)
+#define GPIO16_SLIM0_DAT       PIN_CFG(16, ALT_C)
+
+#define GPIO17_GPIO            PIN_CFG(17, GPIO)
+#define GPIO17_MSP0_RCK                PIN_CFG(17, ALT_A)
+#define GPIO17_I2C1_SDA                PIN_CFG_PULL(17, ALT_B, UP)
+#define GPIO17_SLIM0_CLK       PIN_CFG(17, ALT_C)
+
+#define GPIO18_GPIO            PIN_CFG(18, GPIO)
+#define GPIO18_MC0_CMDDIR      PIN_CFG(18, ALT_A)
+#define GPIO18_U2_RXD          PIN_CFG(18, ALT_B)
+#define GPIO18_MS_IEP          PIN_CFG(18, ALT_C)
+
+#define GPIO19_GPIO            PIN_CFG(19, GPIO)
+#define GPIO19_MC0_DAT0DIR     PIN_CFG(19, ALT_A)
+#define GPIO19_U2_TXD          PIN_CFG(19, ALT_B)
+#define GPIO19_MS_DAT0DIR      PIN_CFG(19, ALT_C)
+
+#define GPIO20_GPIO            PIN_CFG(20, GPIO)
+#define GPIO20_MC0_DAT2DIR     PIN_CFG(20, ALT_A)
+#define GPIO20_UARTMOD_TXD     PIN_CFG(20, ALT_B)
+#define GPIO20_IP_TRIGOUT      PIN_CFG(20, ALT_C)
+
+#define GPIO21_GPIO            PIN_CFG(21, GPIO)
+#define GPIO21_MC0_DAT31DIR    PIN_CFG(21, ALT_A)
+#define GPIO21_MSP0_SCK                PIN_CFG(21, ALT_B)
+#define GPIO21_MS_DAT31DIR     PIN_CFG(21, ALT_C)
+
+#define GPIO22_GPIO            PIN_CFG(22, GPIO)
+#define GPIO22_MC0_FBCLK       PIN_CFG(22, ALT_A)
+#define GPIO22_UARTMOD_RXD     PIN_CFG(22, ALT_B)
+#define GPIO22_MS_FBCLK                PIN_CFG(22, ALT_C)
+
+#define GPIO23_GPIO            PIN_CFG(23, GPIO)
+#define GPIO23_MC0_CLK         PIN_CFG(23, ALT_A)
+#define GPIO23_STMMOD_CLK      PIN_CFG(23, ALT_B)
+#define GPIO23_MS_CLK          PIN_CFG(23, ALT_C)
+
+#define GPIO24_GPIO            PIN_CFG(24, GPIO)
+#define GPIO24_MC0_CMD         PIN_CFG(24, ALT_A)
+#define GPIO24_UARTMOD_RXD     PIN_CFG(24, ALT_B)
+#define GPIO24_MS_BS           PIN_CFG(24, ALT_C)
+
+#define GPIO25_GPIO            PIN_CFG(25, GPIO)
+#define GPIO25_MC0_DAT0                PIN_CFG(25, ALT_A)
+#define GPIO25_STMMOD_DAT0     PIN_CFG(25, ALT_B)
+#define GPIO25_MS_DAT0         PIN_CFG(25, ALT_C)
+
+#define GPIO26_GPIO            PIN_CFG(26, GPIO)
+#define GPIO26_MC0_DAT1                PIN_CFG(26, ALT_A)
+#define GPIO26_STMMOD_DAT1     PIN_CFG(26, ALT_B)
+#define GPIO26_MS_DAT1         PIN_CFG(26, ALT_C)
+
+#define GPIO27_GPIO            PIN_CFG(27, GPIO)
+#define GPIO27_MC0_DAT2                PIN_CFG(27, ALT_A)
+#define GPIO27_STMMOD_DAT2     PIN_CFG(27, ALT_B)
+#define GPIO27_MS_DAT2         PIN_CFG(27, ALT_C)
+
+#define GPIO28_GPIO            PIN_CFG(28, GPIO)
+#define GPIO28_MC0_DAT3                PIN_CFG(28, ALT_A)
+#define GPIO28_STMMOD_DAT3     PIN_CFG(28, ALT_B)
+#define GPIO28_MS_DAT3         PIN_CFG(28, ALT_C)
+
+#define GPIO29_GPIO            PIN_CFG(29, GPIO)
+#define GPIO29_MC0_DAT4                PIN_CFG(29, ALT_A)
+#define GPIO29_SPI3_CLK                PIN_CFG(29, ALT_B)
+#define GPIO29_U2_RXD          PIN_CFG(29, ALT_C)
+
+#define GPIO30_GPIO            PIN_CFG(30, GPIO)
+#define GPIO30_MC0_DAT5                PIN_CFG(30, ALT_A)
+#define GPIO30_SPI3_RXD                PIN_CFG(30, ALT_B)
+#define GPIO30_U2_TXD          PIN_CFG(30, ALT_C)
+
+#define GPIO31_GPIO            PIN_CFG(31, GPIO)
+#define GPIO31_MC0_DAT6                PIN_CFG(31, ALT_A)
+#define GPIO31_SPI3_FRM                PIN_CFG(31, ALT_B)
+#define GPIO31_U2_CTSn         PIN_CFG(31, ALT_C)
+
+#define GPIO32_GPIO            PIN_CFG(32, GPIO)
+#define GPIO32_MC0_DAT7                PIN_CFG(32, ALT_A)
+#define GPIO32_SPI3_TXD                PIN_CFG(32, ALT_B)
+#define GPIO32_U2_RTSn         PIN_CFG(32, ALT_C)
+
+#define GPIO33_GPIO            PIN_CFG(33, GPIO)
+#define GPIO33_MSP1_TXD                PIN_CFG(33, ALT_A)
+#define GPIO33_MSP1_RXD                PIN_CFG(33, ALT_B)
+#define GPIO33_U0_DTRn         PIN_CFG(33, ALT_C)
+
+#define GPIO34_GPIO            PIN_CFG(34, GPIO)
+#define GPIO34_MSP1_TFS                PIN_CFG(34, ALT_A)
+#define GPIO34_NONE            PIN_CFG(34, ALT_B)
+#define GPIO34_U0_DCDn         PIN_CFG(34, ALT_C)
+
+#define GPIO35_GPIO            PIN_CFG(35, GPIO)
+#define GPIO35_MSP1_TCK                PIN_CFG(35, ALT_A)
+#define GPIO35_NONE            PIN_CFG(35, ALT_B)
+#define GPIO35_U0_DSRn         PIN_CFG(35, ALT_C)
+
+#define GPIO36_GPIO            PIN_CFG(36, GPIO)
+#define GPIO36_MSP1_RXD                PIN_CFG(36, ALT_A)
+#define GPIO36_MSP1_TXD                PIN_CFG(36, ALT_B)
+#define GPIO36_U0_RIn          PIN_CFG(36, ALT_C)
+
+#define GPIO64_GPIO            PIN_CFG(64, GPIO)
+#define GPIO64_LCDB_DE         PIN_CFG(64, ALT_A)
+#define GPIO64_KP_O1           PIN_CFG(64, ALT_B)
+#define GPIO64_IP_GPIO4                PIN_CFG(64, ALT_C)
+
+#define GPIO65_GPIO            PIN_CFG(65, GPIO)
+#define GPIO65_LCDB_HSO                PIN_CFG(65, ALT_A)
+#define GPIO65_KP_O0           PIN_CFG(65, ALT_B)
+#define GPIO65_IP_GPIO5                PIN_CFG(65, ALT_C)
+
+#define GPIO66_GPIO            PIN_CFG(66, GPIO)
+#define GPIO66_LCDB_VSO                PIN_CFG(66, ALT_A)
+#define GPIO66_KP_I1           PIN_CFG(66, ALT_B)
+#define GPIO66_IP_GPIO6                PIN_CFG(66, ALT_C)
+
+#define GPIO67_GPIO            PIN_CFG(67, GPIO)
+#define GPIO67_LCDB_CLK                PIN_CFG(67, ALT_A)
+#define GPIO67_KP_I0           PIN_CFG(67, ALT_B)
+#define GPIO67_IP_GPIO7                PIN_CFG(67, ALT_C)
+
+#define GPIO68_GPIO            PIN_CFG(68, GPIO)
+#define GPIO68_LCD_VSI0                PIN_CFG(68, ALT_A)
+#define GPIO68_KP_O7           PIN_CFG(68, ALT_B)
+#define GPIO68_SM_CLE          PIN_CFG(68, ALT_C)
+
+#define GPIO69_GPIO            PIN_CFG(69, GPIO)
+#define GPIO69_LCD_VSI1                PIN_CFG(69, ALT_A)
+#define GPIO69_KP_I7           PIN_CFG(69, ALT_B)
+#define GPIO69_SM_ALE          PIN_CFG(69, ALT_C)
+
+#define GPIO70_GPIO            PIN_CFG(70, GPIO)
+#define GPIO70_LCD_D0          PIN_CFG(70, ALT_A)
+#define GPIO70_KP_O5           PIN_CFG(70, ALT_B)
+#define GPIO70_STMAPE_CLK      PIN_CFG(70, ALT_C)
+
+#define GPIO71_GPIO            PIN_CFG(71, GPIO)
+#define GPIO71_LCD_D1          PIN_CFG(71, ALT_A)
+#define GPIO71_KP_O4           PIN_CFG(71, ALT_B)
+#define GPIO71_STMAPE_DAT3     PIN_CFG(71, ALT_C)
+
+#define GPIO72_GPIO            PIN_CFG(72, GPIO)
+#define GPIO72_LCD_D2          PIN_CFG(72, ALT_A)
+#define GPIO72_KP_O3           PIN_CFG(72, ALT_B)
+#define GPIO72_STMAPE_DAT2     PIN_CFG(72, ALT_C)
+
+#define GPIO73_GPIO            PIN_CFG(73, GPIO)
+#define GPIO73_LCD_D3          PIN_CFG(73, ALT_A)
+#define GPIO73_KP_O2           PIN_CFG(73, ALT_B)
+#define GPIO73_STMAPE_DAT1     PIN_CFG(73, ALT_C)
+
+#define GPIO74_GPIO            PIN_CFG(74, GPIO)
+#define GPIO74_LCD_D4          PIN_CFG(74, ALT_A)
+#define GPIO74_KP_I5           PIN_CFG(74, ALT_B)
+#define GPIO74_STMAPE_DAT0     PIN_CFG(74, ALT_C)
+
+#define GPIO75_GPIO            PIN_CFG(75, GPIO)
+#define GPIO75_LCD_D5          PIN_CFG(75, ALT_A)
+#define GPIO75_KP_I4           PIN_CFG(75, ALT_B)
+#define GPIO75_U2_RXD          PIN_CFG(75, ALT_C)
+
+#define GPIO76_GPIO            PIN_CFG(76, GPIO)
+#define GPIO76_LCD_D6          PIN_CFG(76, ALT_A)
+#define GPIO76_KP_I3           PIN_CFG(76, ALT_B)
+#define GPIO76_U2_TXD          PIN_CFG(76, ALT_C)
+
+#define GPIO77_GPIO            PIN_CFG(77, GPIO)
+#define GPIO77_LCD_D7          PIN_CFG(77, ALT_A)
+#define GPIO77_KP_I2           PIN_CFG(77, ALT_B)
+#define GPIO77_NONE            PIN_CFG(77, ALT_C)
+
+#define GPIO78_GPIO            PIN_CFG(78, GPIO)
+#define GPIO78_LCD_D8          PIN_CFG(78, ALT_A)
+#define GPIO78_KP_O6           PIN_CFG(78, ALT_B)
+#define GPIO78_IP_GPIO2                PIN_CFG(78, ALT_C)
+
+#define GPIO79_GPIO            PIN_CFG(79, GPIO)
+#define GPIO79_LCD_D9          PIN_CFG(79, ALT_A)
+#define GPIO79_KP_I6           PIN_CFG(79, ALT_B)
+#define GPIO79_IP_GPIO3                PIN_CFG(79, ALT_C)
+
+#define GPIO80_GPIO            PIN_CFG(80, GPIO)
+#define GPIO80_LCD_D10         PIN_CFG(80, ALT_A)
+#define GPIO80_KP_SKA0         PIN_CFG(80, ALT_B)
+#define GPIO80_IP_GPIO4                PIN_CFG(80, ALT_C)
+
+#define GPIO81_GPIO            PIN_CFG(81, GPIO)
+#define GPIO81_LCD_D11         PIN_CFG(81, ALT_A)
+#define GPIO81_KP_SKB0         PIN_CFG(81, ALT_B)
+#define GPIO81_IP_GPIO5                PIN_CFG(81, ALT_C)
+
+#define GPIO82_GPIO            PIN_CFG(82, GPIO)
+#define GPIO82_LCD_D12         PIN_CFG(82, ALT_A)
+#define GPIO82_KP_O5           PIN_CFG(82, ALT_B)
+
+#define GPIO83_GPIO            PIN_CFG(83, GPIO)
+#define GPIO83_LCD_D13         PIN_CFG(83, ALT_A)
+#define GPIO83_KP_O4           PIN_CFG(83, ALT_B)
+
+#define GPIO84_GPIO            PIN_CFG(84, GPIO)
+#define GPIO84_LCD_D14         PIN_CFG(84, ALT_A)
+#define GPIO84_KP_I5           PIN_CFG(84, ALT_B)
+
+#define GPIO85_GPIO            PIN_CFG(85, GPIO)
+#define GPIO85_LCD_D15         PIN_CFG(85, ALT_A)
+#define GPIO85_KP_I4           PIN_CFG(85, ALT_B)
+
+#define GPIO86_GPIO            PIN_CFG(86, GPIO)
+#define GPIO86_LCD_D16         PIN_CFG(86, ALT_A)
+#define GPIO86_SM_ADQ0         PIN_CFG(86, ALT_B)
+#define GPIO86_MC5_DAT0                PIN_CFG(86, ALT_C)
+
+#define GPIO87_GPIO            PIN_CFG(87, GPIO)
+#define GPIO87_LCD_D17         PIN_CFG(87, ALT_A)
+#define GPIO87_SM_ADQ1         PIN_CFG(87, ALT_B)
+#define GPIO87_MC5_DAT1                PIN_CFG(87, ALT_C)
+
+#define GPIO88_GPIO            PIN_CFG(88, GPIO)
+#define GPIO88_LCD_D18         PIN_CFG(88, ALT_A)
+#define GPIO88_SM_ADQ2         PIN_CFG(88, ALT_B)
+#define GPIO88_MC5_DAT2                PIN_CFG(88, ALT_C)
+
+#define GPIO89_GPIO            PIN_CFG(89, GPIO)
+#define GPIO89_LCD_D19         PIN_CFG(89, ALT_A)
+#define GPIO89_SM_ADQ3         PIN_CFG(89, ALT_B)
+#define GPIO89_MC5_DAT3                PIN_CFG(89, ALT_C)
+
+#define GPIO90_GPIO            PIN_CFG(90, GPIO)
+#define GPIO90_LCD_D20         PIN_CFG(90, ALT_A)
+#define GPIO90_SM_ADQ4         PIN_CFG(90, ALT_B)
+#define GPIO90_MC5_CMD         PIN_CFG(90, ALT_C)
+
+#define GPIO91_GPIO            PIN_CFG(91, GPIO)
+#define GPIO91_LCD_D21         PIN_CFG(91, ALT_A)
+#define GPIO91_SM_ADQ5         PIN_CFG(91, ALT_B)
+#define GPIO91_MC5_FBCLK       PIN_CFG(91, ALT_C)
+
+#define GPIO92_GPIO            PIN_CFG(92, GPIO)
+#define GPIO92_LCD_D22         PIN_CFG(92, ALT_A)
+#define GPIO92_SM_ADQ6         PIN_CFG(92, ALT_B)
+#define GPIO92_MC5_CLK         PIN_CFG(92, ALT_C)
+
+#define GPIO93_GPIO            PIN_CFG(93, GPIO)
+#define GPIO93_LCD_D23         PIN_CFG(93, ALT_A)
+#define GPIO93_SM_ADQ7         PIN_CFG(93, ALT_B)
+#define GPIO93_MC5_DAT4                PIN_CFG(93, ALT_C)
+
+#define GPIO94_GPIO            PIN_CFG(94, GPIO)
+#define GPIO94_KP_O7           PIN_CFG(94, ALT_A)
+#define GPIO94_SM_ADVn         PIN_CFG(94, ALT_B)
+#define GPIO94_MC5_DAT5                PIN_CFG(94, ALT_C)
+
+#define GPIO95_GPIO            PIN_CFG(95, GPIO)
+#define GPIO95_KP_I7           PIN_CFG(95, ALT_A)
+#define GPIO95_SM_CS0n         PIN_CFG(95, ALT_B)
+#define GPIO95_SM_PS0n         PIN_CFG(95, ALT_C)
+
+#define GPIO96_GPIO            PIN_CFG(96, GPIO)
+#define GPIO96_KP_O6           PIN_CFG(96, ALT_A)
+#define GPIO96_SM_OEn          PIN_CFG(96, ALT_B)
+#define GPIO96_MC5_DAT6                PIN_CFG(96, ALT_C)
+
+#define GPIO97_GPIO            PIN_CFG(97, GPIO)
+#define GPIO97_KP_I6           PIN_CFG(97, ALT_A)
+#define GPIO97_SM_WEn          PIN_CFG(97, ALT_B)
+#define GPIO97_MC5_DAT7                PIN_CFG(97, ALT_C)
+
+#define GPIO128_GPIO           PIN_CFG(128, GPIO)
+#define GPIO128_MC2_CLK                PIN_CFG(128, ALT_A)
+#define GPIO128_SM_CKO         PIN_CFG(128, ALT_B)
+
+#define GPIO129_GPIO           PIN_CFG(129, GPIO)
+#define GPIO129_MC2_CMD                PIN_CFG(129, ALT_A)
+#define GPIO129_SM_WAIT0n      PIN_CFG(129, ALT_B)
+
+#define GPIO130_GPIO           PIN_CFG(130, GPIO)
+#define GPIO130_MC2_FBCLK      PIN_CFG(130, ALT_A)
+#define GPIO130_SM_FBCLK       PIN_CFG(130, ALT_B)
+#define GPIO130_MC2_RSTN       PIN_CFG(130, ALT_C)
+
+#define GPIO131_GPIO           PIN_CFG(131, GPIO)
+#define GPIO131_MC2_DAT0       PIN_CFG(131, ALT_A)
+#define GPIO131_SM_ADQ8                PIN_CFG(131, ALT_B)
+
+#define GPIO132_GPIO           PIN_CFG(132, GPIO)
+#define GPIO132_MC2_DAT1       PIN_CFG(132, ALT_A)
+#define GPIO132_SM_ADQ9                PIN_CFG(132, ALT_B)
+
+#define GPIO133_GPIO           PIN_CFG(133, GPIO)
+#define GPIO133_MC2_DAT2       PIN_CFG(133, ALT_A)
+#define GPIO133_SM_ADQ10       PIN_CFG(133, ALT_B)
+
+#define GPIO134_GPIO           PIN_CFG(134, GPIO)
+#define GPIO134_MC2_DAT3       PIN_CFG(134, ALT_A)
+#define GPIO134_SM_ADQ11       PIN_CFG(134, ALT_B)
+
+#define GPIO135_GPIO           PIN_CFG(135, GPIO)
+#define GPIO135_MC2_DAT4       PIN_CFG(135, ALT_A)
+#define GPIO135_SM_ADQ12       PIN_CFG(135, ALT_B)
+
+#define GPIO136_GPIO           PIN_CFG(136, GPIO)
+#define GPIO136_MC2_DAT5       PIN_CFG(136, ALT_A)
+#define GPIO136_SM_ADQ13       PIN_CFG(136, ALT_B)
+
+#define GPIO137_GPIO           PIN_CFG(137, GPIO)
+#define GPIO137_MC2_DAT6       PIN_CFG(137, ALT_A)
+#define GPIO137_SM_ADQ14       PIN_CFG(137, ALT_B)
+
+#define GPIO138_GPIO           PIN_CFG(138, GPIO)
+#define GPIO138_MC2_DAT7       PIN_CFG(138, ALT_A)
+#define GPIO138_SM_ADQ15       PIN_CFG(138, ALT_B)
+
+#define GPIO139_GPIO           PIN_CFG(139, GPIO)
+#define GPIO139_SSP1_RXD       PIN_CFG(139, ALT_A)
+#define GPIO139_SM_WAIT1n      PIN_CFG(139, ALT_B)
+#define GPIO139_KP_O8          PIN_CFG(139, ALT_C)
+
+#define GPIO140_GPIO           PIN_CFG(140, GPIO)
+#define GPIO140_SSP1_TXD       PIN_CFG(140, ALT_A)
+#define GPIO140_IP_GPIO7       PIN_CFG(140, ALT_B)
+#define GPIO140_KP_SKA1                PIN_CFG(140, ALT_C)
+
+#define GPIO141_GPIO           PIN_CFG(141, GPIO)
+#define GPIO141_SSP1_CLK       PIN_CFG(141, ALT_A)
+#define GPIO141_IP_GPIO2       PIN_CFG(141, ALT_B)
+#define GPIO141_KP_O9          PIN_CFG(141, ALT_C)
+
+#define GPIO142_GPIO           PIN_CFG(142, GPIO)
+#define GPIO142_SSP1_FRM       PIN_CFG(142, ALT_A)
+#define GPIO142_IP_GPIO3       PIN_CFG(142, ALT_B)
+#define GPIO142_KP_SKB1                PIN_CFG(142, ALT_C)
+
+#define GPIO143_GPIO           PIN_CFG(143, GPIO)
+#define GPIO143_SSP0_CLK       PIN_CFG(143, ALT_A)
+
+#define GPIO144_GPIO           PIN_CFG(144, GPIO)
+#define GPIO144_SSP0_FRM       PIN_CFG(144, ALT_A)
+
+#define GPIO145_GPIO           PIN_CFG(145, GPIO)
+#define GPIO145_SSP0_RXD       PIN_CFG(145, ALT_A)
+
+#define GPIO146_GPIO           PIN_CFG(146, GPIO)
+#define GPIO146_SSP0_TXD       PIN_CFG(146, ALT_A)
+
+#define GPIO147_GPIO           PIN_CFG(147, GPIO)
+#define GPIO147_I2C0_SCL       PIN_CFG_PULL(147, ALT_A, UP)
+
+#define GPIO148_GPIO           PIN_CFG(148, GPIO)
+#define GPIO148_I2C0_SDA       PIN_CFG_PULL(148, ALT_A, UP)
+
+#define GPIO149_GPIO           PIN_CFG(149, GPIO)
+#define GPIO149_IP_GPIO0       PIN_CFG(149, ALT_A)
+#define GPIO149_SM_CS1n                PIN_CFG(149, ALT_B)
+#define GPIO149_SM_PS1n                PIN_CFG(149, ALT_C)
+
+#define GPIO150_GPIO           PIN_CFG(150, GPIO)
+#define GPIO150_IP_GPIO1       PIN_CFG(150, ALT_A)
+#define GPIO150_LCDA_CLK       PIN_CFG(150, ALT_B)
+
+#define GPIO151_GPIO           PIN_CFG(151, GPIO)
+#define GPIO151_KP_SKA0                PIN_CFG(151, ALT_A)
+#define GPIO151_LCD_VSI0       PIN_CFG(151, ALT_B)
+#define GPIO151_KP_O8          PIN_CFG(151, ALT_C)
+
+#define GPIO152_GPIO           PIN_CFG(152, GPIO)
+#define GPIO152_KP_SKB0                PIN_CFG(152, ALT_A)
+#define GPIO152_LCD_VSI1       PIN_CFG(152, ALT_B)
+#define GPIO152_KP_O9          PIN_CFG(152, ALT_C)
+
+#define GPIO153_GPIO           PIN_CFG(153, GPIO)
+#define GPIO153_KP_I7          PIN_CFG(153, ALT_A)
+#define GPIO153_LCD_D24                PIN_CFG(153, ALT_B)
+#define GPIO153_U2_RXD         PIN_CFG(153, ALT_C)
+
+#define GPIO154_GPIO           PIN_CFG(154, GPIO)
+#define GPIO154_KP_I6          PIN_CFG(154, ALT_A)
+#define GPIO154_LCD_D25                PIN_CFG(154, ALT_B)
+#define GPIO154_U2_TXD         PIN_CFG(154, ALT_C)
+
+#define GPIO155_GPIO           PIN_CFG(155, GPIO)
+#define GPIO155_KP_I5          PIN_CFG(155, ALT_A)
+#define GPIO155_LCD_D26                PIN_CFG(155, ALT_B)
+#define GPIO155_STMAPE_CLK     PIN_CFG(155, ALT_C)
+
+#define GPIO156_GPIO           PIN_CFG(156, GPIO)
+#define GPIO156_KP_I4          PIN_CFG(156, ALT_A)
+#define GPIO156_LCD_D27                PIN_CFG(156, ALT_B)
+#define GPIO156_STMAPE_DAT3    PIN_CFG(156, ALT_C)
+
+#define GPIO157_GPIO           PIN_CFG(157, GPIO)
+#define GPIO157_KP_O7          PIN_CFG(157, ALT_A)
+#define GPIO157_LCD_D28                PIN_CFG(157, ALT_B)
+#define GPIO157_STMAPE_DAT2    PIN_CFG(157, ALT_C)
+
+#define GPIO158_GPIO           PIN_CFG(158, GPIO)
+#define GPIO158_KP_O6          PIN_CFG(158, ALT_A)
+#define GPIO158_LCD_D29                PIN_CFG(158, ALT_B)
+#define GPIO158_STMAPE_DAT1    PIN_CFG(158, ALT_C)
+
+#define GPIO159_GPIO           PIN_CFG(159, GPIO)
+#define GPIO159_KP_O5          PIN_CFG(159, ALT_A)
+#define GPIO159_LCD_D30                PIN_CFG(159, ALT_B)
+#define GPIO159_STMAPE_DAT0    PIN_CFG(159, ALT_C)
+
+#define GPIO160_GPIO           PIN_CFG(160, GPIO)
+#define GPIO160_KP_O4          PIN_CFG(160, ALT_A)
+#define GPIO160_LCD_D31                PIN_CFG(160, ALT_B)
+#define GPIO160_NONE           PIN_CFG(160, ALT_C)
+
+#define GPIO161_GPIO           PIN_CFG(161, GPIO)
+#define GPIO161_KP_I3          PIN_CFG(161, ALT_A)
+#define GPIO161_LCD_D32                PIN_CFG(161, ALT_B)
+#define GPIO161_UARTMOD_RXD    PIN_CFG(161, ALT_C)
+
+#define GPIO162_GPIO           PIN_CFG(162, GPIO)
+#define GPIO162_KP_I2          PIN_CFG(162, ALT_A)
+#define GPIO162_LCD_D33                PIN_CFG(162, ALT_B)
+#define GPIO162_UARTMOD_TXD    PIN_CFG(162, ALT_C)
+
+#define GPIO163_GPIO           PIN_CFG(163, GPIO)
+#define GPIO163_KP_I1          PIN_CFG(163, ALT_A)
+#define GPIO163_LCD_D34                PIN_CFG(163, ALT_B)
+#define GPIO163_STMMOD_CLK     PIN_CFG(163, ALT_C)
+
+#define GPIO164_GPIO           PIN_CFG(164, GPIO)
+#define GPIO164_KP_I0          PIN_CFG(164, ALT_A)
+#define GPIO164_LCD_D35                PIN_CFG(164, ALT_B)
+#define GPIO164_STMMOD_DAT3    PIN_CFG(164, ALT_C)
+
+#define GPIO165_GPIO           PIN_CFG(165, GPIO)
+#define GPIO165_KP_O3          PIN_CFG(165, ALT_A)
+#define GPIO165_LCD_D36                PIN_CFG(165, ALT_B)
+#define GPIO165_STMMOD_DAT2    PIN_CFG(165, ALT_C)
+
+#define GPIO166_GPIO           PIN_CFG(166, GPIO)
+#define GPIO166_KP_O2          PIN_CFG(166, ALT_A)
+#define GPIO166_LCD_D37                PIN_CFG(166, ALT_B)
+#define GPIO166_STMMOD_DAT1    PIN_CFG(166, ALT_C)
+
+#define GPIO167_GPIO           PIN_CFG(167, GPIO)
+#define GPIO167_KP_O1          PIN_CFG(167, ALT_A)
+#define GPIO167_LCD_D38                PIN_CFG(167, ALT_B)
+#define GPIO167_STMMOD_DAT0    PIN_CFG(167, ALT_C)
+
+#define GPIO168_GPIO           PIN_CFG(168, GPIO)
+#define GPIO168_KP_O0          PIN_CFG(168, ALT_A)
+#define GPIO168_LCD_D39                PIN_CFG(168, ALT_B)
+#define GPIO168_NONE           PIN_CFG(168, ALT_C)
+
+#define GPIO169_GPIO           PIN_CFG(169, GPIO)
+#define GPIO169_RF_PURn                PIN_CFG(169, ALT_A)
+#define GPIO169_LCDA_DE                PIN_CFG(169, ALT_B)
+#define GPIO169_USBSIM_PDC     PIN_CFG(169, ALT_C)
+
+#define GPIO170_GPIO           PIN_CFG(170, GPIO)
+#define GPIO170_MODEM_STATE    PIN_CFG(170, ALT_A)
+#define GPIO170_LCDA_VSO       PIN_CFG(170, ALT_B)
+#define GPIO170_KP_SKA1                PIN_CFG(170, ALT_C)
+
+#define GPIO171_GPIO           PIN_CFG(171, GPIO)
+#define GPIO171_MODEM_PWREN    PIN_CFG(171, ALT_A)
+#define GPIO171_LCDA_HSO       PIN_CFG(171, ALT_B)
+#define GPIO171_KP_SKB1                PIN_CFG(171, ALT_C)
+
+#define GPIO192_GPIO           PIN_CFG(192, GPIO)
+#define GPIO192_MSP2_SCK       PIN_CFG(192, ALT_A)
+
+#define GPIO193_GPIO           PIN_CFG(193, GPIO)
+#define GPIO193_MSP2_TXD       PIN_CFG(193, ALT_A)
+
+#define GPIO194_GPIO           PIN_CFG(194, GPIO)
+#define GPIO194_MSP2_TCK       PIN_CFG(194, ALT_A)
+
+#define GPIO195_GPIO           PIN_CFG(195, GPIO)
+#define GPIO195_MSP2_TFS       PIN_CFG(195, ALT_A)
+
+#define GPIO196_GPIO           PIN_CFG(196, GPIO)
+#define GPIO196_MSP2_RXD       PIN_CFG(196, ALT_A)
+
+#define GPIO197_GPIO           PIN_CFG(197, GPIO)
+#define GPIO197_MC4_DAT3       PIN_CFG(197, ALT_A)
+
+#define GPIO198_GPIO           PIN_CFG(198, GPIO)
+#define GPIO198_MC4_DAT2       PIN_CFG(198, ALT_A)
+
+#define GPIO199_GPIO           PIN_CFG(199, GPIO)
+#define GPIO199_MC4_DAT1       PIN_CFG(199, ALT_A)
+
+#define GPIO200_GPIO           PIN_CFG(200, GPIO)
+#define GPIO200_MC4_DAT0       PIN_CFG(200, ALT_A)
+
+#define GPIO201_GPIO           PIN_CFG(201, GPIO)
+#define GPIO201_MC4_CMD                PIN_CFG(201, ALT_A)
+
+#define GPIO202_GPIO           PIN_CFG(202, GPIO)
+#define GPIO202_MC4_FBCLK      PIN_CFG(202, ALT_A)
+#define GPIO202_PWL            PIN_CFG(202, ALT_B)
+#define GPIO202_MC4_RSTN       PIN_CFG(202, ALT_C)
+
+#define GPIO203_GPIO           PIN_CFG(203, GPIO)
+#define GPIO203_MC4_CLK                PIN_CFG(203, ALT_A)
+
+#define GPIO204_GPIO           PIN_CFG(204, GPIO)
+#define GPIO204_MC4_DAT7       PIN_CFG(204, ALT_A)
+
+#define GPIO205_GPIO           PIN_CFG(205, GPIO)
+#define GPIO205_MC4_DAT6       PIN_CFG(205, ALT_A)
+
+#define GPIO206_GPIO           PIN_CFG(206, GPIO)
+#define GPIO206_MC4_DAT5       PIN_CFG(206, ALT_A)
+
+#define GPIO207_GPIO           PIN_CFG(207, GPIO)
+#define GPIO207_MC4_DAT4       PIN_CFG(207, ALT_A)
+
+#define GPIO208_GPIO           PIN_CFG(208, GPIO)
+#define GPIO208_MC1_CLK                PIN_CFG(208, ALT_A)
+
+#define GPIO209_GPIO           PIN_CFG(209, GPIO)
+#define GPIO209_MC1_FBCLK      PIN_CFG(209, ALT_A)
+#define GPIO209_SPI1_CLK       PIN_CFG(209, ALT_B)
+
+#define GPIO210_GPIO           PIN_CFG(210, GPIO)
+#define GPIO210_MC1_CMD                PIN_CFG(210, ALT_A)
+
+#define GPIO211_GPIO           PIN_CFG(211, GPIO)
+#define GPIO211_MC1_DAT0       PIN_CFG(211, ALT_A)
+
+#define GPIO212_GPIO           PIN_CFG(212, GPIO)
+#define GPIO212_MC1_DAT1       PIN_CFG(212, ALT_A)
+#define GPIO212_SPI1_FRM       PIN_CFG(212, ALT_B)
+
+#define GPIO213_GPIO           PIN_CFG(213, GPIO)
+#define GPIO213_MC1_DAT2       PIN_CFG(213, ALT_A)
+#define GPIO213_SPI1_TXD       PIN_CFG(213, ALT_B)
+
+#define GPIO214_GPIO           PIN_CFG(214, GPIO)
+#define GPIO214_MC1_DAT3       PIN_CFG(214, ALT_A)
+#define GPIO214_SPI1_RXD       PIN_CFG(214, ALT_B)
+
+#define GPIO215_GPIO           PIN_CFG(215, GPIO)
+#define GPIO215_MC1_CMDDIR     PIN_CFG(215, ALT_A)
+#define GPIO215_MC3_DAT2DIR    PIN_CFG(215, ALT_B)
+#define GPIO215_CLKOUT1                PIN_CFG(215, ALT_C)
+
+#define GPIO216_GPIO           PIN_CFG(216, GPIO)
+#define GPIO216_MC1_DAT2DIR    PIN_CFG(216, ALT_A)
+#define GPIO216_MC3_CMDDIR     PIN_CFG(216, ALT_B)
+#define GPIO216_I2C3_SDA       PIN_CFG_PULL(216, ALT_C, UP)
+
+#define GPIO217_GPIO           PIN_CFG(217, GPIO)
+#define GPIO217_MC1_DAT0DIR    PIN_CFG(217, ALT_A)
+#define GPIO217_MC3_DAT31DIR   PIN_CFG(217, ALT_B)
+#define GPIO217_CLKOUT2                PIN_CFG(217, ALT_C)
+
+#define GPIO218_GPIO           PIN_CFG(218, GPIO)
+#define GPIO218_MC1_DAT31DIR   PIN_CFG(218, ALT_A)
+#define GPIO218_MC3_DAT0DIR    PIN_CFG(218, ALT_B)
+#define GPIO218_I2C3_SCL       PIN_CFG_PULL(218, ALT_C, UP)
+
+#define GPIO219_GPIO           PIN_CFG(219, GPIO)
+#define GPIO219_HSIR_FLA0      PIN_CFG(219, ALT_A)
+#define GPIO219_MC3_CLK                PIN_CFG(219, ALT_B)
+
+#define GPIO220_GPIO           PIN_CFG(220, GPIO)
+#define GPIO220_HSIR_DAT0      PIN_CFG(220, ALT_A)
+#define GPIO220_MC3_FBCLK      PIN_CFG(220, ALT_B)
+#define GPIO220_SPI0_CLK       PIN_CFG(220, ALT_C)
+
+#define GPIO221_GPIO           PIN_CFG(221, GPIO)
+#define GPIO221_HSIR_RDY0      PIN_CFG(221, ALT_A)
+#define GPIO221_MC3_CMD                PIN_CFG(221, ALT_B)
+
+#define GPIO222_GPIO           PIN_CFG(222, GPIO)
+#define GPIO222_HSIT_FLA0      PIN_CFG(222, ALT_A)
+#define GPIO222_MC3_DAT0       PIN_CFG(222, ALT_B)
+
+#define GPIO223_GPIO           PIN_CFG(223, GPIO)
+#define GPIO223_HSIT_DAT0      PIN_CFG(223, ALT_A)
+#define GPIO223_MC3_DAT1       PIN_CFG(223, ALT_B)
+#define GPIO223_SPI0_FRM       PIN_CFG(223, ALT_C)
+
+#define GPIO224_GPIO           PIN_CFG(224, GPIO)
+#define GPIO224_HSIT_RDY0      PIN_CFG(224, ALT_A)
+#define GPIO224_MC3_DAT2       PIN_CFG(224, ALT_B)
+#define GPIO224_SPI0_TXD       PIN_CFG(224, ALT_C)
+
+#define GPIO225_GPIO           PIN_CFG(225, GPIO)
+#define GPIO225_HSIT_CAWAKE0   PIN_CFG(225, ALT_A)
+#define GPIO225_MC3_DAT3       PIN_CFG(225, ALT_B)
+#define GPIO225_SPI0_RXD       PIN_CFG(225, ALT_C)
+
+#define GPIO226_GPIO           PIN_CFG(226, GPIO)
+#define GPIO226_HSIT_ACWAKE0   PIN_CFG(226, ALT_A)
+#define GPIO226_PWL            PIN_CFG(226, ALT_B)
+#define GPIO226_USBSIM_PDC     PIN_CFG(226, ALT_C)
+
+#define GPIO227_GPIO           PIN_CFG(227, GPIO)
+#define GPIO227_CLKOUT1                PIN_CFG(227, ALT_A)
+
+#define GPIO228_GPIO           PIN_CFG(228, GPIO)
+#define GPIO228_CLKOUT2                PIN_CFG(228, ALT_A)
+
+#define GPIO229_GPIO           PIN_CFG(229, GPIO)
+#define GPIO229_CLKOUT1                PIN_CFG(229, ALT_A)
+#define GPIO229_PWL            PIN_CFG(229, ALT_B)
+#define GPIO229_I2C3_SDA       PIN_CFG_PULL(229, ALT_C, UP)
+
+#define GPIO230_GPIO           PIN_CFG(230, GPIO)
+#define GPIO230_CLKOUT2                PIN_CFG(230, ALT_A)
+#define GPIO230_PWL            PIN_CFG(230, ALT_B)
+#define GPIO230_I2C3_SCL       PIN_CFG_PULL(230, ALT_C, UP)
+
+#define GPIO256_GPIO           PIN_CFG(256, GPIO)
+#define GPIO256_USB_NXT                PIN_CFG(256, ALT_A)
+
+#define GPIO257_GPIO           PIN_CFG(257, GPIO)
+#define GPIO257_USB_STP                PIN_CFG(257, ALT_A)
+
+#define GPIO258_GPIO           PIN_CFG(258, GPIO)
+#define GPIO258_USB_XCLK       PIN_CFG(258, ALT_A)
+#define GPIO258_NONE           PIN_CFG(258, ALT_B)
+#define GPIO258_DDR_TRIG       PIN_CFG(258, ALT_C)
+
+#define GPIO259_GPIO           PIN_CFG(259, GPIO)
+#define GPIO259_USB_DIR                PIN_CFG(259, ALT_A)
+
+#define GPIO260_GPIO           PIN_CFG(260, GPIO)
+#define GPIO260_USB_DAT7       PIN_CFG(260, ALT_A)
+
+#define GPIO261_GPIO           PIN_CFG(261, GPIO)
+#define GPIO261_USB_DAT6       PIN_CFG(261, ALT_A)
+
+#define GPIO262_GPIO           PIN_CFG(262, GPIO)
+#define GPIO262_USB_DAT5       PIN_CFG(262, ALT_A)
+
+#define GPIO263_GPIO           PIN_CFG(263, GPIO)
+#define GPIO263_USB_DAT4       PIN_CFG(263, ALT_A)
+
+#define GPIO264_GPIO           PIN_CFG(264, GPIO)
+#define GPIO264_USB_DAT3       PIN_CFG(264, ALT_A)
+
+#define GPIO265_GPIO           PIN_CFG(265, GPIO)
+#define GPIO265_USB_DAT2       PIN_CFG(265, ALT_A)
+
+#define GPIO266_GPIO           PIN_CFG(266, GPIO)
+#define GPIO266_USB_DAT1       PIN_CFG(266, ALT_A)
+
+#define GPIO267_GPIO           PIN_CFG(267, GPIO)
+#define GPIO267_USB_DAT0       PIN_CFG(267, ALT_A)
+
+#endif
index 3dff8641b03fa7a639d5f886345dad1e84706445..e38acb0f89c884b961bdb1dc11fa59b1a0112bc0 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/amba/clcd.h>
 #include <linux/amba/pl061.h>
 #include <linux/amba/mmci.h>
+#include <linux/amba/pl022.h>
 #include <linux/io.h>
 #include <linux/gfp.h>
 
@@ -354,6 +355,21 @@ static struct mmci_platform_data mmc0_plat_data = {
        .gpio_cd        = -1,
 };
 
+static struct resource char_lcd_resources[] = {
+       {
+               .start = VERSATILE_CHAR_LCD_BASE,
+               .end   = (VERSATILE_CHAR_LCD_BASE + SZ_4K - 1),
+               .flags = IORESOURCE_MEM,
+       },
+};
+
+static struct platform_device char_lcd_device = {
+       .name           =       "arm-charlcd",
+       .id             =       -1,
+       .num_resources  =       ARRAY_SIZE(char_lcd_resources),
+       .resource       =       char_lcd_resources,
+};
+
 /*
  * Clock handling
  */
@@ -400,8 +416,13 @@ static struct clk ref24_clk = {
        .rate   = 24000000,
 };
 
+static struct clk dummy_apb_pclk;
+
 static struct clk_lookup lookups[] = {
-       {       /* UART0 */
+       {       /* AMBA bus clock */
+               .con_id         = "apb_pclk",
+               .clk            = &dummy_apb_pclk,
+       }, {    /* UART0 */
                .dev_id         = "dev:f1",
                .clk            = &ref24_clk,
        }, {    /* UART1 */
@@ -425,6 +446,9 @@ static struct clk_lookup lookups[] = {
        }, {    /* MMC1 */
                .dev_id         = "fpga:0b",
                .clk            = &ref24_clk,
+       }, {    /* SSP */
+               .dev_id         = "dev:f4",
+               .clk            = &ref24_clk,
        }, {    /* CLCD */
                .dev_id         = "dev:20",
                .clk            = &osc4_clk,
@@ -703,6 +727,12 @@ static struct pl061_platform_data gpio1_plat_data = {
        .irq_base       = IRQ_GPIO1_START,
 };
 
+static struct pl022_ssp_controller ssp0_plat_data = {
+       .bus_id = 0,
+       .enable_dma = 0,
+       .num_chipselect = 1,
+};
+
 #define AACI_IRQ       { IRQ_AACI, NO_IRQ }
 #define AACI_DMA       { 0x80, 0x81 }
 #define MMCI0_IRQ      { IRQ_MMCI0A,IRQ_SIC_MMCI0B }
@@ -772,7 +802,7 @@ AMBA_DEVICE(sci0,  "dev:f0",  SCI,      NULL);
 AMBA_DEVICE(uart0, "dev:f1",  UART0,    NULL);
 AMBA_DEVICE(uart1, "dev:f2",  UART1,    NULL);
 AMBA_DEVICE(uart2, "dev:f3",  UART2,    NULL);
-AMBA_DEVICE(ssp0,  "dev:f4",  SSP,      NULL);
+AMBA_DEVICE(ssp0,  "dev:f4",  SSP,      &ssp0_plat_data);
 
 static struct amba_device *amba_devs[] __initdata = {
        &dmac_device,
@@ -843,6 +873,7 @@ void __init versatile_init(void)
        platform_device_register(&versatile_flash_device);
        platform_device_register(&versatile_i2c_device);
        platform_device_register(&smc91x_device);
+       platform_device_register(&char_lcd_device);
 
        for (i = 0; i < ARRAY_SIZE(amba_devs); i++) {
                struct amba_device *d = amba_devs[i];
index 334f0df4e948bc46c322c3ca0c50fe8002b676c0..13c7e5f90a82eb1d4f52883e784eea8d08257546 100644 (file)
@@ -304,7 +304,7 @@ int __init pci_versatile_setup(int nr, struct pci_sys_data *sys)
 }
 
 
-struct pci_bus *pci_versatile_scan_bus(int nr, struct pci_sys_data *sys)
+struct pci_bus * __init pci_versatile_scan_bus(int nr, struct pci_sys_data *sys)
 {
        return pci_scan_bus(sys->busnr, &pci_versatile_ops, sys);
 }
index 6353459bb5671bc2623377529b9a6dfcd5db4a8f..577df6cccb0891503bf0188f3c0f33103c159000 100644 (file)
@@ -16,6 +16,7 @@
 #include <asm/hardware/gic.h>
 #include <asm/mach-types.h>
 #include <asm/pmu.h>
+#include <asm/smp_twd.h>
 
 #include <mach/clkdev.h>
 #include <mach/ct-ca9x4.h>
@@ -53,6 +54,7 @@ static struct map_desc ct_ca9x4_io_desc[] __initdata = {
 
 static void __init ct_ca9x4_map_io(void)
 {
+       twd_base = MMIO_P2V(A9_MPCORE_TWD);
        v2m_map_io(ct_ca9x4_io_desc, ARRAY_SIZE(ct_ca9x4_io_desc));
 }
 
index 8650f04136efa0e744edb230f4d94afb1325f755..f9e2f8d229623d5825251e1999b0bf501a18b4a6 100644 (file)
@@ -28,6 +28,7 @@
 #define A9_MPCORE_SCU          (CT_CA9X4_MPIC + 0x0000)
 #define A9_MPCORE_GIC_CPU      (CT_CA9X4_MPIC + 0x0100)
 #define A9_MPCORE_GIT          (CT_CA9X4_MPIC + 0x0200)
+#define A9_MPCORE_TWD          (CT_CA9X4_MPIC + 0x0600)
 #define A9_MPCORE_GIC_DIST     (CT_CA9X4_MPIC + 0x1000)
 
 /*
index c84239761cb4a2881d226f6f82b3acb694d30dae..817f0ad38a0b5100ec0884e8c908c84af471bec4 100644 (file)
@@ -298,8 +298,13 @@ static struct clk osc2_clk = {
        .rate   = 24000000,
 };
 
+static struct clk dummy_apb_pclk;
+
 static struct clk_lookup v2m_lookups[] = {
-       {       /* UART0 */
+       {       /* AMBA bus clock */
+               .con_id         = "apb_pclk",
+               .clk            = &dummy_apb_pclk,
+       }, {    /* UART0 */
                .dev_id         = "mb:uart0",
                .clk            = &osc2_clk,
        }, {    /* UART1 */
index b2eda4dc1c34ea7172a773899275c18bbfab5dd4..7a1fa6adb7c32d5645b1f0e608b1e61794081afc 100644 (file)
@@ -36,6 +36,8 @@
 #include <mach/nuc900_spi.h>
 #include <mach/map.h>
 #include <mach/fb.h>
+#include <mach/regs-ldm.h>
+#include <mach/w90p910_keypad.h>
 
 #include "cpu.h"
 
@@ -207,7 +209,7 @@ static struct nuc900_spi_info nuc900_spiflash_data = {
        .divider        = 24,
        .sleep          = 0,
        .txnum          = 0,
-       .txbitlen       = 1,
+       .txbitlen       = 8,
        .bus_num        = 0,
 };
 
@@ -256,7 +258,7 @@ static struct spi_board_info nuc900_spi_board_info[] __initdata = {
                .modalias = "m25p80",
                .max_speed_hz = 20000000,
                .bus_num = 0,
-               .chip_select = 1,
+               .chip_select = 0,
                .platform_data = &nuc900_spi_flash_data,
                .mode = SPI_MODE_0,
        },
@@ -361,6 +363,39 @@ struct platform_device nuc900_device_fmi = {
 
 /* KPI controller*/
 
+static int nuc900_keymap[] = {
+       KEY(0, 0, KEY_A),
+       KEY(0, 1, KEY_B),
+       KEY(0, 2, KEY_C),
+       KEY(0, 3, KEY_D),
+
+       KEY(1, 0, KEY_E),
+       KEY(1, 1, KEY_F),
+       KEY(1, 2, KEY_G),
+       KEY(1, 3, KEY_H),
+
+       KEY(2, 0, KEY_I),
+       KEY(2, 1, KEY_J),
+       KEY(2, 2, KEY_K),
+       KEY(2, 3, KEY_L),
+
+       KEY(3, 0, KEY_M),
+       KEY(3, 1, KEY_N),
+       KEY(3, 2, KEY_O),
+       KEY(3, 3, KEY_P),
+};
+
+static struct matrix_keymap_data nuc900_map_data = {
+       .keymap                 = nuc900_keymap,
+       .keymap_size            = ARRAY_SIZE(nuc900_keymap),
+};
+
+struct w90p910_keypad_platform_data nuc900_keypad_info = {
+       .keymap_data    = &nuc900_map_data,
+       .prescale       = 0xfa,
+       .debounce       = 0x50,
+};
+
 static struct resource nuc900_kpi_resource[] = {
        [0] = {
                .start = W90X900_PA_KPI,
@@ -380,9 +415,49 @@ struct platform_device nuc900_device_kpi = {
        .id             = -1,
        .num_resources  = ARRAY_SIZE(nuc900_kpi_resource),
        .resource       = nuc900_kpi_resource,
+       .dev            = {
+                               .platform_data = &nuc900_keypad_info,
+                       }
 };
 
-#ifdef CONFIG_FB_NUC900
+/* LCD controller*/
+
+static struct nuc900fb_display __initdata nuc900_lcd_info[] = {
+       /* Giantplus Technology GPM1040A0 320x240 Color TFT LCD */
+       [0] = {
+               .type           = LCM_DCCS_VA_SRC_RGB565,
+               .width          = 320,
+               .height         = 240,
+               .xres           = 320,
+               .yres           = 240,
+               .bpp            = 16,
+               .pixclock       = 200000,
+               .left_margin    = 34,
+               .right_margin   = 54,
+               .hsync_len      = 10,
+               .upper_margin   = 18,
+               .lower_margin   = 4,
+               .vsync_len      = 1,
+               .dccs           = 0x8e00041a,
+               .devctl         = 0x060800c0,
+               .fbctrl         = 0x00a000a0,
+               .scale          = 0x04000400,
+       },
+};
+
+static struct nuc900fb_mach_info nuc900_fb_info __initdata = {
+#if defined(CONFIG_GPM1040A0_320X240)
+       .displays               = &nuc900_lcd_info[0],
+#else
+       .displays               = nuc900_lcd_info,
+#endif
+       .num_displays           = ARRAY_SIZE(nuc900_lcd_info),
+       .default_display        = 0,
+       .gpio_dir               = 0x00000004,
+       .gpio_dir_mask          = 0xFFFFFFFD,
+       .gpio_data              = 0x00000004,
+       .gpio_data_mask         = 0xFFFFFFFD,
+};
 
 static struct resource nuc900_lcd_resource[] = {
        [0] = {
@@ -406,23 +481,10 @@ struct platform_device nuc900_device_lcd = {
        .dev              = {
                .dma_mask               = &nuc900_device_lcd_dmamask,
                .coherent_dma_mask      = -1,
+               .platform_data = &nuc900_fb_info,
        }
 };
 
-void  nuc900_fb_set_platdata(struct nuc900fb_mach_info *pd)
-{
-       struct nuc900fb_mach_info *npd;
-
-       npd = kmalloc(sizeof(*npd), GFP_KERNEL);
-       if (npd) {
-               memcpy(npd, pd, sizeof(*npd));
-               nuc900_device_lcd.dev.platform_data = npd;
-       } else {
-               printk(KERN_ERR "no memory for LCD platform data\n");
-       }
-}
-#endif
-
 /* AUDIO controller*/
 static u64 nuc900_device_audio_dmamask = -1;
 static struct resource nuc900_ac97_resource[] = {
diff --git a/arch/arm/mach-w90x900/include/mach/regs-gcr.h b/arch/arm/mach-w90x900/include/mach/regs-gcr.h
new file mode 100644 (file)
index 0000000..6087abd
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ * arch/arm/mach-w90x900/include/mach/regs-gcr.h
+ *
+ * Copyright (c) 2010 Nuvoton technology corporation
+ * All rights reserved.
+ *
+ * Wan ZongShun <mcuos.com@gmail.com>
+ *
+ * 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.
+ *
+ */
+
+#ifndef __ASM_ARCH_REGS_GCR_H
+#define __ASM_ARCH_REGS_GCR_H
+
+/* Global control registers */
+
+#define GCR_BA         W90X900_VA_GCR
+#define REG_PDID       (GCR_BA+0x000)
+#define REG_PWRON      (GCR_BA+0x004)
+#define REG_ARBCON     (GCR_BA+0x008)
+#define REG_MFSEL      (GCR_BA+0x00C)
+#define REG_EBIDPE     (GCR_BA+0x010)
+#define REG_LCDDPE     (GCR_BA+0x014)
+#define REG_GPIOCPE    (GCR_BA+0x018)
+#define REG_GPIODPE    (GCR_BA+0x01C)
+#define REG_GPIOEPE    (GCR_BA+0x020)
+#define REG_GPIOFPE    (GCR_BA+0x024)
+#define REG_GPIOGPE    (GCR_BA+0x028)
+#define REG_GPIOHPE    (GCR_BA+0x02C)
+#define REG_GPIOIPE    (GCR_BA+0x030)
+#define REG_GTMP1      (GCR_BA+0x034)
+#define REG_GTMP2      (GCR_BA+0x038)
+#define REG_GTMP3      (GCR_BA+0x03C)
+
+#endif /*  __ASM_ARCH_REGS_GCR_H */
index b3edc3cccf52f4c152ce9008e4d92fcc157c1584..04d295f89eb049f86ed0b8c6ba8386c5d0c0c09e 100644 (file)
 #include <asm/mach/map.h>
 #include <asm/mach-types.h>
 #include <mach/map.h>
-#include <mach/regs-ldm.h>
 #include <mach/fb.h>
 
 #include "nuc950.h"
 
-#ifdef CONFIG_FB_NUC900
-/* LCD Controller */
-static struct nuc900fb_display __initdata nuc950_lcd_info[] = {
-       /* Giantplus Technology GPM1040A0 320x240 Color TFT LCD */
-       [0] = {
-               .type           = LCM_DCCS_VA_SRC_RGB565,
-               .width          = 320,
-               .height         = 240,
-               .xres           = 320,
-               .yres           = 240,
-               .bpp            = 16,
-               .pixclock       = 200000,
-               .left_margin    = 34,
-               .right_margin   = 54,
-               .hsync_len      = 10,
-               .upper_margin   = 18,
-               .lower_margin   = 4,
-               .vsync_len      = 1,
-               .dccs           = 0x8e00041a,
-               .devctl         = 0x060800c0,
-               .fbctrl         = 0x00a000a0,
-               .scale          = 0x04000400,
-       },
-};
-
-static struct nuc900fb_mach_info nuc950_fb_info __initdata = {
-#if defined(CONFIG_GPM1040A0_320X240)
-       .displays               = &nuc950_lcd_info[0],
-#else
-       .displays               = nuc950_lcd_info,
-#endif
-       .num_displays           = ARRAY_SIZE(nuc950_lcd_info),
-       .default_display        = 0,
-       .gpio_dir               = 0x00000004,
-       .gpio_dir_mask          = 0xFFFFFFFD,
-       .gpio_data              = 0x00000004,
-       .gpio_data_mask         = 0xFFFFFFFD,
-};
-#endif
-
 static void __init nuc950evb_map_io(void)
 {
        nuc950_map_io();
@@ -74,9 +33,6 @@ static void __init nuc950evb_map_io(void)
 static void __init nuc950evb_init(void)
 {
        nuc950_board_init();
-#ifdef CONFIG_FB_NUC900
-       nuc900_fb_set_platdata(&nuc950_fb_info);
-#endif
 }
 
 MACHINE_START(W90P950EVB, "W90P950EVB")
index 656f03b3b629f28e8972d983f652a406ef7d7e94..1523f41369857a95ad8669679bae3ecf88820a00 100644 (file)
@@ -26,6 +26,8 @@
 static struct platform_device *nuc910_dev[] __initdata = {
        &nuc900_device_ts,
        &nuc900_device_rtc,
+       &nuc900_device_lcd,
+       &nuc900_device_kpi,
 };
 
 /* define specific CPU platform io map */
index 4d1f1ab044c48868d588b6081d8ebcabad98c7b5..5704f74a50eeaf768667c07669108396fdcd1fe0 100644 (file)
@@ -26,9 +26,7 @@
 static struct platform_device *nuc950_dev[] __initdata = {
        &nuc900_device_kpi,
        &nuc900_device_fmi,
-#ifdef CONFIG_FB_NUC900
        &nuc900_device_lcd,
-#endif
 };
 
 /* define specific CPU platform io map */
index 101105e5261070118f8039c5ecbcde350792f38f..87ec141fcaa6e5ad0d5d7eef0e1a8249ac2bdcc3 100644 (file)
@@ -717,17 +717,6 @@ config TLS_REG_EMUL
          a few prototypes like that in existence) and therefore access to
          that required register must be emulated.
 
-config HAS_TLS_REG
-       bool
-       depends on !TLS_REG_EMUL
-       default y if SMP || CPU_32v7
-       help
-         This selects support for the CP15 thread register.
-         It is defined to be available on some ARMv6 processors (including
-         all SMP capable ARMv6's) or later processors.  User space may
-         assume directly accessing that register and always obtain the
-         expected value only on ARMv7 and above.
-
 config NEEDS_SYSCALL_FOR_CMPXCHG
        bool
        help
index e8d34a80851c66baf47c3d97e89e029e5e9a96ca..d63b6c413758a23389cbb09ea1ab8686c61e56db 100644 (file)
@@ -15,7 +15,6 @@ endif
 obj-$(CONFIG_MODULES)          += proc-syms.o
 
 obj-$(CONFIG_ALIGNMENT_TRAP)   += alignment.o
-obj-$(CONFIG_DISCONTIGMEM)     += discontig.o
 obj-$(CONFIG_HIGHMEM)          += highmem.o
 
 obj-$(CONFIG_CPU_ABRT_NOMMU)   += abort-nommu.o
index 6f98c358989a63347a6a1150f99f25b52b106dbe..d073b64ae87ec4f6652c67959244292dbb3e69ad 100644 (file)
@@ -924,8 +924,20 @@ static int __init alignment_init(void)
                ai_usermode = UM_FIXUP;
        }
 
-       hook_fault_code(1, do_alignment, SIGILL, "alignment exception");
-       hook_fault_code(3, do_alignment, SIGILL, "alignment exception");
+       hook_fault_code(1, do_alignment, SIGBUS, BUS_ADRALN,
+                       "alignment exception");
+
+       /*
+        * ARMv6K and ARMv7 use fault status 3 (0b00011) as Access Flag section
+        * fault, not as alignment error.
+        *
+        * TODO: handle ARMv6K properly. Runtime check for 'K' extension is
+        * needed.
+        */
+       if (cpu_architecture() <= CPU_ARCH_ARMv6) {
+               hook_fault_code(3, do_alignment, SIGBUS, BUS_ADRALN,
+                               "alignment exception");
+       }
 
        return 0;
 }
diff --git a/arch/arm/mm/discontig.c b/arch/arm/mm/discontig.c
deleted file mode 100644 (file)
index c8c0c4b..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-/*
- * linux/arch/arm/mm/discontig.c
- *
- * Discontiguous memory support.
- *
- * Initial code: Copyright (C) 1999-2000 Nicolas Pitre
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-#include <linux/module.h>
-#include <linux/mmzone.h>
-#include <linux/bootmem.h>
-
-#if MAX_NUMNODES != 4 && MAX_NUMNODES != 16
-# error Fix Me Please
-#endif
-
-/*
- * Our node_data structure for discontiguous memory.
- */
-
-pg_data_t discontig_node_data[MAX_NUMNODES] = {
-  { .bdata = &bootmem_node_data[0] },
-  { .bdata = &bootmem_node_data[1] },
-  { .bdata = &bootmem_node_data[2] },
-  { .bdata = &bootmem_node_data[3] },
-#if MAX_NUMNODES == 16
-  { .bdata = &bootmem_node_data[4] },
-  { .bdata = &bootmem_node_data[5] },
-  { .bdata = &bootmem_node_data[6] },
-  { .bdata = &bootmem_node_data[7] },
-  { .bdata = &bootmem_node_data[8] },
-  { .bdata = &bootmem_node_data[9] },
-  { .bdata = &bootmem_node_data[10] },
-  { .bdata = &bootmem_node_data[11] },
-  { .bdata = &bootmem_node_data[12] },
-  { .bdata = &bootmem_node_data[13] },
-  { .bdata = &bootmem_node_data[14] },
-  { .bdata = &bootmem_node_data[15] },
-#endif
-};
-
-EXPORT_SYMBOL(discontig_node_data);
index 9e7742f0a102fe5c7d091134391db81d93d71726..c704eed63c5ddba4c5f849f7ab7b6420008cef21 100644 (file)
@@ -183,6 +183,8 @@ static void *
 __dma_alloc_remap(struct page *page, size_t size, gfp_t gfp, pgprot_t prot)
 {
        struct arm_vmregion *c;
+       size_t align;
+       int bit;
 
        if (!consistent_pte[0]) {
                printk(KERN_ERR "%s: not initialised\n", __func__);
@@ -190,10 +192,21 @@ __dma_alloc_remap(struct page *page, size_t size, gfp_t gfp, pgprot_t prot)
                return NULL;
        }
 
+       /*
+        * Align the virtual region allocation - maximum alignment is
+        * a section size, minimum is a page size.  This helps reduce
+        * fragmentation of the DMA space, and also prevents allocations
+        * smaller than a section from crossing a section boundary.
+        */
+       bit = fls(size - 1) + 1;
+       if (bit > SECTION_SHIFT)
+               bit = SECTION_SHIFT;
+       align = 1 << bit;
+
        /*
         * Allocate a virtual address in the consistent mapping region.
         */
-       c = arm_vmregion_alloc(&consistent_head, size,
+       c = arm_vmregion_alloc(&consistent_head, align, size,
                            gfp & ~(__GFP_DMA | __GFP_HIGHMEM));
        if (c) {
                pte_t *pte;
index cbfb2edcf7d12a3a1cae18f04c041d94dc055bcc..23b0b03af5ea84b8a01e10c59a97091d92f4618b 100644 (file)
@@ -413,7 +413,16 @@ do_translation_fault(unsigned long addr, unsigned int fsr,
        pmd_k = pmd_offset(pgd_k, addr);
        pmd   = pmd_offset(pgd, addr);
 
-       if (pmd_none(*pmd_k))
+       /*
+        * On ARM one Linux PGD entry contains two hardware entries (see page
+        * tables layout in pgtable.h). We normally guarantee that we always
+        * fill both L1 entries. But create_mapping() doesn't follow the rule.
+        * It can create inidividual L1 entries, so here we have to call
+        * pmd_none() check for the entry really corresponded to address, not
+        * for the first of pair.
+        */
+       index = (addr >> SECTION_SHIFT) & 1;
+       if (pmd_none(pmd_k[index]))
                goto bad_area;
 
        copy_pmd(pmd, pmd_k);
@@ -463,15 +472,10 @@ static struct fsr_info {
         * defines these to be "precise" aborts.
         */
        { do_bad,               SIGSEGV, 0,             "vector exception"                 },
-       { do_bad,               SIGILL,  BUS_ADRALN,    "alignment exception"              },
+       { do_bad,               SIGBUS,  BUS_ADRALN,    "alignment exception"              },
        { do_bad,               SIGKILL, 0,             "terminal exception"               },
-       { do_bad,               SIGILL,  BUS_ADRALN,    "alignment exception"              },
-/* Do we need runtime check ? */
-#if __LINUX_ARM_ARCH__ < 6
+       { do_bad,               SIGBUS,  BUS_ADRALN,    "alignment exception"              },
        { do_bad,               SIGBUS,  0,             "external abort on linefetch"      },
-#else
-       { do_translation_fault, SIGSEGV, SEGV_MAPERR,   "I-cache maintenance fault"        },
-#endif
        { do_translation_fault, SIGSEGV, SEGV_MAPERR,   "section translation fault"        },
        { do_bad,               SIGBUS,  0,             "external abort on linefetch"      },
        { do_page_fault,        SIGSEGV, SEGV_MAPERR,   "page translation fault"           },
@@ -508,13 +512,15 @@ static struct fsr_info {
 
 void __init
 hook_fault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *),
-               int sig, const char *name)
+               int sig, int code, const char *name)
 {
-       if (nr >= 0 && nr < ARRAY_SIZE(fsr_info)) {
-               fsr_info[nr].fn   = fn;
-               fsr_info[nr].sig  = sig;
-               fsr_info[nr].name = name;
-       }
+       if (nr < 0 || nr >= ARRAY_SIZE(fsr_info))
+               BUG();
+
+       fsr_info[nr].fn   = fn;
+       fsr_info[nr].sig  = sig;
+       fsr_info[nr].code = code;
+       fsr_info[nr].name = name;
 }
 
 /*
@@ -594,3 +600,25 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
        arm_notify_die("", regs, &info, ifsr, 0);
 }
 
+static int __init exceptions_init(void)
+{
+       if (cpu_architecture() >= CPU_ARCH_ARMv6) {
+               hook_fault_code(4, do_translation_fault, SIGSEGV, SEGV_MAPERR,
+                               "I-cache maintenance fault");
+       }
+
+       if (cpu_architecture() >= CPU_ARCH_ARMv7) {
+               /*
+                * TODO: Access flag faults introduced in ARMv6K.
+                * Runtime check for 'K' extension is needed
+                */
+               hook_fault_code(3, do_bad, SIGSEGV, SEGV_MAPERR,
+                               "section access flag fault");
+               hook_fault_code(6, do_bad, SIGSEGV, SEGV_MAPERR,
+                               "section access flag fault");
+       }
+
+       return 0;
+}
+
+arch_initcall(exceptions_init);
index f6a9994653237ddc2a56c7c1fbd9070615cea937..7185b00650fe419d0fa0f43b3e79e2e0d90cf6e6 100644 (file)
@@ -17,6 +17,7 @@
 #include <linux/initrd.h>
 #include <linux/highmem.h>
 #include <linux/gfp.h>
+#include <linux/memblock.h>
 
 #include <asm/mach-types.h>
 #include <asm/sections.h>
@@ -79,38 +80,37 @@ struct meminfo meminfo;
 void show_mem(void)
 {
        int free = 0, total = 0, reserved = 0;
-       int shared = 0, cached = 0, slab = 0, node, i;
+       int shared = 0, cached = 0, slab = 0, i;
        struct meminfo * mi = &meminfo;
 
        printk("Mem-info:\n");
        show_free_areas();
-       for_each_online_node(node) {
-               for_each_nodebank (i,mi,node) {
-                       struct membank *bank = &mi->bank[i];
-                       unsigned int pfn1, pfn2;
-                       struct page *page, *end;
-
-                       pfn1 = bank_pfn_start(bank);
-                       pfn2 = bank_pfn_end(bank);
-
-                       page = pfn_to_page(pfn1);
-                       end  = pfn_to_page(pfn2 - 1) + 1;
-
-                       do {
-                               total++;
-                               if (PageReserved(page))
-                                       reserved++;
-                               else if (PageSwapCache(page))
-                                       cached++;
-                               else if (PageSlab(page))
-                                       slab++;
-                               else if (!page_count(page))
-                                       free++;
-                               else
-                                       shared += page_count(page) - 1;
-                               page++;
-                       } while (page < end);
-               }
+
+       for_each_bank (i, mi) {
+               struct membank *bank = &mi->bank[i];
+               unsigned int pfn1, pfn2;
+               struct page *page, *end;
+
+               pfn1 = bank_pfn_start(bank);
+               pfn2 = bank_pfn_end(bank);
+
+               page = pfn_to_page(pfn1);
+               end  = pfn_to_page(pfn2 - 1) + 1;
+
+               do {
+                       total++;
+                       if (PageReserved(page))
+                               reserved++;
+                       else if (PageSwapCache(page))
+                               cached++;
+                       else if (PageSlab(page))
+                               slab++;
+                       else if (!page_count(page))
+                               free++;
+                       else
+                               shared += page_count(page) - 1;
+                       page++;
+               } while (page < end);
        }
 
        printk("%d pages of RAM\n", total);
@@ -121,7 +121,7 @@ void show_mem(void)
        printk("%d pages swap cached\n", cached);
 }
 
-static void __init find_node_limits(int node, struct meminfo *mi,
+static void __init find_limits(struct meminfo *mi,
        unsigned long *min, unsigned long *max_low, unsigned long *max_high)
 {
        int i;
@@ -129,7 +129,7 @@ static void __init find_node_limits(int node, struct meminfo *mi,
        *min = -1UL;
        *max_low = *max_high = 0;
 
-       for_each_nodebank(i, mi, node) {
+       for_each_bank (i, mi) {
                struct membank *bank = &mi->bank[i];
                unsigned long start, end;
 
@@ -147,155 +147,64 @@ static void __init find_node_limits(int node, struct meminfo *mi,
        }
 }
 
-/*
- * FIXME: We really want to avoid allocating the bootmap bitmap
- * over the top of the initrd.  Hopefully, this is located towards
- * the start of a bank, so if we allocate the bootmap bitmap at
- * the end, we won't clash.
- */
-static unsigned int __init
-find_bootmap_pfn(int node, struct meminfo *mi, unsigned int bootmap_pages)
-{
-       unsigned int start_pfn, i, bootmap_pfn;
-
-       start_pfn   = PAGE_ALIGN(__pa(_end)) >> PAGE_SHIFT;
-       bootmap_pfn = 0;
-
-       for_each_nodebank(i, mi, node) {
-               struct membank *bank = &mi->bank[i];
-               unsigned int start, end;
-
-               start = bank_pfn_start(bank);
-               end   = bank_pfn_end(bank);
-
-               if (end < start_pfn)
-                       continue;
-
-               if (start < start_pfn)
-                       start = start_pfn;
-
-               if (end <= start)
-                       continue;
-
-               if (end - start >= bootmap_pages) {
-                       bootmap_pfn = start;
-                       break;
-               }
-       }
-
-       if (bootmap_pfn == 0)
-               BUG();
-
-       return bootmap_pfn;
-}
-
-static int __init check_initrd(struct meminfo *mi)
-{
-       int initrd_node = -2;
-#ifdef CONFIG_BLK_DEV_INITRD
-       unsigned long end = phys_initrd_start + phys_initrd_size;
-
-       /*
-        * Make sure that the initrd is within a valid area of
-        * memory.
-        */
-       if (phys_initrd_size) {
-               unsigned int i;
-
-               initrd_node = -1;
-
-               for (i = 0; i < mi->nr_banks; i++) {
-                       struct membank *bank = &mi->bank[i];
-                       if (bank_phys_start(bank) <= phys_initrd_start &&
-                           end <= bank_phys_end(bank))
-                               initrd_node = bank->node;
-               }
-       }
-
-       if (initrd_node == -1) {
-               printk(KERN_ERR "INITRD: 0x%08lx+0x%08lx extends beyond "
-                      "physical memory - disabling initrd\n",
-                      phys_initrd_start, phys_initrd_size);
-               phys_initrd_start = phys_initrd_size = 0;
-       }
-#endif
-
-       return initrd_node;
-}
-
-static void __init bootmem_init_node(int node, struct meminfo *mi,
+static void __init arm_bootmem_init(struct meminfo *mi,
        unsigned long start_pfn, unsigned long end_pfn)
 {
-       unsigned long boot_pfn;
        unsigned int boot_pages;
+       phys_addr_t bitmap;
        pg_data_t *pgdat;
        int i;
 
        /*
-        * Allocate the bootmem bitmap page.
+        * Allocate the bootmem bitmap page.  This must be in a region
+        * of memory which has already been mapped.
         */
        boot_pages = bootmem_bootmap_pages(end_pfn - start_pfn);
-       boot_pfn = find_bootmap_pfn(node, mi, boot_pages);
+       bitmap = memblock_alloc_base(boot_pages << PAGE_SHIFT, L1_CACHE_BYTES,
+                               __pfn_to_phys(end_pfn));
 
        /*
-        * Initialise the bootmem allocator for this node, handing the
+        * Initialise the bootmem allocator, handing the
         * memory banks over to bootmem.
         */
-       node_set_online(node);
-       pgdat = NODE_DATA(node);
-       init_bootmem_node(pgdat, boot_pfn, start_pfn, end_pfn);
+       node_set_online(0);
+       pgdat = NODE_DATA(0);
+       init_bootmem_node(pgdat, __phys_to_pfn(bitmap), start_pfn, end_pfn);
 
-       for_each_nodebank(i, mi, node) {
+       for_each_bank(i, mi) {
                struct membank *bank = &mi->bank[i];
                if (!bank->highmem)
-                       free_bootmem_node(pgdat, bank_phys_start(bank), bank_phys_size(bank));
+                       free_bootmem(bank_phys_start(bank), bank_phys_size(bank));
        }
 
        /*
-        * Reserve the bootmem bitmap for this node.
+        * Reserve the memblock reserved regions in bootmem.
         */
-       reserve_bootmem_node(pgdat, boot_pfn << PAGE_SHIFT,
-                            boot_pages << PAGE_SHIFT, BOOTMEM_DEFAULT);
-}
-
-static void __init bootmem_reserve_initrd(int node)
-{
-#ifdef CONFIG_BLK_DEV_INITRD
-       pg_data_t *pgdat = NODE_DATA(node);
-       int res;
-
-       res = reserve_bootmem_node(pgdat, phys_initrd_start,
-                            phys_initrd_size, BOOTMEM_EXCLUSIVE);
-
-       if (res == 0) {
-               initrd_start = __phys_to_virt(phys_initrd_start);
-               initrd_end = initrd_start + phys_initrd_size;
-       } else {
-               printk(KERN_ERR
-                       "INITRD: 0x%08lx+0x%08lx overlaps in-use "
-                       "memory region - disabling initrd\n",
-                       phys_initrd_start, phys_initrd_size);
+       for (i = 0; i < memblock.reserved.cnt; i++) {
+               phys_addr_t start = memblock_start_pfn(&memblock.reserved, i);
+               if (start >= start_pfn &&
+                   memblock_end_pfn(&memblock.reserved, i) <= end_pfn)
+                       reserve_bootmem_node(pgdat, __pfn_to_phys(start),
+                               memblock_size_bytes(&memblock.reserved, i),
+                               BOOTMEM_DEFAULT);
        }
-#endif
 }
 
-static void __init bootmem_free_node(int node, struct meminfo *mi)
+static void __init arm_bootmem_free(struct meminfo *mi, unsigned long min,
+       unsigned long max_low, unsigned long max_high)
 {
        unsigned long zone_size[MAX_NR_ZONES], zhole_size[MAX_NR_ZONES];
-       unsigned long min, max_low, max_high;
        int i;
 
-       find_node_limits(node, mi, &min, &max_low, &max_high);
-
        /*
-        * initialise the zones within this node.
+        * initialise the zones.
         */
        memset(zone_size, 0, sizeof(zone_size));
 
        /*
-        * The size of this node has already been determined.  If we need
-        * to do anything fancy with the allocation of this memory to the
-        * zones, now is the time to do it.
+        * The memory size has already been determined.  If we need
+        * to do anything fancy with the allocation of this memory
+        * to the zones, now is the time to do it.
         */
        zone_size[0] = max_low - min;
 #ifdef CONFIG_HIGHMEM
@@ -303,11 +212,11 @@ static void __init bootmem_free_node(int node, struct meminfo *mi)
 #endif
 
        /*
-        * For each bank in this node, calculate the size of the holes.
-        *  holes = node_size - sum(bank_sizes_in_node)
+        * Calculate the size of the holes.
+        *  holes = node_size - sum(bank_sizes)
         */
        memcpy(zhole_size, zone_size, sizeof(zhole_size));
-       for_each_nodebank(i, mi, node) {
+       for_each_bank(i, mi) {
                int idx = 0;
 #ifdef CONFIG_HIGHMEM
                if (mi->bank[i].highmem)
@@ -320,24 +229,23 @@ static void __init bootmem_free_node(int node, struct meminfo *mi)
         * Adjust the sizes according to any special requirements for
         * this machine type.
         */
-       arch_adjust_zones(node, zone_size, zhole_size);
+       arch_adjust_zones(zone_size, zhole_size);
 
-       free_area_init_node(node, zone_size, min, zhole_size);
+       free_area_init_node(0, zone_size, min, zhole_size);
 }
 
 #ifndef CONFIG_SPARSEMEM
 int pfn_valid(unsigned long pfn)
 {
-       struct meminfo *mi = &meminfo;
-       unsigned int left = 0, right = mi->nr_banks;
+       struct memblock_region *mem = &memblock.memory;
+       unsigned int left = 0, right = mem->cnt;
 
        do {
                unsigned int mid = (right + left) / 2;
-               struct membank *bank = &mi->bank[mid];
 
-               if (pfn < bank_pfn_start(bank))
+               if (pfn < memblock_start_pfn(mem, mid))
                        right = mid;
-               else if (pfn >= bank_pfn_end(bank))
+               else if (pfn >= memblock_end_pfn(mem, mid))
                        left = mid + 1;
                else
                        return 1;
@@ -346,73 +254,69 @@ int pfn_valid(unsigned long pfn)
 }
 EXPORT_SYMBOL(pfn_valid);
 
-static void arm_memory_present(struct meminfo *mi, int node)
+static void arm_memory_present(void)
 {
 }
 #else
-static void arm_memory_present(struct meminfo *mi, int node)
+static void arm_memory_present(void)
 {
        int i;
-       for_each_nodebank(i, mi, node) {
-               struct membank *bank = &mi->bank[i];
-               memory_present(node, bank_pfn_start(bank), bank_pfn_end(bank));
-       }
+       for (i = 0; i < memblock.memory.cnt; i++)
+               memory_present(0, memblock_start_pfn(&memblock.memory, i),
+                                 memblock_end_pfn(&memblock.memory, i));
 }
 #endif
 
-void __init bootmem_init(void)
+void __init arm_memblock_init(struct meminfo *mi, struct machine_desc *mdesc)
 {
-       struct meminfo *mi = &meminfo;
-       unsigned long min, max_low, max_high;
-       int node, initrd_node;
+       int i;
 
-       /*
-        * Locate which node contains the ramdisk image, if any.
-        */
-       initrd_node = check_initrd(mi);
+       memblock_init();
+       for (i = 0; i < mi->nr_banks; i++)
+               memblock_add(mi->bank[i].start, mi->bank[i].size);
 
-       max_low = max_high = 0;
+       /* Register the kernel text, kernel data and initrd with memblock. */
+#ifdef CONFIG_XIP_KERNEL
+       memblock_reserve(__pa(_data), _end - _data);
+#else
+       memblock_reserve(__pa(_stext), _end - _stext);
+#endif
+#ifdef CONFIG_BLK_DEV_INITRD
+       if (phys_initrd_size) {
+               memblock_reserve(phys_initrd_start, phys_initrd_size);
 
-       /*
-        * Run through each node initialising the bootmem allocator.
-        */
-       for_each_node(node) {
-               unsigned long node_low, node_high;
+               /* Now convert initrd to virtual addresses */
+               initrd_start = __phys_to_virt(phys_initrd_start);
+               initrd_end = initrd_start + phys_initrd_size;
+       }
+#endif
 
-               find_node_limits(node, mi, &min, &node_low, &node_high);
+       arm_mm_memblock_reserve();
 
-               if (node_low > max_low)
-                       max_low = node_low;
-               if (node_high > max_high)
-                       max_high = node_high;
+       /* reserve any platform specific memblock areas */
+       if (mdesc->reserve)
+               mdesc->reserve();
 
-               /*
-                * If there is no memory in this node, ignore it.
-                * (We can't have nodes which have no lowmem)
-                */
-               if (node_low == 0)
-                       continue;
+       memblock_analyze();
+       memblock_dump_all();
+}
 
-               bootmem_init_node(node, mi, min, node_low);
+void __init bootmem_init(void)
+{
+       struct meminfo *mi = &meminfo;
+       unsigned long min, max_low, max_high;
 
-               /*
-                * Reserve any special node zero regions.
-                */
-               if (node == 0)
-                       reserve_node_zero(NODE_DATA(node));
+       max_low = max_high = 0;
 
-               /*
-                * If the initrd is in this node, reserve its memory.
-                */
-               if (node == initrd_node)
-                       bootmem_reserve_initrd(node);
+       find_limits(mi, &min, &max_low, &max_high);
 
-               /*
-                * Sparsemem tries to allocate bootmem in memory_present(),
-                * so must be done after the fixed reservations
-                */
-               arm_memory_present(mi, node);
-       }
+       arm_bootmem_init(mi, min, max_low);
+
+       /*
+        * Sparsemem tries to allocate bootmem in memory_present(),
+        * so must be done after the fixed reservations
+        */
+       arm_memory_present();
 
        /*
         * sparse_init() needs the bootmem allocator up and running.
@@ -420,12 +324,11 @@ void __init bootmem_init(void)
        sparse_init();
 
        /*
-        * Now free memory in each node - free_area_init_node needs
+        * Now free the memory - free_area_init_node needs
         * the sparse mem_map arrays initialized by sparse_init()
         * for memmap_init_zone(), otherwise all PFNs are invalid.
         */
-       for_each_node(node)
-               bootmem_free_node(node, mi);
+       arm_bootmem_free(mi, min, max_low, max_high);
 
        high_memory = __va((max_low << PAGE_SHIFT) - 1) + 1;
 
@@ -460,7 +363,7 @@ static inline int free_area(unsigned long pfn, unsigned long end, char *s)
 }
 
 static inline void
-free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn)
+free_memmap(unsigned long start_pfn, unsigned long end_pfn)
 {
        struct page *start_pg, *end_pg;
        unsigned long pg, pgend;
@@ -483,40 +386,39 @@ free_memmap(int node, unsigned long start_pfn, unsigned long end_pfn)
         * free the section of the memmap array.
         */
        if (pg < pgend)
-               free_bootmem_node(NODE_DATA(node), pg, pgend - pg);
+               free_bootmem(pg, pgend - pg);
 }
 
 /*
  * The mem_map array can get very big.  Free the unused area of the memory map.
  */
-static void __init free_unused_memmap_node(int node, struct meminfo *mi)
+static void __init free_unused_memmap(struct meminfo *mi)
 {
        unsigned long bank_start, prev_bank_end = 0;
        unsigned int i;
 
        /*
-        * [FIXME] This relies on each bank being in address order.  This
-        * may not be the case, especially if the user has provided the
-        * information on the command line.
+        * This relies on each bank being in address order.
+        * The banks are sorted previously in bootmem_init().
         */
-       for_each_nodebank(i, mi, node) {
+       for_each_bank(i, mi) {
                struct membank *bank = &mi->bank[i];
 
                bank_start = bank_pfn_start(bank);
-               if (bank_start < prev_bank_end) {
-                       printk(KERN_ERR "MEM: unordered memory banks.  "
-                               "Not freeing memmap.\n");
-                       break;
-               }
 
                /*
                 * If we had a previous bank, and there is a space
                 * between the current bank and the previous, free it.
                 */
-               if (prev_bank_end && prev_bank_end != bank_start)
-                       free_memmap(node, prev_bank_end, bank_start);
+               if (prev_bank_end && prev_bank_end < bank_start)
+                       free_memmap(prev_bank_end, bank_start);
 
-               prev_bank_end = bank_pfn_end(bank);
+               /*
+                * Align up here since the VM subsystem insists that the
+                * memmap entries are valid from the bank end aligned to
+                * MAX_ORDER_NR_PAGES.
+                */
+               prev_bank_end = ALIGN(bank_pfn_end(bank), MAX_ORDER_NR_PAGES);
        }
 }
 
@@ -528,21 +430,19 @@ static void __init free_unused_memmap_node(int node, struct meminfo *mi)
 void __init mem_init(void)
 {
        unsigned long reserved_pages, free_pages;
-       int i, node;
+       int i;
+#ifdef CONFIG_HAVE_TCM
+       /* These pointers are filled in on TCM detection */
+       extern u32 dtcm_end;
+       extern u32 itcm_end;
+#endif
 
-#ifndef CONFIG_DISCONTIGMEM
        max_mapnr   = pfn_to_page(max_pfn + PHYS_PFN_OFFSET) - mem_map;
-#endif
 
        /* this will put all unused low memory onto the freelists */
-       for_each_online_node(node) {
-               pg_data_t *pgdat = NODE_DATA(node);
+       free_unused_memmap(&meminfo);
 
-               free_unused_memmap_node(node, &meminfo);
-
-               if (pgdat->node_spanned_pages != 0)
-                       totalram_pages += free_all_bootmem_node(pgdat);
-       }
+       totalram_pages += free_all_bootmem();
 
 #ifdef CONFIG_SA1111
        /* now that our DMA memory is actually so designated, we can free it */
@@ -552,39 +452,35 @@ void __init mem_init(void)
 
 #ifdef CONFIG_HIGHMEM
        /* set highmem page free */
-       for_each_online_node(node) {
-               for_each_nodebank (i, &meminfo, node) {
-                       unsigned long start = bank_pfn_start(&meminfo.bank[i]);
-                       unsigned long end = bank_pfn_end(&meminfo.bank[i]);
-                       if (start >= max_low_pfn + PHYS_PFN_OFFSET)
-                               totalhigh_pages += free_area(start, end, NULL);
-               }
+       for_each_bank (i, &meminfo) {
+               unsigned long start = bank_pfn_start(&meminfo.bank[i]);
+               unsigned long end = bank_pfn_end(&meminfo.bank[i]);
+               if (start >= max_low_pfn + PHYS_PFN_OFFSET)
+                       totalhigh_pages += free_area(start, end, NULL);
        }
        totalram_pages += totalhigh_pages;
 #endif
 
        reserved_pages = free_pages = 0;
 
-       for_each_online_node(node) {
-               for_each_nodebank(i, &meminfo, node) {
-                       struct membank *bank = &meminfo.bank[i];
-                       unsigned int pfn1, pfn2;
-                       struct page *page, *end;
-
-                       pfn1 = bank_pfn_start(bank);
-                       pfn2 = bank_pfn_end(bank);
-
-                       page = pfn_to_page(pfn1);
-                       end  = pfn_to_page(pfn2 - 1) + 1;
-
-                       do {
-                               if (PageReserved(page))
-                                       reserved_pages++;
-                               else if (!page_count(page))
-                                       free_pages++;
-                               page++;
-                       } while (page < end);
-               }
+       for_each_bank(i, &meminfo) {
+               struct membank *bank = &meminfo.bank[i];
+               unsigned int pfn1, pfn2;
+               struct page *page, *end;
+
+               pfn1 = bank_pfn_start(bank);
+               pfn2 = bank_pfn_end(bank);
+
+               page = pfn_to_page(pfn1);
+               end  = pfn_to_page(pfn2 - 1) + 1;
+
+               do {
+                       if (PageReserved(page))
+                               reserved_pages++;
+                       else if (!page_count(page))
+                               free_pages++;
+                       page++;
+               } while (page < end);
        }
 
        /*
@@ -611,6 +507,10 @@ void __init mem_init(void)
 
        printk(KERN_NOTICE "Virtual kernel memory layout:\n"
                        "    vector  : 0x%08lx - 0x%08lx   (%4ld kB)\n"
+#ifdef CONFIG_HAVE_TCM
+                       "    DTCM    : 0x%08lx - 0x%08lx   (%4ld kB)\n"
+                       "    ITCM    : 0x%08lx - 0x%08lx   (%4ld kB)\n"
+#endif
                        "    fixmap  : 0x%08lx - 0x%08lx   (%4ld kB)\n"
 #ifdef CONFIG_MMU
                        "    DMA     : 0x%08lx - 0x%08lx   (%4ld MB)\n"
@@ -627,6 +527,10 @@ void __init mem_init(void)
 
                        MLK(UL(CONFIG_VECTORS_BASE), UL(CONFIG_VECTORS_BASE) +
                                (PAGE_SIZE)),
+#ifdef CONFIG_HAVE_TCM
+                       MLK(DTCM_OFFSET, (unsigned long) dtcm_end),
+                       MLK(ITCM_OFFSET, (unsigned long) itcm_end),
+#endif
                        MLK(FIXADDR_START, FIXADDR_TOP),
 #ifdef CONFIG_MMU
                        MLM(CONSISTENT_BASE, CONSISTENT_END),
index 28c8b950ef04e84f6d0893712fb22c5394808ee6..ab506272b2d3ef459b264b7741d61af46f6aa6b8 100644 (file)
  */
 #define VM_ARM_SECTION_MAPPING 0x80000000
 
-static int remap_area_pte(pmd_t *pmd, unsigned long addr, unsigned long end,
-                         unsigned long phys_addr, const struct mem_type *type)
-{
-       pgprot_t prot = __pgprot(type->prot_pte);
-       pte_t *pte;
-
-       pte = pte_alloc_kernel(pmd, addr);
-       if (!pte)
-               return -ENOMEM;
-
-       do {
-               if (!pte_none(*pte))
-                       goto bad;
-
-               set_pte_ext(pte, pfn_pte(phys_addr >> PAGE_SHIFT, prot), 0);
-               phys_addr += PAGE_SIZE;
-       } while (pte++, addr += PAGE_SIZE, addr != end);
-       return 0;
-
- bad:
-       printk(KERN_CRIT "remap_area_pte: page already exists\n");
-       BUG();
-}
-
-static inline int remap_area_pmd(pgd_t *pgd, unsigned long addr,
-                                unsigned long end, unsigned long phys_addr,
-                                const struct mem_type *type)
-{
-       unsigned long next;
-       pmd_t *pmd;
-       int ret = 0;
-
-       pmd = pmd_alloc(&init_mm, pgd, addr);
-       if (!pmd)
-               return -ENOMEM;
-
-       do {
-               next = pmd_addr_end(addr, end);
-               ret = remap_area_pte(pmd, addr, next, phys_addr, type);
-               if (ret)
-                       return ret;
-               phys_addr += next - addr;
-       } while (pmd++, addr = next, addr != end);
-       return ret;
-}
-
-static int remap_area_pages(unsigned long start, unsigned long pfn,
-                           size_t size, const struct mem_type *type)
-{
-       unsigned long addr = start;
-       unsigned long next, end = start + size;
-       unsigned long phys_addr = __pfn_to_phys(pfn);
-       pgd_t *pgd;
-       int err = 0;
-
-       BUG_ON(addr >= end);
-       pgd = pgd_offset_k(addr);
-       do {
-               next = pgd_addr_end(addr, end);
-               err = remap_area_pmd(pgd, addr, next, phys_addr, type);
-               if (err)
-                       break;
-               phys_addr += next - addr;
-       } while (pgd++, addr = next, addr != end);
-
-       return err;
-}
-
 int ioremap_page(unsigned long virt, unsigned long phys,
                 const struct mem_type *mtype)
 {
-       return remap_area_pages(virt, __phys_to_pfn(phys), PAGE_SIZE, mtype);
+       return ioremap_page_range(virt, virt + PAGE_SIZE, phys,
+                                 __pgprot(mtype->prot_pte));
 }
 EXPORT_SYMBOL(ioremap_page);
 
@@ -268,6 +201,12 @@ void __iomem * __arm_ioremap_pfn_caller(unsigned long pfn,
        if (pfn >= 0x100000 && (__pfn_to_phys(pfn) & ~SUPERSECTION_MASK))
                return NULL;
 
+       /*
+        * Don't allow RAM to be mapped - this causes problems with ARMv6+
+        */
+       if (WARN_ON(pfn_valid(pfn)))
+               return NULL;
+
        type = get_mem_type(mtype);
        if (!type)
                return NULL;
@@ -294,7 +233,8 @@ void __iomem * __arm_ioremap_pfn_caller(unsigned long pfn,
                err = remap_area_sections(addr, pfn, size, type);
        } else
 #endif
-               err = remap_area_pages(addr, pfn, size, type);
+               err = ioremap_page_range(addr, addr + size, __pfn_to_phys(pfn),
+                                        __pgprot(type->prot_pte));
 
        if (err) {
                vunmap((void *)addr);
index 815d08eecbb0f69a15a46f6990c481fd49dae779..6630620380a4aa0f538aed006a2de6f04c71d3dd 100644 (file)
@@ -28,7 +28,5 @@ extern void __flush_dcache_page(struct address_space *mapping, struct page *page
 
 #endif
 
-struct pglist_data;
-
 void __init bootmem_init(void);
-void reserve_node_zero(struct pglist_data *pgdat);
+void arm_mm_memblock_reserve(void);
index f5abc51c5a07ff24e047ef333c7dd47b942fc3a4..4f5b39687df541a417d4c3a9ac888fc53a31b999 100644 (file)
@@ -7,6 +7,7 @@
 #include <linux/shm.h>
 #include <linux/sched.h>
 #include <linux/io.h>
+#include <linux/random.h>
 #include <asm/cputype.h>
 #include <asm/system.h>
 
@@ -80,6 +81,9 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
                start_addr = addr = TASK_UNMAPPED_BASE;
                mm->cached_hole_size = 0;
        }
+       /* 8 bits of randomness in 20 address space bits */
+       if (current->flags & PF_RANDOMIZE)
+               addr += (get_random_int() % (1 << 8)) << PAGE_SHIFT;
 
 full_search:
        if (do_align)
index 28589417118643aec349aff677e3c1e0be53efa3..6e1c4f6a2b3f3a09ed3f10be9aeafab36c9a0924 100644 (file)
 #include <linux/kernel.h>
 #include <linux/errno.h>
 #include <linux/init.h>
-#include <linux/bootmem.h>
 #include <linux/mman.h>
 #include <linux/nodemask.h>
+#include <linux/memblock.h>
 #include <linux/sort.h>
 
 #include <asm/cputype.h>
-#include <asm/mach-types.h>
 #include <asm/sections.h>
 #include <asm/cachetype.h>
 #include <asm/setup.h>
@@ -258,6 +257,19 @@ static struct mem_type mem_types[] = {
                .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
                .domain    = DOMAIN_KERNEL,
        },
+       [MT_MEMORY_DTCM] = {
+               .prot_pte       = L_PTE_PRESENT | L_PTE_YOUNG |
+                                 L_PTE_DIRTY | L_PTE_WRITE,
+               .prot_l1        = PMD_TYPE_TABLE,
+               .prot_sect      = PMD_TYPE_SECT | PMD_SECT_XN,
+               .domain         = DOMAIN_KERNEL,
+       },
+       [MT_MEMORY_ITCM] = {
+               .prot_pte  = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
+                               L_PTE_USER | L_PTE_EXEC,
+               .prot_l1   = PMD_TYPE_TABLE,
+               .domain    = DOMAIN_IO,
+       },
 };
 
 const struct mem_type *get_mem_type(unsigned int type)
@@ -488,18 +500,28 @@ static void __init build_mem_type_table(void)
 
 #define vectors_base() (vectors_high() ? 0xffff0000 : 0)
 
-static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
-                                 unsigned long end, unsigned long pfn,
-                                 const struct mem_type *type)
+static void __init *early_alloc(unsigned long sz)
 {
-       pte_t *pte;
+       void *ptr = __va(memblock_alloc(sz, sz));
+       memset(ptr, 0, sz);
+       return ptr;
+}
 
+static pte_t * __init early_pte_alloc(pmd_t *pmd, unsigned long addr, unsigned long prot)
+{
        if (pmd_none(*pmd)) {
-               pte = alloc_bootmem_low_pages(2 * PTRS_PER_PTE * sizeof(pte_t));
-               __pmd_populate(pmd, __pa(pte) | type->prot_l1);
+               pte_t *pte = early_alloc(2 * PTRS_PER_PTE * sizeof(pte_t));
+               __pmd_populate(pmd, __pa(pte) | prot);
        }
+       BUG_ON(pmd_bad(*pmd));
+       return pte_offset_kernel(pmd, addr);
+}
 
-       pte = pte_offset_kernel(pmd, addr);
+static void __init alloc_init_pte(pmd_t *pmd, unsigned long addr,
+                                 unsigned long end, unsigned long pfn,
+                                 const struct mem_type *type)
+{
+       pte_t *pte = early_pte_alloc(pmd, addr, type->prot_l1);
        do {
                set_pte_ext(pte, pfn_pte(pfn, __pgprot(type->prot_pte)), 0);
                pfn++;
@@ -668,7 +690,7 @@ void __init iotable_init(struct map_desc *io_desc, int nr)
                create_mapping(io_desc + i);
 }
 
-static unsigned long __initdata vmalloc_reserve = SZ_128M;
+static void * __initdata vmalloc_min = (void *)(VMALLOC_END - SZ_128M);
 
 /*
  * vmalloc=size forces the vmalloc area to be exactly 'size'
@@ -677,7 +699,7 @@ static unsigned long __initdata vmalloc_reserve = SZ_128M;
  */
 static int __init early_vmalloc(char *arg)
 {
-       vmalloc_reserve = memparse(arg, NULL);
+       unsigned long vmalloc_reserve = memparse(arg, NULL);
 
        if (vmalloc_reserve < SZ_16M) {
                vmalloc_reserve = SZ_16M;
@@ -692,22 +714,26 @@ static int __init early_vmalloc(char *arg)
                        "vmalloc area is too big, limiting to %luMB\n",
                        vmalloc_reserve >> 20);
        }
+
+       vmalloc_min = (void *)(VMALLOC_END - vmalloc_reserve);
        return 0;
 }
 early_param("vmalloc", early_vmalloc);
 
-#define VMALLOC_MIN    (void *)(VMALLOC_END - vmalloc_reserve)
+phys_addr_t lowmem_end_addr;
 
 static void __init sanity_check_meminfo(void)
 {
        int i, j, highmem = 0;
 
+       lowmem_end_addr = __pa(vmalloc_min - 1) + 1;
+
        for (i = 0, j = 0; i < meminfo.nr_banks; i++) {
                struct membank *bank = &meminfo.bank[j];
                *bank = meminfo.bank[i];
 
 #ifdef CONFIG_HIGHMEM
-               if (__va(bank->start) > VMALLOC_MIN ||
+               if (__va(bank->start) > vmalloc_min ||
                    __va(bank->start) < (void *)PAGE_OFFSET)
                        highmem = 1;
 
@@ -717,8 +743,8 @@ static void __init sanity_check_meminfo(void)
                 * Split those memory banks which are partially overlapping
                 * the vmalloc area greatly simplifying things later.
                 */
-               if (__va(bank->start) < VMALLOC_MIN &&
-                   bank->size > VMALLOC_MIN - __va(bank->start)) {
+               if (__va(bank->start) < vmalloc_min &&
+                   bank->size > vmalloc_min - __va(bank->start)) {
                        if (meminfo.nr_banks >= NR_BANKS) {
                                printk(KERN_CRIT "NR_BANKS too low, "
                                                 "ignoring high memory\n");
@@ -727,12 +753,12 @@ static void __init sanity_check_meminfo(void)
                                        (meminfo.nr_banks - i) * sizeof(*bank));
                                meminfo.nr_banks++;
                                i++;
-                               bank[1].size -= VMALLOC_MIN - __va(bank->start);
-                               bank[1].start = __pa(VMALLOC_MIN - 1) + 1;
+                               bank[1].size -= vmalloc_min - __va(bank->start);
+                               bank[1].start = __pa(vmalloc_min - 1) + 1;
                                bank[1].highmem = highmem = 1;
                                j++;
                        }
-                       bank->size = VMALLOC_MIN - __va(bank->start);
+                       bank->size = vmalloc_min - __va(bank->start);
                }
 #else
                bank->highmem = highmem;
@@ -741,7 +767,7 @@ static void __init sanity_check_meminfo(void)
                 * Check whether this memory bank would entirely overlap
                 * the vmalloc area.
                 */
-               if (__va(bank->start) >= VMALLOC_MIN ||
+               if (__va(bank->start) >= vmalloc_min ||
                    __va(bank->start) < (void *)PAGE_OFFSET) {
                        printk(KERN_NOTICE "Ignoring RAM at %.8lx-%.8lx "
                               "(vmalloc region overlap).\n",
@@ -753,9 +779,9 @@ static void __init sanity_check_meminfo(void)
                 * Check whether this memory bank would partially overlap
                 * the vmalloc area.
                 */
-               if (__va(bank->start + bank->size) > VMALLOC_MIN ||
+               if (__va(bank->start + bank->size) > vmalloc_min ||
                    __va(bank->start + bank->size) < __va(bank->start)) {
-                       unsigned long newsize = VMALLOC_MIN - __va(bank->start);
+                       unsigned long newsize = vmalloc_min - __va(bank->start);
                        printk(KERN_NOTICE "Truncating RAM at %.8lx-%.8lx "
                               "to -%.8lx (vmalloc region overlap).\n",
                               bank->start, bank->start + bank->size - 1,
@@ -827,101 +853,23 @@ static inline void prepare_page_table(void)
 }
 
 /*
- * Reserve the various regions of node 0
+ * Reserve the special regions of memory
  */
-void __init reserve_node_zero(pg_data_t *pgdat)
+void __init arm_mm_memblock_reserve(void)
 {
-       unsigned long res_size = 0;
-
-       /*
-        * Register the kernel text and data with bootmem.
-        * Note that this can only be in node 0.
-        */
-#ifdef CONFIG_XIP_KERNEL
-       reserve_bootmem_node(pgdat, __pa(_data), _end - _data,
-                       BOOTMEM_DEFAULT);
-#else
-       reserve_bootmem_node(pgdat, __pa(_stext), _end - _stext,
-                       BOOTMEM_DEFAULT);
-#endif
-
        /*
         * Reserve the page tables.  These are already in use,
         * and can only be in node 0.
         */
-       reserve_bootmem_node(pgdat, __pa(swapper_pg_dir),
-                            PTRS_PER_PGD * sizeof(pgd_t), BOOTMEM_DEFAULT);
-
-       /*
-        * Hmm... This should go elsewhere, but we really really need to
-        * stop things allocating the low memory; ideally we need a better
-        * implementation of GFP_DMA which does not assume that DMA-able
-        * memory starts at zero.
-        */
-       if (machine_is_integrator() || machine_is_cintegrator())
-               res_size = __pa(swapper_pg_dir) - PHYS_OFFSET;
-
-       /*
-        * These should likewise go elsewhere.  They pre-reserve the
-        * screen memory region at the start of main system memory.
-        */
-       if (machine_is_edb7211())
-               res_size = 0x00020000;
-       if (machine_is_p720t())
-               res_size = 0x00014000;
-
-       /* H1940, RX3715 and RX1950 need to reserve this for suspend */
-
-       if (machine_is_h1940() || machine_is_rx3715()
-               || machine_is_rx1950()) {
-               reserve_bootmem_node(pgdat, 0x30003000, 0x1000,
-                               BOOTMEM_DEFAULT);
-               reserve_bootmem_node(pgdat, 0x30081000, 0x1000,
-                               BOOTMEM_DEFAULT);
-       }
-
-       if (machine_is_palmld() || machine_is_palmtx()) {
-               reserve_bootmem_node(pgdat, 0xa0000000, 0x1000,
-                               BOOTMEM_EXCLUSIVE);
-               reserve_bootmem_node(pgdat, 0xa0200000, 0x1000,
-                               BOOTMEM_EXCLUSIVE);
-       }
-
-       if (machine_is_treo680() || machine_is_centro()) {
-               reserve_bootmem_node(pgdat, 0xa0000000, 0x1000,
-                               BOOTMEM_EXCLUSIVE);
-               reserve_bootmem_node(pgdat, 0xa2000000, 0x1000,
-                               BOOTMEM_EXCLUSIVE);
-       }
-
-       if (machine_is_palmt5())
-               reserve_bootmem_node(pgdat, 0xa0200000, 0x1000,
-                               BOOTMEM_EXCLUSIVE);
-
-       /*
-        * U300 - This platform family can share physical memory
-        * between two ARM cpus, one running Linux and the other
-        * running another OS.
-        */
-       if (machine_is_u300()) {
-#ifdef CONFIG_MACH_U300_SINGLE_RAM
-#if ((CONFIG_MACH_U300_ACCESS_MEM_SIZE & 1) == 1) &&   \
-       CONFIG_MACH_U300_2MB_ALIGNMENT_FIX
-               res_size = 0x00100000;
-#endif
-#endif
-       }
+       memblock_reserve(__pa(swapper_pg_dir), PTRS_PER_PGD * sizeof(pgd_t));
 
 #ifdef CONFIG_SA1111
        /*
         * Because of the SA1111 DMA bug, we want to preserve our
         * precious DMA-able memory...
         */
-       res_size = __pa(swapper_pg_dir) - PHYS_OFFSET;
+       memblock_reserve(PHYS_OFFSET, __pa(swapper_pg_dir) - PHYS_OFFSET);
 #endif
-       if (res_size)
-               reserve_bootmem_node(pgdat, PHYS_OFFSET, res_size,
-                               BOOTMEM_DEFAULT);
 }
 
 /*
@@ -940,7 +888,7 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
        /*
         * Allocate the vector page early.
         */
-       vectors = alloc_bootmem_low_pages(PAGE_SIZE);
+       vectors = early_alloc(PAGE_SIZE);
 
        for (addr = VMALLOC_END; addr; addr += PGDIR_SIZE)
                pmd_clear(pmd_off_k(addr));
@@ -1011,11 +959,8 @@ static void __init devicemaps_init(struct machine_desc *mdesc)
 static void __init kmap_init(void)
 {
 #ifdef CONFIG_HIGHMEM
-       pmd_t *pmd = pmd_off_k(PKMAP_BASE);
-       pte_t *pte = alloc_bootmem_low_pages(2 * PTRS_PER_PTE * sizeof(pte_t));
-       BUG_ON(!pmd_none(*pmd) || !pte);
-       __pmd_populate(pmd, __pa(pte) | _PAGE_KERNEL_TABLE);
-       pkmap_page_table = pte + PTRS_PER_PTE;
+       pkmap_page_table = early_pte_alloc(pmd_off_k(PKMAP_BASE),
+               PKMAP_BASE, _PAGE_KERNEL_TABLE);
 #endif
 }
 
@@ -1066,17 +1011,16 @@ void __init paging_init(struct machine_desc *mdesc)
        sanity_check_meminfo();
        prepare_page_table();
        map_lowmem();
-       bootmem_init();
        devicemaps_init(mdesc);
        kmap_init();
 
        top_pmd = pmd_off_k(0xffff0000);
 
-       /*
-        * allocate the zero page.  Note that this always succeeds and
-        * returns a zeroed result.
-        */
-       zero_page = alloc_bootmem_low_pages(PAGE_SIZE);
+       /* allocate the zero page. */
+       zero_page = early_alloc(PAGE_SIZE);
+
+       bootmem_init();
+
        empty_zero_page = virt_to_page(zero_page);
        __flush_dcache_page(NULL, empty_zero_page);
 }
index 33b327379f0756e14eff3d9f0cd23a2f022eb112..687d02319a41ea68afcfe65698204a4db84d8400 100644 (file)
@@ -6,8 +6,8 @@
 #include <linux/module.h>
 #include <linux/mm.h>
 #include <linux/pagemap.h>
-#include <linux/bootmem.h>
 #include <linux/io.h>
+#include <linux/memblock.h>
 
 #include <asm/cacheflush.h>
 #include <asm/sections.h>
 
 #include "mm.h"
 
-/*
- * Reserve the various regions of node 0
- */
-void __init reserve_node_zero(pg_data_t *pgdat)
+void __init arm_mm_memblock_reserve(void)
 {
-       /*
-        * Register the kernel text and data with bootmem.
-        * Note that this can only be in node 0.
-        */
-#ifdef CONFIG_XIP_KERNEL
-       reserve_bootmem_node(pgdat, __pa(_data), _end - _data,
-                       BOOTMEM_DEFAULT);
-#else
-       reserve_bootmem_node(pgdat, __pa(_stext), _end - _stext,
-                       BOOTMEM_DEFAULT);
-#endif
-
        /*
         * Register the exception vector page.
         * some architectures which the DRAM is the exception vector to trap,
         * alloc_page breaks with error, although it is not NULL, but "0."
         */
-       reserve_bootmem_node(pgdat, CONFIG_VECTORS_BASE, PAGE_SIZE,
-                       BOOTMEM_DEFAULT);
+       memblock_reserve(CONFIG_VECTORS_BASE, PAGE_SIZE);
 }
 
 /*
index 72507c630ceb563e9242145722b542b52731a7b3..203a4e944d9e43c53051725c084f542cceb8b7a3 100644 (file)
@@ -79,15 +79,11 @@ ENTRY(cpu_arm1020_proc_init)
  * cpu_arm1020_proc_fin()
  */
 ENTRY(cpu_arm1020_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      arm1020_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm1020_reset(loc)
index d27829805609f5793e23bb2fd0c67ac85993e955..1a511e765909957d81b463c17f0000b8893d3770 100644 (file)
@@ -79,15 +79,11 @@ ENTRY(cpu_arm1020e_proc_init)
  * cpu_arm1020e_proc_fin()
  */
 ENTRY(cpu_arm1020e_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      arm1020e_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm1020e_reset(loc)
index ce13e4a827de8ed9e787b11bf3a784b0bf803dab..1ffa4eb9c34f7d7d2f1b5ad5e3825daf67d14156 100644 (file)
@@ -68,15 +68,11 @@ ENTRY(cpu_arm1022_proc_init)
  * cpu_arm1022_proc_fin()
  */
 ENTRY(cpu_arm1022_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      arm1022_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm1022_reset(loc)
index 636672a29c6d1e58ad905850cba7374ba09d8f45..5697c34b95b0cdb38c31aad752c172b6990b5567 100644 (file)
@@ -68,15 +68,11 @@ ENTRY(cpu_arm1026_proc_init)
  * cpu_arm1026_proc_fin()
  */
 ENTRY(cpu_arm1026_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      arm1026_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm1026_reset(loc)
index 795dc615f43bb6f4b6513f4ac6a17a287911876e..64e0b327c7c5f504ec00757dcfd832d1fe56ac9e 100644 (file)
@@ -184,8 +184,6 @@ ENTRY(cpu_arm7_proc_init)
 
 ENTRY(cpu_arm6_proc_fin)
 ENTRY(cpu_arm7_proc_fin)
-               mov     r0, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-               msr     cpsr_c, r0
                mov     r0, #0x31                       @ ....S..DP...M
                mcr     p15, 0, r0, c1, c0, 0           @ disable caches
                mov     pc, lr
index 0b62de24466646d8b7e8aa65b84e8ac5191335f5..9d96824134fc4db4b0cd24f9df65c405717b4341 100644 (file)
@@ -54,15 +54,11 @@ ENTRY(cpu_arm720_proc_init)
                mov     pc, lr
 
 ENTRY(cpu_arm720_proc_fin)
-               stmfd   sp!, {lr}
-               mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-               msr     cpsr_c, ip
                mrc     p15, 0, r0, c1, c0, 0
                bic     r0, r0, #0x1000                 @ ...i............
                bic     r0, r0, #0x000e                 @ ............wca.
                mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-               mcr     p15, 0, r1, c7, c7, 0           @ invalidate cache
-               ldmfd   sp!, {pc}
+               mov     pc, lr
 
 /*
  * Function: arm720_proc_do_idle(void)
index 01860cdeb2ec3df451947f325c7d132449820717..6c1a9ab059aedb2f48e0d2bff8b823b3bb306dab 100644 (file)
@@ -36,15 +36,11 @@ ENTRY(cpu_arm740_switch_mm)
  * cpu_arm740_proc_fin()
  */
 ENTRY(cpu_arm740_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
        mrc     p15, 0, r0, c1, c0, 0
        bic     r0, r0, #0x3f000000             @ bank/f/lock/s
        bic     r0, r0, #0x0000000c             @ w-buffer/cache
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       mcr     p15, 0, r0, c7, c0, 0           @ invalidate cache
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm740_reset(loc)
index 1201b98638298087063d3ec02eefd3a7e58d9aa6..6a850dbba22e5ff7be9aae70476489feeaaeef18 100644 (file)
@@ -36,8 +36,6 @@ ENTRY(cpu_arm7tdmi_switch_mm)
  * cpu_arm7tdmi_proc_fin()
  */
 ENTRY(cpu_arm7tdmi_proc_fin)
-               mov     r0, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-               msr     cpsr_c, r0
                mov     pc, lr
 
 /*
index 8be81992645d8d814517510ea473d85c604888bd..86f80aa56216b8ecf3159c090a83eeb2da372820 100644 (file)
@@ -69,19 +69,11 @@ ENTRY(cpu_arm920_proc_init)
  * cpu_arm920_proc_fin()
  */
 ENTRY(cpu_arm920_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
-       bl      arm920_flush_kern_cache_all
-#else
-       bl      v4wt_flush_kern_cache_all
-#endif
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm920_reset(loc)
index c0ff8e4b1074bac560f318a25c2715b89976c603..f76ce9b62883be61a1abe9baf67ae1a4ca4d8324 100644 (file)
@@ -71,19 +71,11 @@ ENTRY(cpu_arm922_proc_init)
  * cpu_arm922_proc_fin()
  */
 ENTRY(cpu_arm922_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-#ifndef CONFIG_CPU_DCACHE_WRITETHROUGH
-       bl      arm922_flush_kern_cache_all
-#else
-       bl      v4wt_flush_kern_cache_all
-#endif
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm922_reset(loc)
index 3c6cffe400f685f4dc3e32ccf078ef726d88d625..657bd3f7c153bf033f704636a323339129bb5d11 100644 (file)
@@ -92,15 +92,11 @@ ENTRY(cpu_arm925_proc_init)
  * cpu_arm925_proc_fin()
  */
 ENTRY(cpu_arm925_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      arm925_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm925_reset(loc)
index 75b707c9cce1ad31c2adf960d99e99cb5a266f8d..73f1f3c689108fcade13d8dbb26e057105247645 100644 (file)
@@ -61,15 +61,11 @@ ENTRY(cpu_arm926_proc_init)
  * cpu_arm926_proc_fin()
  */
 ENTRY(cpu_arm926_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      arm926_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm926_reset(loc)
index 1af1657819eb8e32caf40dbbc148ca2c0259144f..fffb061a45a558ee8dc5883dcba4a0e64ef53311 100644 (file)
@@ -37,15 +37,11 @@ ENTRY(cpu_arm940_switch_mm)
  * cpu_arm940_proc_fin()
  */
 ENTRY(cpu_arm940_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      arm940_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x00001000             @ i-cache
        bic     r0, r0, #0x00000004             @ d-cache
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm940_reset(loc)
index 1664b6aaff794957723cfac21696e8a2af030f3b..249a6053760a357baa0dca13c3d67bf49ebf975e 100644 (file)
@@ -44,15 +44,11 @@ ENTRY(cpu_arm946_switch_mm)
  * cpu_arm946_proc_fin()
  */
 ENTRY(cpu_arm946_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      arm946_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x00001000             @ i-cache
        bic     r0, r0, #0x00000004             @ d-cache
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_arm946_reset(loc)
index 28545c29dbcda317db178a564a7a894f3a846f96..db475667fac2c95df3ab30fdabda084eab94c3f3 100644 (file)
@@ -36,8 +36,6 @@ ENTRY(cpu_arm9tdmi_switch_mm)
  * cpu_arm9tdmi_proc_fin()
  */
 ENTRY(cpu_arm9tdmi_proc_fin)
-               mov     r0, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-               msr     cpsr_c, r0
                mov     pc, lr
 
 /*
index 08f5ac237ad4e83e67b7540a9680d28c619edc41..7803fdf7002933da8e63a3383f9da818ecea724c 100644 (file)
@@ -39,17 +39,13 @@ ENTRY(cpu_fa526_proc_init)
  * cpu_fa526_proc_fin()
  */
 ENTRY(cpu_fa526_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      fa_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
        nop
        nop
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_fa526_reset(loc)
index 53e63234384992ed07daf2eb48da91eaa5fa4a7d..b304d0104a4ef9c240191e42b7e08460706408b8 100644 (file)
@@ -75,11 +75,6 @@ ENTRY(cpu_feroceon_proc_init)
  * cpu_feroceon_proc_fin()
  */
 ENTRY(cpu_feroceon_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      feroceon_flush_kern_cache_all
-
 #if defined(CONFIG_CACHE_FEROCEON_L2) && \
        !defined(CONFIG_CACHE_FEROCEON_L2_WRITETHROUGH)
        mov     r0, #0
@@ -91,7 +86,7 @@ ENTRY(cpu_feroceon_proc_fin)
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_feroceon_reset(loc)
index caa31154e7dbf71417beebc71128e0d061fb17ce..5f6892fcc1671f28070f175bc6eeda03bbe614c5 100644 (file)
@@ -51,15 +51,11 @@ ENTRY(cpu_mohawk_proc_init)
  * cpu_mohawk_proc_fin()
  */
 ENTRY(cpu_mohawk_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      mohawk_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1800                 @ ...iz...........
        bic     r0, r0, #0x0006                 @ .............ca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_mohawk_reset(loc)
index 7b706b38990625c08ca3595ff19b6657fcbb0648..a201eb04b5e1a6327d1a5375c00b669ee7fc439c 100644 (file)
@@ -44,17 +44,13 @@ ENTRY(cpu_sa110_proc_init)
  * cpu_sa110_proc_fin()
  */
 ENTRY(cpu_sa110_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      v4wb_flush_kern_cache_all       @ clean caches
-1:     mov     r0, #0
+       mov     r0, #0
        mcr     p15, 0, r0, c15, c2, 2          @ Disable clock switching
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_sa110_reset(loc)
index 5c47760c206437c0fbe7219aebae464b19929c7b..7ddc4805bf97a6fe722f54b3a769974bfaa42a1b 100644 (file)
@@ -55,16 +55,12 @@ ENTRY(cpu_sa1100_proc_init)
  *  - Clean and turn off caches.
  */
 ENTRY(cpu_sa1100_proc_fin)
-       stmfd   sp!, {lr}
-       mov     ip, #PSR_F_BIT | PSR_I_BIT | SVC_MODE
-       msr     cpsr_c, ip
-       bl      v4wb_flush_kern_cache_all
        mcr     p15, 0, ip, c15, c2, 2          @ Disable clock switching
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x000e                 @ ............wca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  * cpu_sa1100_reset(loc)
index 7a5337ed7d68b6b1112e59ede2ce2dd5ed630a5f..22aac85151966d3058ace5cdb24eb4a608605e16 100644 (file)
@@ -42,14 +42,11 @@ ENTRY(cpu_v6_proc_init)
        mov     pc, lr
 
 ENTRY(cpu_v6_proc_fin)
-       stmfd   sp!, {lr}
-       cpsid   if                              @ disable interrupts
-       bl      v6_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x0006                 @ .............ca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 
 /*
  *     cpu_v6_reset(loc)
@@ -239,7 +236,8 @@ __v6_proc_info:
        b       __v6_setup
        .long   cpu_arch_name
        .long   cpu_elf_name
-       .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA
+       /* See also feat_v6_fixup() for HWCAP_TLS */
+       .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_JAVA|HWCAP_TLS
        .long   cpu_v6_name
        .long   v6_processor_functions
        .long   v6wbi_tlb_fns
@@ -262,7 +260,7 @@ __pj4_v6_proc_info:
        b       __v6_setup
        .long   cpu_arch_name
        .long   cpu_elf_name
-       .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
+       .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_TLS
        .long   cpu_pj4_name
        .long   v6_processor_functions
        .long   v6wbi_tlb_fns
index 7aaf88a3b7aabb7a8a7268d435eda8aa78bd7671..6a8506d99ee9abbb0845f39d94d663f802c56885 100644 (file)
@@ -45,14 +45,11 @@ ENTRY(cpu_v7_proc_init)
 ENDPROC(cpu_v7_proc_init)
 
 ENTRY(cpu_v7_proc_fin)
-       stmfd   sp!, {lr}
-       cpsid   if                              @ disable interrupts
-       bl      v7_flush_kern_cache_all
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1000                 @ ...i............
        bic     r0, r0, #0x0006                 @ .............ca.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldmfd   sp!, {pc}
+       mov     pc, lr
 ENDPROC(cpu_v7_proc_fin)
 
 /*
@@ -344,7 +341,7 @@ __v7_proc_info:
        b       __v7_setup
        .long   cpu_arch_name
        .long   cpu_elf_name
-       .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP
+       .long   HWCAP_SWP|HWCAP_HALF|HWCAP_THUMB|HWCAP_FAST_MULT|HWCAP_EDSP|HWCAP_TLS
        .long   cpu_v7_name
        .long   v7_processor_functions
        .long   v7wbi_tlb_fns
index e5797f1c1db7d0dd4ccf06ff308655be1d2aa2a9..361a51e4903063ffc82f6831f3bee47e3a957860 100644 (file)
@@ -90,15 +90,11 @@ ENTRY(cpu_xsc3_proc_init)
  * cpu_xsc3_proc_fin()
  */
 ENTRY(cpu_xsc3_proc_fin)
-       str     lr, [sp, #-4]!
-       mov     r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
-       msr     cpsr_c, r0
-       bl      xsc3_flush_kern_cache_all       @ clean caches
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1800                 @ ...IZ...........
        bic     r0, r0, #0x0006                 @ .............CA.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldr     pc, [sp], #4
+       mov     pc, lr
 
 /*
  * cpu_xsc3_reset(loc)
index 63037e2162f201ba76ad34604c2cd09ab450d71b..14075979bcbac1a4bfe7ae346e97058de819d448 100644 (file)
@@ -124,15 +124,11 @@ ENTRY(cpu_xscale_proc_init)
  * cpu_xscale_proc_fin()
  */
 ENTRY(cpu_xscale_proc_fin)
-       str     lr, [sp, #-4]!
-       mov     r0, #PSR_F_BIT|PSR_I_BIT|SVC_MODE
-       msr     cpsr_c, r0
-       bl      xscale_flush_kern_cache_all     @ clean caches
        mrc     p15, 0, r0, c1, c0, 0           @ ctrl register
        bic     r0, r0, #0x1800                 @ ...IZ...........
        bic     r0, r0, #0x0006                 @ .............CA.
        mcr     p15, 0, r0, c1, c0, 0           @ disable caches
-       ldr     pc, [sp], #4
+       mov     pc, lr
 
 /*
  * cpu_xscale_reset(loc)
index 19e09bdb1b8a4ea3e4d892f8ab753eee25d6cd0b..935993e1b1ef53f5372344cbc6a5c764186557b9 100644 (file)
@@ -35,7 +35,8 @@
  */
 
 struct arm_vmregion *
-arm_vmregion_alloc(struct arm_vmregion_head *head, size_t size, gfp_t gfp)
+arm_vmregion_alloc(struct arm_vmregion_head *head, size_t align,
+                  size_t size, gfp_t gfp)
 {
        unsigned long addr = head->vm_start, end = head->vm_end - size;
        unsigned long flags;
@@ -58,7 +59,7 @@ arm_vmregion_alloc(struct arm_vmregion_head *head, size_t size, gfp_t gfp)
                        goto nospc;
                if ((addr + size) <= c->vm_start)
                        goto found;
-               addr = c->vm_end;
+               addr = ALIGN(c->vm_end, align);
                if (addr > end)
                        goto nospc;
        }
index 6b2cdbdf3a857a12162654140185d61616f77d49..15e9f044db9feab45a25d79eed9e1f0dce5a2a1a 100644 (file)
@@ -21,7 +21,7 @@ struct arm_vmregion {
        int                     vm_active;
 };
 
-struct arm_vmregion *arm_vmregion_alloc(struct arm_vmregion_head *, size_t, gfp_t);
+struct arm_vmregion *arm_vmregion_alloc(struct arm_vmregion_head *, size_t, size_t, gfp_t);
 struct arm_vmregion *arm_vmregion_find(struct arm_vmregion_head *, unsigned long);
 struct arm_vmregion *arm_vmregion_find_remove(struct arm_vmregion_head *, unsigned long);
 void arm_vmregion_free(struct arm_vmregion_head *, struct arm_vmregion *);
index ce31f316ac75c1e72af3693a58633a10e50e7f7a..43f2b158237c71c99cc51f0e3d99066a05ee65cb 100644 (file)
@@ -359,7 +359,7 @@ static void __init iop3xx_atu_debug(void)
        DBG("ATU: IOP3XX_ATUCMD=0x%04x\n", *IOP3XX_ATUCMD);
        DBG("ATU: IOP3XX_ATUCR=0x%08x\n", *IOP3XX_ATUCR);
 
-       hook_fault_code(16+6, iop3xx_pci_abort, SIGBUS, "imprecise external abort");
+       hook_fault_code(16+6, iop3xx_pci_abort, SIGBUS, 0, "imprecise external abort");
 }
 
 /* for platforms that might be host-bus-adapters */
index 6c8a02ad98e33f9a374fd62c58c5ea7630427f0c..85d3e55ca4a9c293c67d4b2557bb52d90f93d22f 100644 (file)
 #include <asm/mach/time.h>
 #include <mach/time.h>
 
+/*
+ * Minimum clocksource/clockevent timer range in seconds
+ */
+#define IOP_MIN_RANGE 4
+
 /*
  * IOP clocksource (free-running timer 1).
  */
@@ -44,27 +49,6 @@ static struct clocksource iop_clocksource = {
        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
-static void __init iop_clocksource_set_hz(struct clocksource *cs, unsigned int hz)
-{
-       u64 temp;
-       u32 shift;
-
-       /* Find shift and mult values for hz. */
-       shift = 32;
-       do {
-               temp = (u64) NSEC_PER_SEC << shift;
-               do_div(temp, hz);
-               if ((temp >> 32) == 0)
-                       break;
-       } while (--shift != 0);
-
-       cs->shift = shift;
-       cs->mult = (u32) temp;
-
-       printk(KERN_INFO "clocksource: %s uses shift %u mult %#x\n",
-              cs->name, cs->shift, cs->mult);
-}
-
 /*
  * IOP sched_clock() implementation via its clocksource.
  */
@@ -130,27 +114,6 @@ static struct clock_event_device iop_clockevent = {
        .set_mode       = iop_set_mode,
 };
 
-static void __init iop_clockevent_set_hz(struct clock_event_device *ce, unsigned int hz)
-{
-       u64 temp;
-       u32 shift;
-
-       /* Find shift and mult values for hz. */
-       shift = 32;
-       do {
-               temp = (u64) hz << shift;
-               do_div(temp, NSEC_PER_SEC);
-               if ((temp >> 32) == 0)
-                       break;
-       } while (--shift != 0);
-
-       ce->shift = shift;
-       ce->mult = (u32) temp;
-
-       printk(KERN_INFO "clockevent: %s uses shift %u mult %#lx\n",
-              ce->name, ce->shift, ce->mult);
-}
-
 static irqreturn_t
 iop_timer_interrupt(int irq, void *dev_id)
 {
@@ -190,7 +153,8 @@ void __init iop_init_time(unsigned long tick_rate)
         */
        write_tmr0(timer_ctl & ~IOP_TMR_EN);
        setup_irq(IRQ_IOP_TIMER0, &iop_timer_irq);
-       iop_clockevent_set_hz(&iop_clockevent, tick_rate);
+       clockevents_calc_mult_shift(&iop_clockevent,
+                                   tick_rate, IOP_MIN_RANGE);
        iop_clockevent.max_delta_ns =
                clockevent_delta2ns(0xfffffffe, &iop_clockevent);
        iop_clockevent.min_delta_ns =
@@ -207,6 +171,7 @@ void __init iop_init_time(unsigned long tick_rate)
        write_trr1(0xffffffff);
        write_tcr1(0xffffffff);
        write_tmr1(timer_ctl);
-       iop_clocksource_set_hz(&iop_clocksource, tick_rate);
+       clocksource_calc_mult_shift(&iop_clocksource, tick_rate,
+                                   IOP_MIN_RANGE);
        clocksource_register(&iop_clocksource);
 }
diff --git a/arch/arm/plat-mxc/3ds_debugboard.c b/arch/arm/plat-mxc/3ds_debugboard.c
new file mode 100644 (file)
index 0000000..639c54a
--- /dev/null
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ * Copyright (C) 2010 Jason Wang <jason77.wang@gmail.com>
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/io.h>
+#include <linux/platform_device.h>
+#include <linux/gpio.h>
+#include <linux/smsc911x.h>
+
+#include <mach/hardware.h>
+
+/* LAN9217 ethernet base address */
+#define LAN9217_BASE_ADDR(n)   (n + 0x0)
+/* External UART */
+#define UARTA_BASE_ADDR(n)     (n + 0x8000)
+#define UARTB_BASE_ADDR(n)     (n + 0x10000)
+
+#define BOARD_IO_ADDR(n)       (n + 0x20000)
+/* LED switchs */
+#define LED_SWITCH_REG         0x00
+/* buttons */
+#define SWITCH_BUTTONS_REG     0x08
+/* status, interrupt */
+#define INTR_STATUS_REG        0x10
+#define INTR_MASK_REG          0x38
+#define INTR_RESET_REG         0x20
+/* magic word for debug CPLD */
+#define MAGIC_NUMBER1_REG      0x40
+#define MAGIC_NUMBER2_REG      0x48
+/* CPLD code version */
+#define CPLD_CODE_VER_REG      0x50
+/* magic word for debug CPLD */
+#define MAGIC_NUMBER3_REG      0x58
+/* module reset register*/
+#define MODULE_RESET_REG       0x60
+/* CPU ID and Personality ID */
+#define MCU_BOARD_ID_REG       0x68
+
+#define MXC_IRQ_TO_EXPIO(irq)   ((irq) - MXC_BOARD_IRQ_START)
+#define MXC_IRQ_TO_GPIO(irq)   ((irq) - MXC_INTERNAL_IRQS)
+
+#define MXC_EXP_IO_BASE                (MXC_BOARD_IRQ_START)
+#define MXC_MAX_EXP_IO_LINES   16
+
+/* interrupts like external uart , external ethernet etc*/
+#define EXPIO_INT_ENET         (MXC_BOARD_IRQ_START + 0)
+#define EXPIO_INT_XUART_A      (MXC_BOARD_IRQ_START + 1)
+#define EXPIO_INT_XUART_B      (MXC_BOARD_IRQ_START + 2)
+#define EXPIO_INT_BUTTON_A     (MXC_BOARD_IRQ_START + 3)
+#define EXPIO_INT_BUTTON_B     (MXC_BOARD_IRQ_START + 4)
+
+static void __iomem *brd_io;
+static void expio_ack_irq(u32 irq);
+
+static struct resource smsc911x_resources[] = {
+       {
+               .flags = IORESOURCE_MEM,
+       } , {
+               .start = EXPIO_INT_ENET,
+               .end = EXPIO_INT_ENET,
+               .flags = IORESOURCE_IRQ,
+       },
+};
+
+static struct smsc911x_platform_config smsc911x_config = {
+       .irq_polarity = SMSC911X_IRQ_POLARITY_ACTIVE_LOW,
+       .flags = SMSC911X_USE_32BIT | SMSC911X_FORCE_INTERNAL_PHY,
+};
+
+static struct platform_device smsc_lan9217_device = {
+       .name = "smsc911x",
+       .id = 0,
+       .dev = {
+               .platform_data = &smsc911x_config,
+       },
+       .num_resources = ARRAY_SIZE(smsc911x_resources),
+       .resource = smsc911x_resources,
+};
+
+static void mxc_expio_irq_handler(u32 irq, struct irq_desc *desc)
+{
+       u32 imr_val;
+       u32 int_valid;
+       u32 expio_irq;
+
+       desc->chip->mask(irq);  /* irq = gpio irq number */
+
+       imr_val = __raw_readw(brd_io + INTR_MASK_REG);
+       int_valid = __raw_readw(brd_io + INTR_STATUS_REG) & ~imr_val;
+
+       expio_irq = MXC_BOARD_IRQ_START;
+       for (; int_valid != 0; int_valid >>= 1, expio_irq++) {
+               struct irq_desc *d;
+               if ((int_valid & 1) == 0)
+                       continue;
+               d = irq_desc + expio_irq;
+               if (unlikely(!(d->handle_irq)))
+                       pr_err("\nEXPIO irq: %d unhandled\n", expio_irq);
+               else
+                       d->handle_irq(expio_irq, d);
+       }
+
+       desc->chip->ack(irq);
+       desc->chip->unmask(irq);
+}
+
+/*
+ * Disable an expio pin's interrupt by setting the bit in the imr.
+ * Irq is an expio virtual irq number
+ */
+static void expio_mask_irq(u32 irq)
+{
+       u16 reg;
+       u32 expio = MXC_IRQ_TO_EXPIO(irq);
+
+       reg = __raw_readw(brd_io + INTR_MASK_REG);
+       reg |= (1 << expio);
+       __raw_writew(reg, brd_io + INTR_MASK_REG);
+}
+
+static void expio_ack_irq(u32 irq)
+{
+       u32 expio = MXC_IRQ_TO_EXPIO(irq);
+
+       __raw_writew(1 << expio, brd_io + INTR_RESET_REG);
+       __raw_writew(0, brd_io + INTR_RESET_REG);
+       expio_mask_irq(irq);
+}
+
+static void expio_unmask_irq(u32 irq)
+{
+       u16 reg;
+       u32 expio = MXC_IRQ_TO_EXPIO(irq);
+
+       reg = __raw_readw(brd_io + INTR_MASK_REG);
+       reg &= ~(1 << expio);
+       __raw_writew(reg, brd_io + INTR_MASK_REG);
+}
+
+static struct irq_chip expio_irq_chip = {
+       .ack = expio_ack_irq,
+       .mask = expio_mask_irq,
+       .unmask = expio_unmask_irq,
+};
+
+int __init mxc_expio_init(u32 base, u32 p_irq)
+{
+       int i;
+
+       brd_io = ioremap(BOARD_IO_ADDR(base), SZ_4K);
+       if (brd_io == NULL)
+               return -ENOMEM;
+
+       if ((__raw_readw(brd_io + MAGIC_NUMBER1_REG) != 0xAAAA) ||
+           (__raw_readw(brd_io + MAGIC_NUMBER2_REG) != 0x5555) ||
+           (__raw_readw(brd_io + MAGIC_NUMBER3_REG) != 0xCAFE)) {
+               pr_info("3-Stack Debug board not detected\n");
+               iounmap(brd_io);
+               brd_io = NULL;
+               return -ENODEV;
+       }
+
+       pr_info("3-Stack Debug board detected, rev = 0x%04X\n",
+               readw(brd_io + CPLD_CODE_VER_REG));
+
+       /*
+        * Configure INT line as GPIO input
+        */
+       gpio_request(MXC_IRQ_TO_GPIO(p_irq), "expio_pirq");
+       gpio_direction_input(MXC_IRQ_TO_GPIO(p_irq));
+
+       /* disable the interrupt and clear the status */
+       __raw_writew(0, brd_io + INTR_MASK_REG);
+       __raw_writew(0xFFFF, brd_io + INTR_RESET_REG);
+       __raw_writew(0, brd_io + INTR_RESET_REG);
+       __raw_writew(0x1F, brd_io + INTR_MASK_REG);
+       for (i = MXC_EXP_IO_BASE;
+            i < (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES); i++) {
+               set_irq_chip(i, &expio_irq_chip);
+               set_irq_handler(i, handle_level_irq);
+               set_irq_flags(i, IRQF_VALID);
+       }
+       set_irq_type(p_irq, IRQF_TRIGGER_LOW);
+       set_irq_chained_handler(p_irq, mxc_expio_irq_handler);
+
+       /* Register Lan device on the debugboard */
+       smsc911x_resources[0].start = LAN9217_BASE_ADDR(base);
+       smsc911x_resources[0].end = LAN9217_BASE_ADDR(base) + 0x100 - 1;
+       platform_device_register(&smsc_lan9217_device);
+
+       return 0;
+}
index 7f7ad6f289bd53383ed5ed952099d62c2a4f52b1..0527e65318f4a647b5b00192ce08ba47368ce5f8 100644 (file)
@@ -1,5 +1,7 @@
 if ARCH_MXC
 
+source "arch/arm/plat-mxc/devices/Kconfig"
+
 menu "Freescale MXC Implementations"
 
 choice
@@ -8,15 +10,12 @@ choice
 
 config ARCH_MX1
        bool "MX1-based"
-       select CPU_ARM920T
-       select IMX_HAVE_IOMUX_V1
+       select SOC_IMX1
        help
          This enables support for systems based on the Freescale i.MX1 family
 
 config ARCH_MX2
        bool "MX2-based"
-       select CPU_ARM926T
-       select IMX_HAVE_IOMUX_V1
        help
          This enables support for systems based on the Freescale i.MX2 family
 
@@ -25,6 +24,7 @@ config ARCH_MX25
        select CPU_ARM926T
        select ARCH_MXC_IOMUX_V3
        select HAVE_FB_IMX
+       select ARCH_MXC_AUDMUX_V2
        help
          This enables support for systems based on the Freescale i.MX25 family
 
@@ -48,8 +48,7 @@ config ARCH_MX5
 
 endchoice
 
-source "arch/arm/mach-mx1/Kconfig"
-source "arch/arm/mach-mx2/Kconfig"
+source "arch/arm/mach-imx/Kconfig"
 source "arch/arm/mach-mx3/Kconfig"
 source "arch/arm/mach-mx25/Kconfig"
 source "arch/arm/mach-mxc91231/Kconfig"
@@ -81,6 +80,17 @@ config MXC_PWM
        help
          Enable support for the i.MX PWM controller(s).
 
+config MXC_DEBUG_BOARD
+       bool "Enable MXC debug board(for 3-stack)"
+       help
+         The debug board is an integral part of the MXC 3-stack(PDK)
+         platforms, it can be attached or removed from the peripheral
+         board. On debug board, several debug devices(ethernet, UART,
+         buttons, LEDs and JTAG) are implemented. Between the MCU and
+         these devices, a CPLD is added as a bridge which performs
+         data/address de-multiplexing and decode, signal level shift,
+         interrupt control and various board functions.
+
 config MXC_ULPI
        bool
 
index 895bc3c5e0c0a5f709018a9f855536961d1a3da6..78d405ed861656ef83182a7242c385dcab805ce0 100644 (file)
@@ -8,8 +8,6 @@ obj-y := irq.o clock.o gpio.o time.o devices.o cpu.o system.o
 # MX51 uses the TZIC interrupt controller, older platforms use AVIC (irq.o)
 obj-$(CONFIG_MXC_TZIC) += tzic.o
 
-obj-$(CONFIG_ARCH_MX1) += dma-mx1-mx2.o
-obj-$(CONFIG_ARCH_MX2) += dma-mx1-mx2.o
 obj-$(CONFIG_IMX_HAVE_IOMUX_V1) += iomux-v1.o
 obj-$(CONFIG_ARCH_MXC_IOMUX_V3) += iomux-v3.o
 obj-$(CONFIG_MXC_PWM)  += pwm.o
@@ -17,7 +15,10 @@ obj-$(CONFIG_USB_EHCI_MXC) += ehci.o
 obj-$(CONFIG_MXC_ULPI) += ulpi.o
 obj-$(CONFIG_ARCH_MXC_AUDMUX_V1) += audmux-v1.o
 obj-$(CONFIG_ARCH_MXC_AUDMUX_V2) += audmux-v2.o
+obj-$(CONFIG_MXC_DEBUG_BOARD) += 3ds_debugboard.o
 ifdef CONFIG_SND_IMX_SOC
 obj-y += ssi-fiq.o
 obj-y += ssi-fiq-ksym.o
 endif
+
+obj-y += devices/
index b62917ca3f954bba4e2b5925879ed96c55f24738..1180bef7664b3ca34359d37940a2fd20081b7017 100644 (file)
  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
index 0c2cc5cd4d83ac6ec5129dcba1a896eab8230f00..f9e7cdbd000568a562ac4bd062a550df73f3a853 100644 (file)
  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/module.h>
@@ -191,6 +187,7 @@ static int mxc_audmux_v2_init(void)
 {
        int ret;
 
+#if defined(CONFIG_ARCH_MX3)
        if (cpu_is_mx31())
                audmux_base = MX31_IO_ADDRESS(MX31_AUDMUX_BASE_ADDR);
 
@@ -204,7 +201,19 @@ static int mxc_audmux_v2_init(void)
                }
                audmux_base = MX35_IO_ADDRESS(MX35_AUDMUX_BASE_ADDR);
        }
-
+#endif
+#if defined(CONFIG_ARCH_MX25)
+       if (cpu_is_mx25()) {
+               audmux_clk = clk_get(NULL, "audmux");
+               if (IS_ERR(audmux_clk)) {
+                       ret = PTR_ERR(audmux_clk);
+                       printk(KERN_ERR "%s: cannot get clock: %d\n", __func__,
+                                       ret);
+                       return ret;
+               }
+               audmux_base = MX25_IO_ADDRESS(MX25_AUDMUX_BASE_ADDR);
+       }
+#endif
        audmux_debugfs_init();
 
        return 0;
index 323ff8ccc877161042a72bbf309c955878160966..2ed3ab173addcae894a1c52190e7cc9419dddc90 100644 (file)
@@ -52,13 +52,14 @@ static void __clk_disable(struct clk *clk)
 {
        if (clk == NULL || IS_ERR(clk))
                return;
-
-       __clk_disable(clk->parent);
-       __clk_disable(clk->secondary);
-
        WARN_ON(!clk->usecount);
-       if (!(--clk->usecount) && clk->disable)
-               clk->disable(clk);
+
+       if (!(--clk->usecount)) {
+               if (clk->disable)
+                       clk->disable(clk);
+               __clk_disable(clk->parent);
+               __clk_disable(clk->secondary);
+       }
 }
 
 static int __clk_enable(struct clk *clk)
@@ -66,12 +67,13 @@ static int __clk_enable(struct clk *clk)
        if (clk == NULL || IS_ERR(clk))
                return -EINVAL;
 
-       __clk_enable(clk->parent);
-       __clk_enable(clk->secondary);
-
-       if (clk->usecount++ == 0 && clk->enable)
-               clk->enable(clk);
+       if (clk->usecount++ == 0) {
+               __clk_enable(clk->parent);
+               __clk_enable(clk->secondary);
 
+               if (clk->enable)
+                       clk->enable(clk);
+       }
        return 0;
 }
 
@@ -160,17 +162,28 @@ EXPORT_SYMBOL(clk_set_rate);
 int clk_set_parent(struct clk *clk, struct clk *parent)
 {
        int ret = -EINVAL;
+       struct clk *old;
 
        if (clk == NULL || IS_ERR(clk) || parent == NULL ||
            IS_ERR(parent) || clk->set_parent == NULL)
                return ret;
 
+       if (clk->usecount)
+               clk_enable(parent);
+
        mutex_lock(&clocks_mutex);
        ret = clk->set_parent(clk, parent);
-       if (ret == 0)
+       if (ret == 0) {
+               old = clk->parent;
                clk->parent = parent;
+       } else {
+               old = parent;
+       }
        mutex_unlock(&clocks_mutex);
 
+       if (clk->usecount)
+               clk_disable(old);
+
        return ret;
 }
 EXPORT_SYMBOL(clk_set_parent);
index 56f2fb5cc456433e6a7f4d23b129a77004b67655..735776d8495636fd8e7429fc2d21b9797bd575ff 100644 (file)
@@ -18,6 +18,7 @@
 
 #include <linux/kernel.h>
 #include <linux/init.h>
+#include <linux/err.h>
 #include <linux/platform_device.h>
 #include <mach/common.h>
 
@@ -35,3 +36,35 @@ int __init mxc_register_device(struct platform_device *pdev, void *data)
        return ret;
 }
 
+struct platform_device *__init imx_add_platform_device(const char *name, int id,
+               const struct resource *res, unsigned int num_resources,
+               const void *data, size_t size_data)
+{
+       int ret = -ENOMEM;
+       struct platform_device *pdev;
+
+       pdev = platform_device_alloc(name, id);
+       if (!pdev)
+               goto err;
+
+       if (res) {
+               ret = platform_device_add_resources(pdev, res, num_resources);
+               if (ret)
+                       goto err;
+       }
+
+       if (data) {
+               ret = platform_device_add_data(pdev, data, size_data);
+               if (ret)
+                       goto err;
+       }
+
+       ret = platform_device_add(pdev);
+       if (ret) {
+err:
+               platform_device_put(pdev);
+               return ERR_PTR(ret);
+       }
+
+       return pdev;
+}
diff --git a/arch/arm/plat-mxc/devices/Kconfig b/arch/arm/plat-mxc/devices/Kconfig
new file mode 100644 (file)
index 0000000..9ab784b
--- /dev/null
@@ -0,0 +1,15 @@
+config IMX_HAVE_PLATFORM_FLEXCAN
+       select HAVE_CAN_FLEXCAN
+       bool
+
+config IMX_HAVE_PLATFORM_IMX_I2C
+       bool
+
+config IMX_HAVE_PLATFORM_IMX_UART
+       bool
+
+config IMX_HAVE_PLATFORM_MXC_NAND
+       bool
+
+config IMX_HAVE_PLATFORM_SPI_IMX
+       bool
diff --git a/arch/arm/plat-mxc/devices/Makefile b/arch/arm/plat-mxc/devices/Makefile
new file mode 100644 (file)
index 0000000..347da51
--- /dev/null
@@ -0,0 +1,8 @@
+ifdef CONFIG_CAN_FLEXCAN
+# the ifdef can be removed once the flexcan driver has been merged
+obj-$(CONFIG_IMX_HAVE_PLATFORM_FLEXCAN) +=  platform-flexcan.o
+endif
+obj-$(CONFIG_IMX_HAVE_PLATFORM_IMX_I2C) += platform-imx-i2c.o
+obj-$(CONFIG_IMX_HAVE_PLATFORM_IMX_UART) += platform-imx-uart.o
+obj-$(CONFIG_IMX_HAVE_PLATFORM_MXC_NAND) += platform-mxc_nand.o
+obj-$(CONFIG_IMX_HAVE_PLATFORM_SPI_IMX) +=  platform-spi_imx.o
diff --git a/arch/arm/plat-mxc/devices/platform-flexcan.c b/arch/arm/plat-mxc/devices/platform-flexcan.c
new file mode 100644 (file)
index 0000000..5e97a01
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2010 Pengutronix, Marc Kleine-Budde <kernel@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+
+#include <mach/devices-common.h>
+
+struct platform_device *__init imx_add_flexcan(int id,
+               resource_size_t iobase, resource_size_t iosize,
+               resource_size_t irq,
+               const struct flexcan_platform_data *pdata)
+{
+       struct resource res[] = {
+               {
+                       .start = iobase,
+                       .end = iobase + iosize - 1,
+                       .flags = IORESOURCE_MEM,
+               }, {
+                       .start = irq,
+                       .end = irq,
+                       .flags = IORESOURCE_IRQ,
+               },
+       };
+
+       return imx_add_platform_device("flexcan", id, res, ARRAY_SIZE(res),
+                       pdata, sizeof(*pdata));
+}
diff --git a/arch/arm/plat-mxc/devices/platform-imx-i2c.c b/arch/arm/plat-mxc/devices/platform-imx-i2c.c
new file mode 100644 (file)
index 0000000..d0af9f7
--- /dev/null
@@ -0,0 +1,29 @@
+/*
+ * Copyright (C) 2009-2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <mach/devices-common.h>
+
+struct platform_device *__init imx_add_imx_i2c(int id,
+               resource_size_t iobase, resource_size_t iosize, int irq,
+               const struct imxi2c_platform_data *pdata)
+{
+       struct resource res[] = {
+               {
+                       .start = iobase,
+                       .end = iobase + iosize - 1,
+                       .flags = IORESOURCE_MEM,
+               }, {
+                       .start = irq,
+                       .end = irq,
+                       .flags = IORESOURCE_IRQ,
+               },
+       };
+
+       return imx_add_platform_device("imx-i2c", id, res, ARRAY_SIZE(res),
+                       pdata, sizeof(*pdata));
+}
diff --git a/arch/arm/plat-mxc/devices/platform-imx-uart.c b/arch/arm/plat-mxc/devices/platform-imx-uart.c
new file mode 100644 (file)
index 0000000..fa3dff1
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009-2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <mach/devices-common.h>
+
+struct platform_device *__init imx_add_imx_uart_3irq(int id,
+               resource_size_t iobase, resource_size_t iosize,
+               resource_size_t irqrx, resource_size_t irqtx,
+               resource_size_t irqrts,
+               const struct imxuart_platform_data *pdata)
+{
+       struct resource res[] = {
+               {
+                       .start = iobase,
+                       .end = iobase + iosize - 1,
+                       .flags = IORESOURCE_MEM,
+               }, {
+                       .start = irqrx,
+                       .end = irqrx,
+                       .flags = IORESOURCE_IRQ,
+               }, {
+                       .start = irqtx,
+                       .end = irqtx,
+                       .flags = IORESOURCE_IRQ,
+               }, {
+                       .start = irqrts,
+                       .end = irqrx,
+                       .flags = IORESOURCE_IRQ,
+               },
+       };
+
+       return imx_add_platform_device("imx-uart", id, res, ARRAY_SIZE(res),
+                       pdata, sizeof(*pdata));
+}
+
+struct platform_device *__init imx_add_imx_uart_1irq(int id,
+               resource_size_t iobase, resource_size_t iosize,
+               resource_size_t irq,
+               const struct imxuart_platform_data *pdata)
+{
+       struct resource res[] = {
+               {
+                       .start = iobase,
+                       .end = iobase + iosize - 1,
+                       .flags = IORESOURCE_MEM,
+               }, {
+                       .start = irq,
+                       .end = irq,
+                       .flags = IORESOURCE_IRQ,
+               },
+       };
+
+       return imx_add_platform_device("imx-uart", id, res, ARRAY_SIZE(res),
+                       pdata, sizeof(*pdata));
+}
diff --git a/arch/arm/plat-mxc/devices/platform-mxc_nand.c b/arch/arm/plat-mxc/devices/platform-mxc_nand.c
new file mode 100644 (file)
index 0000000..1c28641
--- /dev/null
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2009-2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <asm/sizes.h>
+#include <mach/devices-common.h>
+
+static struct platform_device *__init imx_add_mxc_nand(resource_size_t iobase,
+               int irq, const struct mxc_nand_platform_data *pdata,
+               resource_size_t iosize)
+{
+       static int id = 0;
+       
+       struct resource res[] = {
+               {
+                       .start = iobase,
+                       .end = iobase + iosize - 1,
+                       .flags = IORESOURCE_MEM,
+               }, {
+                       .start = irq,
+                       .end = irq,
+                       .flags = IORESOURCE_IRQ,
+               },
+       };
+
+       return imx_add_platform_device("mxc_nand", id++, res, ARRAY_SIZE(res),
+                       pdata, sizeof(*pdata));
+}
+
+struct platform_device *__init imx_add_mxc_nand_v1(resource_size_t iobase,
+               int irq, const struct mxc_nand_platform_data *pdata)
+{
+       return imx_add_mxc_nand(iobase, irq, pdata, SZ_4K);
+}
+
+struct platform_device *__init imx_add_mxc_nand_v21(resource_size_t iobase,
+               int irq, const struct mxc_nand_platform_data *pdata)
+{
+       return imx_add_mxc_nand(iobase, irq, pdata, SZ_8K);
+}
diff --git a/arch/arm/plat-mxc/devices/platform-spi_imx.c b/arch/arm/plat-mxc/devices/platform-spi_imx.c
new file mode 100644 (file)
index 0000000..2831a6d
--- /dev/null
@@ -0,0 +1,30 @@
+/*
+ * Copyright (C) 2009-2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <asm/sizes.h>
+#include <mach/devices-common.h>
+
+struct platform_device *__init imx_add_spi_imx(int id,
+               resource_size_t iobase, resource_size_t iosize, int irq,
+               const struct spi_imx_master *pdata)
+{
+       struct resource res[] = {
+               {
+                       .start = iobase,
+                       .end = iobase + iosize - 1,
+                       .flags = IORESOURCE_MEM,
+               }, {
+                       .start = irq,
+                       .end = irq,
+                       .flags = IORESOURCE_IRQ,
+               },
+       };
+
+       return imx_add_platform_device("spi_imx", id, res, ARRAY_SIZE(res),
+                       pdata, sizeof(*pdata));
+}
index 2a8646173c2f57b3270bfde937095efb606e3135..35a064ff02ba61a66b4f0425728baa4b7f74cda6 100644 (file)
  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #include <linux/platform_device.h>
 int mxc_initialize_usb_hw(int port, unsigned int flags)
 {
        unsigned int v;
-#ifdef CONFIG_ARCH_MX3
+#if defined(CONFIG_ARCH_MX25)
+       if (cpu_is_mx25()) {
+               v = readl(MX25_IO_ADDRESS(MX25_OTG_BASE_ADDR +
+                                    USBCTRL_OTGBASE_OFFSET));
+
+               switch (port) {
+               case 0: /* OTG port */
+                       v &= ~(MX35_OTG_SIC_MASK | MX35_OTG_PM_BIT);
+                       v |= (flags & MXC_EHCI_INTERFACE_MASK)
+                                       << MX35_OTG_SIC_SHIFT;
+                       if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
+                               v |= MX35_OTG_PM_BIT;
+
+                       break;
+               case 1: /* H1 port */
+                       v &= ~(MX35_H1_SIC_MASK | MX35_H1_PM_BIT | MX35_H1_TLL_BIT |
+                               MX35_H1_USBTE_BIT | MX35_H1_IPPUE_DOWN_BIT | MX35_H1_IPPUE_UP_BIT);
+                       v |= (flags & MXC_EHCI_INTERFACE_MASK)
+                                               << MX35_H1_SIC_SHIFT;
+                       if (!(flags & MXC_EHCI_POWER_PINS_ENABLED))
+                               v |= MX35_H1_PM_BIT;
+
+                       if (!(flags & MXC_EHCI_TTL_ENABLED))
+                               v |= MX35_H1_TLL_BIT;
+
+                       if (flags & MXC_EHCI_INTERNAL_PHY)
+                               v |= MX35_H1_USBTE_BIT;
+
+                       if (flags & MXC_EHCI_IPPUE_DOWN)
+                               v |= MX35_H1_IPPUE_DOWN_BIT;
+
+                       if (flags & MXC_EHCI_IPPUE_UP)
+                               v |= MX35_H1_IPPUE_UP_BIT;
+
+                       break;
+               default:
+                       return -EINVAL;
+               }
+
+               writel(v, MX25_IO_ADDRESS(MX25_OTG_BASE_ADDR +
+                                    USBCTRL_OTGBASE_OFFSET));
+               return 0;
+       }
+#endif /* CONFIG_ARCH_MX25 */
+#if defined(CONFIG_ARCH_MX3)
        if (cpu_is_mx31()) {
                v = readl(MX31_IO_ADDRESS(MX31_OTG_BASE_ADDR +
                                     USBCTRL_OTGBASE_OFFSET));
index 71437c61cfd70f65e1aafd73095faf3718e3e8e3..57ec4a896a5d983556ebae058dbf52293ebe669e 100644 (file)
@@ -214,13 +214,16 @@ static void _set_gpio_direction(struct gpio_chip *chip, unsigned offset,
        struct mxc_gpio_port *port =
                container_of(chip, struct mxc_gpio_port, chip);
        u32 l;
+       unsigned long flags;
 
+       spin_lock_irqsave(&port->lock, flags);
        l = __raw_readl(port->base + GPIO_GDIR);
        if (dir)
                l |= 1 << offset;
        else
                l &= ~(1 << offset);
        __raw_writel(l, port->base + GPIO_GDIR);
+       spin_unlock_irqrestore(&port->lock, flags);
 }
 
 static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
@@ -229,9 +232,12 @@ static void mxc_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
                container_of(chip, struct mxc_gpio_port, chip);
        void __iomem *reg = port->base + GPIO_DR;
        u32 l;
+       unsigned long flags;
 
+       spin_lock_irqsave(&port->lock, flags);
        l = (__raw_readl(reg) & (~(1 << offset))) | (value << offset);
        __raw_writel(l, reg);
+       spin_unlock_irqrestore(&port->lock, flags);
 }
 
 static int mxc_gpio_get(struct gpio_chip *chip, unsigned offset)
@@ -285,6 +291,8 @@ int __init mxc_gpio_init(struct mxc_gpio_port *port, int cnt)
                port[i].chip.base = i * 32;
                port[i].chip.ngpio = 32;
 
+               spin_lock_init(&port[i].lock);
+
                /* its a serious configuration bug when it fails */
                BUG_ON( gpiochip_add(&port[i].chip) < 0 );
 
@@ -292,6 +300,12 @@ int __init mxc_gpio_init(struct mxc_gpio_port *port, int cnt)
                        /* setup one handler for each entry */
                        set_irq_chained_handler(port[i].irq, mx3_gpio_irq_handler);
                        set_irq_data(port[i].irq, &port[i]);
+                       if (port[i].irq_high) {
+                               /* setup handler for GPIO 16 to 31 */
+                               set_irq_chained_handler(port[i].irq_high,
+                                               mx3_gpio_irq_handler);
+                               set_irq_data(port[i].irq_high, &port[i]);
+                       }
                }
        }
 
diff --git a/arch/arm/plat-mxc/include/mach/3ds_debugboard.h b/arch/arm/plat-mxc/include/mach/3ds_debugboard.h
new file mode 100644 (file)
index 0000000..a384fdd
--- /dev/null
@@ -0,0 +1,18 @@
+/*
+ * Copyright 2008-2009 Freescale Semiconductor, Inc. All Rights Reserved.
+ *
+ *
+ * The code contained herein is licensed under the GNU General Public
+ * License. You may obtain a copy of the GNU General Public License
+ * Version 2 or later at the following locations:
+ *
+ * http://www.opensource.org/licenses/gpl-license.html
+ * http://www.gnu.org/copyleft/gpl.html
+ */
+
+#ifndef __ASM_ARCH_MXC_3DS_DB_H__
+#define __ASM_ARCH_MXC_3DS_DB_H__
+
+extern int __init mxc_expio_init(u32 base, u32 p_irq);
+
+#endif /* __ASM_ARCH_MXC_3DS_DB_H__ */
diff --git a/arch/arm/plat-mxc/include/mach/board-armadillo5x0.h b/arch/arm/plat-mxc/include/mach/board-armadillo5x0.h
deleted file mode 100644 (file)
index 0376c13..0000000
+++ /dev/null
@@ -1,15 +0,0 @@
-/*
- * Copyright 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>.
- * All Rights Reserved.
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef __ASM_ARCH_MXC_BOARD_ARMADILLO5X0_H__
-#define __ASM_ARCH_MXC_BOARD_ARMADILLO5X0_H__
-
-#endif
diff --git a/arch/arm/plat-mxc/include/mach/board-kzmarm11.h b/arch/arm/plat-mxc/include/mach/board-kzmarm11.h
deleted file mode 100644 (file)
index 93cc66f..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-/*
- *  Copyright (C) 2009  Yoichi Yuasa <yuasa@linux-mips.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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- */
-#ifndef __ARM_ARCH_BOARD_KZM_ARM11_H
-#define __ARM_ARCH_BOARD_KZM_ARM11_H
-
-/*
- *  KZM-ARM11-01 Board Control Registers on FPGA
- */
-#define KZM_ARM11_CTL1         (MX31_CS4_BASE_ADDR + 0x1000)
-#define KZM_ARM11_CTL2         (MX31_CS4_BASE_ADDR + 0x1001)
-#define KZM_ARM11_RSW1         (MX31_CS4_BASE_ADDR + 0x1002)
-#define KZM_ARM11_BACK_LIGHT   (MX31_CS4_BASE_ADDR + 0x1004)
-#define KZM_ARM11_FPGA_REV     (MX31_CS4_BASE_ADDR + 0x1008)
-#define KZM_ARM11_7SEG_LED     (MX31_CS4_BASE_ADDR + 0x1010)
-#define KZM_ARM11_LEDS         (MX31_CS4_BASE_ADDR + 0x1020)
-#define KZM_ARM11_DIPSW2       (MX31_CS4_BASE_ADDR + 0x1003)
-
-/*
- * External UART for touch panel on FPGA
- */
-#define KZM_ARM11_16550                (MX31_CS4_BASE_ADDR + 0x1050)
-
-#endif /* __ARM_ARCH_BOARD_KZM_ARM11_H */
-
diff --git a/arch/arm/plat-mxc/include/mach/board-mx21ads.h b/arch/arm/plat-mxc/include/mach/board-mx21ads.h
deleted file mode 100644 (file)
index 0cf4fa2..0000000
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
- */
-
-/*
- * The code contained herein is licensed under the GNU General Public
- * License. You may obtain a copy of the GNU General Public License
- * Version 2 or later at the following locations:
- *
- * http://www.opensource.org/licenses/gpl-license.html
- * http://www.gnu.org/copyleft/gpl.html
- */
-
-#ifndef __ASM_ARCH_MXC_BOARD_MX21ADS_H__
-#define __ASM_ARCH_MXC_BOARD_MX21ADS_H__
-
-/*
- * Memory-mapped I/O on MX21ADS base board
- */
-#define MX21ADS_MMIO_BASE_ADDR   0xF5000000
-#define MX21ADS_MMIO_SIZE        SZ_16M
-
-#define MX21ADS_REG_ADDR(offset)    (void __force __iomem *) \
-               (MX21ADS_MMIO_BASE_ADDR + (offset))
-
-#define MX21ADS_CS8900A_IRQ         IRQ_GPIOE(11)
-#define MX21ADS_CS8900A_IOBASE_REG  MX21ADS_REG_ADDR(0x000000)
-#define MX21ADS_ST16C255_IOBASE_REG MX21ADS_REG_ADDR(0x200000)
-#define MX21ADS_VERSION_REG         MX21ADS_REG_ADDR(0x400000)
-#define MX21ADS_IO_REG              MX21ADS_REG_ADDR(0x800000)
-
-/* MX21ADS_IO_REG bit definitions */
-#define MX21ADS_IO_SD_WP        0x0001 /* read */
-#define MX21ADS_IO_TP6          0x0001 /* write */
-#define MX21ADS_IO_SW_SEL       0x0002 /* read */
-#define MX21ADS_IO_TP7          0x0002 /* write */
-#define MX21ADS_IO_RESET_E_UART 0x0004
-#define MX21ADS_IO_RESET_BASE   0x0008
-#define MX21ADS_IO_CSI_CTL2     0x0010
-#define MX21ADS_IO_CSI_CTL1     0x0020
-#define MX21ADS_IO_CSI_CTL0     0x0040
-#define MX21ADS_IO_UART1_EN     0x0080
-#define MX21ADS_IO_UART4_EN     0x0100
-#define MX21ADS_IO_LCDON        0x0200
-#define MX21ADS_IO_IRDA_EN      0x0400
-#define MX21ADS_IO_IRDA_FIR_SEL 0x0800
-#define MX21ADS_IO_IRDA_MD0_B   0x1000
-#define MX21ADS_IO_IRDA_MD1     0x2000
-#define MX21ADS_IO_LED4_ON      0x4000
-#define MX21ADS_IO_LED3_ON      0x8000
-
-#endif                         /* __ASM_ARCH_MXC_BOARD_MX21ADS_H__ */
diff --git a/arch/arm/plat-mxc/include/mach/board-mx27ads.h b/arch/arm/plat-mxc/include/mach/board-mx27ads.h
deleted file mode 100644 (file)
index 7776d23..0000000
+++ /dev/null
@@ -1,344 +0,0 @@
-/*
- * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
- */
-
-/*
- * The code contained herein is licensed under the GNU General Public
- * License. You may obtain a copy of the GNU General Public License
- * Version 2 or later at the following locations:
- *
- * http://www.opensource.org/licenses/gpl-license.html
- * http://www.gnu.org/copyleft/gpl.html
- */
-
-#ifndef __ASM_ARCH_MXC_BOARD_MX27ADS_H__
-#define __ASM_ARCH_MXC_BOARD_MX27ADS_H__
-
-/* external interrupt multiplexer */
-#define MXC_EXP_IO_BASE                (MXC_BOARD_IRQ_START)
-
-#define MXC_VIRTUAL_INTS_BASE  (MXC_EXP_IO_BASE + MXC_MAX_EXP_IO_LINES)
-#define MXC_SDIO1_CARD_IRQ     MXC_VIRTUAL_INTS_BASE
-#define MXC_SDIO2_CARD_IRQ     (MXC_VIRTUAL_INTS_BASE + 1)
-#define MXC_SDIO3_CARD_IRQ     (MXC_VIRTUAL_INTS_BASE + 2)
-
-#define MXC_MAX_BOARD_INTS      (MXC_MAX_EXP_IO_LINES + \
-                               MXC_MAX_VIRTUAL_INTS)
-
-/*
- * @name Memory Size parameters
- */
-
-/*
- * Size of SDRAM memory
- */
-#define SDRAM_MEM_SIZE          SZ_128M
-
-/*
- * PBC Controller parameters
- */
-
-/*
- * Base address of PBC controller, CS4
- */
-#define PBC_BASE_ADDRESS        0xf4300000
-#define PBC_REG_ADDR(offset)    (void __force __iomem *) \
-               (PBC_BASE_ADDRESS + (offset))
-
-/*
- * PBC Interupt name definitions
- */
-#define PBC_GPIO1_0  0
-#define PBC_GPIO1_1  1
-#define PBC_GPIO1_2  2
-#define PBC_GPIO1_3  3
-#define PBC_GPIO1_4  4
-#define PBC_GPIO1_5  5
-
-#define PBC_INTR_MAX_NUM 6
-#define PBC_INTR_SHARED_MAX_NUM 8
-
-/* When the PBC address connection is fixed in h/w, defined as 1 */
-#define PBC_ADDR_SH             0
-
-/* Offsets for the PBC Controller register */
-/*
- * PBC Board version register offset
- */
-#define PBC_VERSION_REG         PBC_REG_ADDR(0x00000 >> PBC_ADDR_SH)
-/*
- * PBC Board control register 1 set address.
- */
-#define PBC_BCTRL1_SET_REG      PBC_REG_ADDR(0x00008 >> PBC_ADDR_SH)
-/*
- * PBC Board control register 1 clear address.
- */
-#define PBC_BCTRL1_CLEAR_REG    PBC_REG_ADDR(0x0000C >> PBC_ADDR_SH)
-/*
- * PBC Board control register 2 set address.
- */
-#define PBC_BCTRL2_SET_REG      PBC_REG_ADDR(0x00010 >> PBC_ADDR_SH)
-/*
- * PBC Board control register 2 clear address.
- */
-#define PBC_BCTRL2_CLEAR_REG    PBC_REG_ADDR(0x00014 >> PBC_ADDR_SH)
-/*
- * PBC Board control register 3 set address.
- */
-#define PBC_BCTRL3_SET_REG      PBC_REG_ADDR(0x00018 >> PBC_ADDR_SH)
-/*
- * PBC Board control register 3 clear address.
- */
-#define PBC_BCTRL3_CLEAR_REG    PBC_REG_ADDR(0x0001C >> PBC_ADDR_SH)
-/*
- * PBC Board control register 3 set address.
- */
-#define PBC_BCTRL4_SET_REG      PBC_REG_ADDR(0x00020 >> PBC_ADDR_SH)
-/*
- * PBC Board control register 4 clear address.
- */
-#define PBC_BCTRL4_CLEAR_REG    PBC_REG_ADDR(0x00024 >> PBC_ADDR_SH)
-/*PBC_ADDR_SH
- * PBC Board status register 1.
- */
-#define PBC_BSTAT1_REG          PBC_REG_ADDR(0x00028 >> PBC_ADDR_SH)
-/*
- * PBC Board interrupt status register.
- */
-#define PBC_INTSTATUS_REG       PBC_REG_ADDR(0x0002C >> PBC_ADDR_SH)
-/*
- * PBC Board interrupt current status register.
- */
-#define PBC_INTCURR_STATUS_REG  PBC_REG_ADDR(0x00034 >> PBC_ADDR_SH)
-/*
- * PBC Interrupt mask register set address.
- */
-#define PBC_INTMASK_SET_REG     PBC_REG_ADDR(0x00038 >> PBC_ADDR_SH)
-/*
- * PBC Interrupt mask register clear address.
- */
-#define PBC_INTMASK_CLEAR_REG   PBC_REG_ADDR(0x0003C >> PBC_ADDR_SH)
-/*
- * External UART A.
- */
-#define PBC_SC16C652_UARTA_REG  PBC_REG_ADDR(0x20000 >> PBC_ADDR_SH)
-/*
- * UART 4 Expanding Signal Status.
- */
-#define PBC_UART_STATUS_REG     PBC_REG_ADDR(0x22000 >> PBC_ADDR_SH)
-/*
- * UART 4 Expanding Signal Control Set.
- */
-#define PBC_UCTRL_SET_REG       PBC_REG_ADDR(0x24000 >> PBC_ADDR_SH)
-/*
- * UART 4 Expanding Signal Control Clear.
- */
-#define PBC_UCTRL_CLR_REG       PBC_REG_ADDR(0x26000 >> PBC_ADDR_SH)
-/*
- * Ethernet Controller IO base address.
- */
-#define PBC_CS8900A_IOBASE_REG  PBC_REG_ADDR(0x40000 >> PBC_ADDR_SH)
-/*
- * Ethernet Controller Memory base address.
- */
-#define PBC_CS8900A_MEMBASE_REG PBC_REG_ADDR(0x42000 >> PBC_ADDR_SH)
-/*
- * Ethernet Controller DMA base address.
- */
-#define PBC_CS8900A_DMABASE_REG PBC_REG_ADDR(0x44000 >> PBC_ADDR_SH)
-
-/* PBC Board Version Register bit definition */
-#define PBC_VERSION_ADS         0x8000 /* Bit15=1 means version for ads */
-#define PBC_VERSION_EVB_REVB    0x4000 /* BIT14=1 means version for evb revb */
-
-/* PBC Board Control Register 1 bit definitions */
-#define PBC_BCTRL1_ERST         0x0001 /* Ethernet Reset */
-#define PBC_BCTRL1_URST         0x0002 /* Reset External UART controller */
-#define PBC_BCTRL1_FRST         0x0004 /* FEC Reset */
-#define PBC_BCTRL1_ESLEEP       0x0010 /* Enable ethernet Sleep */
-#define PBC_BCTRL1_LCDON        0x0800 /* Enable the LCD */
-
-/* PBC Board Control Register 2 bit definitions */
-#define PBC_BCTRL2_VCC_EN       0x0004 /*   Enable VCC */
-#define PBC_BCTRL2_VPP_EN       0x0008 /*   Enable Vpp */
-#define PBC_BCTRL2_ATAFEC_EN    0X0010
-#define PBC_BCTRL2_ATAFEC_SEL   0X0020
-#define PBC_BCTRL2_ATA_EN       0X0040
-#define PBC_BCTRL2_IRDA_SD      0X0080
-#define PBC_BCTRL2_IRDA_EN      0X0100
-#define PBC_BCTRL2_CCTL10       0X0200
-#define PBC_BCTRL2_CCTL11       0X0400
-
-/* PBC Board Control Register 3 bit definitions */
-#define PBC_BCTRL3_HSH_EN       0X0020
-#define PBC_BCTRL3_FSH_MOD      0X0040
-#define PBC_BCTRL3_OTG_HS_EN    0X0080
-#define PBC_BCTRL3_OTG_VBUS_EN  0X0100
-#define PBC_BCTRL3_FSH_VBUS_EN  0X0200
-#define PBC_BCTRL3_USB_OTG_ON   0X0800
-#define PBC_BCTRL3_USB_FSH_ON   0X1000
-
-/* PBC Board Control Register 4 bit definitions */
-#define PBC_BCTRL4_REGEN_SEL    0X0001
-#define PBC_BCTRL4_USER_OFF     0X0002
-#define PBC_BCTRL4_VIB_EN       0X0004
-#define PBC_BCTRL4_PWRGT1_EN    0X0008
-#define PBC_BCTRL4_PWRGT2_EN    0X0010
-#define PBC_BCTRL4_STDBY_PRI    0X0020
-
-#ifndef __ASSEMBLY__
-/*
- * Enumerations for SD cards and memory stick card. This corresponds to
- * the card EN bits in the IMR: SD1_EN | MS_EN | SD3_EN | SD2_EN.
- */
-enum mxc_card_no {
-       MXC_CARD_SD2 = 0,
-       MXC_CARD_SD3,
-       MXC_CARD_MS,
-       MXC_CARD_SD1,
-       MXC_CARD_MIN = MXC_CARD_SD2,
-       MXC_CARD_MAX = MXC_CARD_SD1,
-};
-#endif
-
-#define MXC_CPLD_VER_1_50       0x01
-
-/*
- * PBC BSTAT Register bit definitions
- */
-#define PBC_BSTAT_PRI_INT       0X0001
-#define PBC_BSTAT_USB_BYP       0X0002
-#define PBC_BSTAT_ATA_IOCS16    0X0004
-#define PBC_BSTAT_ATA_CBLID     0X0008
-#define PBC_BSTAT_ATA_DASP      0X0010
-#define PBC_BSTAT_PWR_RDY       0X0020
-#define PBC_BSTAT_SD3_WP        0X0100
-#define PBC_BSTAT_SD2_WP        0X0200
-#define PBC_BSTAT_SD1_WP        0X0400
-#define PBC_BSTAT_SD3_DET       0X0800
-#define PBC_BSTAT_SD2_DET       0X1000
-#define PBC_BSTAT_SD1_DET       0X2000
-#define PBC_BSTAT_MS_DET        0X4000
-#define PBC_BSTAT_SD3_DET_BIT   11
-#define PBC_BSTAT_SD2_DET_BIT   12
-#define PBC_BSTAT_SD1_DET_BIT   13
-#define PBC_BSTAT_MS_DET_BIT    14
-#define MXC_BSTAT_BIT(n)        ((n == MXC_CARD_SD2) ? PBC_BSTAT_SD2_DET : \
-                                ((n == MXC_CARD_SD3) ? PBC_BSTAT_SD3_DET : \
-                                ((n == MXC_CARD_SD1) ? PBC_BSTAT_SD1_DET : \
-                                ((n == MXC_CARD_MS) ? PBC_BSTAT_MS_DET : \
-                                       0x0))))
-
-/*
- * PBC UART Control Register bit definitions
- */
-#define PBC_UCTRL_DCE_DCD       0X0001
-#define PBC_UCTRL_DCE_DSR       0X0002
-#define PBC_UCTRL_DCE_RI        0X0004
-#define PBC_UCTRL_DTE_DTR       0X0100
-
-/*
- * PBC UART Status Register bit definitions
- */
-#define PBC_USTAT_DTE_DCD       0X0001
-#define PBC_USTAT_DTE_DSR       0X0002
-#define PBC_USTAT_DTE_RI        0X0004
-#define PBC_USTAT_DCE_DTR       0X0100
-
-/*
- * PBC Interupt mask register bit definitions
- */
-#define PBC_INTR_SD3_R_EN_BIT   4
-#define PBC_INTR_SD2_R_EN_BIT   0
-#define PBC_INTR_SD1_R_EN_BIT   6
-#define PBC_INTR_MS_R_EN_BIT    5
-#define PBC_INTR_SD3_EN_BIT     13
-#define PBC_INTR_SD2_EN_BIT     12
-#define PBC_INTR_MS_EN_BIT      14
-#define PBC_INTR_SD1_EN_BIT     15
-
-#define PBC_INTR_SD2_R_EN       0x0001
-#define PBC_INTR_LOW_BAT        0X0002
-#define PBC_INTR_OTG_FSOVER     0X0004
-#define PBC_INTR_FSH_OVER       0X0008
-#define PBC_INTR_SD3_R_EN       0x0010
-#define PBC_INTR_MS_R_EN        0x0020
-#define PBC_INTR_SD1_R_EN       0x0040
-#define PBC_INTR_FEC_INT        0X0080
-#define PBC_INTR_ENET_INT       0X0100
-#define PBC_INTR_OTGFS_INT      0X0200
-#define PBC_INTR_XUART_INT      0X0400
-#define PBC_INTR_CCTL12         0X0800
-#define PBC_INTR_SD2_EN         0x1000
-#define PBC_INTR_SD3_EN         0x2000
-#define PBC_INTR_MS_EN          0x4000
-#define PBC_INTR_SD1_EN         0x8000
-
-
-
-/* For interrupts like xuart, enet etc */
-#define EXPIO_PARENT_INT        IOMUX_TO_IRQ(MX27_PIN_TIN)
-#define MXC_MAX_EXP_IO_LINES    16
-
-/*
- * This corresponds to PBC_INTMASK_SET_REG at offset 0x38.
- *
- */
-#define EXPIO_INT_LOW_BAT       (MXC_EXP_IO_BASE + 1)
-#define EXPIO_INT_OTG_FS_OVR    (MXC_EXP_IO_BASE + 2)
-#define EXPIO_INT_FSH_OVR       (MXC_EXP_IO_BASE + 3)
-#define EXPIO_INT_RES4          (MXC_EXP_IO_BASE + 4)
-#define EXPIO_INT_RES5          (MXC_EXP_IO_BASE + 5)
-#define EXPIO_INT_RES6          (MXC_EXP_IO_BASE + 6)
-#define EXPIO_INT_FEC           (MXC_EXP_IO_BASE + 7)
-#define EXPIO_INT_ENET_INT      (MXC_EXP_IO_BASE + 8)
-#define EXPIO_INT_OTG_FS_INT    (MXC_EXP_IO_BASE + 9)
-#define EXPIO_INT_XUART_INTA    (MXC_EXP_IO_BASE + 10)
-#define EXPIO_INT_CCTL12_INT    (MXC_EXP_IO_BASE + 11)
-#define EXPIO_INT_SD2_EN        (MXC_EXP_IO_BASE + 12)
-#define EXPIO_INT_SD3_EN        (MXC_EXP_IO_BASE + 13)
-#define EXPIO_INT_MS_EN         (MXC_EXP_IO_BASE + 14)
-#define EXPIO_INT_SD1_EN        (MXC_EXP_IO_BASE + 15)
-
-/*
- * This is System IRQ used by CS8900A for interrupt generation
- * taken from platform.h
- */
-#define CS8900AIRQ              EXPIO_INT_ENET_INT
-/* This is I/O Base address used to access registers of CS8900A on MXC ADS */
-#define CS8900A_BASE_ADDRESS    (PBC_CS8900A_IOBASE_REG + 0x300)
-
-#define MXC_PMIC_INT_LINE       IOMUX_TO_IRQ(MX27_PIN_TOUT)
-
-/*
-* This is used to detect if the CPLD version is for mx27 evb board rev-a
-*/
-#define PBC_CPLD_VERSION_IS_REVA() \
-       ((__raw_readw(PBC_VERSION_REG) & \
-       (PBC_VERSION_ADS | PBC_VERSION_EVB_REVB))\
-       == 0)
-
-/* This is used to active or inactive ata signal in CPLD .
- *  It is dependent with hardware
- */
-#define PBC_ATA_SIGNAL_ACTIVE() \
-       __raw_writew(           \
-               PBC_BCTRL2_ATAFEC_EN|PBC_BCTRL2_ATAFEC_SEL|PBC_BCTRL2_ATA_EN, \
-               PBC_BCTRL2_CLEAR_REG)
-
-#define PBC_ATA_SIGNAL_INACTIVE() \
-       __raw_writew(  \
-               PBC_BCTRL2_ATAFEC_EN|PBC_BCTRL2_ATAFEC_SEL|PBC_BCTRL2_ATA_EN, \
-               PBC_BCTRL2_SET_REG)
-
-#define MXC_BD_LED1             (1 << 5)
-#define MXC_BD_LED2             (1 << 6)
-#define MXC_BD_LED_ON(led) \
-       __raw_writew(led, PBC_BCTRL1_SET_REG)
-#define MXC_BD_LED_OFF(led) \
-       __raw_writew(led, PBC_BCTRL1_CLEAR_REG)
-
-/* to determine the correct external crystal reference */
-#define CKIH_27MHZ_BIT_SET      (1 << 3)
-
-#endif                         /* __ASM_ARCH_MXC_BOARD_MX27ADS_H__ */
diff --git a/arch/arm/plat-mxc/include/mach/board-mx27lite.h b/arch/arm/plat-mxc/include/mach/board-mx27lite.h
deleted file mode 100644 (file)
index ea87551..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef __ASM_ARCH_MXC_BOARD_MX27LITE_H__
-#define __ASM_ARCH_MXC_BOARD_MX27LITE_H__
-
-#endif /* __ASM_ARCH_MXC_BOARD_MX27LITE_H__ */
diff --git a/arch/arm/plat-mxc/include/mach/board-mx27pdk.h b/arch/arm/plat-mxc/include/mach/board-mx27pdk.h
deleted file mode 100644 (file)
index fec1bcf..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * Copyright 2009 Freescale Semiconductor, Inc. All Rights Reserved.
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef __ASM_ARCH_MXC_BOARD_MX27PDK_H__
-#define __ASM_ARCH_MXC_BOARD_MX27PDK_H__
-
-#endif /* __ASM_ARCH_MXC_BOARD_MX27PDK_H__ */
diff --git a/arch/arm/plat-mxc/include/mach/board-mx31_3ds.h b/arch/arm/plat-mxc/include/mach/board-mx31_3ds.h
deleted file mode 100644 (file)
index da92933..0000000
+++ /dev/null
@@ -1,59 +0,0 @@
-/*
- * Copyright 2008 Freescale Semiconductor, Inc. All Rights Reserved.
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef __ASM_ARCH_MXC_BOARD_MX31_3DS_H__
-#define __ASM_ARCH_MXC_BOARD_MX31_3DS_H__
-
-/* Definitions for components on the Debug board */
-
-/* Base address of CPLD controller on the Debug board */
-#define DEBUG_BASE_ADDRESS             CS5_IO_ADDRESS(CS5_BASE_ADDR)
-
-/* LAN9217 ethernet base address */
-#define LAN9217_BASE_ADDR              CS5_BASE_ADDR
-
-/* CPLD config and interrupt base address */
-#define CPLD_ADDR                      (DEBUG_BASE_ADDRESS + 0x20000)
-
-/* LED switchs */
-#define CPLD_LED_REG                   (CPLD_ADDR + 0x00)
-/* buttons */
-#define CPLD_SWITCH_BUTTONS_REG        (EXPIO_ADDR + 0x08)
-/* status, interrupt */
-#define CPLD_INT_STATUS_REG            (CPLD_ADDR + 0x10)
-#define CPLD_INT_MASK_REG              (CPLD_ADDR + 0x38)
-#define CPLD_INT_RESET_REG             (CPLD_ADDR + 0x20)
-/* magic word for debug CPLD */
-#define CPLD_MAGIC_NUMBER1_REG         (CPLD_ADDR + 0x40)
-#define CPLD_MAGIC_NUMBER2_REG         (CPLD_ADDR + 0x48)
-/* CPLD code version */
-#define CPLD_CODE_VER_REG              (CPLD_ADDR + 0x50)
-/* magic word for debug CPLD */
-#define CPLD_MAGIC_NUMBER3_REG         (CPLD_ADDR + 0x58)
-/* module reset register */
-#define CPLD_MODULE_RESET_REG          (CPLD_ADDR + 0x60)
-/* CPU ID and Personality ID */
-#define CPLD_MCU_BOARD_ID_REG          (CPLD_ADDR + 0x68)
-
-/* CPLD IRQ line for external uart, external ethernet etc */
-#define EXPIO_PARENT_INT       IOMUX_TO_IRQ(MX31_PIN_GPIO1_1)
-
-#define MXC_EXP_IO_BASE                (MXC_BOARD_IRQ_START)
-#define MXC_IRQ_TO_EXPIO(irq)  ((irq) - MXC_EXP_IO_BASE)
-
-#define EXPIO_INT_ENET         (MXC_EXP_IO_BASE + 0)
-#define EXPIO_INT_XUART_A      (MXC_EXP_IO_BASE + 1)
-#define EXPIO_INT_XUART_B      (MXC_EXP_IO_BASE + 2)
-#define EXPIO_INT_BUTTON_A     (MXC_EXP_IO_BASE + 3)
-#define EXPIO_INT_BUTTON_B     (MXC_EXP_IO_BASE + 4)
-
-#define MXC_MAX_EXP_IO_LINES   16
-
-#endif /* __ASM_ARCH_MXC_BOARD_MX31_3DS_H__ */
diff --git a/arch/arm/plat-mxc/include/mach/board-mx31ads.h b/arch/arm/plat-mxc/include/mach/board-mx31ads.h
deleted file mode 100644 (file)
index 095a199..0000000
+++ /dev/null
@@ -1,117 +0,0 @@
-/*
- * Copyright 2005-2007 Freescale Semiconductor, Inc. All Rights Reserved.
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef __ASM_ARCH_MXC_BOARD_MX31ADS_H__
-#define __ASM_ARCH_MXC_BOARD_MX31ADS_H__
-
-#include <mach/hardware.h>
-
-/* Base address of PBC controller */
-#define PBC_BASE_ADDRESS        MX31_CS4_BASE_ADDR_VIRT
-/* Offsets for the PBC Controller register */
-
-/* PBC Board status register offset */
-#define PBC_BSTAT               0x000002
-
-/* PBC Board control register 1 set address */
-#define PBC_BCTRL1_SET          0x000004
-
-/* PBC Board control register 1 clear address */
-#define PBC_BCTRL1_CLEAR        0x000006
-
-/* PBC Board control register 2 set address */
-#define PBC_BCTRL2_SET          0x000008
-
-/* PBC Board control register 2 clear address */
-#define PBC_BCTRL2_CLEAR        0x00000A
-
-/* PBC Board control register 3 set address */
-#define PBC_BCTRL3_SET          0x00000C
-
-/* PBC Board control register 3 clear address */
-#define PBC_BCTRL3_CLEAR        0x00000E
-
-/* PBC Board control register 4 set address */
-#define PBC_BCTRL4_SET          0x000010
-
-/* PBC Board control register 4 clear address */
-#define PBC_BCTRL4_CLEAR        0x000012
-
-/* PBC Board status register 1 */
-#define PBC_BSTAT1              0x000014
-
-/* PBC Board interrupt status register */
-#define PBC_INTSTATUS           0x000016
-
-/* PBC Board interrupt current status register */
-#define PBC_INTCURR_STATUS      0x000018
-
-/* PBC Interrupt mask register set address */
-#define PBC_INTMASK_SET         0x00001A
-
-/* PBC Interrupt mask register clear address */
-#define PBC_INTMASK_CLEAR       0x00001C
-
-/* External UART A */
-#define PBC_SC16C652_UARTA      0x010000
-
-/* External UART B */
-#define PBC_SC16C652_UARTB      0x010010
-
-/* Ethernet Controller IO base address */
-#define PBC_CS8900A_IOBASE      0x020000
-
-/* Ethernet Controller Memory base address */
-#define PBC_CS8900A_MEMBASE     0x021000
-
-/* Ethernet Controller DMA base address */
-#define PBC_CS8900A_DMABASE     0x022000
-
-/* External chip select 0 */
-#define PBC_XCS0                0x040000
-
-/* LCD Display enable */
-#define PBC_LCD_EN_B            0x060000
-
-/* Code test debug enable */
-#define PBC_CODE_B              0x070000
-
-/* PSRAM memory select */
-#define PBC_PSRAM_B             0x5000000
-
-#define PBC_INTSTATUS_REG      (PBC_INTSTATUS + PBC_BASE_ADDRESS)
-#define PBC_INTCURR_STATUS_REG (PBC_INTCURR_STATUS + PBC_BASE_ADDRESS)
-#define PBC_INTMASK_SET_REG    (PBC_INTMASK_SET + PBC_BASE_ADDRESS)
-#define PBC_INTMASK_CLEAR_REG  (PBC_INTMASK_CLEAR + PBC_BASE_ADDRESS)
-#define EXPIO_PARENT_INT       IOMUX_TO_IRQ(MX31_PIN_GPIO1_4)
-
-#define MXC_EXP_IO_BASE                (MXC_BOARD_IRQ_START)
-#define MXC_IRQ_TO_EXPIO(irq)  ((irq) - MXC_EXP_IO_BASE)
-
-#define EXPIO_INT_LOW_BAT      (MXC_EXP_IO_BASE + 0)
-#define EXPIO_INT_PB_IRQ       (MXC_EXP_IO_BASE + 1)
-#define EXPIO_INT_OTG_FS_OVR   (MXC_EXP_IO_BASE + 2)
-#define EXPIO_INT_FSH_OVR      (MXC_EXP_IO_BASE + 3)
-#define EXPIO_INT_RES4         (MXC_EXP_IO_BASE + 4)
-#define EXPIO_INT_RES5         (MXC_EXP_IO_BASE + 5)
-#define EXPIO_INT_RES6         (MXC_EXP_IO_BASE + 6)
-#define EXPIO_INT_RES7         (MXC_EXP_IO_BASE + 7)
-#define EXPIO_INT_ENET_INT     (MXC_EXP_IO_BASE + 8)
-#define EXPIO_INT_OTG_FS_INT   (MXC_EXP_IO_BASE + 9)
-#define EXPIO_INT_XUART_INTA   (MXC_EXP_IO_BASE + 10)
-#define EXPIO_INT_XUART_INTB   (MXC_EXP_IO_BASE + 11)
-#define EXPIO_INT_SYNTH_IRQ    (MXC_EXP_IO_BASE + 12)
-#define EXPIO_INT_CE_INT1      (MXC_EXP_IO_BASE + 13)
-#define EXPIO_INT_CE_INT2      (MXC_EXP_IO_BASE + 14)
-#define EXPIO_INT_RES15                (MXC_EXP_IO_BASE + 15)
-
-#define MXC_MAX_EXP_IO_LINES   16
-
-#endif /* __ASM_ARCH_MXC_BOARD_MX31ADS_H__ */
index eb5a5024622efbe9da16228e44b338b51037f559..0df71bfefbb10819883de74f5bae623227b0d7f5 100644 (file)
@@ -31,7 +31,7 @@ enum mx31lilly_boards {
 
 /*
  * This CPU module needs a baseboard to work. After basic initializing
- * its own devices, it calls baseboard's init function.
+ * its own devices, it calls the baseboard's init function.
  */
 
 extern void mx31lilly_db_init(void);
index 2b2da0367578dbb13a4dbf6e12894709f079acec..c1ad0ae807cc57ee20cbddd3cb8021efe61196c6 100644 (file)
@@ -32,7 +32,7 @@ enum mx31lite_boards {
 
 /*
  * This CPU module needs a baseboard to work. After basic initializing
- * its own devices, it calls baseboard's init function.
+ * its own devices, it calls the baseboard's init function.
  */
 
 extern void mx31lite_db_init(void);
index 36ff3cedee1a1d3cd3d7ffbc1c32ab185ed1cdcf..de14543891cf4b40ff569fbc7a889170fdbb5c7f 100644 (file)
@@ -31,7 +31,7 @@ enum mx31moboard_boards {
 
 /*
  * This CPU module needs a baseboard to work. After basic initializing
- * its own devices, it calls baseboard's init function.
+ * its own devices, it calls the baseboard's init function.
  */
 
 extern void mx31moboard_devboard_init(void);
index 410f9786ed2292d7c909ddd2b690a8d7cbf83c51..6f371e35753dfbb557840a0307a931685615563a 100644 (file)
@@ -22,7 +22,7 @@
 #ifndef __ASSEMBLY__
 /*
  * This CPU module needs a baseboard to work. After basic initializing
- * its own devices, it calls baseboard's init function.
+ * its own devices, it calls the baseboard's init function.
  * TODO: Add your own baseboard init function and call it from
  * inside pcm038_init().
  *
diff --git a/arch/arm/plat-mxc/include/mach/board-qong.h b/arch/arm/plat-mxc/include/mach/board-qong.h
deleted file mode 100644 (file)
index 6d88c7a..0000000
+++ /dev/null
@@ -1,17 +0,0 @@
-/*
- * Copyright 2009 Ilya Yanok, Emcraft Systems Ltd, <yanok@emcraft.com>
- */
-
-/*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- */
-
-#ifndef __ASM_ARCH_MXC_BOARD_QONG_H__
-#define __ASM_ARCH_MXC_BOARD_QONG_H__
-
-/* NOR FLASH */
-#define QONG_NOR_SIZE          (128*1024*1024)
-
-#endif /* __ASM_ARCH_MXC_BOARD_QONG_H__ */
index 0b6e11eaeb8ca0b2d64c847810a44fbc96355909..25606409aabcfb7de02a3dbce55e7221b68d2ece 100644 (file)
@@ -23,8 +23,8 @@
 #error "CONFIG_DEBUG_LL is incompatible with multiple archs"
 #endif
 #include <mach/mx25.h>
-#define UART_PADDR     UART1_BASE_ADDR
-#define UART_VADDR     MX25_AIPS1_IO_ADDRESS(UART1_BASE_ADDR)
+#define UART_PADDR     MX25_UART1_BASE_ADDR
+#define UART_VADDR     MX25_AIPS1_IO_ADDRESS(MX25_UART1_BASE_ADDR)
 #endif
 
 #ifdef CONFIG_ARCH_MX2
diff --git a/arch/arm/plat-mxc/include/mach/devices-common.h b/arch/arm/plat-mxc/include/mach/devices-common.h
new file mode 100644 (file)
index 0000000..c5f68c5
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * Copyright (C) 2009-2010 Pengutronix
+ * Uwe Kleine-Koenig <u.kleine-koenig@pengutronix.de>
+ *
+ * This program is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License version 2 as published by the
+ * Free Software Foundation.
+ */
+#include <linux/kernel.h>
+#include <linux/platform_device.h>
+#include <linux/init.h>
+
+struct platform_device *imx_add_platform_device(const char *name, int id,
+               const struct resource *res, unsigned int num_resources,
+               const void *data, size_t size_data);
+
+#if defined (CONFIG_CAN_FLEXCAN) || defined (CONFIG_CAN_FLEXCAN_MODULE)
+#include <linux/can/platform/flexcan.h>
+struct platform_device *__init imx_add_flexcan(int id,
+               resource_size_t iobase, resource_size_t iosize,
+               resource_size_t irq,
+               const struct flexcan_platform_data *pdata);
+#else
+/* the ifdef can be removed once the flexcan driver has been merged */
+struct flexcan_platform_data;
+static inline struct platform_device *__init imx_add_flexcan(int id,
+               resource_size_t iobase, resource_size_t iosize,
+               resource_size_t irq,
+               const struct flexcan_platform_data *pdata)
+{
+       return NULL;
+}
+#endif
+
+#include <mach/i2c.h>
+struct platform_device *__init imx_add_imx_i2c(int id,
+               resource_size_t iobase, resource_size_t iosize, int irq,
+               const struct imxi2c_platform_data *pdata);
+
+#include <mach/imx-uart.h>
+struct platform_device *__init imx_add_imx_uart_3irq(int id,
+               resource_size_t iobase, resource_size_t iosize,
+               resource_size_t irqrx, resource_size_t irqtx,
+               resource_size_t irqrts,
+               const struct imxuart_platform_data *pdata);
+struct platform_device *__init imx_add_imx_uart_1irq(int id,
+               resource_size_t iobase, resource_size_t iosize,
+               resource_size_t irq,
+               const struct imxuart_platform_data *pdata);
+
+#include <mach/mxc_nand.h>
+struct platform_device *__init imx_add_mxc_nand_v1(resource_size_t iobase,
+               int irq, const struct mxc_nand_platform_data *pdata);
+struct platform_device *__init imx_add_mxc_nand_v21(resource_size_t iobase,
+               int irq, const struct mxc_nand_platform_data *pdata);
+
+#include <mach/spi.h>
+struct platform_device *__init imx_add_spi_imx(int id,
+               resource_size_t iobase, resource_size_t iosize, int irq,
+               const struct spi_imx_master *pdata);
similarity index 64%
rename from arch/arm/plat-mxc/include/mach/board-eukrea_cpuimx27.h
rename to arch/arm/plat-mxc/include/mach/eukrea-baseboards.h
index a1fd5830af484758c21c70d453b595746f063091..634e3f4c454df222728aa678bdcd657967286dbc 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2009 Eric Benard - eric@eukrea.com
+ * Copyright (C) 2010 Eric Benard - eric@eukrea.com
  *
  * Based on board-pcm038.h which is :
  * Copyright (C) 2008 Juergen Beisert (kernel@pengutronix.de)
  * MA 02110-1301, USA.
  */
 
-#ifndef __ASM_ARCH_MXC_BOARD_EUKREA_CPUIMX27_H__
-#define __ASM_ARCH_MXC_BOARD_EUKREA_CPUIMX27_H__
+#ifndef __MACH_EUKREA_BASEBOARDS_H__
+#define __MACH_EUKREA_BASEBOARDS_H__
 
 #ifndef __ASSEMBLY__
 /*
  * This CPU module needs a baseboard to work. After basic initializing
  * its own devices, it calls baseboard's init function.
  * TODO: Add your own baseboard init function and call it from
- * inside eukrea_cpuimx27_init().
+ * inside eukrea_cpuimx25_init() eukrea_cpuimx27_init()
+ * eukrea_cpuimx35_init() or eukrea_cpuimx51_init().
  *
  * This example here is for the development board. Refer
- * eukrea_mbimx27-baseboard.c
+ * mach-mx25/eukrea_mbimxsd-baseboard.c for cpuimx25
+ * mach-imx/eukrea_mbimx27-baseboard.c for cpuimx27
+ * mach-mx3/eukrea_mbimxsd-baseboard.c for cpuimx35
+ * mach-mx5/eukrea_mbimx51-baseboard.c for cpuimx51
  */
 
+extern void eukrea_mbimx25_baseboard_init(void);
 extern void eukrea_mbimx27_baseboard_init(void);
+extern void eukrea_mbimx35_baseboard_init(void);
+extern void eukrea_mbimx51_baseboard_init(void);
 
 #endif
 
-#endif /* __ASM_ARCH_MXC_BOARD_EUKREA_CPUIMX27_H__ */
+#endif /* __MACH_EUKREA_BASEBOARDS_H__ */
index 894d2f87c85600c495d117a6d0f524060ee15aaa..661fbc6057597c2bec30545af8904396ad4d4328 100644 (file)
 struct mxc_gpio_port {
        void __iomem *base;
        int irq;
+       int irq_high;
        int virtual_irq_start;
        struct gpio_chip chip;
        u32 both_edges;
+       spinlock_t lock;
 };
 
 int mxc_gpio_init(struct mxc_gpio_port*, int);
index f39220d1b67af1112a31ab72f713f0c45153df6d..d7f52c91f82edb09f5aa686abdae16b6ce78963b 100644 (file)
 #define MX25_PAD_OE_ACD__GPIO_1_25     IOMUX_PAD(0x30c, 0x114, 0x15, 0, 0, NO_PAD_CTRL)
 
 #define MX25_PAD_CONTRAST__CONTRAST    IOMUX_PAD(0x310, 0x118, 0x10, 0, 0, NO_PAD_CTRL)
+#define MX25_PAD_CONTRAST__PWM4_PWMO   IOMUX_PAD(0x310, 0x118, 0x14, 0, 0, NO_PAD_CTRL)
 #define MX25_PAD_CONTRAST__FEC_CRS     IOMUX_PAD(0x310, 0x118, 0x15, 0x508, 1, NO_PAD_CTRL)
 
 #define MX25_PAD_PWM__PWM              IOMUX_PAD(0x314, 0x11c, 0x10, 0, 0, NO_PAD_CTRL)
 #define MX25_PAD_SD1_DATA3__FEC_CRS    IOMUX_PAD(0x39c, 0x1a4, 0x10, 0x508, 2, NO_PAD_CTRL)
 #define MX25_PAD_SD1_DATA3__GPIO_2_28  IOMUX_PAD(0x39c, 0x1a4, 0x15, 0, 0, NO_PAD_CTRL)
 
-#define MX25_PAD_KPP_ROW0__KPP_ROW0    IOMUX_PAD(0x3a0, 0x1a8, 0x10, 0, 0, PAD_CTL_PKE)
+#define KPP_CTL_ROW    (PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP)
+#define KPP_CTL_COL    (PAD_CTL_PKE | PAD_CTL_PUE | PAD_CTL_PUS_100K_UP | PAD_CTL_ODE)
+
+#define MX25_PAD_KPP_ROW0__KPP_ROW0    IOMUX_PAD(0x3a0, 0x1a8, 0x10, 0, 0, KPP_CTL_ROW)
 #define MX25_PAD_KPP_ROW0__GPIO_2_29   IOMUX_PAD(0x3a0, 0x1a8, 0x15, 0, 0, NO_PAD_CTRL)
 
-#define MX25_PAD_KPP_ROW1__KPP_ROW1    IOMUX_PAD(0x3a4, 0x1ac, 0x10, 0, 0, PAD_CTL_PKE)
+#define MX25_PAD_KPP_ROW1__KPP_ROW1    IOMUX_PAD(0x3a4, 0x1ac, 0x10, 0, 0, KPP_CTL_ROW)
 #define MX25_PAD_KPP_ROW1__GPIO_2_30   IOMUX_PAD(0x3a4, 0x1ac, 0x15, 0, 0, NO_PAD_CTRL)
 
-#define MX25_PAD_KPP_ROW2__KPP_ROW2    IOMUX_PAD(0x3a8, 0x1b0, 0x10, 0, 0, PAD_CTL_PKE)
+#define MX25_PAD_KPP_ROW2__KPP_ROW2    IOMUX_PAD(0x3a8, 0x1b0, 0x10, 0, 0, KPP_CTL_ROW)
 #define MX25_PAD_KPP_ROW2__CSI_D0      IOMUX_PAD(0x3a8, 0x1b0, 0x13, 0x488, 2, NO_PAD_CTRL)
 #define MX25_PAD_KPP_ROW2__GPIO_2_31   IOMUX_PAD(0x3a8, 0x1b0, 0x15, 0, 0, NO_PAD_CTRL)
 
-#define MX25_PAD_KPP_ROW3__KPP_ROW3    IOMUX_PAD(0x3ac, 0x1b4, 0x10, 0, 0, PAD_CTL_PKE)
+#define MX25_PAD_KPP_ROW3__KPP_ROW3    IOMUX_PAD(0x3ac, 0x1b4, 0x10, 0, 0, KPP_CTL_ROW)
 #define MX25_PAD_KPP_ROW3__CSI_LD1     IOMUX_PAD(0x3ac, 0x1b4, 0x13, 0x48c, 2, NO_PAD_CTRL)
 #define MX25_PAD_KPP_ROW3__GPIO_3_0    IOMUX_PAD(0x3ac, 0x1b4, 0x15, 0, 0, NO_PAD_CTRL)
 
-#define MX25_PAD_KPP_COL0__KPP_COL0    IOMUX_PAD(0x3b0, 0x1b8, 0x10, 0, 0, PAD_CTL_PKE | PAD_CTL_ODE)
+#define MX25_PAD_KPP_COL0__KPP_COL0    IOMUX_PAD(0x3b0, 0x1b8, 0x10, 0, 0, KPP_CTL_COL)
+#define MX25_PAD_KPP_COL0__UART4_RXD_MUX IOMUX_PAD(0x3b0, 0x1b8, 0x11, 0x570, 1, NO_PAD_CTRL)
+#define MX25_PAD_KPP_COL0__AUD5_TXD    IOMUX_PAD(0x3b0, 0x1b8, 0x12, 0, 0, PAD_CTL_PKE | PAD_CTL_PUS_100K_UP)
 #define MX25_PAD_KPP_COL0__GPIO_3_1    IOMUX_PAD(0x3b0, 0x1b8, 0x15, 0, 0, NO_PAD_CTRL)
 
-#define MX25_PAD_KPP_COL1__KPP_COL1    IOMUX_PAD(0x3b4, 0x1bc, 0x10, 0, 0, PAD_CTL_PKE | PAD_CTL_ODE)
+#define MX25_PAD_KPP_COL1__KPP_COL1    IOMUX_PAD(0x3b4, 0x1bc, 0x10, 0, 0, KPP_CTL_COL)
+#define MX25_PAD_KPP_COL1__UART4_TXD_MUX IOMUX_PAD(0x3b4, 0x1bc, 0x11, 0, 0, NO_PAD_CTRL)
+#define MX25_PAD_KPP_COL1__AUD5_RXD    IOMUX_PAD(0x3b4, 0x1bc, 0x12, 0, 0, PAD_CTL_PKE | PAD_CTL_PUS_100K_UP)
 #define MX25_PAD_KPP_COL1__GPIO_3_2    IOMUX_PAD(0x3b4, 0x1bc, 0x15, 0, 0, NO_PAD_CTRL)
 
-#define MX25_PAD_KPP_COL2__KPP_COL2    IOMUX_PAD(0x3b8, 0x1c0, 0x10, 0, 0, PAD_CTL_PKE | PAD_CTL_ODE)
+#define MX25_PAD_KPP_COL2__KPP_COL2    IOMUX_PAD(0x3b8, 0x1c0, 0x10, 0, 0, KPP_CTL_COL)
+#define MX25_PAD_KPP_COL2__UART4_RTS   IOMUX_PAD(0x3b8, 0x1c0, 0x11, 0, 0, NO_PAD_CTRL)
+#define MX25_PAD_KPP_COL2__AUD5_TXC    IOMUX_PAD(0x3b8, 0x1c0, 0x12, 0, 0, PAD_CTL_PKE | PAD_CTL_PUS_100K_UP)
 #define MX25_PAD_KPP_COL2__GPIO_3_3    IOMUX_PAD(0x3b8, 0x1c0, 0x15, 0, 0, NO_PAD_CTRL)
 
-#define MX25_PAD_KPP_COL3__KPP_COL3    IOMUX_PAD(0x3bc, 0x1c4, 0x10, 0, 0, PAD_CTL_PKE | PAD_CTL_ODE)
+#define MX25_PAD_KPP_COL3__KPP_COL3    IOMUX_PAD(0x3bc, 0x1c4, 0x10, 0, 0, KPP_CTL_COL)
+#define MX25_PAD_KPP_COL3__UART4_CTS   IOMUX_PAD(0x3bc, 0x1c4, 0x11, 0, 0, NO_PAD_CTRL)
+#define MX25_PAD_KPP_COL3__AUD5_TXFS   IOMUX_PAD(0x3bc, 0x1c4, 0x12, 0, 0, PAD_CTL_PKE | PAD_CTL_PUS_100K_UP)
 #define MX25_PAD_KPP_COL3__GPIO_3_4    IOMUX_PAD(0x3bc, 0x1c4, 0x15, 0, 0, NO_PAD_CTRL)
 
 #define MX25_PAD_FEC_MDC__FEC_MDC      IOMUX_PAD(0x3c0, 0x1c8, 0x10, 0, 0, NO_PAD_CTRL)
index ab0f95d953d02539ab76e69973056814a79ffcd4..21bfa46785bb5254e16ed1cfd8f36d7e384dbfcc 100644 (file)
@@ -27,8 +27,8 @@ typedef enum iomux_config {
        IOMUX_CONFIG_ALT5,
        IOMUX_CONFIG_ALT6,
        IOMUX_CONFIG_ALT7,
-       IOMUX_CONFIG_GPIO,      /* added to help user use GPIO mode */
-       IOMUX_CONFIG_SION = 0x1 << 4,   /* LOOPBACK:MUX SION bit */
+       IOMUX_CONFIG_GPIO,      /* added to help user use GPIO mode */
+       IOMUX_CONFIG_SION = 0x1 << 4,   /* LOOPBACK:MUX SION bit */
 } iomux_pin_cfg_t;
 
 /* Pad control groupings */
@@ -38,6 +38,8 @@ typedef enum iomux_config {
                                PAD_CTL_SRE_FAST)
 #define MX51_UART3_PAD_CTRL    (PAD_CTL_PKE | PAD_CTL_DSE_HIGH | \
                                PAD_CTL_SRE_FAST)
+#define MX51_I2C_PAD_CTRL      (PAD_CTL_SRE_FAST | PAD_CTL_ODE | \
+                               PAD_CTL_DSE_HIGH | PAD_CTL_PUS_100K_UP | PAD_CTL_HYS)
 #define MX51_USBH1_PAD_CTRL    (PAD_CTL_SRE_FAST | PAD_CTL_DSE_HIGH | \
                                PAD_CTL_PUS_100K_UP | PAD_CTL_PUE | \
                                PAD_CTL_PKE | PAD_CTL_HYS)
@@ -46,289 +48,278 @@ typedef enum iomux_config {
 
 /*
  * The naming convention for the pad modes is MX51_PAD_<padname>__<padmode>
- * If <padname> or <padmode> refers to a GPIO, it is named
- * GPIO_<unit>_<num> see also iomux-v3.h
+ * If <padname> or <padmode> refers to a GPIO, it is named GPIO_<unit>_<num>
+ * See also iomux-v3.h
  */
 
-/*
- * FIXME: This was converted using scripts from existing Freescale code to
- * this form used upstream. Need to verify the name format.
- */
-
-/*                                             PAD      MUX   ALT INPSE PATH PADCTRL */
-
-#define MX51_PAD_GPIO_2_0__EIM_D16     IOMUX_PAD(0x3f0, 0x05c, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_1__EIM_D17     IOMUX_PAD(0x3f4, 0x060, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_2__EIM_D18     IOMUX_PAD(0x3f8, 0x064, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_3__EIM_D19     IOMUX_PAD(0x3fc, 0x068, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_4__EIM_D20     IOMUX_PAD(0x400, 0x06c, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_5__EIM_D21     IOMUX_PAD(0x404, 0x070, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_D21__GPIO_2_5     IOMUX_PAD(0x404, 0x070, IOMUX_CONFIG_ALT1, 0x0,   0, MX51_GPIO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_6__EIM_D22     IOMUX_PAD(0x408, 0x074, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_7__EIM_D23     IOMUX_PAD(0x40c, 0x078, 1, 0x0,   0, NO_PAD_CTRL)
-
-/* Babbage UART3 */
-#define MX51_PAD_EIM_D24__UART3_CTS    IOMUX_PAD(0x410, 0x07c, IOMUX_CONFIG_ALT3, 0x0, 0, MX51_UART3_PAD_CTRL)
-#define MX51_PAD_EIM_D25__UART3_RXD    IOMUX_PAD(0x414, 0x080, IOMUX_CONFIG_ALT3, 0x9f4, 0, MX51_UART3_PAD_CTRL)
-#define MX51_PAD_EIM_D26__UART3_TXD    IOMUX_PAD(0x418, 0x084, IOMUX_CONFIG_ALT3, 0x0, 0, MX51_UART3_PAD_CTRL)
-#define MX51_PAD_EIM_D27__UART3_RTS    IOMUX_PAD(0x41c, 0x088, IOMUX_CONFIG_ALT3, 0x9f0, 0, MX51_UART3_PAD_CTRL)
-
-#define MX51_PAD_EIM_D28__EIM_D28      IOMUX_PAD(0x420, 0x08c, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_D29__EIM_D29      IOMUX_PAD(0x424, 0x090, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_D30__EIM_D30      IOMUX_PAD(0x428, 0x094, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_D31__EIM_D31      IOMUX_PAD(0x42c, 0x09c, 0, 0x0,   0, NO_PAD_CTRL)
-
-#define MX51_PAD_GPIO_2_10__EIM_A16    IOMUX_PAD(0x430, 0x09c, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_11__EIM_A17    IOMUX_PAD(0x434, 0x0a0, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_12__EIM_A18    IOMUX_PAD(0x438, 0x0a4, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_13__EIM_A19    IOMUX_PAD(0x43c, 0x0a8, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_14__EIM_A20    IOMUX_PAD(0x440, 0x0ac, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_15__EIM_A21    IOMUX_PAD(0x444, 0x0b0, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_16__EIM_A22    IOMUX_PAD(0x448, 0x0b4, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_17__EIM_A23    IOMUX_PAD(0x44c, 0x0b8, 1, 0x0,   0, NO_PAD_CTRL)
-
-#define MX51_PAD_GPIO_2_18__EIM_A24    IOMUX_PAD(0x450, 0x0bc, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_19__EIM_A25    IOMUX_PAD(0x454, 0x0c0, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_20__EIM_A26    IOMUX_PAD(0x458, 0x0c4, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_21__EIM_A27    IOMUX_PAD(0x45c, 0x0c8, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_EB0__EIM_EB0      IOMUX_PAD(0x460, 0x0cc, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_EB1__EIM_EB1      IOMUX_PAD(0x464, 0x0d0, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_22__EIM_EB2    IOMUX_PAD(0x468, 0x0d4, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_23__EIM_EB3    IOMUX_PAD(0x46c, 0x0d8, 1, 0x0,   0, NO_PAD_CTRL)
-
-#define MX51_PAD_GPIO_2_24__EIM_OE     IOMUX_PAD(0x470, 0x0dc, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_25__EIM_CS0    IOMUX_PAD(0x474, 0x0e0, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_26__EIM_CS1    IOMUX_PAD(0x478, 0x0e4, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_27__EIM_CS2    IOMUX_PAD(0x47c, 0x0e8, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_28__EIM_CS3    IOMUX_PAD(0x480, 0x0ec, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_29__EIM_CS4    IOMUX_PAD(0x484, 0x0f0, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_30__EIM_CS5    IOMUX_PAD(0x488, 0x0f4, 1, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_2_31__EIM_DTACK  IOMUX_PAD(0x48c, 0x0f8, 1, 0x0,   0, NO_PAD_CTRL)
-
-#define MX51_PAD_GPIO_3_1__EIM_LBA     IOMUX_PAD(0x494, 0xFC, 1, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_2__EIM_CRE     IOMUX_PAD(0x4A0, 0x100, 1, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DRAM_CS1__DRAM_CS1    IOMUX_PAD(0x4D0, 0x104, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_3__NANDF_WE_B  IOMUX_PAD(0x4E4, 0x108, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_4__NANDF_RE_B  IOMUX_PAD(0x4E8, 0x10C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_5__NANDF_ALE   IOMUX_PAD(0x4EC, 0x110, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_6__NANDF_CLE   IOMUX_PAD(0x4F0, 0x114, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_7__NANDF_WP_B  IOMUX_PAD(0x4F4, 0x118, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_8__NANDF_RB0   IOMUX_PAD(0x4F8, 0x11C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_9__NANDF_RB1   IOMUX_PAD(0x4FC, 0x120, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_10__NANDF_RB2  IOMUX_PAD(0x500, 0x124, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_11__NANDF_RB3  IOMUX_PAD(0x504, 0x128, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_12__GPIO_NAND  IOMUX_PAD(0x514, 0x12C, 3, 0x0, 0, NO_PAD_CTRL)
-/* REVISIT: Not sure of these values
-
-  #define MX51_PAD_GPIO_1___NANDF_RB4  IOMUX_PAD(, , , 0x0, 0, NO_PAD_CTRL)
-  #define MX51_PAD_GPIO_3_13__NANDF_RB5        IOMUX_PAD(0x5D8, 0x130, 3, 0x0, 0, NO_PAD_CTRL)
-  #define MX51_PAD_GPIO_3_15__NANDF_RB7        IOMUX_PAD(0x5E0, 0x138, 3, 0x0, 0, NO_PAD_CTRL)
-*/
-#define MX51_PAD_GPIO_3_14__NANDF_RB6  IOMUX_PAD(0x5DC, 0x134, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_16__NANDF_CS0  IOMUX_PAD(0x518, 0x130, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_17__NANDF_CS1  IOMUX_PAD(0x51C, 0x134, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_18__NANDF_CS2  IOMUX_PAD(0x520, 0x138, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_19__NANDF_CS3  IOMUX_PAD(0x524, 0x13C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_20__NANDF_CS4  IOMUX_PAD(0x528, 0x140, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_21__NANDF_CS5  IOMUX_PAD(0x52C, 0x144, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_22__NANDF_CS6  IOMUX_PAD(0x530, 0x148, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_23__NANDF_CS7  IOMUX_PAD(0x534, 0x14C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_24__NANDF_RDY_INT      IOMUX_PAD(0x538, 0x150, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_25__NANDF_D15  IOMUX_PAD(0x53C, 0x154, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_26__NANDF_D14  IOMUX_PAD(0x540, 0x158, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_27__NANDF_D13  IOMUX_PAD(0x544, 0x15C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_28__NANDF_D12  IOMUX_PAD(0x548, 0x160, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_29__NANDF_D11  IOMUX_PAD(0x54C, 0x164, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_30__NANDF_D10  IOMUX_PAD(0x550, 0x168, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_31__NANDF_D9   IOMUX_PAD(0x554, 0x16C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_0__NANDF_D8    IOMUX_PAD(0x558, 0x170, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_1__NANDF_D7    IOMUX_PAD(0x55C, 0x174, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_2__NANDF_D6    IOMUX_PAD(0x560, 0x178, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_3__NANDF_D5    IOMUX_PAD(0x564, 0x17C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_4__NANDF_D4    IOMUX_PAD(0x568, 0x180, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_5__NANDF_D3    IOMUX_PAD(0x56C, 0x184, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_6__NANDF_D2    IOMUX_PAD(0x570, 0x188, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_7__NANDF_D1    IOMUX_PAD(0x574, 0x18C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_8__NANDF_D0    IOMUX_PAD(0x578, 0x190, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_12__CSI1_D8    IOMUX_PAD(0x57C, 0x194, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_13__CSI1_D9    IOMUX_PAD(0x580, 0x198, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D10__CSI1_D10    IOMUX_PAD(0x584, 0x19C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D11__CSI1_D11    IOMUX_PAD(0x588, 0x1A0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D12__CSI1_D12    IOMUX_PAD(0x58C, 0x1A4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D13__CSI1_D13    IOMUX_PAD(0x590, 0x1A8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D14__CSI1_D14    IOMUX_PAD(0x594, 0x1AC, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D15__CSI1_D15    IOMUX_PAD(0x598, 0x1B0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D16__CSI1_D16    IOMUX_PAD(0x59C, 0x1B4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D17__CSI1_D17    IOMUX_PAD(0x5A0, 0x1B8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D18__CSI1_D18    IOMUX_PAD(0x5A4, 0x1BC, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_D19__CSI1_D19    IOMUX_PAD(0x5A8, 0x1C0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_VSYNC__CSI1_VSYNC        IOMUX_PAD(0x5AC, 0x1C4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_HSYNC__CSI1_HSYNC        IOMUX_PAD(0x5B0, 0x1C8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_PIXCLK__CSI1_PIXCLK      IOMUX_PAD(0x5B4, 0x0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_MCLK__CSI1_MCLK  IOMUX_PAD(0x5B8, 0x0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI1_PKE0__CSI1_PKE0  IOMUX_PAD(0x860, 0x0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_9__CSI2_D12    IOMUX_PAD(0x5BC, 0x1CC, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_10__CSI2_D13   IOMUX_PAD(0x5C0, 0x1D0, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_11__CSI2_D14   IOMUX_PAD(0x5C4, 0x1D4, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_12__CSI2_D15   IOMUX_PAD(0x5C8, 0x1D8, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_11__CSI2_D16   IOMUX_PAD(0x5CC, 0x1DC, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_12__CSI2_D17   IOMUX_PAD(0x5D0, 0x1E0, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_11__CSI2_D18   IOMUX_PAD(0x5D4, 0x1E4, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_12__CSI2_D19   IOMUX_PAD(0x5D8, 0x1E8, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_13__CSI2_VSYNC IOMUX_PAD(0x5DC, 0x1EC, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_14__CSI2_HSYNC IOMUX_PAD(0x5E0, 0x1F0, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_15__CSI2_PIXCLK        IOMUX_PAD(0x5E4, 0x1F4, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_CSI2_PKE0__CSI2_PKE0  IOMUX_PAD(0x81C, 0x0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_16__I2C1_CLK   IOMUX_PAD(0x5E8, 0x1F8, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_17__I2C1_DAT   IOMUX_PAD(0x5EC, 0x1FC, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_18__AUD3_BB_TXD        IOMUX_PAD(0x5F0, 0x200, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_19__AUD3_BB_RXD        IOMUX_PAD(0x5F4, 0x204, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_20__AUD3_BB_CK IOMUX_PAD(0x5F8, 0x208, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_21__AUD3_BB_FS IOMUX_PAD(0x5FC, 0x20C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_22__CSPI1_MOSI IOMUX_PAD(0x600, 0x210, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_23__CSPI1_MISO IOMUX_PAD(0x604, 0x214, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_24__CSPI1_SS0  IOMUX_PAD(0x608, 0x218, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_25__CSPI1_SS1  IOMUX_PAD(0x60C, 0x21C, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_26__CSPI1_RDY  IOMUX_PAD(0x610, 0x220, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_4_27__CSPI1_SCLK IOMUX_PAD(0x614, 0x224, 3, 0x0, 0, NO_PAD_CTRL)
-
-/* Babbage UART1 */
-#define MX51_PAD_UART1_RXD__UART1_RXD  IOMUX_PAD(0x618, 0x228, IOMUX_CONFIG_ALT0, 0x9e4, 0, MX51_UART1_PAD_CTRL | PAD_CTL_SRE_FAST)
-#define MX51_PAD_UART1_TXD__UART1_TXD  IOMUX_PAD(0x61C, 0x22C, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_UART1_PAD_CTRL | PAD_CTL_SRE_FAST)
-#define MX51_PAD_UART1_RTS__UART1_RTS  IOMUX_PAD(0x620, 0x230, IOMUX_CONFIG_ALT0, 0x9e0, 0, MX51_UART1_PAD_CTRL)
-#define MX51_PAD_UART1_CTS__UART1_CTS  IOMUX_PAD(0x624, 0x234, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_UART1_PAD_CTRL)
-
-/* Babbage UART2 */
-#define MX51_PAD_UART2_RXD__UART2_RXD  IOMUX_PAD(0x628, 0x238, IOMUX_CONFIG_ALT0, 0x9ec, 2, MX51_UART2_PAD_CTRL)
-#define MX51_PAD_UART2_TXD__UART2_TXD  IOMUX_PAD(0x62C, 0x23C, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_UART2_PAD_CTRL)
-
-#define MX51_PAD_GPIO_1_22__UART3_RXD  IOMUX_PAD(0x630, 0x240, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_23__UART3_TXD  IOMUX_PAD(0x634, 0x244, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_24__OWIRE_LINE IOMUX_PAD(0x638, 0x248, 3, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_ROW0__KEY_ROW0    IOMUX_PAD(0x63C, 0x24C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_ROW1__KEY_ROW1    IOMUX_PAD(0x640, 0x250, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_ROW2__KEY_ROW2    IOMUX_PAD(0x644, 0x254, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_ROW3__KEY_ROW3    IOMUX_PAD(0x648, 0x258, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_COL0__KEY_COL0    IOMUX_PAD(0x64C, 0x25C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_COL1__KEY_COL1    IOMUX_PAD(0x650, 0x260, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_COL2__KEY_COL2    IOMUX_PAD(0x654, 0x264, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_COL3__KEY_COL3    IOMUX_PAD(0x658, 0x268, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_COL4__KEY_COL4    IOMUX_PAD(0x65C, 0x26C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_KEY_COL5__KEY_COL5    IOMUX_PAD(0x660, 0x270, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_USBH1_CLK__USBH1_CLK  IOMUX_PAD(0x678, 0x278, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_DIR__USBH1_DIR  IOMUX_PAD(0x67C, 0x27C, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_STP__USBH1_STP  IOMUX_PAD(0x680, 0x280, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_STP__GPIO_1_27  IOMUX_PAD(0x680, 0x280, IOMUX_CONFIG_GPIO, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_NXT__USBH1_NXT  IOMUX_PAD(0x684, 0x284, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_DATA0__USBH1_DATA0      IOMUX_PAD(0x688, 0x288, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_DATA1__USBH1_DATA1      IOMUX_PAD(0x68C, 0x28C, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_DATA2__USBH1_DATA2      IOMUX_PAD(0x690, 0x290, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_DATA3__USBH1_DATA3      IOMUX_PAD(0x694, 0x294, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_DATA4__USBH1_DATA4      IOMUX_PAD(0x698, 0x298, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_DATA5__USBH1_DATA5      IOMUX_PAD(0x69C, 0x29C, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_DATA6__USBH1_DATA6      IOMUX_PAD(0x6A0, 0x2A0, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_USBH1_DATA7__USBH1_DATA7      IOMUX_PAD(0x6A4, 0x2A4, IOMUX_CONFIG_ALT0, 0x0, 0, MX51_USBH1_PAD_CTRL)
-#define MX51_PAD_GPIO_3_0__DI1_PIN11   IOMUX_PAD(0x6A8, 0x2A8, 4, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_1__DI1_PIN12   IOMUX_PAD(0x6AC, 0x2AC, 4, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_2__DI1_PIN13   IOMUX_PAD(0x6B0, 0x2B0, 4, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_3__DI1_D0_CS   IOMUX_PAD(0x6B4, 0x2B4, 4, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_4__DI1_D1_CS   IOMUX_PAD(0x6B8, 0x2B8, 4, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_5__DISPB2_SER_DIN      IOMUX_PAD(0x6BC, 0x2BC, 4, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_6__DISPB2_SER_DIO      IOMUX_PAD(0x6C0, 0x2C0, 4, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_7__DISPB2_SER_CLK      IOMUX_PAD(0x6C4, 0x2C4, 4, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_3_8__DISPB2_SER_RS       IOMUX_PAD(0x6C8, 0x2C8, 4, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT0__DISP1_DAT0        IOMUX_PAD(0x6CC, 0x2CC, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT1__DISP1_DAT1        IOMUX_PAD(0x6D0, 0x2D0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT2__DISP1_DAT2        IOMUX_PAD(0x6D4, 0x2D4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT3__DISP1_DAT3        IOMUX_PAD(0x6D8, 0x2D8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT4__DISP1_DAT4        IOMUX_PAD(0x6DC, 0x2DC, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT5__DISP1_DAT5        IOMUX_PAD(0x6E0, 0x2E0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT6__DISP1_DAT6        IOMUX_PAD(0x6E4, 0x2E4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT7__DISP1_DAT7        IOMUX_PAD(0x6E8, 0x2E8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT8__DISP1_DAT8        IOMUX_PAD(0x6EC, 0x2EC, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT9__DISP1_DAT9        IOMUX_PAD(0x6F0, 0x2F0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT10__DISP1_DAT10      IOMUX_PAD(0x6F4, 0x2F4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT11__DISP1_DAT11      IOMUX_PAD(0x6F8, 0x2F8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT12__DISP1_DAT12      IOMUX_PAD(0x6FC, 0x2FC, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT13__DISP1_DAT13      IOMUX_PAD(0x700, 0x300, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT14__DISP1_DAT14      IOMUX_PAD(0x704, 0x304, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT15__DISP1_DAT15      IOMUX_PAD(0x708, 0x308, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT16__DISP1_DAT16      IOMUX_PAD(0x70C, 0x30C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT17__DISP1_DAT17      IOMUX_PAD(0x710, 0x310, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT18__DISP1_DAT18      IOMUX_PAD(0x714, 0x314, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT19__DISP1_DAT19      IOMUX_PAD(0x718, 0x318, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT20__DISP1_DAT20      IOMUX_PAD(0x71C, 0x31C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT21__DISP1_DAT21      IOMUX_PAD(0x720, 0x320, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT22__DISP1_DAT22      IOMUX_PAD(0x724, 0x324, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP1_DAT23__DISP1_DAT23      IOMUX_PAD(0x728, 0x328, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI1_PIN3__DI1_PIN3    IOMUX_PAD(0x72C, 0x32C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI1_PIN2__DI1_PIN2    IOMUX_PAD(0x734, 0x330, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI_GP1__DI_GP1        IOMUX_PAD(0x73C, 0x334, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI_GP2__DI_GP2        IOMUX_PAD(0x740, 0x338, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI_GP3__DI_GP3        IOMUX_PAD(0x744, 0x33C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI2_PIN4__DI2_PIN4    IOMUX_PAD(0x748, 0x340, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI2_PIN2__DI2_PIN2    IOMUX_PAD(0x74C, 0x344, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI2_PIN3__DI2_PIN3    IOMUX_PAD(0x750, 0x348, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI2_DISP_CLK__DI2_DISP_CLK    IOMUX_PAD(0x754, 0x34C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DI_GP4__DI_GP4        IOMUX_PAD(0x758, 0x350, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT0__DISP2_DAT0        IOMUX_PAD(0x75C, 0x354, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT1__DISP2_DAT1        IOMUX_PAD(0x760, 0x358, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT2__DISP2_DAT2        IOMUX_PAD(0x764, 0x35C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT3__DISP2_DAT3        IOMUX_PAD(0x768, 0x360, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT4__DISP2_DAT4        IOMUX_PAD(0x76C, 0x364, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT5__DISP2_DAT5        IOMUX_PAD(0x770, 0x368, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_19__DISP2_DAT6 IOMUX_PAD(0x774, 0x36C, 5, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_29__DISP2_DAT7 IOMUX_PAD(0x778, 0x370, 5, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_30__DISP2_DAT8 IOMUX_PAD(0x77C, 0x374, 5, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_31__DISP2_DAT9 IOMUX_PAD(0x780, 0x378, 5, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT10__DISP2_DAT10      IOMUX_PAD(0x784, 0x37C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT11__DISP2_DAT11      IOMUX_PAD(0x788, 0x380, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT12__DISP2_DAT12      IOMUX_PAD(0x78C, 0x384, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT13__DISP2_DAT13      IOMUX_PAD(0x790, 0x388, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT14__DISP2_DAT14      IOMUX_PAD(0x794, 0x38C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_DISP2_DAT15__DISP2_DAT15      IOMUX_PAD(0x798, 0x390, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD1_CMD__SD1_CMD      IOMUX_PAD(0x79C, 0x394, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD1_CLK__SD1_CLK      IOMUX_PAD(0x7A0, 0x398, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD1_DATA0__SD1_DATA0  IOMUX_PAD(0x7A4, 0x39C, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD1_DATA1__SD1_DATA1  IOMUX_PAD(0x7A8, 0x3A0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD1_DATA2__SD1_DATA2  IOMUX_PAD(0x7AC, 0x3A4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD1_DATA3__SD1_DATA3  IOMUX_PAD(0x7B0, 0x3A8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_0__GPIO1_0     IOMUX_PAD(0x7B4, 0x3AC, 1, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_1__GPIO1_1     IOMUX_PAD(0x7B8, 0x3B0, 1, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD2_CMD__SD2_CMD      IOMUX_PAD(0x7BC, 0x3B4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD2_CLK__SD2_CLK      IOMUX_PAD(0x7C0, 0x3B8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD2_DATA0__SD2_DATA0  IOMUX_PAD(0x7C4, 0x3BC, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD2_DATA1__SD2_DATA1  IOMUX_PAD(0x7C8, 0x3C0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD2_DATA2__SD2_DATA2  IOMUX_PAD(0x7CC, 0x3C4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_SD2_DATA3__SD2_DATA3  IOMUX_PAD(0x7D0, 0x3C8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_2__GPIO1_2     IOMUX_PAD(0x7D4, 0x3CC, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_3__GPIO1_3     IOMUX_PAD(0x7D8, 0x3D0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_PMIC_INT_REQ__PMIC_INT_REQ    IOMUX_PAD(0x7FC, 0x3D4, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_4__GPIO1_4     IOMUX_PAD(0x804, 0x3D8, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_5__GPIO1_5     IOMUX_PAD(0x808, 0x3DC, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_6__GPIO1_6     IOMUX_PAD(0x80C, 0x3E0, 0, 0x0, 0, NO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_7__GPIO1_7     IOMUX_PAD(0x810, 0x3E4, 0, 0x0, 0, MX51_GPIO_PAD_CTRL)
-#define MX51_PAD_GPIO_1_8__GPIO1_8     IOMUX_PAD(0x814, 0x3E8, 0, 0x0, 1, \
-                                               (PAD_CTL_SRE_SLOW | PAD_CTL_DSE_MED | PAD_CTL_PUS_100K_UP |  PAD_CTL_HYS))
-#define MX51_PAD_GPIO_1_9__GPIO1_9     IOMUX_PAD(0x818, 0x3EC, 0, 0x0, 0, NO_PAD_CTRL)
-
-/* EIM */
-#define MX51_PAD_EIM_DA0__EIM_DA0      IOMUX_PAD(0x7a8, 0x01c, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA1__EIM_DA1      IOMUX_PAD(0x7a8, 0x020, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA2__EIM_DA2      IOMUX_PAD(0x7a8, 0x024, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA3__EIM_DA3      IOMUX_PAD(0x7a8, 0x028, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA4__EIM_DA4      IOMUX_PAD(0x7ac, 0x02c, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA5__EIM_DA5      IOMUX_PAD(0x7ac, 0x030, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA6__EIM_DA6      IOMUX_PAD(0x7ac, 0x034, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA7__EIM_DA7      IOMUX_PAD(0x7ac, 0x038, 0, 0x0,   0, NO_PAD_CTRL)
-
-#define MX51_PAD_EIM_DA8__EIM_DA8      IOMUX_PAD(0x7b0, 0x03c, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA9__EIM_DA9      IOMUX_PAD(0x7b0, 0x040, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA10__EIM_DA10    IOMUX_PAD(0x7b0, 0x044, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA11__EIM_DA11    IOMUX_PAD(0x7b0, 0x048, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA12__EIM_DA12    IOMUX_PAD(0x7bc, 0x04c, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA13__EIM_DA13    IOMUX_PAD(0x7bc, 0x050, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA14__EIM_DA14    IOMUX_PAD(0x7bc, 0x054, 0, 0x0,   0, NO_PAD_CTRL)
-#define MX51_PAD_EIM_DA15__EIM_DA15    IOMUX_PAD(0x7bc, 0x058, 0, 0x0,   0, NO_PAD_CTRL)
+/*                                                       PAD    MUX   ALT INPSE PATH PADCTRL */
+#define MX51_PAD_EIM_DA0__EIM_DA0              IOMUX_PAD(0x7a8, 0x01c, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA1__EIM_DA1              IOMUX_PAD(0x7a8, 0x020, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA2__EIM_DA2              IOMUX_PAD(0x7a8, 0x024, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA3__EIM_DA3              IOMUX_PAD(0x7a8, 0x028, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA4__EIM_DA4              IOMUX_PAD(0x7ac, 0x02c, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA5__EIM_DA5              IOMUX_PAD(0x7ac, 0x030, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA6__EIM_DA6              IOMUX_PAD(0x7ac, 0x034, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA7__EIM_DA7              IOMUX_PAD(0x7ac, 0x038, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA8__EIM_DA8              IOMUX_PAD(0x7b0, 0x03c, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA9__EIM_DA9              IOMUX_PAD(0x7b0, 0x040, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA10__EIM_DA10            IOMUX_PAD(0x7b0, 0x044, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA11__EIM_DA11            IOMUX_PAD(0x7b0, 0x048, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA12__EIM_DA12            IOMUX_PAD(0x7bc, 0x04c, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA13__EIM_DA13            IOMUX_PAD(0x7bc, 0x050, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA14__EIM_DA14            IOMUX_PAD(0x7bc, 0x054, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DA15__EIM_DA15            IOMUX_PAD(0x7bc, 0x058, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D16__GPIO_2_0              IOMUX_PAD(0x3f0, 0x05c, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D16__I2C1_SDA             IOMUX_PAD(0x3f0, 0x05c, (4 | IOMUX_CONFIG_SION), \
+                                                       0x09b4, 0, MX51_I2C_PAD_CTRL)
+#define MX51_PAD_EIM_D17__GPIO_2_1              IOMUX_PAD(0x3f4, 0x060, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D18__GPIO_2_2              IOMUX_PAD(0x3f8, 0x064, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D19__GPIO_2_3              IOMUX_PAD(0x3fc, 0x068, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D19__I2C1_SCL             IOMUX_PAD(0x3fc, 0x068, (4 | IOMUX_CONFIG_SION), \
+                                                       0x09b0, 0, MX51_I2C_PAD_CTRL)
+#define MX51_PAD_EIM_D20__GPIO_2_4              IOMUX_PAD(0x400, 0x06c, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D21__GPIO_2_5             IOMUX_PAD(0x404, 0x070, 1, 0x0,   0, MX51_GPIO_PAD_CTRL)
+#define MX51_PAD_EIM_D22__GPIO_2_6              IOMUX_PAD(0x408, 0x074, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D23__GPIO_2_7              IOMUX_PAD(0x40c, 0x078, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D24__UART3_CTS             IOMUX_PAD(0x410, 0x07c, 3, 0x0,   0, MX51_UART3_PAD_CTRL)
+#define MX51_PAD_EIM_D25__UART3_RXD             IOMUX_PAD(0x414, 0x080, 3, 0x9f4, 0, MX51_UART3_PAD_CTRL)
+#define MX51_PAD_EIM_D25__UART2_CTS            IOMUX_PAD(0x414, 0x080, 4, 0x0,   0, MX51_UART2_PAD_CTRL)
+#define MX51_PAD_EIM_D26__UART3_TXD             IOMUX_PAD(0x418, 0x084, 3, 0x0,   0, MX51_UART3_PAD_CTRL)
+#define MX51_PAD_EIM_D26__UART2_RTS            IOMUX_PAD(0x418, 0x084, 4, 0x9e8, 3, MX51_UART2_PAD_CTRL)
+#define MX51_PAD_EIM_D27__UART3_RTS             IOMUX_PAD(0x41c, 0x088, 3, 0x9f0, 3, MX51_UART3_PAD_CTRL)
+#define MX51_PAD_EIM_D28__EIM_D28               IOMUX_PAD(0x420, 0x08c, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D29__EIM_D29               IOMUX_PAD(0x424, 0x090, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D30__EIM_D30               IOMUX_PAD(0x428, 0x094, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_D31__EIM_D31               IOMUX_PAD(0x42c, 0x09c, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A16__GPIO_2_10             IOMUX_PAD(0x430, 0x09c, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A17__GPIO_2_11             IOMUX_PAD(0x434, 0x0a0, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A18__GPIO_2_12             IOMUX_PAD(0x438, 0x0a4, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A19__GPIO_2_13             IOMUX_PAD(0x43c, 0x0a8, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A20__GPIO_2_14             IOMUX_PAD(0x440, 0x0ac, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A21__GPIO_2_15             IOMUX_PAD(0x444, 0x0b0, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A22__GPIO_2_16             IOMUX_PAD(0x448, 0x0b4, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A23__GPIO_2_17             IOMUX_PAD(0x44c, 0x0b8, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A24__GPIO_2_18             IOMUX_PAD(0x450, 0x0bc, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A25__GPIO_2_19             IOMUX_PAD(0x454, 0x0c0, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A26__GPIO_2_20             IOMUX_PAD(0x458, 0x0c4, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_A27__GPIO_2_21             IOMUX_PAD(0x45c, 0x0c8, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_EB0__EIM_EB0               IOMUX_PAD(0x460, 0x0cc, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_EB1__EIM_EB1               IOMUX_PAD(0x464, 0x0d0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_EB2__GPIO_2_22             IOMUX_PAD(0x468, 0x0d4, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_EB3__GPIO_2_23             IOMUX_PAD(0x46c, 0x0d8, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_OE__GPIO_2_24              IOMUX_PAD(0x470, 0x0dc, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_CS0__GPIO_2_25             IOMUX_PAD(0x474, 0x0e0, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_CS1__GPIO_2_26             IOMUX_PAD(0x478, 0x0e4, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_CS2__GPIO_2_27             IOMUX_PAD(0x47c, 0x0e8, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_CS3__GPIO_2_28             IOMUX_PAD(0x480, 0x0ec, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_CS4__GPIO_2_29             IOMUX_PAD(0x484, 0x0f0, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_CS5__GPIO_2_30             IOMUX_PAD(0x488, 0x0f4, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_DTACK__GPIO_2_31           IOMUX_PAD(0x48c, 0x0f8, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_LBA__GPIO_3_1              IOMUX_PAD(0x494, 0x0FC, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_EIM_CRE__GPIO_3_2              IOMUX_PAD(0x4A0, 0x100, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DRAM_CS1__DRAM_CS1             IOMUX_PAD(0x4D0, 0x104, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_WE_B__GPIO_3_3           IOMUX_PAD(0x4E4, 0x108, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_RE_B__GPIO_3_4           IOMUX_PAD(0x4E8, 0x10C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_ALE__GPIO_3_5            IOMUX_PAD(0x4EC, 0x110, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_CLE__GPIO_3_6            IOMUX_PAD(0x4F0, 0x114, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_WP_B__GPIO_3_7           IOMUX_PAD(0x4F4, 0x118, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_RB0__GPIO_3_8            IOMUX_PAD(0x4F8, 0x11C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_RB1__GPIO_3_9            IOMUX_PAD(0x4FC, 0x120, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_RB2__GPIO_3_10           IOMUX_PAD(0x500, 0x124, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_RB3__GPIO_3_11           IOMUX_PAD(0x504, 0x128, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_GPIO_NAND__GPIO_3_12           IOMUX_PAD(0x514, 0x12C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_CS0__GPIO_3_16           IOMUX_PAD(0x518, 0x130, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_CS1__GPIO_3_17           IOMUX_PAD(0x51C, 0x134, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_CS2__GPIO_3_18           IOMUX_PAD(0x520, 0x138, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_CS3__GPIO_3_19           IOMUX_PAD(0x524, 0x13C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_CS4__GPIO_3_20           IOMUX_PAD(0x528, 0x140, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_CS5__GPIO_3_21           IOMUX_PAD(0x52C, 0x144, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_CS6__GPIO_3_22           IOMUX_PAD(0x530, 0x148, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_CS7__GPIO_3_23           IOMUX_PAD(0x534, 0x14C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_RDY_INT__GPIO_3_24       IOMUX_PAD(0x538, 0x150, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D15__GPIO_3_25           IOMUX_PAD(0x53C, 0x154, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D14__GPIO_3_26           IOMUX_PAD(0x540, 0x158, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D13__GPIO_3_27           IOMUX_PAD(0x544, 0x15C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D12__GPIO_3_28           IOMUX_PAD(0x548, 0x160, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D11__GPIO_3_29           IOMUX_PAD(0x54C, 0x164, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D10__GPIO_3_30           IOMUX_PAD(0x550, 0x168, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D9__GPIO_3_31            IOMUX_PAD(0x554, 0x16C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D8__GPIO_4_0             IOMUX_PAD(0x558, 0x170, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D7__GPIO_4_1             IOMUX_PAD(0x55C, 0x174, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D6__GPIO_4_2             IOMUX_PAD(0x560, 0x178, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D5__GPIO_4_3             IOMUX_PAD(0x564, 0x17C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D4__GPIO_4_4             IOMUX_PAD(0x568, 0x180, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D3__GPIO_4_5             IOMUX_PAD(0x56C, 0x184, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D2__GPIO_4_6             IOMUX_PAD(0x570, 0x188, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D1__GPIO_4_7             IOMUX_PAD(0x574, 0x18C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_NANDF_D0__GPIO_4_8             IOMUX_PAD(0x578, 0x190, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D8__GPIO_3_12             IOMUX_PAD(0x57C, 0x194, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D9__GPIO_3_13             IOMUX_PAD(0x580, 0x198, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D10__CSI1_D10             IOMUX_PAD(0x584, 0x19C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D11__CSI1_D11             IOMUX_PAD(0x588, 0x1A0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D12__CSI1_D12             IOMUX_PAD(0x58C, 0x1A4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D13__CSI1_D13             IOMUX_PAD(0x590, 0x1A8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D14__CSI1_D14             IOMUX_PAD(0x594, 0x1AC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D15__CSI1_D15             IOMUX_PAD(0x598, 0x1B0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D16__CSI1_D16             IOMUX_PAD(0x59C, 0x1B4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D17__CSI1_D17             IOMUX_PAD(0x5A0, 0x1B8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D18__CSI1_D18             IOMUX_PAD(0x5A4, 0x1BC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_D19__CSI1_D19             IOMUX_PAD(0x5A8, 0x1C0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_VSYNC__CSI1_VSYNC         IOMUX_PAD(0x5AC, 0x1C4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_HSYNC__CSI1_HSYNC         IOMUX_PAD(0x5B0, 0x1C8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_PIXCLK__CSI1_PIXCLK       IOMUX_PAD(0x5B4, 0x000, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_MCLK__CSI1_MCLK           IOMUX_PAD(0x5B8, 0x000, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI1_PKE0__CSI1_PKE0           IOMUX_PAD(0x860, 0x000, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_D12__GPIO_4_9             IOMUX_PAD(0x5BC, 0x1CC, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_D13__GPIO_4_10            IOMUX_PAD(0x5C0, 0x1D0, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_D14__GPIO_4_11            IOMUX_PAD(0x5C4, 0x1D4, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_D15__GPIO_4_12            IOMUX_PAD(0x5C8, 0x1D8, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_D16__GPIO_4_11            IOMUX_PAD(0x5CC, 0x1DC, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_D17__GPIO_4_12            IOMUX_PAD(0x5D0, 0x1E0, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_D18__GPIO_4_11            IOMUX_PAD(0x5D4, 0x1E4, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_D19__GPIO_4_12            IOMUX_PAD(0x5D8, 0x1E8, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_VSYNC__GPIO_4_13          IOMUX_PAD(0x5DC, 0x1EC, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_HSYNC__GPIO_4_14          IOMUX_PAD(0x5E0, 0x1F0, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSI2_PIXCLK__GPIO_4_15         IOMUX_PAD(0x5E4, 0x1F4, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_I2C1_CLK__GPIO_4_16            IOMUX_PAD(0x5E8, 0x1F8, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_I2C1_CLK__HSI2C_CLK           IOMUX_PAD(0x5E8, 0x1F8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_I2C1_DAT__GPIO_4_17            IOMUX_PAD(0x5EC, 0x1FC, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_I2C1_DAT__HSI2C_DAT           IOMUX_PAD(0x5EC, 0x1FC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_AUD3_BB_TXD__GPIO_4_18         IOMUX_PAD(0x5F0, 0x200, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_AUD3_BB_RXD__GPIO_4_19         IOMUX_PAD(0x5F4, 0x204, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_AUD3_BB_CK__GPIO_4_20          IOMUX_PAD(0x5F8, 0x208, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_AUD3_BB_FS__GPIO_4_21          IOMUX_PAD(0x5FC, 0x20C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSPI1_MOSI__GPIO_4_22          IOMUX_PAD(0x600, 0x210, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSPI1_MISO__GPIO_4_23          IOMUX_PAD(0x604, 0x214, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSPI1_SS0__GPIO_4_24           IOMUX_PAD(0x608, 0x218, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSPI1_SS1__GPIO_4_25           IOMUX_PAD(0x60C, 0x21C, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSPI1_RDY__GPIO_4_26           IOMUX_PAD(0x610, 0x220, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_CSPI1_SCLK__GPIO_4_27          IOMUX_PAD(0x614, 0x224, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_UART1_RXD__UART1_RXD           IOMUX_PAD(0x618, 0x228, 0, 0x9e4, 0, MX51_UART1_PAD_CTRL | PAD_CTL_SRE_FAST)
+#define MX51_PAD_UART1_TXD__UART1_TXD           IOMUX_PAD(0x61C, 0x22C, 0, 0x0,   0, MX51_UART1_PAD_CTRL | PAD_CTL_SRE_FAST)
+#define MX51_PAD_UART1_RTS__UART1_RTS           IOMUX_PAD(0x620, 0x230, 0, 0x9e0, 0, MX51_UART1_PAD_CTRL)
+#define MX51_PAD_UART1_CTS__UART1_CTS           IOMUX_PAD(0x624, 0x234, 0, 0x0,   0, MX51_UART1_PAD_CTRL)
+#define MX51_PAD_UART2_RXD__UART2_RXD           IOMUX_PAD(0x628, 0x238, 0, 0x9ec, 2, MX51_UART2_PAD_CTRL)
+#define MX51_PAD_UART2_TXD__UART2_TXD           IOMUX_PAD(0x62C, 0x23C, 0, 0x0,   0, MX51_UART2_PAD_CTRL)
+#define MX51_PAD_UART3_RXD__UART3_RXD          IOMUX_PAD(0x630, 0x240, 1, 0x9f4, 4, MX51_UART3_PAD_CTRL)
+#define MX51_PAD_UART3_RXD__GPIO_1_22           IOMUX_PAD(0x630, 0x240, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_UART3_TXD__UART3_TXD          IOMUX_PAD(0x634, 0x244, 1, 0x0,   0, MX51_UART3_PAD_CTRL)
+#define MX51_PAD_UART3_TXD__GPIO_1_23           IOMUX_PAD(0x634, 0x244, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_OWIRE_LINE__GPIO_1_24          IOMUX_PAD(0x638, 0x248, 3, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_ROW0__KEY_ROW0             IOMUX_PAD(0x63C, 0x24C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_ROW1__KEY_ROW1             IOMUX_PAD(0x640, 0x250, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_ROW2__KEY_ROW2             IOMUX_PAD(0x644, 0x254, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_ROW3__KEY_ROW3             IOMUX_PAD(0x648, 0x258, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_COL0__KEY_COL0             IOMUX_PAD(0x64C, 0x25C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_COL1__KEY_COL1             IOMUX_PAD(0x650, 0x260, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_COL2__KEY_COL2             IOMUX_PAD(0x654, 0x264, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_COL3__KEY_COL3             IOMUX_PAD(0x658, 0x268, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_COL4__KEY_COL4             IOMUX_PAD(0x65C, 0x26C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_COL4__UART3_RTS           IOMUX_PAD(0x65C, 0x26C, 2, 0x9f0, 4, MX51_UART3_PAD_CTRL)
+#define MX51_PAD_KEY_COL4__I2C2_SCL            IOMUX_PAD(0x65C, 0x26C, (3 | IOMUX_CONFIG_SION), \
+                                                       0x09b8, 1, MX51_I2C_PAD_CTRL)
+#define MX51_PAD_KEY_COL5__KEY_COL5             IOMUX_PAD(0x660, 0x270, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_KEY_COL5__UART3_CTS           IOMUX_PAD(0x660, 0x270, 2, 0,     0, MX51_UART3_PAD_CTRL)
+#define MX51_PAD_KEY_COL5__I2C2_SDA            IOMUX_PAD(0x660, 0x270, (3 | IOMUX_CONFIG_SION), \
+                                                       0x09bc, 1, MX51_I2C_PAD_CTRL)
+#define MX51_PAD_USBH1_CLK__USBH1_CLK           IOMUX_PAD(0x678, 0x278, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_DIR__USBH1_DIR           IOMUX_PAD(0x67C, 0x27C, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_STP__USBH1_STP           IOMUX_PAD(0x680, 0x280, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_STP__GPIO_1_27           IOMUX_PAD(0x680, 0x280, 2, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_NXT__USBH1_NXT           IOMUX_PAD(0x684, 0x284, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_DATA0__USBH1_DATA0       IOMUX_PAD(0x688, 0x288, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_DATA1__USBH1_DATA1       IOMUX_PAD(0x68C, 0x28C, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_DATA2__USBH1_DATA2       IOMUX_PAD(0x690, 0x290, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_DATA3__USBH1_DATA3       IOMUX_PAD(0x694, 0x294, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_DATA4__USBH1_DATA4       IOMUX_PAD(0x698, 0x298, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_DATA5__USBH1_DATA5       IOMUX_PAD(0x69C, 0x29C, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_DATA6__USBH1_DATA6       IOMUX_PAD(0x6A0, 0x2A0, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_USBH1_DATA7__USBH1_DATA7       IOMUX_PAD(0x6A4, 0x2A4, 0, 0x0,   0, MX51_USBH1_PAD_CTRL)
+#define MX51_PAD_DI1_PIN11__GPIO_3_0            IOMUX_PAD(0x6A8, 0x2A8, 4, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI1_PIN12__GPIO_3_1            IOMUX_PAD(0x6AC, 0x2AC, 4, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI1_PIN13__GPIO_3_2            IOMUX_PAD(0x6B0, 0x2B0, 4, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI1_D0_CS__GPIO_3_3            IOMUX_PAD(0x6B4, 0x2B4, 4, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI1_D1_CS__GPIO_3_4            IOMUX_PAD(0x6B8, 0x2B8, 4, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISPB2_SER_DIN__GPIO_3_5       IOMUX_PAD(0x6BC, 0x2BC, 4, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISPB2_SER_DIO__GPIO_3_6       IOMUX_PAD(0x6C0, 0x2C0, 4, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISPB2_SER_CLK__GPIO_3_7       IOMUX_PAD(0x6C4, 0x2C4, 4, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISPB2_SER_RS__GPIO_3_8        IOMUX_PAD(0x6C8, 0x2C8, 4, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT0__DISP1_DAT0         IOMUX_PAD(0x6CC, 0x2CC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT1__DISP1_DAT1         IOMUX_PAD(0x6D0, 0x2D0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT2__DISP1_DAT2         IOMUX_PAD(0x6D4, 0x2D4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT3__DISP1_DAT3         IOMUX_PAD(0x6D8, 0x2D8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT4__DISP1_DAT4         IOMUX_PAD(0x6DC, 0x2DC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT5__DISP1_DAT5         IOMUX_PAD(0x6E0, 0x2E0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT6__DISP1_DAT6         IOMUX_PAD(0x6E4, 0x2E4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT7__DISP1_DAT7         IOMUX_PAD(0x6E8, 0x2E8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT8__DISP1_DAT8         IOMUX_PAD(0x6EC, 0x2EC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT9__DISP1_DAT9         IOMUX_PAD(0x6F0, 0x2F0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT10__DISP1_DAT10       IOMUX_PAD(0x6F4, 0x2F4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT11__DISP1_DAT11       IOMUX_PAD(0x6F8, 0x2F8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT12__DISP1_DAT12       IOMUX_PAD(0x6FC, 0x2FC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT13__DISP1_DAT13       IOMUX_PAD(0x700, 0x300, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT14__DISP1_DAT14       IOMUX_PAD(0x704, 0x304, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT15__DISP1_DAT15       IOMUX_PAD(0x708, 0x308, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT16__DISP1_DAT16       IOMUX_PAD(0x70C, 0x30C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT17__DISP1_DAT17       IOMUX_PAD(0x710, 0x310, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT18__DISP1_DAT18       IOMUX_PAD(0x714, 0x314, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT19__DISP1_DAT19       IOMUX_PAD(0x718, 0x318, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT20__DISP1_DAT20       IOMUX_PAD(0x71C, 0x31C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT21__DISP1_DAT21       IOMUX_PAD(0x720, 0x320, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT22__DISP1_DAT22       IOMUX_PAD(0x724, 0x324, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP1_DAT23__DISP1_DAT23       IOMUX_PAD(0x728, 0x328, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI1_PIN3__DI1_PIN3             IOMUX_PAD(0x72C, 0x32C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI1_PIN2__DI1_PIN2             IOMUX_PAD(0x734, 0x330, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI_GP1__DI_GP1                 IOMUX_PAD(0x73C, 0x334, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI_GP2__DI_GP2                 IOMUX_PAD(0x740, 0x338, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI_GP3__DI_GP3                 IOMUX_PAD(0x744, 0x33C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI2_PIN4__DI2_PIN4             IOMUX_PAD(0x748, 0x340, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI2_PIN2__DI2_PIN2             IOMUX_PAD(0x74C, 0x344, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI2_PIN3__DI2_PIN3             IOMUX_PAD(0x750, 0x348, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI2_DISP_CLK__DI2_DISP_CLK     IOMUX_PAD(0x754, 0x34C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DI_GP4__DI_GP4                 IOMUX_PAD(0x758, 0x350, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT0__DISP2_DAT0         IOMUX_PAD(0x75C, 0x354, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT1__DISP2_DAT1         IOMUX_PAD(0x760, 0x358, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT2__DISP2_DAT2         IOMUX_PAD(0x764, 0x35C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT3__DISP2_DAT3         IOMUX_PAD(0x768, 0x360, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT4__DISP2_DAT4         IOMUX_PAD(0x76C, 0x364, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT5__DISP2_DAT5         IOMUX_PAD(0x770, 0x368, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT6__GPIO_1_19          IOMUX_PAD(0x774, 0x36C, 5, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT7__GPIO_1_29          IOMUX_PAD(0x778, 0x370, 5, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT8__GPIO_1_30          IOMUX_PAD(0x77C, 0x374, 5, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT9__GPIO_1_31          IOMUX_PAD(0x780, 0x378, 5, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT10__DISP2_DAT10       IOMUX_PAD(0x784, 0x37C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT11__DISP2_DAT11       IOMUX_PAD(0x788, 0x380, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT12__DISP2_DAT12       IOMUX_PAD(0x78C, 0x384, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT13__DISP2_DAT13       IOMUX_PAD(0x790, 0x388, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT14__DISP2_DAT14       IOMUX_PAD(0x794, 0x38C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_DISP2_DAT15__DISP2_DAT15       IOMUX_PAD(0x798, 0x390, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD1_CMD__SD1_CMD               IOMUX_PAD(0x79C, 0x394, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD1_CLK__SD1_CLK               IOMUX_PAD(0x7A0, 0x398, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD1_DATA0__SD1_DATA0           IOMUX_PAD(0x7A4, 0x39C, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD1_DATA1__SD1_DATA1           IOMUX_PAD(0x7A8, 0x3A0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD1_DATA2__SD1_DATA2           IOMUX_PAD(0x7AC, 0x3A4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD1_DATA3__SD1_DATA3           IOMUX_PAD(0x7B0, 0x3A8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_0__GPIO_1_0            IOMUX_PAD(0x7B4, 0x3AC, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_1__GPIO_1_1            IOMUX_PAD(0x7B8, 0x3B0, 1, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD2_CMD__SD2_CMD               IOMUX_PAD(0x7BC, 0x3B4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD2_CLK__SD2_CLK               IOMUX_PAD(0x7C0, 0x3B8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD2_DATA0__SD2_DATA0           IOMUX_PAD(0x7C4, 0x3BC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD2_DATA1__SD2_DATA1           IOMUX_PAD(0x7C8, 0x3C0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD2_DATA2__SD2_DATA2           IOMUX_PAD(0x7CC, 0x3C4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_SD2_DATA3__SD2_DATA3           IOMUX_PAD(0x7D0, 0x3C8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_2__GPIO_1_2            IOMUX_PAD(0x7D4, 0x3CC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_2__I2C2_SCL            IOMUX_PAD(0x7D4, 0x3CC, (2 | IOMUX_CONFIG_SION), \
+                                                       0x9b8,   3, MX51_I2C_PAD_CTRL)
+#define MX51_PAD_GPIO_1_3__GPIO_1_3            IOMUX_PAD(0x7D8, 0x3D0, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_3__I2C2_SDA            IOMUX_PAD(0x7D8, 0x3D0, (2 | IOMUX_CONFIG_SION), \
+                                                       0x9bc,   3, MX51_I2C_PAD_CTRL)
+#define MX51_PAD_PMIC_INT_REQ__PMIC_INT_REQ    IOMUX_PAD(0x7FC, 0x3D4, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_4__GPIO_1_4            IOMUX_PAD(0x804, 0x3D8, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_5__GPIO_1_5            IOMUX_PAD(0x808, 0x3DC, 0, 0x0,   0, NO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_6__GPIO_1_6            IOMUX_PAD(0x80C, 0x3E0, 0, 0x0,   0, MX51_GPIO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_7__GPIO_1_7            IOMUX_PAD(0x810, 0x3E4, 0, 0x0,   0, MX51_GPIO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_8__GPIO_1_8            IOMUX_PAD(0x814, 0x3E8, 0, 0x0,   1, MX51_GPIO_PAD_CTRL)
+#define MX51_PAD_GPIO_1_9__GPIO_1_9            IOMUX_PAD(0x818, 0x3EC, 0, 0x0,   0, NO_PAD_CTRL)
 
 #endif /* __MACH_IOMUX_MX51_H__ */
index 3887f3fe29d4401b62584a905fcaa642dd7a80b6..15d59510f597ed8eb5e37df2c44a5c34cdc6dcc9 100644 (file)
  * 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 __MACH_IOMUX_MXC91231_H__
index f2f73d31d5ba5cf579d035b52b9f106c4f741d0d..0880a4a1aed1e91c397653515dca3d979cf9b804 100644 (file)
@@ -89,6 +89,21 @@ struct pad_desc {
 #define PAD_CTL_SRE_FAST               (1 << 0)
 #define PAD_CTL_SRE_SLOW               (0 << 0)
 
+
+#define MX51_NUM_GPIO_PORT     4
+
+#define GPIO_PIN_MASK 0x1f
+
+#define GPIO_PORT_SHIFT 5
+#define GPIO_PORT_MASK (0x7 << GPIO_PORT_SHIFT)
+
+#define GPIO_PORTA     (0 << GPIO_PORT_SHIFT)
+#define GPIO_PORTB     (1 << GPIO_PORT_SHIFT)
+#define GPIO_PORTC     (2 << GPIO_PORT_SHIFT)
+#define GPIO_PORTD     (3 << GPIO_PORT_SHIFT)
+#define GPIO_PORTE     (4 << GPIO_PORT_SHIFT)
+#define GPIO_PORTF     (5 << GPIO_PORT_SHIFT)
+
 /*
  * setups a single pad in the iomuxer
  */
index c4b40c35a6a1e429f14476a4f76491229c8560cc..564ec9dbc93d324a208cf407de178974435e9eea 100644 (file)
  */
 #define CONSISTENT_DMA_SIZE SZ_8M
 
-#elif defined(CONFIG_MX1_VIDEO)
+#elif defined(CONFIG_MX1_VIDEO) || defined(CONFIG_VIDEO_MX2_HOSTSUPPORT)
 /*
  * Increase size of DMA-consistent memory region.
  * This is required for i.MX camera driver to capture at least four VGA frames.
  */
 #define CONSISTENT_DMA_SIZE SZ_4M
-#endif /* CONFIG_MX1_VIDEO */
+#endif /* CONFIG_MX1_VIDEO || CONFIG_VIDEO_MX2_HOSTSUPPORT */
 
 #endif /* __ASM_ARCH_MXC_MEMORY_H__ */
index de2128dada5cf2856118181bec1771fddef95fac..29115f405af91653683465fa9112fd0cff78213f 100644 (file)
@@ -31,6 +31,9 @@ struct imxmmc_platform_data {
 
        /* adjust slot voltage */
        void (*setpower)(struct device *, unsigned int vdd);
+
+       /* enable card detect using DAT3 */
+       int dat3_card_detect;
 };
 
 #endif
index 5eba7e6785dec6ddf643366965c5734bdc1fa89a..641b2461823950be06d2573131f7f2b8ba74d3e4 100644 (file)
 #define MX1_SIM_DATA_INT       16
 #define MX1_RTC_INT            17
 #define MX1_RTC_SAMINT         18
-#define MX1_UART2_MINT_PFERR   19
-#define MX1_UART2_MINT_RTS     20
-#define MX1_UART2_MINT_DTR     21
-#define MX1_UART2_MINT_UARTC   22
-#define MX1_UART2_MINT_TX      23
-#define MX1_UART2_MINT_RX      24
-#define MX1_UART1_MINT_PFERR   25
-#define MX1_UART1_MINT_RTS     26
-#define MX1_UART1_MINT_DTR     27
-#define MX1_UART1_MINT_UARTC   28
-#define MX1_UART1_MINT_TX      29
-#define MX1_UART1_MINT_RX      30
+#define MX1_INT_UART2PFERR     19
+#define MX1_INT_UART2RTS       20
+#define MX1_INT_UART2DTR       21
+#define MX1_INT_UART2UARTC     22
+#define MX1_INT_UART2TX                23
+#define MX1_INT_UART2RX                24
+#define MX1_INT_UART1PFERR     25
+#define MX1_INT_UART1RTS       26
+#define MX1_INT_UART1DTR       27
+#define MX1_INT_UART1UARTC     28
+#define MX1_INT_UART1TX                29
+#define MX1_INT_UART1RX                30
 #define MX1_VOICE_DAC_INT      31
 #define MX1_VOICE_ADC_INT      32
 #define MX1_PEN_DATA_INT       33
 #define MX1_PWM_INT            34
 #define MX1_SDHC_INT           35
-#define MX1_I2C_INT            39
+#define MX1_INT_I2C            39
 #define MX1_CSPI_INT           41
 #define MX1_SSI_TX_INT         42
 #define MX1_SSI_TX_ERR_INT     43
 #define PEN_DATA_INT MX1_PEN_DATA_INT
 #define PWM_INT MX1_PWM_INT
 #define SDHC_INT MX1_SDHC_INT
-#define I2C_INT MX1_I2C_INT
+#define I2C_INT MX1_INT_I2C
 #define CSPI_INT MX1_CSPI_INT
 #define SSI_TX_INT MX1_SSI_TX_INT
 #define SSI_TX_ERR_INT MX1_SSI_TX_ERR_INT
index 4eb6e334bda589f6d210dc2c3de1a70a60cb6b1b..4a6f800990f83a826e687ae6a8d8776def7a3689 100644 (file)
 #define MX25_AVIC_BASE_ADDR_VIRT       0xfc400000
 #define MX25_AVIC_SIZE                 SZ_1M
 
+#define MX25_I2C1_BASE_ADDR            (MX25_AIPS1_BASE_ADDR + 0x80000)
+#define MX25_I2C3_BASE_ADDR            (MX25_AIPS1_BASE_ADDR + 0x84000)
+#define MX25_CAN1_BASE_ADDR            (MX25_AIPS1_BASE_ADDR + 0x88000)
+#define MX25_CAN2_BASE_ADDR            (MX25_AIPS1_BASE_ADDR + 0x8c000)
+#define MX25_I2C2_BASE_ADDR            (MX25_AIPS1_BASE_ADDR + 0x98000)
+#define MX25_CSPI1_BASE_ADDR           (MX25_AIPS1_BASE_ADDR + 0xa4000)
 #define MX25_IOMUXC_BASE_ADDR          (MX25_AIPS1_BASE_ADDR + 0xac000)
 
 #define MX25_CRM_BASE_ADDR             (MX25_AIPS2_BASE_ADDR + 0x80000)
        IMX_IO_ADDRESS(x, MX25_AIPS2) ?:                        \
        IMX_IO_ADDRESS(x, MX25_AVIC))
 
+#define MX25_AIPS1_IO_ADDRESS(x) \
+       (((x) - MX25_AIPS1_BASE_ADDR) + MX25_AIPS1_BASE_ADDR_VIRT)
+
 #define MX25_UART1_BASE_ADDR           0x43f90000
 #define MX25_UART2_BASE_ADDR           0x43f94000
+#define MX25_AUDMUX_BASE_ADDR          0x43fb0000
+#define MX25_UART3_BASE_ADDR           0x5000c000
+#define MX25_UART4_BASE_ADDR           0x50008000
+#define MX25_UART5_BASE_ADDR           0x5002c000
 
+#define MX25_CSPI3_BASE_ADDR           0x50004000
+#define MX25_CSPI2_BASE_ADDR           0x50010000
 #define MX25_FEC_BASE_ADDR             0x50038000
+#define MX25_SSI2_BASE_ADDR            0x50014000
+#define MX25_SSI1_BASE_ADDR            0x50034000
 #define MX25_NFC_BASE_ADDR             0xbb000000
 #define MX25_DRYICE_BASE_ADDR          0x53ffc000
 #define MX25_LCDC_BASE_ADDR            0x53fbc000
+#define MX25_KPP_BASE_ADDR             0x43fa8000
+#define MX25_OTG_BASE_ADDR             0x53ff4000
+#define MX25_CSI_BASE_ADDR             0x53ff8000
 
-#define MX25_INT_DRYICE        25
-#define MX25_INT_FEC   57
-#define MX25_INT_NANDFC        33
-#define MX25_INT_LCDC  39
-
-#if defined(IMX_NEEDS_DEPRECATED_SYMBOLS)
-#define UART1_BASE_ADDR                        MX25_UART1_BASE_ADDR
-#define UART2_BASE_ADDR                        MX25_UART2_BASE_ADDR
-#endif
+#define MX25_INT_CSPI3         0
+#define MX25_INT_I2C1          3
+#define MX25_INT_I2C2          4
+#define MX25_INT_UART4         5
+#define MX25_INT_I2C3          10
+#define MX25_INT_SSI2          11
+#define MX25_INT_SSI1          12
+#define MX25_INT_CSPI2         13
+#define MX25_INT_CSPI1         14
+#define MX25_INT_CSI           17
+#define MX25_INT_UART3         18
+#define MX25_INT_KPP           24
+#define MX25_INT_DRYICE                25
+#define MX25_INT_UART2         32
+#define MX25_INT_NANDFC                33
+#define MX25_INT_LCDC          39
+#define MX25_INT_UART5         40
+#define MX25_INT_CAN1          43
+#define MX25_INT_CAN2          44
+#define MX25_INT_UART1         45
+#define MX25_INT_FEC           57
 
 #endif /* ifndef __MACH_MX25_H__ */
index bae9cd75beee333f097edc45a772add44f5d1d7c..a8ab2e02a8caf36460591865237e6d6c34d534de 100644 (file)
@@ -48,7 +48,7 @@
 #define MX27_CSPI2_BASE_ADDR                   (MX27_AIPI_BASE_ADDR + 0x0f000)
 #define MX27_SSI1_BASE_ADDR                    (MX27_AIPI_BASE_ADDR + 0x10000)
 #define MX27_SSI2_BASE_ADDR                    (MX27_AIPI_BASE_ADDR + 0x11000)
-#define MX27_I2C_BASE_ADDR                     (MX27_AIPI_BASE_ADDR + 0x12000)
+#define MX27_I2C1_BASE_ADDR                    (MX27_AIPI_BASE_ADDR + 0x12000)
 #define MX27_SDHC1_BASE_ADDR                   (MX27_AIPI_BASE_ADDR + 0x13000)
 #define MX27_SDHC2_BASE_ADDR                   (MX27_AIPI_BASE_ADDR + 0x14000)
 #define MX27_GPIO_BASE_ADDR                    (MX27_AIPI_BASE_ADDR + 0x15000)
@@ -150,7 +150,7 @@ static inline void mx27_setup_weimcs(size_t cs,
 #define MX27_INT_SDHC3         9
 #define MX27_INT_SDHC2         10
 #define MX27_INT_SDHC1         11
-#define MX27_INT_I2C           12
+#define MX27_INT_I2C1          12
 #define MX27_INT_SSI2          13
 #define MX27_INT_SSI1          14
 #define MX27_INT_CSPI2         15
diff --git a/arch/arm/plat-mxc/include/mach/mx2_cam.h b/arch/arm/plat-mxc/include/mach/mx2_cam.h
new file mode 100644 (file)
index 0000000..3c080a3
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * mx2-cam.h - i.MX27/i.MX25 camera driver header file
+ *
+ * Copyright (C) 2003, Intel Corporation
+ * Copyright (C) 2008, Sascha Hauer <s.hauer@pengutronix.de>
+ * Copyright (C) 2010, Baruch Siach <baruch@tkos.co.il>
+ *
+ * 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., 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __MACH_MX2_CAM_H_
+#define __MACH_MX2_CAM_H_
+
+#define MX2_CAMERA_SWAP16              (1 << 0)
+#define MX2_CAMERA_EXT_VSYNC           (1 << 1)
+#define MX2_CAMERA_CCIR                        (1 << 2)
+#define MX2_CAMERA_CCIR_INTERLACE      (1 << 3)
+#define MX2_CAMERA_HSYNC_HIGH          (1 << 4)
+#define MX2_CAMERA_GATED_CLOCK         (1 << 5)
+#define MX2_CAMERA_INV_DATA            (1 << 6)
+#define MX2_CAMERA_PCLK_SAMPLE_RISING  (1 << 7)
+#define MX2_CAMERA_PACK_DIR_MSB                (1 << 8)
+
+/**
+ * struct mx2_camera_platform_data - optional platform data for mx2_camera
+ * @flags: any combination of MX2_CAMERA_*
+ * @clk: clock rate of the csi block / 2
+ */
+struct mx2_camera_platform_data {
+       unsigned long flags;
+       unsigned long clk;
+};
+
+#endif /* __MACH_MX2_CAM_H_ */
index fb90e119c2b5db473a3d4e01ef48dd6a76921493..afee3ab9d62e2aef32a366f21c82350a562dab22 100644 (file)
@@ -23,7 +23,7 @@
 #define MX31_ETB_SLOT4_BASE_ADDR               (MX31_AIPS1_BASE_ADDR + 0x10000)
 #define MX31_ETB_SLOT5_BASE_ADDR               (MX31_AIPS1_BASE_ADDR + 0x14000)
 #define MX31_ECT_CTIO_BASE_ADDR                        (MX31_AIPS1_BASE_ADDR + 0x18000)
-#define MX31_I2C_BASE_ADDR                     (MX31_AIPS1_BASE_ADDR + 0x80000)
+#define MX31_I2C1_BASE_ADDR                    (MX31_AIPS1_BASE_ADDR + 0x80000)
 #define MX31_I2C3_BASE_ADDR                    (MX31_AIPS1_BASE_ADDR + 0x84000)
 #define MX31_OTG_BASE_ADDR                     (MX31_AIPS1_BASE_ADDR + 0x88000)
 #define MX31_ATA_BASE_ADDR                     (MX31_AIPS1_BASE_ADDR + 0x8c000)
@@ -145,7 +145,7 @@ static inline void mx31_setup_weimcs(size_t cs,
 #define MX31_INT_FIRI          7
 #define MX31_INT_MMC_SDHC2     8
 #define MX31_INT_MMC_SDHC1     9
-#define MX31_INT_I2C           10
+#define MX31_INT_I2C1          10
 #define MX31_INT_SSI2          11
 #define MX31_INT_SSI1          12
 #define MX31_INT_CSPI2         13
index 526a55842ae53d6719a1221f4d8b3ccc33a75429..af3038c12e39c03b16d00855e5f5f40b75ba9b97 100644 (file)
@@ -18,7 +18,7 @@
 #define MX35_ETB_SLOT4_BASE_ADDR               (MX35_AIPS1_BASE_ADDR + 0x10000)
 #define MX35_ETB_SLOT5_BASE_ADDR               (MX35_AIPS1_BASE_ADDR + 0x14000)
 #define MX35_ECT_CTIO_BASE_ADDR                        (MX35_AIPS1_BASE_ADDR + 0x18000)
-#define MX35_I2C_BASE_ADDR                     (MX35_AIPS1_BASE_ADDR + 0x80000)
+#define MX35_I2C1_BASE_ADDR                    (MX35_AIPS1_BASE_ADDR + 0x80000)
 #define MX35_I2C3_BASE_ADDR                    (MX35_AIPS1_BASE_ADDR + 0x84000)
 #define MX35_UART1_BASE_ADDR                   (MX35_AIPS1_BASE_ADDR + 0x90000)
 #define MX35_UART2_BASE_ADDR                   (MX35_AIPS1_BASE_ADDR + 0x94000)
@@ -60,6 +60,8 @@
 #define MX35_RTC_BASE_ADDR                     (MX35_AIPS2_BASE_ADDR + 0xd8000)
 #define MX35_WDOG_BASE_ADDR                    (MX35_AIPS2_BASE_ADDR + 0xdc000)
 #define MX35_PWM_BASE_ADDR                     (MX35_AIPS2_BASE_ADDR + 0xe0000)
+#define MX35_CAN1_BASE_ADDR                    (MX35_AIPS2_BASE_ADDR + 0xe4000)
+#define MX35_CAN2_BASE_ADDR                    (MX35_AIPS2_BASE_ADDR + 0xe8000)
 #define MX35_RTIC_BASE_ADDR                    (MX35_AIPS2_BASE_ADDR + 0xec000)
 #define MX35_OTG_BASE_ADDR             0x53ff4000
 
 #define MX35_INT_MMC_SDHC1     7
 #define MX35_INT_MMC_SDHC2     8
 #define MX35_INT_MMC_SDHC3     9
-#define MX35_INT_I2C           10
+#define MX35_INT_I2C1          10
 #define MX35_INT_SSI1          11
 #define MX35_INT_SSI2          12
 #define MX35_INT_CSPI2         13
index 36d7ff27b5e2244861cd7f4750d857e20c7c8fcf..f226ee3777e17368c7901ebfeddaca2d523acf1a 100644 (file)
  * 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., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
 #ifndef _MX3_CAMERA_H_
index 5182b986b7851e0d91513b37969312adf15d69de..0ca3101ebf36e92364b33a78fbf4e7db916f2af6 100644 (file)
  * 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 __MACH_MXC91231_H__
 #define __MACH_MXC91231_H__
index 5d2d21d414e0e71716ab8878a14548010faff253..04c0d060d8143ae4c60d526a6198178f2e02bccb 100644 (file)
 #ifndef __ASM_ARCH_NAND_H
 #define __ASM_ARCH_NAND_H
 
+#include <linux/mtd/partitions.h>
+
 struct mxc_nand_platform_data {
-       int width;      /* data bus width in bytes */
-       int hw_ecc:1;   /* 0 if supress hardware ECC */
-       int flash_bbt:1; /* set to 1 to use a flash based bbt */
+       unsigned int width;     /* data bus width in bytes */
+       unsigned int hw_ecc:1;  /* 0 if supress hardware ECC */
+       unsigned int flash_bbt:1; /* set to 1 to use a flash based bbt */
+       struct mtd_partition *parts;    /* partition table */
+       int nr_parts;                   /* size of parts */
 };
 #endif /* __ASM_ARCH_NAND_H */
index ef00199568de15f998571b3cd20a34a29ff56de7..4acd1143a9bdd7444c12ca547ed957b47ef302d6 100644 (file)
  * 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_ARCH_MXC_SYSTEM_H__
index 024416ed11cd9673bf5bf478f17412c81f6e98c8..2d9624697cc9c9e7d99c5733e5e750b90c0a592b 100644 (file)
  * 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_ARCH_MXC_TIMEX_H__
index b6d3d0fddc48aebb62763c2d364bed0103909063..d9bd37e4667a23f04e3f20ba0fd4fcd8f599b6d6 100644 (file)
  * 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_ARCH_MXC_UNCOMPRESS_H__
 #define __ASM_ARCH_MXC_UNCOMPRESS_H__
index 44243a278434b027d604ed590e43d9cdb5749653..ef6379c474be8a66656583cca426bd7b23386f6a 100644 (file)
  * 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_ARCH_MXC_VMALLOC_H__
index 778ddfe57d895c5db1a4969886bd1dac6226f5f0..7331f2ace5fe12b49e1ce431fd01459bc6bae785 100644 (file)
@@ -142,9 +142,6 @@ void __init mxc_init_irq(void __iomem *irqbase)
        for (i = 0; i < 8; i++)
                __raw_writel(0, avic_base + AVIC_NIPRIORITY(i));
 
-       /* init architectures chained interrupt handler */
-       mxc_register_gpios();
-
 #ifdef CONFIG_FIQ
        /* Initialize FIQ */
        init_FIQ();
index 97f42799fa589caae5f1c99ebc11670ee16f93a3..925bce4607e78bc91f2fb4605e4c8d5195027ff2 100644 (file)
  * 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
  */
 
 #include <linux/kernel.h>
index 9b86d2a60d43789a22d644105981815169123dd7..b3da9aad4295704ef9ea8a4a43c95127d74e6d9e 100644 (file)
@@ -145,8 +145,6 @@ void __init tzic_init_irq(void __iomem *irqbase)
                set_irq_handler(i, handle_level_irq);
                set_irq_flags(i, IRQF_VALID);
        }
-       mxc_register_gpios();
-
        pr_info("TrustZone Interrupt Controller (TZIC) initialized\n");
 }
 
index 5a6ef252c38b37732d36e8dc52c97b96d9385604..977c8f9a07a2194322deada32da2afd0481d50ad 100644 (file)
@@ -23,6 +23,7 @@
 #include <linux/irq.h>
 #include <linux/slab.h>
 
+#include <plat/pincfg.h>
 #include <mach/hardware.h>
 #include <mach/gpio.h>
 
@@ -46,28 +47,217 @@ struct nmk_gpio_chip {
        u32 edge_falling;
 };
 
+static void __nmk_gpio_set_mode(struct nmk_gpio_chip *nmk_chip,
+                               unsigned offset, int gpio_mode)
+{
+       u32 bit = 1 << offset;
+       u32 afunc, bfunc;
+
+       afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & ~bit;
+       bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & ~bit;
+       if (gpio_mode & NMK_GPIO_ALT_A)
+               afunc |= bit;
+       if (gpio_mode & NMK_GPIO_ALT_B)
+               bfunc |= bit;
+       writel(afunc, nmk_chip->addr + NMK_GPIO_AFSLA);
+       writel(bfunc, nmk_chip->addr + NMK_GPIO_AFSLB);
+}
+
+static void __nmk_gpio_set_slpm(struct nmk_gpio_chip *nmk_chip,
+                               unsigned offset, enum nmk_gpio_slpm mode)
+{
+       u32 bit = 1 << offset;
+       u32 slpm;
+
+       slpm = readl(nmk_chip->addr + NMK_GPIO_SLPC);
+       if (mode == NMK_GPIO_SLPM_NOCHANGE)
+               slpm |= bit;
+       else
+               slpm &= ~bit;
+       writel(slpm, nmk_chip->addr + NMK_GPIO_SLPC);
+}
+
+static void __nmk_gpio_set_pull(struct nmk_gpio_chip *nmk_chip,
+                               unsigned offset, enum nmk_gpio_pull pull)
+{
+       u32 bit = 1 << offset;
+       u32 pdis;
+
+       pdis = readl(nmk_chip->addr + NMK_GPIO_PDIS);
+       if (pull == NMK_GPIO_PULL_NONE)
+               pdis |= bit;
+       else
+               pdis &= ~bit;
+       writel(pdis, nmk_chip->addr + NMK_GPIO_PDIS);
+
+       if (pull == NMK_GPIO_PULL_UP)
+               writel(bit, nmk_chip->addr + NMK_GPIO_DATS);
+       else if (pull == NMK_GPIO_PULL_DOWN)
+               writel(bit, nmk_chip->addr + NMK_GPIO_DATC);
+}
+
+static void __nmk_gpio_make_input(struct nmk_gpio_chip *nmk_chip,
+                                 unsigned offset)
+{
+       writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC);
+}
+
+static void __nmk_config_pin(struct nmk_gpio_chip *nmk_chip, unsigned offset,
+                            pin_cfg_t cfg)
+{
+       static const char *afnames[] = {
+               [NMK_GPIO_ALT_GPIO]     = "GPIO",
+               [NMK_GPIO_ALT_A]        = "A",
+               [NMK_GPIO_ALT_B]        = "B",
+               [NMK_GPIO_ALT_C]        = "C"
+       };
+       static const char *pullnames[] = {
+               [NMK_GPIO_PULL_NONE]    = "none",
+               [NMK_GPIO_PULL_UP]      = "up",
+               [NMK_GPIO_PULL_DOWN]    = "down",
+               [3] /* illegal */       = "??"
+       };
+       static const char *slpmnames[] = {
+               [NMK_GPIO_SLPM_INPUT]           = "input",
+               [NMK_GPIO_SLPM_NOCHANGE]        = "no-change",
+       };
+
+       int pin = PIN_NUM(cfg);
+       int pull = PIN_PULL(cfg);
+       int af = PIN_ALT(cfg);
+       int slpm = PIN_SLPM(cfg);
+
+       dev_dbg(nmk_chip->chip.dev, "pin %d: af %s, pull %s, slpm %s\n",
+               pin, afnames[af], pullnames[pull], slpmnames[slpm]);
+
+       __nmk_gpio_make_input(nmk_chip, offset);
+       __nmk_gpio_set_pull(nmk_chip, offset, pull);
+       __nmk_gpio_set_slpm(nmk_chip, offset, slpm);
+       __nmk_gpio_set_mode(nmk_chip, offset, af);
+}
+
+/**
+ * nmk_config_pin - configure a pin's mux attributes
+ * @cfg: pin confguration
+ *
+ * Configures a pin's mode (alternate function or GPIO), its pull up status,
+ * and its sleep mode based on the specified configuration.  The @cfg is
+ * usually one of the SoC specific macros defined in mach/<soc>-pins.h.  These
+ * are constructed using, and can be further enhanced with, the macros in
+ * plat/pincfg.h.
+ *
+ * If a pin's mode is set to GPIO, it is configured as an input to avoid
+ * side-effects.  The gpio can be manipulated later using standard GPIO API
+ * calls.
+ */
+int nmk_config_pin(pin_cfg_t cfg)
+{
+       struct nmk_gpio_chip *nmk_chip;
+       int gpio = PIN_NUM(cfg);
+       unsigned long flags;
+
+       nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
+       if (!nmk_chip)
+               return -EINVAL;
+
+       spin_lock_irqsave(&nmk_chip->lock, flags);
+       __nmk_config_pin(nmk_chip, gpio - nmk_chip->chip.base, cfg);
+       spin_unlock_irqrestore(&nmk_chip->lock, flags);
+
+       return 0;
+}
+EXPORT_SYMBOL(nmk_config_pin);
+
+/**
+ * nmk_config_pins - configure several pins at once
+ * @cfgs: array of pin configurations
+ * @num: number of elments in the array
+ *
+ * Configures several pins using nmk_config_pin().  Refer to that function for
+ * further information.
+ */
+int nmk_config_pins(pin_cfg_t *cfgs, int num)
+{
+       int ret = 0;
+       int i;
+
+       for (i = 0; i < num; i++) {
+               int ret = nmk_config_pin(cfgs[i]);
+               if (ret)
+                       break;
+       }
+
+       return ret;
+}
+EXPORT_SYMBOL(nmk_config_pins);
+
+/**
+ * nmk_gpio_set_slpm() - configure the sleep mode of a pin
+ * @gpio: pin number
+ * @mode: NMK_GPIO_SLPM_INPUT or NMK_GPIO_SLPM_NOCHANGE,
+ *
+ * Sets the sleep mode of a pin.  If @mode is NMK_GPIO_SLPM_INPUT, the pin is
+ * changed to an input (with pullup/down enabled) in sleep and deep sleep.  If
+ * @mode is NMK_GPIO_SLPM_NOCHANGE, the pin remains in the state it was
+ * configured even when in sleep and deep sleep.
+ */
+int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode)
+{
+       struct nmk_gpio_chip *nmk_chip;
+       unsigned long flags;
+
+       nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
+       if (!nmk_chip)
+               return -EINVAL;
+
+       spin_lock_irqsave(&nmk_chip->lock, flags);
+       __nmk_gpio_set_slpm(nmk_chip, gpio - nmk_chip->chip.base, mode);
+       spin_unlock_irqrestore(&nmk_chip->lock, flags);
+
+       return 0;
+}
+
+/**
+ * nmk_gpio_set_pull() - enable/disable pull up/down on a gpio
+ * @gpio: pin number
+ * @pull: one of NMK_GPIO_PULL_DOWN, NMK_GPIO_PULL_UP, and NMK_GPIO_PULL_NONE
+ *
+ * Enables/disables pull up/down on a specified pin.  This only takes effect if
+ * the pin is configured as an input (either explicitly or by the alternate
+ * function).
+ *
+ * NOTE: If enabling the pull up/down, the caller must ensure that the GPIO is
+ * configured as an input.  Otherwise, due to the way the controller registers
+ * work, this function will change the value output on the pin.
+ */
+int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull)
+{
+       struct nmk_gpio_chip *nmk_chip;
+       unsigned long flags;
+
+       nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
+       if (!nmk_chip)
+               return -EINVAL;
+
+       spin_lock_irqsave(&nmk_chip->lock, flags);
+       __nmk_gpio_set_pull(nmk_chip, gpio - nmk_chip->chip.base, pull);
+       spin_unlock_irqrestore(&nmk_chip->lock, flags);
+
+       return 0;
+}
+
 /* Mode functions */
 int nmk_gpio_set_mode(int gpio, int gpio_mode)
 {
        struct nmk_gpio_chip *nmk_chip;
        unsigned long flags;
-       u32 afunc, bfunc, bit;
 
        nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
        if (!nmk_chip)
                return -EINVAL;
 
-       bit = 1 << (gpio - nmk_chip->chip.base);
-
        spin_lock_irqsave(&nmk_chip->lock, flags);
-       afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & ~bit;
-       bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & ~bit;
-       if (gpio_mode & NMK_GPIO_ALT_A)
-               afunc |= bit;
-       if (gpio_mode & NMK_GPIO_ALT_B)
-               bfunc |= bit;
-       writel(afunc, nmk_chip->addr + NMK_GPIO_AFSLA);
-       writel(bfunc, nmk_chip->addr + NMK_GPIO_AFSLB);
+       __nmk_gpio_set_mode(nmk_chip, gpio - nmk_chip->chip.base, gpio_mode);
        spin_unlock_irqrestore(&nmk_chip->lock, flags);
 
        return 0;
@@ -111,32 +301,41 @@ static void nmk_gpio_irq_ack(unsigned int irq)
        writel(nmk_gpio_get_bitmask(gpio), nmk_chip->addr + NMK_GPIO_IC);
 }
 
+enum nmk_gpio_irq_type {
+       NORMAL,
+       WAKE,
+};
+
 static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip,
-                                 int gpio, bool enable)
+                                 int gpio, enum nmk_gpio_irq_type which,
+                                 bool enable)
 {
+       u32 rimsc = which == WAKE ? NMK_GPIO_RWIMSC : NMK_GPIO_RIMSC;
+       u32 fimsc = which == WAKE ? NMK_GPIO_FWIMSC : NMK_GPIO_FIMSC;
        u32 bitmask = nmk_gpio_get_bitmask(gpio);
        u32 reg;
 
        /* we must individually set/clear the two edges */
        if (nmk_chip->edge_rising & bitmask) {
-               reg = readl(nmk_chip->addr + NMK_GPIO_RIMSC);
+               reg = readl(nmk_chip->addr + rimsc);
                if (enable)
                        reg |= bitmask;
                else
                        reg &= ~bitmask;
-               writel(reg, nmk_chip->addr + NMK_GPIO_RIMSC);
+               writel(reg, nmk_chip->addr + rimsc);
        }
        if (nmk_chip->edge_falling & bitmask) {
-               reg = readl(nmk_chip->addr + NMK_GPIO_FIMSC);
+               reg = readl(nmk_chip->addr + fimsc);
                if (enable)
                        reg |= bitmask;
                else
                        reg &= ~bitmask;
-               writel(reg, nmk_chip->addr + NMK_GPIO_FIMSC);
+               writel(reg, nmk_chip->addr + fimsc);
        }
 }
 
-static void nmk_gpio_irq_modify(unsigned int irq, bool enable)
+static int nmk_gpio_irq_modify(unsigned int irq, enum nmk_gpio_irq_type which,
+                              bool enable)
 {
        int gpio;
        struct nmk_gpio_chip *nmk_chip;
@@ -147,26 +346,35 @@ static void nmk_gpio_irq_modify(unsigned int irq, bool enable)
        nmk_chip = get_irq_chip_data(irq);
        bitmask = nmk_gpio_get_bitmask(gpio);
        if (!nmk_chip)
-               return;
+               return -EINVAL;
 
        spin_lock_irqsave(&nmk_chip->lock, flags);
-       __nmk_gpio_irq_modify(nmk_chip, gpio, enable);
+       __nmk_gpio_irq_modify(nmk_chip, gpio, which, enable);
        spin_unlock_irqrestore(&nmk_chip->lock, flags);
+
+       return 0;
 }
 
 static void nmk_gpio_irq_mask(unsigned int irq)
 {
-       nmk_gpio_irq_modify(irq, false);
-};
+       nmk_gpio_irq_modify(irq, NORMAL, false);
+}
 
 static void nmk_gpio_irq_unmask(unsigned int irq)
 {
-       nmk_gpio_irq_modify(irq, true);
+       nmk_gpio_irq_modify(irq, NORMAL, true);
+}
+
+static int nmk_gpio_irq_set_wake(unsigned int irq, unsigned int on)
+{
+       return nmk_gpio_irq_modify(irq, WAKE, on);
 }
 
 static int nmk_gpio_irq_set_type(unsigned int irq, unsigned int type)
 {
-       bool enabled = !(irq_to_desc(irq)->status & IRQ_DISABLED);
+       struct irq_desc *desc = irq_to_desc(irq);
+       bool enabled = !(desc->status & IRQ_DISABLED);
+       bool wake = desc->wake_depth;
        int gpio;
        struct nmk_gpio_chip *nmk_chip;
        unsigned long flags;
@@ -186,7 +394,10 @@ static int nmk_gpio_irq_set_type(unsigned int irq, unsigned int type)
        spin_lock_irqsave(&nmk_chip->lock, flags);
 
        if (enabled)
-               __nmk_gpio_irq_modify(nmk_chip, gpio, false);
+               __nmk_gpio_irq_modify(nmk_chip, gpio, NORMAL, false);
+
+       if (wake)
+               __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, false);
 
        nmk_chip->edge_rising &= ~bitmask;
        if (type & IRQ_TYPE_EDGE_RISING)
@@ -197,7 +408,10 @@ static int nmk_gpio_irq_set_type(unsigned int irq, unsigned int type)
                nmk_chip->edge_falling |= bitmask;
 
        if (enabled)
-               __nmk_gpio_irq_modify(nmk_chip, gpio, true);
+               __nmk_gpio_irq_modify(nmk_chip, gpio, NORMAL, true);
+
+       if (wake)
+               __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, true);
 
        spin_unlock_irqrestore(&nmk_chip->lock, flags);
 
@@ -210,6 +424,7 @@ static struct irq_chip nmk_gpio_irq_chip = {
        .mask           = nmk_gpio_irq_mask,
        .unmask         = nmk_gpio_irq_unmask,
        .set_type       = nmk_gpio_irq_set_type,
+       .set_wake       = nmk_gpio_irq_set_wake,
 };
 
 static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
@@ -266,16 +481,6 @@ static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset)
        return 0;
 }
 
-static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset,
-                               int val)
-{
-       struct nmk_gpio_chip *nmk_chip =
-               container_of(chip, struct nmk_gpio_chip, chip);
-
-       writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRS);
-       return 0;
-}
-
 static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset)
 {
        struct nmk_gpio_chip *nmk_chip =
@@ -298,12 +503,33 @@ static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset,
                writel(bit, nmk_chip->addr + NMK_GPIO_DATC);
 }
 
+static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset,
+                               int val)
+{
+       struct nmk_gpio_chip *nmk_chip =
+               container_of(chip, struct nmk_gpio_chip, chip);
+
+       writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRS);
+       nmk_gpio_set_output(chip, offset, val);
+
+       return 0;
+}
+
+static int nmk_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
+{
+       struct nmk_gpio_chip *nmk_chip =
+               container_of(chip, struct nmk_gpio_chip, chip);
+
+       return NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base) + offset;
+}
+
 /* This structure is replicated for each GPIO block allocated at probe time */
 static struct gpio_chip nmk_gpio_template = {
        .direction_input        = nmk_gpio_make_input,
        .get                    = nmk_gpio_get_input,
        .direction_output       = nmk_gpio_make_output,
        .set                    = nmk_gpio_set_output,
+       .to_irq                 = nmk_gpio_to_irq,
        .ngpio                  = NMK_GPIO_PER_CHIP,
        .can_sleep              = 0,
 };
@@ -393,30 +619,12 @@ out:
        return ret;
 }
 
-static int __exit nmk_gpio_remove(struct platform_device *dev)
-{
-       struct nmk_gpio_chip *nmk_chip;
-       struct resource *res;
-
-       res = platform_get_resource(dev, IORESOURCE_MEM, 0);
-
-       nmk_chip = platform_get_drvdata(dev);
-       gpiochip_remove(&nmk_chip->chip);
-       clk_disable(nmk_chip->clk);
-       clk_put(nmk_chip->clk);
-       kfree(nmk_chip);
-       release_mem_region(res->start, resource_size(res));
-       return 0;
-}
-
-
 static struct platform_driver nmk_gpio_driver = {
        .driver = {
                .owner = THIS_MODULE,
                .name = "gpio",
                },
        .probe = nmk_gpio_probe,
-       .remove = __exit_p(nmk_gpio_remove),
        .suspend = NULL, /* to be done */
        .resume = NULL,
 };
@@ -426,7 +634,7 @@ static int __init nmk_gpio_init(void)
        return platform_driver_register(&nmk_gpio_driver);
 }
 
-arch_initcall(nmk_gpio_init);
+core_initcall(nmk_gpio_init);
 
 MODULE_AUTHOR("Prafulla WADASKAR and Alessandro Rubini");
 MODULE_DESCRIPTION("Nomadik GPIO Driver");
index 4200811249ca25180e9b2357ed58140f17cb9cd4..aba355101f492687e39e303fff8b26ceb761541e 100644 (file)
 #define NMK_GPIO_ALT_B 2
 #define NMK_GPIO_ALT_C (NMK_GPIO_ALT_A | NMK_GPIO_ALT_B)
 
+/* Pull up/down values */
+enum nmk_gpio_pull {
+       NMK_GPIO_PULL_NONE,
+       NMK_GPIO_PULL_UP,
+       NMK_GPIO_PULL_DOWN,
+};
+
+/* Sleep mode */
+enum nmk_gpio_slpm {
+       NMK_GPIO_SLPM_INPUT,
+       NMK_GPIO_SLPM_NOCHANGE,
+};
+
+extern int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode);
+extern int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull);
 extern int nmk_gpio_set_mode(int gpio, int gpio_mode);
 extern int nmk_gpio_get_mode(int gpio);
 
index 42c907258b14a04e34622d1ca99c638c5827631f..65704a3d42410890b044fd499cfba2ceaf067b9c 100644 (file)
@@ -1,6 +1,12 @@
 #ifndef __PLAT_MTU_H
 #define __PLAT_MTU_H
 
+/*
+ * Guaranteed runtime conversion range in seconds for
+ * the clocksource and clockevent.
+ */
+#define MTU_MIN_RANGE 4
+
 /* should be set by the platform code */
 extern void __iomem *mtu_base;
 
diff --git a/arch/arm/plat-nomadik/include/plat/pincfg.h b/arch/arm/plat-nomadik/include/plat/pincfg.h
new file mode 100644 (file)
index 0000000..7eed11c
--- /dev/null
@@ -0,0 +1,72 @@
+/*
+ * Copyright (C) ST-Ericsson SA 2010
+ *
+ * License terms: GNU General Public License, version 2
+ * Author: Rabin Vincent <rabin.vincent@stericsson.com> for ST-Ericsson
+ *
+ * Based on arch/arm/mach-pxa/include/mach/mfp.h:
+ *   Copyright (C) 2007 Marvell International Ltd.
+ *   eric miao <eric.miao@marvell.com>
+ */
+
+#ifndef __PLAT_PINCFG_H
+#define __PLAT_PINCFG_H
+
+/*
+ * pin configurations are represented by 32-bit integers:
+ *
+ *     bit  0.. 8 - Pin Number (512 Pins Maximum)
+ *     bit  9..10 - Alternate Function Selection
+ *     bit 11..12 - Pull up/down state
+ *     bit     13 - Sleep mode behaviour
+ *
+ * to facilitate the definition, the following macros are provided
+ *
+ * PIN_CFG_DEFAULT - default config (0):
+ *                  pull up/down = disabled
+ *                  sleep mode = input
+ *
+ * PIN_CFG        - default config with alternate function
+ * PIN_CFG_PULL           - default config with alternate function and pull up/down
+ */
+
+typedef unsigned long pin_cfg_t;
+
+#define PIN_NUM_MASK           0x1ff
+#define PIN_NUM(x)             ((x) & PIN_NUM_MASK)
+
+#define PIN_ALT_SHIFT          9
+#define PIN_ALT_MASK           (0x3 << PIN_ALT_SHIFT)
+#define PIN_ALT(x)             (((x) & PIN_ALT_MASK) >> PIN_ALT_SHIFT)
+#define PIN_GPIO               (NMK_GPIO_ALT_GPIO << PIN_ALT_SHIFT)
+#define PIN_ALT_A              (NMK_GPIO_ALT_A << PIN_ALT_SHIFT)
+#define PIN_ALT_B              (NMK_GPIO_ALT_B << PIN_ALT_SHIFT)
+#define PIN_ALT_C              (NMK_GPIO_ALT_C << PIN_ALT_SHIFT)
+
+#define PIN_PULL_SHIFT         11
+#define PIN_PULL_MASK          (0x3 << PIN_PULL_SHIFT)
+#define PIN_PULL(x)            (((x) & PIN_PULL_MASK) >> PIN_PULL_SHIFT)
+#define PIN_PULL_NONE          (NMK_GPIO_PULL_NONE << PIN_PULL_SHIFT)
+#define PIN_PULL_UP            (NMK_GPIO_PULL_UP << PIN_PULL_SHIFT)
+#define PIN_PULL_DOWN          (NMK_GPIO_PULL_DOWN << PIN_PULL_SHIFT)
+
+#define PIN_SLPM_SHIFT         13
+#define PIN_SLPM_MASK          (0x1 << PIN_SLPM_SHIFT)
+#define PIN_SLPM(x)            (((x) & PIN_SLPM_MASK) >> PIN_SLPM_SHIFT)
+#define PIN_SLPM_INPUT         (NMK_GPIO_SLPM_INPUT << PIN_SLPM_SHIFT)
+#define PIN_SLPM_NOCHANGE      (NMK_GPIO_SLPM_NOCHANGE << PIN_SLPM_SHIFT)
+
+#define PIN_CFG_DEFAULT                (PIN_PULL_NONE | PIN_SLPM_INPUT)
+
+#define PIN_CFG(num, alt)              \
+       (PIN_CFG_DEFAULT |\
+        (PIN_NUM(num) | PIN_##alt))
+
+#define PIN_CFG_PULL(num, alt, pull)   \
+       ((PIN_CFG_DEFAULT & ~PIN_PULL_MASK) |\
+        (PIN_NUM(num) | PIN_##alt | PIN_PULL_##pull))
+
+extern int nmk_config_pin(pin_cfg_t cfg);
+extern int nmk_config_pins(pin_cfg_t *cfgs, int num);
+
+#endif
index 08aaa4a7f65fe0e868b1a8cbfa8dd80d73209cec..ea3ca86c52836ba1ec9fe780da9c1629db91723f 100644 (file)
@@ -42,7 +42,6 @@ static struct clocksource nmdk_clksrc = {
        .rating         = 200,
        .read           = nmdk_read_timer_dummy,
        .mask           = CLOCKSOURCE_MASK(32),
-       .shift          = 20,
        .flags          = CLOCK_SOURCE_IS_CONTINUOUS,
 };
 
@@ -82,6 +81,12 @@ static void nmdk_clkevt_mode(enum clock_event_mode mode,
        case CLOCK_EVT_MODE_UNUSED:
                /* disable irq */
                writel(0, mtu_base + MTU_IMSC);
+               /* disable timer */
+               cr = readl(mtu_base + MTU_CR(1));
+               cr &= ~MTU_CRn_ENA;
+               writel(cr, mtu_base + MTU_CR(1));
+               /* load some high default value */
+               writel(0xffffffff, mtu_base + MTU_LR(1));
                break;
        case CLOCK_EVT_MODE_RESUME:
                break;
@@ -98,7 +103,6 @@ static int nmdk_clkevt_next(unsigned long evt, struct clock_event_device *ev)
 static struct clock_event_device nmdk_clkevt = {
        .name           = "mtu_1",
        .features       = CLOCK_EVT_FEAT_ONESHOT,
-       .shift          = 32,
        .rating         = 200,
        .set_mode       = nmdk_clkevt_mode,
        .set_next_event = nmdk_clkevt_next,
@@ -151,6 +155,7 @@ void __init nmdk_timer_init(void)
        } else {
                cr |= MTU_CRn_PRESCALE_1;
        }
+       clocksource_calc_mult_shift(&nmdk_clksrc, rate, MTU_MIN_RANGE);
 
        /* Timer 0 is the free running clocksource */
        writel(cr, mtu_base + MTU_CR(0));
@@ -158,7 +163,6 @@ void __init nmdk_timer_init(void)
        writel(0, mtu_base + MTU_BGLR(0));
        writel(cr | MTU_CRn_ENA, mtu_base + MTU_CR(0));
 
-       nmdk_clksrc.mult = clocksource_hz2mult(rate, nmdk_clksrc.shift);
        /* Now the scheduling clock is ready */
        nmdk_clksrc.read = nmdk_read_timer;
 
@@ -175,8 +179,10 @@ void __init nmdk_timer_init(void)
        } else {
                cr |= MTU_CRn_PRESCALE_1;
        }
+       clockevents_calc_mult_shift(&nmdk_clkevt, rate, MTU_MIN_RANGE);
+
        writel(cr | MTU_CRn_ONESHOT, mtu_base + MTU_CR(1)); /* off, currently */
-       nmdk_clkevt.mult = div_sc(rate, NSEC_PER_SEC, nmdk_clkevt.shift);
+
        nmdk_clkevt.max_delta_ns =
                clockevent_delta2ns(0xffffffff, &nmdk_clkevt);
        nmdk_clkevt.min_delta_ns =
index 219c01e82bc5a3cf70055f5e7593b0c115000e21..ebed82699eb2625b87898b6fcbc6f75bd44a9325 100644 (file)
@@ -22,6 +22,7 @@
 #include <linux/serial_reg.h>
 #include <linux/clk.h>
 #include <linux/io.h>
+#include <linux/omapfb.h>
 
 #include <mach/hardware.h>
 #include <asm/system.h>
@@ -35,6 +36,7 @@
 #include <plat/mux.h>
 #include <plat/fpga.h>
 #include <plat/serial.h>
+#include <plat/vram.h>
 
 #include <plat/clock.h>
 
@@ -81,6 +83,12 @@ const void *omap_get_var_config(u16 tag, size_t *len)
 }
 EXPORT_SYMBOL(omap_get_var_config);
 
+void __init omap_reserve(void)
+{
+       omapfb_reserve_sdram_memblock();
+       omap_vram_reserve_sdram_memblock();
+}
+
 /*
  * 32KHz clocksource ... always available, on pretty most chips except
  * OMAP 730 and 1510.  Other timers could be used as clocksources, with
index d3eea4f47533050618ce2a0e489a79f5f2725088..0054b9501a53976a384cde437b43be7c03cc582a 100644 (file)
@@ -26,7 +26,7 @@
 #include <linux/mm.h>
 #include <linux/init.h>
 #include <linux/platform_device.h>
-#include <linux/bootmem.h>
+#include <linux/memblock.h>
 #include <linux/io.h>
 #include <linux/omapfb.h>
 
@@ -171,49 +171,78 @@ static int check_fbmem_region(int region_idx, struct omapfb_mem_region *rg,
        return 0;
 }
 
+static int valid_sdram(unsigned long addr, unsigned long size)
+{
+       struct memblock_property res;
+
+       res.base = addr;
+       res.size = size;
+       return !memblock_find(&res) && res.base == addr && res.size == size;
+}
+
+static int reserve_sdram(unsigned long addr, unsigned long size)
+{
+       if (memblock_is_region_reserved(addr, size))
+               return -EBUSY;
+       if (memblock_reserve(addr, size))
+               return -ENOMEM;
+       return 0;
+}
+
 /*
  * Called from map_io. We need to call to this early enough so that we
  * can reserve the fixed SDRAM regions before VM could get hold of them.
  */
-void __init omapfb_reserve_sdram(void)
+void __init omapfb_reserve_sdram_memblock(void)
 {
-       struct bootmem_data     *bdata;
-       unsigned long           sdram_start, sdram_size;
-       unsigned long           reserved;
-       int                     i;
+       unsigned long reserved = 0;
+       int i;
 
        if (config_invalid)
                return;
 
-       bdata = NODE_DATA(0)->bdata;
-       sdram_start = bdata->node_min_pfn << PAGE_SHIFT;
-       sdram_size = (bdata->node_low_pfn << PAGE_SHIFT) - sdram_start;
-       reserved = 0;
        for (i = 0; ; i++) {
-               struct omapfb_mem_region        rg;
+               struct omapfb_mem_region rg;
 
                if (get_fbmem_region(i, &rg) < 0)
                        break;
+
                if (i == OMAPFB_PLANE_NUM) {
-                       printk(KERN_ERR
-                               "Extraneous FB mem configuration entries\n");
+                       pr_err("Extraneous FB mem configuration entries\n");
                        config_invalid = 1;
                        return;
                }
+
                /* Check if it's our memory type. */
-               if (set_fbmem_region_type(&rg, OMAPFB_MEMTYPE_SDRAM,
-                                         sdram_start, sdram_size) < 0 ||
-                   (rg.type != OMAPFB_MEMTYPE_SDRAM))
+               if (rg.type != OMAPFB_MEMTYPE_SDRAM)
                        continue;
-               BUG_ON(omapfb_config.mem_desc.region[i].size);
-               if (check_fbmem_region(i, &rg, sdram_start, sdram_size) < 0) {
+
+               /* Check if the region falls within SDRAM */
+               if (rg.paddr && !valid_sdram(rg.paddr, rg.size))
+                       continue;
+
+               if (rg.size == 0) {
+                       pr_err("Zero size for FB region %d\n", i);
                        config_invalid = 1;
                        return;
                }
+
                if (rg.paddr) {
-                       reserve_bootmem(rg.paddr, rg.size, BOOTMEM_DEFAULT);
+                       if (reserve_sdram(rg.paddr, rg.size)) {
+                               pr_err("Trying to use reserved memory for FB region %d\n",
+                                       i);
+                               config_invalid = 1;
+                               return;
+                       }
                        reserved += rg.size;
                }
+
+               if (omapfb_config.mem_desc.region[i].size) {
+                       pr_err("FB region %d already set\n", i);
+                       config_invalid = 1;
+                       return;
+               }
+
                omapfb_config.mem_desc.region[i] = rg;
                configured_regions++;
        }
@@ -359,7 +388,10 @@ static inline int omap_init_fb(void)
 
 arch_initcall(omap_init_fb);
 
-void omapfb_reserve_sdram(void) {}
+void omapfb_reserve_sdram_memblock(void)
+{
+}
+
 unsigned long omapfb_reserve_sram(unsigned long sram_pstart,
                                  unsigned long sram_vstart,
                                  unsigned long sram_size,
@@ -375,7 +407,10 @@ void omapfb_set_platform_data(struct omapfb_platform_data *data)
 {
 }
 
-void omapfb_reserve_sdram(void) {}
+void omapfb_reserve_sdram_memblock(void)
+{
+}
+
 unsigned long omapfb_reserve_sram(unsigned long sram_pstart,
                                  unsigned long sram_vstart,
                                  unsigned long sram_size,
index d265018f5e6b729a146a351388f3213dc8c72472..5e4afbee0fd7812e2fe907b67fb7abaab0fb34fa 100644 (file)
@@ -34,6 +34,8 @@ struct sys_timer;
 extern void omap_map_common_io(void);
 extern struct sys_timer omap_timer;
 
+extern void omap_reserve(void);
+
 /*
  * IO bases for various OMAP processors
  * Except the tap base, rest all the io bases
index edd4987758a64db91d606a26806593ae2a48d698..0aa4ecd12c7d5768f74efa2d4e7977f729e2338d 100644 (file)
@@ -38,7 +38,7 @@ extern void omap_vram_get_info(unsigned long *vram, unsigned long *free_vram,
 extern void omap_vram_set_sdram_vram(u32 size, u32 start);
 extern void omap_vram_set_sram_vram(u32 size, u32 start);
 
-extern void omap_vram_reserve_sdram(void);
+extern void omap_vram_reserve_sdram_memblock(void);
 extern unsigned long omap_vram_reserve_sram(unsigned long sram_pstart,
                                            unsigned long sram_vstart,
                                            unsigned long sram_size,
@@ -48,7 +48,7 @@ extern unsigned long omap_vram_reserve_sram(unsigned long sram_pstart,
 static inline void omap_vram_set_sdram_vram(u32 size, u32 start) { }
 static inline void omap_vram_set_sram_vram(u32 size, u32 start) { }
 
-static inline void omap_vram_reserve_sdram(void) { }
+static inline void omap_vram_reserve_sdram_memblock(void) { }
 static inline unsigned long omap_vram_reserve_sram(unsigned long sram_pstart,
                                            unsigned long sram_vstart,
                                            unsigned long sram_size,
index 54c84a492a0f0ab95de7ffa1590e0c5cf5259dc1..779553a1595e938ead6a4764e84ee8d87087acb9 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/mbus.h>
 #include <asm/mach/pci.h>
 #include <plat/pcie.h>
+#include <linux/delay.h>
 
 /*
  * PCIe unit register offsets.
@@ -46,6 +47,8 @@
 #define  PCIE_STAT_BUS_OFFS            8
 #define  PCIE_STAT_BUS_MASK            0xff
 #define  PCIE_STAT_LINK_DOWN           1
+#define PCIE_DEBUG_CTRL         0x1a60
+#define  PCIE_DEBUG_SOFT_RESET         (1<<20)
 
 
 u32 __init orion_pcie_dev_id(void __iomem *base)
@@ -85,6 +88,32 @@ void __init orion_pcie_set_local_bus_nr(void __iomem *base, int nr)
        writel(stat, base + PCIE_STAT_OFF);
 }
 
+void __init orion_pcie_reset(void __iomem *base)
+{
+       u32 reg;
+       int i;
+
+       /*
+        * MV-S104860-U0, Rev. C:
+        * PCI Express Unit Soft Reset
+        * When set, generates an internal reset in the PCI Express unit.
+        * This bit should be cleared after the link is re-established.
+        */
+       reg = readl(base + PCIE_DEBUG_CTRL);
+       reg |= PCIE_DEBUG_SOFT_RESET;
+       writel(reg, base + PCIE_DEBUG_CTRL);
+
+       for (i = 0; i < 20; i++) {
+               mdelay(10);
+
+               if (orion_pcie_link_up(base))
+                       break;
+       }
+
+       reg &= ~(PCIE_DEBUG_SOFT_RESET);
+       writel(reg, base + PCIE_DEBUG_CTRL);
+}
+
 /*
  * Setup PCIE BARs and Address Decode Wins:
  * BAR[0,2] -> disabled, BAR[1] -> covers all DRAM banks
@@ -152,6 +181,11 @@ void __init orion_pcie_setup(void __iomem *base,
        u16 cmd;
        u32 mask;
 
+       /*
+        * soft reset PCIe unit
+        */
+       orion_pcie_reset(base);
+
        /*
         * Point PCIe unit MBUS decode windows to DRAM space.
         */
index a1025d38f38370ddcb769898cf3854bdab2bbe29..ab211652e4ca79d3e814bc9967cdace8d10edf7c 100644 (file)
 
 #define INT_STATUS             0x1
 
+/*
+ * Minimum clocksource/clockevent timer range in seconds
+ */
+#define SPEAR_MIN_RANGE 4
+
 static __iomem void *gpt_base;
 static struct clk *gpt_clk;
 
@@ -66,44 +71,6 @@ static void clockevent_set_mode(enum clock_event_mode mode,
 static int clockevent_next_event(unsigned long evt,
                                 struct clock_event_device *clk_event_dev);
 
-/*
- * Following clocksource_set_clock and clockevent_set_clock picked
- * from arch/mips/kernel/time.c
- */
-
-void __init clocksource_set_clock(struct clocksource *cs, unsigned int clock)
-{
-       u64 temp;
-       u32 shift;
-
-       /* Find a shift value */
-       for (shift = 32; shift > 0; shift--) {
-               temp = (u64) NSEC_PER_SEC << shift;
-               do_div(temp, clock);
-               if ((temp >> 32) == 0)
-                       break;
-       }
-       cs->shift = shift;
-       cs->mult = (u32) temp;
-}
-
-void __init clockevent_set_clock(struct clock_event_device *cd,
-       unsigned int clock)
-{
-       u64 temp;
-       u32 shift;
-
-       /* Find a shift value */
-       for (shift = 32; shift > 0; shift--) {
-               temp = (u64) clock << shift;
-               do_div(temp, NSEC_PER_SEC);
-               if ((temp >> 32) == 0)
-                       break;
-       }
-       cd->shift = shift;
-       cd->mult = (u32) temp;
-}
-
 static cycle_t clocksource_read_cycles(struct clocksource *cs)
 {
        return (cycle_t) readw(gpt_base + COUNT(CLKSRC));
@@ -138,7 +105,7 @@ static void spear_clocksource_init(void)
        val |= CTRL_ENABLE ;
        writew(val, gpt_base + CR(CLKSRC));
 
-       clocksource_set_clock(&clksrc, tick_rate);
+       clocksource_calc_mult_shift(&clksrc, tick_rate, SPEAR_MIN_RANGE);
 
        /* register the clocksource */
        clocksource_register(&clksrc);
@@ -233,7 +200,7 @@ static void __init spear_clockevent_init(void)
        tick_rate = clk_get_rate(gpt_clk);
        tick_rate >>= CTRL_PRESCALER16;
 
-       clockevent_set_clock(&clkevt, tick_rate);
+       clockevents_calc_mult_shift(&clkevt, tick_rate, SPEAR_MIN_RANGE);
 
        clkevt.max_delta_ns = clockevent_delta2ns(0xfff0,
                        &clkevt);
index 9b1a66816aa652d97460bca5feafe5ec97069d61..5cf88e8427b15e66aafa287f1960e937a26fb89a 100644 (file)
@@ -2,3 +2,7 @@ obj-y   := clock.o
 obj-$(CONFIG_ARM_TIMER_SP804) += timer-sp.o
 obj-$(CONFIG_ARCH_REALVIEW) += sched-clock.o
 obj-$(CONFIG_ARCH_VERSATILE) += sched-clock.o
+ifeq ($(CONFIG_LEDS_CLASS),y)
+obj-$(CONFIG_ARCH_REALVIEW) += leds.o
+obj-$(CONFIG_ARCH_VERSATILE) += leds.o
+endif
diff --git a/arch/arm/plat-versatile/leds.c b/arch/arm/plat-versatile/leds.c
new file mode 100644 (file)
index 0000000..3169fa5
--- /dev/null
@@ -0,0 +1,103 @@
+/*
+ * Driver for the 8 user LEDs found on the RealViews and Versatiles
+ * Based on DaVinci's DM365 board code
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ * Author: Linus Walleij <triad@df.lth.se>
+ */
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/leds.h>
+
+#include <mach/hardware.h>
+#include <mach/platform.h>
+
+#ifdef VERSATILE_SYS_BASE
+#define LEDREG (__io_address(VERSATILE_SYS_BASE) + VERSATILE_SYS_LED_OFFSET)
+#endif
+
+#ifdef REALVIEW_SYS_BASE
+#define LEDREG (__io_address(REALVIEW_SYS_BASE) + REALVIEW_SYS_LED_OFFSET)
+#endif
+
+struct versatile_led {
+       struct led_classdev     cdev;
+       u8                      mask;
+};
+
+/*
+ * The triggers lines up below will only be used if the
+ * LED triggers are compiled in.
+ */
+static const struct {
+       const char *name;
+       const char *trigger;
+} versatile_leds[] = {
+       { "versatile:0", "heartbeat", },
+       { "versatile:1", "mmc0", },
+       { "versatile:2", },
+       { "versatile:3", },
+       { "versatile:4", },
+       { "versatile:5", },
+       { "versatile:6", },
+       { "versatile:7", },
+};
+
+static void versatile_led_set(struct led_classdev *cdev,
+                             enum led_brightness b)
+{
+       struct versatile_led *led = container_of(cdev,
+                                                struct versatile_led, cdev);
+       u32 reg = readl(LEDREG);
+
+       if (b != LED_OFF)
+               reg |= led->mask;
+       else
+               reg &= ~led->mask;
+       writel(reg, LEDREG);
+}
+
+static enum led_brightness versatile_led_get(struct led_classdev *cdev)
+{
+       struct versatile_led *led = container_of(cdev,
+                                                struct versatile_led, cdev);
+       u32 reg = readl(LEDREG);
+
+       return (reg & led->mask) ? LED_FULL : LED_OFF;
+}
+
+static int __init versatile_leds_init(void)
+{
+       int i;
+
+       /* All ON */
+       writel(0xff, LEDREG);
+       for (i = 0; i < ARRAY_SIZE(versatile_leds); i++) {
+               struct versatile_led *led;
+
+               led = kzalloc(sizeof(*led), GFP_KERNEL);
+               if (!led)
+                       break;
+
+               led->cdev.name = versatile_leds[i].name;
+               led->cdev.brightness_set = versatile_led_set;
+               led->cdev.brightness_get = versatile_led_get;
+               led->cdev.default_trigger = versatile_leds[i].trigger;
+               led->mask = BIT(i);
+
+               if (led_classdev_register(NULL, &led->cdev) < 0) {
+                       kfree(led);
+                       break;
+               }
+       }
+
+       return 0;
+}
+
+/*
+ * Since we may have triggers on any subsystem, defer registration
+ * until after subsystem_init.
+ */
+fs_initcall(versatile_leds_init);
index 315a540c7ce50370757320350ed07322d0f3bd86..8063a322c790dd80b3c6b0719541d9e937c2a2bc 100644 (file)
@@ -15,6 +15,7 @@
 #include <linux/sched.h>
 #include <linux/init.h>
 
+#include <asm/cputype.h>
 #include <asm/thread_notify.h>
 #include <asm/vfp.h>
 
@@ -549,10 +550,13 @@ static int __init vfp_init(void)
                /*
                 * Check for the presence of the Advanced SIMD
                 * load/store instructions, integer and single
-                * precision floating point operations.
+                * precision floating point operations. Only check
+                * for NEON if the hardware has the MVFR registers.
                 */
-               if ((fmrx(MVFR1) & 0x000fff00) == 0x00011100)
-                       elf_hwcap |= HWCAP_NEON;
+               if ((read_cpuid_id() & 0x000f0000) == 0x000f0000) {
+                       if ((fmrx(MVFR1) & 0x000fff00) == 0x00011100)
+                               elf_hwcap |= HWCAP_NEON;
+               }
 #endif
        }
        return 0;
index f60b2b6a0931d7d7279bfbfe7d29b3ac7ce6efea..d31590e7011bf895092535d15af5df6cc2e62df5 100644 (file)
@@ -122,6 +122,31 @@ static int __init amba_init(void)
 
 postcore_initcall(amba_init);
 
+static int amba_get_enable_pclk(struct amba_device *pcdev)
+{
+       struct clk *pclk = clk_get(&pcdev->dev, "apb_pclk");
+       int ret;
+
+       pcdev->pclk = pclk;
+
+       if (IS_ERR(pclk))
+               return PTR_ERR(pclk);
+
+       ret = clk_enable(pclk);
+       if (ret)
+               clk_put(pclk);
+
+       return ret;
+}
+
+static void amba_put_disable_pclk(struct amba_device *pcdev)
+{
+       struct clk *pclk = pcdev->pclk;
+
+       clk_disable(pclk);
+       clk_put(pclk);
+}
+
 /*
  * These are the device model conversion veneers; they convert the
  * device model structures to our more specific structures.
@@ -130,17 +155,33 @@ static int amba_probe(struct device *dev)
 {
        struct amba_device *pcdev = to_amba_device(dev);
        struct amba_driver *pcdrv = to_amba_driver(dev->driver);
-       struct amba_id *id;
+       struct amba_id *id = amba_lookup(pcdrv->id_table, pcdev);
+       int ret;
 
-       id = amba_lookup(pcdrv->id_table, pcdev);
+       do {
+               ret = amba_get_enable_pclk(pcdev);
+               if (ret)
+                       break;
+
+               ret = pcdrv->probe(pcdev, id);
+               if (ret == 0)
+                       break;
 
-       return pcdrv->probe(pcdev, id);
+               amba_put_disable_pclk(pcdev);
+       } while (0);
+
+       return ret;
 }
 
 static int amba_remove(struct device *dev)
 {
+       struct amba_device *pcdev = to_amba_device(dev);
        struct amba_driver *drv = to_amba_driver(dev->driver);
-       return drv->remove(to_amba_device(dev));
+       int ret = drv->remove(pcdev);
+
+       amba_put_disable_pclk(pcdev);
+
+       return ret;
 }
 
 static void amba_shutdown(struct device *dev)
@@ -203,7 +244,6 @@ static void amba_device_release(struct device *dev)
  */
 int amba_device_register(struct amba_device *dev, struct resource *parent)
 {
-       u32 pid, cid;
        u32 size;
        void __iomem *tmp;
        int i, ret;
@@ -241,25 +281,35 @@ int amba_device_register(struct amba_device *dev, struct resource *parent)
                goto err_release;
        }
 
-       /*
-        * Read pid and cid based on size of resource
-        * they are located at end of region
-        */
-       for (pid = 0, i = 0; i < 4; i++)
-               pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) << (i * 8);
-       for (cid = 0, i = 0; i < 4; i++)
-               cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) << (i * 8);
+       ret = amba_get_enable_pclk(dev);
+       if (ret == 0) {
+               u32 pid, cid;
 
-       iounmap(tmp);
+               /*
+                * Read pid and cid based on size of resource
+                * they are located at end of region
+                */
+               for (pid = 0, i = 0; i < 4; i++)
+                       pid |= (readl(tmp + size - 0x20 + 4 * i) & 255) <<
+                               (i * 8);
+               for (cid = 0, i = 0; i < 4; i++)
+                       cid |= (readl(tmp + size - 0x10 + 4 * i) & 255) <<
+                               (i * 8);
 
-       if (cid == 0xb105f00d)
-               dev->periphid = pid;
+               amba_put_disable_pclk(dev);
 
-       if (!dev->periphid) {
-               ret = -ENODEV;
-               goto err_release;
+               if (cid == 0xb105f00d)
+                       dev->periphid = pid;
+
+               if (!dev->periphid)
+                       ret = -ENODEV;
        }
 
+       iounmap(tmp);
+
+       if (ret)
+               goto err_release;
+
        ret = device_add(&dev->dev);
        if (ret)
                goto err_release;
index ee568c8fcbd01db804dc071be08a1da4b5ee6e87..5005990f751f44e142bbe7ec11869bc45efd9772 100644 (file)
@@ -232,7 +232,7 @@ static void pl061_irq_handler(unsigned irq, struct irq_desc *desc)
        desc->chip->unmask(irq);
 }
 
-static int __init pl061_probe(struct amba_device *dev, struct amba_id *id)
+static int pl061_probe(struct amba_device *dev, struct amba_id *id)
 {
        struct pl061_platform_data *pdata;
        struct pl061_gpio *chip;
@@ -333,7 +333,7 @@ free_mem:
        return ret;
 }
 
-static struct amba_id pl061_ids[] __initdata = {
+static struct amba_id pl061_ids[] = {
        {
                .id     = 0x00041061,
                .mask   = 0x000fffff,
index 81bf25e67ce1668b88a6af271c994dde5e25cbe5..e4112622e5a25e7eb90b615bcc93475bcfd054a7 100644 (file)
@@ -302,6 +302,15 @@ config LEDS_MC13783
          This option enable support for on-chip LED drivers found
          on Freescale Semiconductor MC13783 PMIC.
 
+config LEDS_NS2
+       tristate "LED support for Network Space v2 GPIO LEDs"
+       depends on MACH_NETSPACE_V2 || MACH_INETSPACE_V2 || MACH_NETSPACE_MAX_V2
+       default y
+       help
+         This option enable support for the dual-GPIO LED found on the
+         Network Space v2 board (and parents). This include Internet Space v2,
+         Network Space (Max) v2 and d2 Network v2 boards.
+
 config LEDS_TRIGGERS
        bool "LED Trigger support"
        help
index 2493de4993741d8f59b006292e75c97d245baf9a..7d6b95831f8eb5da86fad02ab6eedf680c437e3c 100644 (file)
@@ -37,6 +37,7 @@ obj-$(CONFIG_LEDS_LT3593)             += leds-lt3593.o
 obj-$(CONFIG_LEDS_ADP5520)             += leds-adp5520.o
 obj-$(CONFIG_LEDS_DELL_NETBOOKS)       += dell-led.o
 obj-$(CONFIG_LEDS_MC13783)             += leds-mc13783.o
+obj-$(CONFIG_LEDS_NS2)                 += leds-ns2.o
 
 # LED SPI Drivers
 obj-$(CONFIG_LEDS_DAC124S085)          += leds-dac124s085.o
diff --git a/drivers/leds/leds-ns2.c b/drivers/leds/leds-ns2.c
new file mode 100644 (file)
index 0000000..74dce4b
--- /dev/null
@@ -0,0 +1,338 @@
+/*
+ * leds-ns2.c - Driver for the Network Space v2 (and parents) dual-GPIO LED
+ *
+ * Copyright (C) 2010 LaCie
+ *
+ * Author: Simon Guinot <sguinot@lacie.com>
+ *
+ * Based on leds-gpio.c by Raphael Assenat <raph@8d.com>
+ *
+ * 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
+ */
+
+#include <linux/kernel.h>
+#include <linux/init.h>
+#include <linux/platform_device.h>
+#include <linux/slab.h>
+#include <linux/gpio.h>
+#include <linux/leds.h>
+#include <mach/leds-ns2.h>
+
+/*
+ * The Network Space v2 dual-GPIO LED is wired to a CPLD and can blink in
+ * relation with the SATA activity. This capability is exposed through the
+ * "sata" sysfs attribute.
+ *
+ * The following array detail the different LED registers and the combination
+ * of their possible values:
+ *
+ *  cmd_led   |  slow_led  | /SATA active | LED state
+ *            |            |              |
+ *     1      |     0      |      x       |  off
+ *     -      |     1      |      x       |  on
+ *     0      |     0      |      1       |  on
+ *     0      |     0      |      0       |  blink (rate 300ms)
+ */
+
+enum ns2_led_modes {
+       NS_V2_LED_OFF,
+       NS_V2_LED_ON,
+       NS_V2_LED_SATA,
+};
+
+struct ns2_led_mode_value {
+       enum ns2_led_modes      mode;
+       int                     cmd_level;
+       int                     slow_level;
+};
+
+static struct ns2_led_mode_value ns2_led_modval[] = {
+       { NS_V2_LED_OFF , 1, 0 },
+       { NS_V2_LED_ON  , 0, 1 },
+       { NS_V2_LED_ON  , 1, 1 },
+       { NS_V2_LED_SATA, 0, 0 },
+};
+
+struct ns2_led_data {
+       struct led_classdev     cdev;
+       unsigned                cmd;
+       unsigned                slow;
+       unsigned char           sata; /* True when SATA mode active. */
+       rwlock_t                rw_lock; /* Lock GPIOs. */
+};
+
+static int ns2_led_get_mode(struct ns2_led_data *led_dat,
+                           enum ns2_led_modes *mode)
+{
+       int i;
+       int ret = -EINVAL;
+       int cmd_level;
+       int slow_level;
+
+       read_lock(&led_dat->rw_lock);
+
+       cmd_level = gpio_get_value(led_dat->cmd);
+       slow_level = gpio_get_value(led_dat->slow);
+
+       for (i = 0; i < ARRAY_SIZE(ns2_led_modval); i++) {
+               if (cmd_level == ns2_led_modval[i].cmd_level &&
+                   slow_level == ns2_led_modval[i].slow_level) {
+                       *mode = ns2_led_modval[i].mode;
+                       ret = 0;
+                       break;
+               }
+       }
+
+       read_unlock(&led_dat->rw_lock);
+
+       return ret;
+}
+
+static void ns2_led_set_mode(struct ns2_led_data *led_dat,
+                            enum ns2_led_modes mode)
+{
+       int i;
+
+       write_lock(&led_dat->rw_lock);
+
+       for (i = 0; i < ARRAY_SIZE(ns2_led_modval); i++) {
+               if (mode == ns2_led_modval[i].mode) {
+                       gpio_set_value(led_dat->cmd,
+                                      ns2_led_modval[i].cmd_level);
+                       gpio_set_value(led_dat->slow,
+                                      ns2_led_modval[i].slow_level);
+               }
+       }
+
+       write_unlock(&led_dat->rw_lock);
+}
+
+static void ns2_led_set(struct led_classdev *led_cdev,
+                       enum led_brightness value)
+{
+       struct ns2_led_data *led_dat =
+               container_of(led_cdev, struct ns2_led_data, cdev);
+       enum ns2_led_modes mode;
+
+       if (value == LED_OFF)
+               mode = NS_V2_LED_OFF;
+       else if (led_dat->sata)
+               mode = NS_V2_LED_SATA;
+       else
+               mode = NS_V2_LED_ON;
+
+       ns2_led_set_mode(led_dat, mode);
+}
+
+static ssize_t ns2_led_sata_store(struct device *dev,
+                                 struct device_attribute *attr,
+                                 const char *buff, size_t count)
+{
+       int ret;
+       unsigned long enable;
+       enum ns2_led_modes mode;
+       struct ns2_led_data *led_dat = dev_get_drvdata(dev);
+
+       ret = strict_strtoul(buff, 10, &enable);
+       if (ret < 0)
+               return ret;
+
+       enable = !!enable;
+
+       if (led_dat->sata == enable)
+               return count;
+
+       ret = ns2_led_get_mode(led_dat, &mode);
+       if (ret < 0)
+               return ret;
+
+       if (enable && mode == NS_V2_LED_ON)
+               ns2_led_set_mode(led_dat, NS_V2_LED_SATA);
+       if (!enable && mode == NS_V2_LED_SATA)
+               ns2_led_set_mode(led_dat, NS_V2_LED_ON);
+
+       led_dat->sata = enable;
+
+       return count;
+}
+
+static ssize_t ns2_led_sata_show(struct device *dev,
+                                struct device_attribute *attr, char *buf)
+{
+       struct ns2_led_data *led_dat = dev_get_drvdata(dev);
+
+       return sprintf(buf, "%d\n", led_dat->sata);
+}
+
+static DEVICE_ATTR(sata, 0644, ns2_led_sata_show, ns2_led_sata_store);
+
+static int __devinit
+create_ns2_led(struct platform_device *pdev, struct ns2_led_data *led_dat,
+              const struct ns2_led *template)
+{
+       int ret;
+       enum ns2_led_modes mode;
+
+       ret = gpio_request(template->cmd, template->name);
+       if (ret == 0) {
+               ret = gpio_direction_output(template->cmd,
+                                           gpio_get_value(template->cmd));
+               if (ret)
+                       gpio_free(template->cmd);
+       }
+       if (ret) {
+               dev_err(&pdev->dev, "%s: failed to setup command GPIO\n",
+                       template->name);
+       }
+
+       ret = gpio_request(template->slow, template->name);
+       if (ret == 0) {
+               ret = gpio_direction_output(template->slow,
+                                           gpio_get_value(template->slow));
+               if (ret)
+                       gpio_free(template->slow);
+       }
+       if (ret) {
+               dev_err(&pdev->dev, "%s: failed to setup slow GPIO\n",
+                       template->name);
+               goto err_free_cmd;
+       }
+
+       rwlock_init(&led_dat->rw_lock);
+
+       led_dat->cdev.name = template->name;
+       led_dat->cdev.default_trigger = template->default_trigger;
+       led_dat->cdev.blink_set = NULL;
+       led_dat->cdev.brightness_set = ns2_led_set;
+       led_dat->cdev.flags |= LED_CORE_SUSPENDRESUME;
+       led_dat->cmd = template->cmd;
+       led_dat->slow = template->slow;
+
+       ret = ns2_led_get_mode(led_dat, &mode);
+       if (ret < 0)
+               goto err_free_slow;
+
+       /* Set LED initial state. */
+       led_dat->sata = (mode == NS_V2_LED_SATA) ? 1 : 0;
+       led_dat->cdev.brightness =
+               (mode == NS_V2_LED_OFF) ? LED_OFF : LED_FULL;
+
+       ret = led_classdev_register(&pdev->dev, &led_dat->cdev);
+       if (ret < 0)
+               goto err_free_slow;
+
+       dev_set_drvdata(led_dat->cdev.dev, led_dat);
+       ret = device_create_file(led_dat->cdev.dev, &dev_attr_sata);
+       if (ret < 0)
+               goto err_free_cdev;
+
+       return 0;
+
+err_free_cdev:
+       led_classdev_unregister(&led_dat->cdev);
+err_free_slow:
+       gpio_free(led_dat->slow);
+err_free_cmd:
+       gpio_free(led_dat->cmd);
+
+       return ret;
+}
+
+static void __devexit delete_ns2_led(struct ns2_led_data *led_dat)
+{
+       device_remove_file(led_dat->cdev.dev, &dev_attr_sata);
+       led_classdev_unregister(&led_dat->cdev);
+       gpio_free(led_dat->cmd);
+       gpio_free(led_dat->slow);
+}
+
+static int __devinit ns2_led_probe(struct platform_device *pdev)
+{
+       struct ns2_led_platform_data *pdata = pdev->dev.platform_data;
+       struct ns2_led_data *leds_data;
+       int i;
+       int ret;
+
+       if (!pdata)
+               return -EINVAL;
+
+       leds_data = kzalloc(sizeof(struct ns2_led_data) *
+                           pdata->num_leds, GFP_KERNEL);
+       if (!leds_data)
+               return -ENOMEM;
+
+       for (i = 0; i < pdata->num_leds; i++) {
+               ret = create_ns2_led(pdev, &leds_data[i], &pdata->leds[i]);
+               if (ret < 0)
+                       goto err;
+
+       }
+
+       platform_set_drvdata(pdev, leds_data);
+
+       return 0;
+
+err:
+       for (i = i - 1; i >= 0; i--)
+               delete_ns2_led(&leds_data[i]);
+
+       kfree(leds_data);
+
+       return ret;
+}
+
+static int __devexit ns2_led_remove(struct platform_device *pdev)
+{
+       int i;
+       struct ns2_led_platform_data *pdata = pdev->dev.platform_data;
+       struct ns2_led_data *leds_data;
+
+       leds_data = platform_get_drvdata(pdev);
+
+       for (i = 0; i < pdata->num_leds; i++)
+               delete_ns2_led(&leds_data[i]);
+
+       kfree(leds_data);
+       platform_set_drvdata(pdev, NULL);
+
+       return 0;
+}
+
+static struct platform_driver ns2_led_driver = {
+       .probe          = ns2_led_probe,
+       .remove         = __devexit_p(ns2_led_remove),
+       .driver         = {
+               .name   = "leds-ns2",
+               .owner  = THIS_MODULE,
+       },
+};
+MODULE_ALIAS("platform:leds-ns2");
+
+static int __init ns2_led_init(void)
+{
+       return platform_driver_register(&ns2_led_driver);
+}
+
+static void __exit ns2_led_exit(void)
+{
+       platform_driver_unregister(&ns2_led_driver);
+}
+
+module_init(ns2_led_init);
+module_exit(ns2_led_exit);
+
+MODULE_AUTHOR("Simon Guinot <sguinot@lacie.com>");
+MODULE_DESCRIPTION("Network Space v2 LED driver");
+MODULE_LICENSE("GPL");
index 0f1ac401dedd9a9172cc7d961b872d869fff8fbd..2e15903b976d79064b53a22e3cbc4210a7fb55cf 100644 (file)
@@ -896,6 +896,19 @@ config VIDEO_OMAP2
        ---help---
          This is a v4l2 driver for the TI OMAP2 camera capture interface
 
+config VIDEO_MX2_HOSTSUPPORT
+        bool
+
+config VIDEO_MX2
+       tristate "i.MX27/i.MX25 Camera Sensor Interface driver"
+       depends on VIDEO_DEV && SOC_CAMERA && (MACH_MX27 || ARCH_MX25)
+       select VIDEOBUF_DMA_CONTIG
+       select VIDEO_MX2_HOSTSUPPORT
+       ---help---
+         This is a v4l2 driver for the i.MX27 and the i.MX25 Camera Sensor
+         Interface
+
+
 #
 # USB Multimedia device configuration
 #
index 88478630e854bca10177ab8b1e2a4d592f6ebcba..1051ecc602e74c07bde2e4abb55c70ca414c5494 100644 (file)
@@ -158,6 +158,7 @@ obj-$(CONFIG_SOC_CAMERA)            += soc_camera.o soc_mediabus.o
 obj-$(CONFIG_SOC_CAMERA_PLATFORM)      += soc_camera_platform.o
 # soc-camera host drivers have to be linked after camera drivers
 obj-$(CONFIG_VIDEO_MX1)                        += mx1_camera.o
+obj-$(CONFIG_VIDEO_MX2)                        += mx2_camera.o
 obj-$(CONFIG_VIDEO_MX3)                        += mx3_camera.o
 obj-$(CONFIG_VIDEO_PXA27x)             += pxa_camera.o
 obj-$(CONFIG_VIDEO_SH_MOBILE_CSI2)     += sh_mobile_csi2.o
diff --git a/drivers/media/video/mx2_camera.c b/drivers/media/video/mx2_camera.c
new file mode 100644 (file)
index 0000000..026bef0
--- /dev/null
@@ -0,0 +1,1513 @@
+/*
+ * V4L2 Driver for i.MX27/i.MX25 camera host
+ *
+ * Copyright (C) 2008, Sascha Hauer, Pengutronix
+ * Copyright (C) 2010, Baruch Siach, Orex Computed Radiography
+ *
+ * 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 <linux/init.h>
+#include <linux/module.h>
+#include <linux/io.h>
+#include <linux/delay.h>
+#include <linux/slab.h>
+#include <linux/dma-mapping.h>
+#include <linux/errno.h>
+#include <linux/fs.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/moduleparam.h>
+#include <linux/time.h>
+#include <linux/version.h>
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/mutex.h>
+#include <linux/clk.h>
+
+#include <media/v4l2-common.h>
+#include <media/v4l2-dev.h>
+#include <media/videobuf-dma-contig.h>
+#include <media/soc_camera.h>
+#include <media/soc_mediabus.h>
+
+#include <linux/videodev2.h>
+
+#include <mach/mx2_cam.h>
+#ifdef CONFIG_MACH_MX27
+#include <mach/dma-mx1-mx2.h>
+#endif
+#include <mach/hardware.h>
+
+#include <asm/dma.h>
+
+#define MX2_CAM_DRV_NAME "mx2-camera"
+#define MX2_CAM_VERSION_CODE KERNEL_VERSION(0, 0, 5)
+#define MX2_CAM_DRIVER_DESCRIPTION "i.MX2x_Camera"
+
+/* reset values */
+#define CSICR1_RESET_VAL       0x40000800
+#define CSICR2_RESET_VAL       0x0
+#define CSICR3_RESET_VAL       0x0
+
+/* csi control reg 1 */
+#define CSICR1_SWAP16_EN       (1 << 31)
+#define CSICR1_EXT_VSYNC       (1 << 30)
+#define CSICR1_EOF_INTEN       (1 << 29)
+#define CSICR1_PRP_IF_EN       (1 << 28)
+#define CSICR1_CCIR_MODE       (1 << 27)
+#define CSICR1_COF_INTEN       (1 << 26)
+#define CSICR1_SF_OR_INTEN     (1 << 25)
+#define CSICR1_RF_OR_INTEN     (1 << 24)
+#define CSICR1_STATFF_LEVEL    (3 << 22)
+#define CSICR1_STATFF_INTEN    (1 << 21)
+#define CSICR1_RXFF_LEVEL(l)   (((l) & 3) << 19)       /* MX27 */
+#define CSICR1_FB2_DMA_INTEN   (1 << 20)               /* MX25 */
+#define CSICR1_FB1_DMA_INTEN   (1 << 19)               /* MX25 */
+#define CSICR1_RXFF_INTEN      (1 << 18)
+#define CSICR1_SOF_POL         (1 << 17)
+#define CSICR1_SOF_INTEN       (1 << 16)
+#define CSICR1_MCLKDIV(d)      (((d) & 0xF) << 12)
+#define CSICR1_HSYNC_POL       (1 << 11)
+#define CSICR1_CCIR_EN         (1 << 10)
+#define CSICR1_MCLKEN          (1 << 9)
+#define CSICR1_FCC             (1 << 8)
+#define CSICR1_PACK_DIR                (1 << 7)
+#define CSICR1_CLR_STATFIFO    (1 << 6)
+#define CSICR1_CLR_RXFIFO      (1 << 5)
+#define CSICR1_GCLK_MODE       (1 << 4)
+#define CSICR1_INV_DATA                (1 << 3)
+#define CSICR1_INV_PCLK                (1 << 2)
+#define CSICR1_REDGE           (1 << 1)
+
+#define SHIFT_STATFF_LEVEL     22
+#define SHIFT_RXFF_LEVEL       19
+#define SHIFT_MCLKDIV          12
+
+/* control reg 3 */
+#define CSICR3_FRMCNT          (0xFFFF << 16)
+#define CSICR3_FRMCNT_RST      (1 << 15)
+#define CSICR3_DMA_REFLASH_RFF (1 << 14)
+#define CSICR3_DMA_REFLASH_SFF (1 << 13)
+#define CSICR3_DMA_REQ_EN_RFF  (1 << 12)
+#define CSICR3_DMA_REQ_EN_SFF  (1 << 11)
+#define CSICR3_RXFF_LEVEL(l)   (((l) & 7) << 4)        /* MX25 */
+#define CSICR3_CSI_SUP         (1 << 3)
+#define CSICR3_ZERO_PACK_EN    (1 << 2)
+#define CSICR3_ECC_INT_EN      (1 << 1)
+#define CSICR3_ECC_AUTO_EN     (1 << 0)
+
+#define SHIFT_FRMCNT           16
+
+/* csi status reg */
+#define CSISR_SFF_OR_INT       (1 << 25)
+#define CSISR_RFF_OR_INT       (1 << 24)
+#define CSISR_STATFF_INT       (1 << 21)
+#define CSISR_DMA_TSF_FB2_INT  (1 << 20)       /* MX25 */
+#define CSISR_DMA_TSF_FB1_INT  (1 << 19)       /* MX25 */
+#define CSISR_RXFF_INT         (1 << 18)
+#define CSISR_EOF_INT          (1 << 17)
+#define CSISR_SOF_INT          (1 << 16)
+#define CSISR_F2_INT           (1 << 15)
+#define CSISR_F1_INT           (1 << 14)
+#define CSISR_COF_INT          (1 << 13)
+#define CSISR_ECC_INT          (1 << 1)
+#define CSISR_DRDY             (1 << 0)
+
+#define CSICR1                 0x00
+#define CSICR2                 0x04
+#define CSISR                  (cpu_is_mx27() ? 0x08 : 0x18)
+#define CSISTATFIFO            0x0c
+#define CSIRFIFO               0x10
+#define CSIRXCNT               0x14
+#define CSICR3                 (cpu_is_mx27() ? 0x1C : 0x08)
+#define CSIDMASA_STATFIFO      0x20
+#define CSIDMATA_STATFIFO      0x24
+#define CSIDMASA_FB1           0x28
+#define CSIDMASA_FB2           0x2c
+#define CSIFBUF_PARA           0x30
+#define CSIIMAG_PARA           0x34
+
+/* EMMA PrP */
+#define PRP_CNTL                       0x00
+#define PRP_INTR_CNTL                  0x04
+#define PRP_INTRSTATUS                 0x08
+#define PRP_SOURCE_Y_PTR               0x0c
+#define PRP_SOURCE_CB_PTR              0x10
+#define PRP_SOURCE_CR_PTR              0x14
+#define PRP_DEST_RGB1_PTR              0x18
+#define PRP_DEST_RGB2_PTR              0x1c
+#define PRP_DEST_Y_PTR                 0x20
+#define PRP_DEST_CB_PTR                        0x24
+#define PRP_DEST_CR_PTR                        0x28
+#define PRP_SRC_FRAME_SIZE             0x2c
+#define PRP_DEST_CH1_LINE_STRIDE       0x30
+#define PRP_SRC_PIXEL_FORMAT_CNTL      0x34
+#define PRP_CH1_PIXEL_FORMAT_CNTL      0x38
+#define PRP_CH1_OUT_IMAGE_SIZE         0x3c
+#define PRP_CH2_OUT_IMAGE_SIZE         0x40
+#define PRP_SRC_LINE_STRIDE            0x44
+#define PRP_CSC_COEF_012               0x48
+#define PRP_CSC_COEF_345               0x4c
+#define PRP_CSC_COEF_678               0x50
+#define PRP_CH1_RZ_HORI_COEF1          0x54
+#define PRP_CH1_RZ_HORI_COEF2          0x58
+#define PRP_CH1_RZ_HORI_VALID          0x5c
+#define PRP_CH1_RZ_VERT_COEF1          0x60
+#define PRP_CH1_RZ_VERT_COEF2          0x64
+#define PRP_CH1_RZ_VERT_VALID          0x68
+#define PRP_CH2_RZ_HORI_COEF1          0x6c
+#define PRP_CH2_RZ_HORI_COEF2          0x70
+#define PRP_CH2_RZ_HORI_VALID          0x74
+#define PRP_CH2_RZ_VERT_COEF1          0x78
+#define PRP_CH2_RZ_VERT_COEF2          0x7c
+#define PRP_CH2_RZ_VERT_VALID          0x80
+
+#define PRP_CNTL_CH1EN         (1 << 0)
+#define PRP_CNTL_CH2EN         (1 << 1)
+#define PRP_CNTL_CSIEN         (1 << 2)
+#define PRP_CNTL_DATA_IN_YUV420        (0 << 3)
+#define PRP_CNTL_DATA_IN_YUV422        (1 << 3)
+#define PRP_CNTL_DATA_IN_RGB16 (2 << 3)
+#define PRP_CNTL_DATA_IN_RGB32 (3 << 3)
+#define PRP_CNTL_CH1_OUT_RGB8  (0 << 5)
+#define PRP_CNTL_CH1_OUT_RGB16 (1 << 5)
+#define PRP_CNTL_CH1_OUT_RGB32 (2 << 5)
+#define PRP_CNTL_CH1_OUT_YUV422        (3 << 5)
+#define PRP_CNTL_CH2_OUT_YUV420        (0 << 7)
+#define PRP_CNTL_CH2_OUT_YUV422 (1 << 7)
+#define PRP_CNTL_CH2_OUT_YUV444        (2 << 7)
+#define PRP_CNTL_CH1_LEN       (1 << 9)
+#define PRP_CNTL_CH2_LEN       (1 << 10)
+#define PRP_CNTL_SKIP_FRAME    (1 << 11)
+#define PRP_CNTL_SWRST         (1 << 12)
+#define PRP_CNTL_CLKEN         (1 << 13)
+#define PRP_CNTL_WEN           (1 << 14)
+#define PRP_CNTL_CH1BYP                (1 << 15)
+#define PRP_CNTL_IN_TSKIP(x)   ((x) << 16)
+#define PRP_CNTL_CH1_TSKIP(x)  ((x) << 19)
+#define PRP_CNTL_CH2_TSKIP(x)  ((x) << 22)
+#define PRP_CNTL_INPUT_FIFO_LEVEL(x)   ((x) << 25)
+#define PRP_CNTL_RZ_FIFO_LEVEL(x)      ((x) << 27)
+#define PRP_CNTL_CH2B1EN       (1 << 29)
+#define PRP_CNTL_CH2B2EN       (1 << 30)
+#define PRP_CNTL_CH2FEN                (1 << 31)
+
+/* IRQ Enable and status register */
+#define PRP_INTR_RDERR         (1 << 0)
+#define PRP_INTR_CH1WERR       (1 << 1)
+#define PRP_INTR_CH2WERR       (1 << 2)
+#define PRP_INTR_CH1FC         (1 << 3)
+#define PRP_INTR_CH2FC         (1 << 5)
+#define PRP_INTR_LBOVF         (1 << 7)
+#define PRP_INTR_CH2OVF                (1 << 8)
+
+#define mx27_camera_emma(pcdev)        (cpu_is_mx27() && pcdev->use_emma)
+
+#define MAX_VIDEO_MEM  16
+
+struct mx2_camera_dev {
+       struct device           *dev;
+       struct soc_camera_host  soc_host;
+       struct soc_camera_device *icd;
+       struct clk              *clk_csi, *clk_emma;
+
+       unsigned int            irq_csi, irq_emma;
+       void __iomem            *base_csi, *base_emma;
+       unsigned long           base_dma;
+
+       struct mx2_camera_platform_data *pdata;
+       struct resource         *res_csi, *res_emma;
+       unsigned long           platform_flags;
+
+       struct list_head        capture;
+       struct list_head        active_bufs;
+
+       spinlock_t              lock;
+
+       int                     dma;
+       struct mx2_buffer       *active;
+       struct mx2_buffer       *fb1_active;
+       struct mx2_buffer       *fb2_active;
+
+       int                     use_emma;
+
+       u32                     csicr1;
+
+       void                    *discard_buffer;
+       dma_addr_t              discard_buffer_dma;
+       size_t                  discard_size;
+};
+
+/* buffer for one video frame */
+struct mx2_buffer {
+       /* common v4l buffer stuff -- must be first */
+       struct videobuf_buffer          vb;
+
+       enum v4l2_mbus_pixelcode        code;
+
+       int bufnum;
+};
+
+static void mx2_camera_deactivate(struct mx2_camera_dev *pcdev)
+{
+       unsigned long flags;
+
+       clk_disable(pcdev->clk_csi);
+       writel(0, pcdev->base_csi + CSICR1);
+       if (mx27_camera_emma(pcdev)) {
+               writel(0, pcdev->base_emma + PRP_CNTL);
+       } else if (cpu_is_mx25()) {
+               spin_lock_irqsave(&pcdev->lock, flags);
+               pcdev->fb1_active = NULL;
+               pcdev->fb2_active = NULL;
+               writel(0, pcdev->base_csi + CSIDMASA_FB1);
+               writel(0, pcdev->base_csi + CSIDMASA_FB2);
+               spin_unlock_irqrestore(&pcdev->lock, flags);
+       }
+}
+
+/*
+ * The following two functions absolutely depend on the fact, that
+ * there can be only one camera on mx2 camera sensor interface
+ */
+static int mx2_camera_add_device(struct soc_camera_device *icd)
+{
+       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct mx2_camera_dev *pcdev = ici->priv;
+       int ret;
+       u32 csicr1;
+
+       if (pcdev->icd)
+               return -EBUSY;
+
+       ret = clk_enable(pcdev->clk_csi);
+       if (ret < 0)
+               return ret;
+
+       csicr1 = CSICR1_MCLKEN;
+
+       if (mx27_camera_emma(pcdev)) {
+               csicr1 |= CSICR1_PRP_IF_EN | CSICR1_FCC |
+                       CSICR1_RXFF_LEVEL(0);
+       } else if (cpu_is_mx27())
+               csicr1 |= CSICR1_SOF_INTEN | CSICR1_RXFF_LEVEL(2);
+
+       pcdev->csicr1 = csicr1;
+       writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
+
+       pcdev->icd = icd;
+
+       dev_info(icd->dev.parent, "Camera driver attached to camera %d\n",
+                icd->devnum);
+
+       return 0;
+}
+
+static void mx2_camera_remove_device(struct soc_camera_device *icd)
+{
+       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct mx2_camera_dev *pcdev = ici->priv;
+
+       BUG_ON(icd != pcdev->icd);
+
+       dev_info(icd->dev.parent, "Camera driver detached from camera %d\n",
+                icd->devnum);
+
+       mx2_camera_deactivate(pcdev);
+
+       if (pcdev->discard_buffer) {
+               dma_free_coherent(ici->v4l2_dev.dev, pcdev->discard_size,
+                               pcdev->discard_buffer,
+                               pcdev->discard_buffer_dma);
+               pcdev->discard_buffer = NULL;
+       }
+
+       pcdev->icd = NULL;
+}
+
+#ifdef CONFIG_MACH_MX27
+static void mx27_camera_dma_enable(struct mx2_camera_dev *pcdev)
+{
+       u32 tmp;
+
+       imx_dma_enable(pcdev->dma);
+
+       tmp = readl(pcdev->base_csi + CSICR1);
+       tmp |= CSICR1_RF_OR_INTEN;
+       writel(tmp, pcdev->base_csi + CSICR1);
+}
+
+static irqreturn_t mx27_camera_irq(int irq_csi, void *data)
+{
+       struct mx2_camera_dev *pcdev = data;
+       u32 status = readl(pcdev->base_csi + CSISR);
+
+       if (status & CSISR_SOF_INT && pcdev->active) {
+               u32 tmp;
+
+               tmp = readl(pcdev->base_csi + CSICR1);
+               writel(tmp | CSICR1_CLR_RXFIFO, pcdev->base_csi + CSICR1);
+               mx27_camera_dma_enable(pcdev);
+       }
+
+       writel(CSISR_SOF_INT | CSISR_RFF_OR_INT, pcdev->base_csi + CSISR);
+
+       return IRQ_HANDLED;
+}
+#else
+static irqreturn_t mx27_camera_irq(int irq_csi, void *data)
+{
+       return IRQ_NONE;
+}
+#endif /* CONFIG_MACH_MX27 */
+
+static void mx25_camera_frame_done(struct mx2_camera_dev *pcdev, int fb,
+               int state)
+{
+       struct videobuf_buffer *vb;
+       struct mx2_buffer *buf;
+       struct mx2_buffer **fb_active = fb == 1 ? &pcdev->fb1_active :
+               &pcdev->fb2_active;
+       u32 fb_reg = fb == 1 ? CSIDMASA_FB1 : CSIDMASA_FB2;
+       unsigned long flags;
+
+       spin_lock_irqsave(&pcdev->lock, flags);
+
+       vb = &(*fb_active)->vb;
+       dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+               vb, vb->baddr, vb->bsize);
+
+       vb->state = state;
+       do_gettimeofday(&vb->ts);
+       vb->field_count++;
+
+       wake_up(&vb->done);
+
+       if (list_empty(&pcdev->capture)) {
+               buf = NULL;
+               writel(0, pcdev->base_csi + fb_reg);
+       } else {
+               buf = list_entry(pcdev->capture.next, struct mx2_buffer,
+                               vb.queue);
+               vb = &buf->vb;
+               list_del(&vb->queue);
+               vb->state = VIDEOBUF_ACTIVE;
+               writel(videobuf_to_dma_contig(vb), pcdev->base_csi + fb_reg);
+       }
+
+       *fb_active = buf;
+
+       spin_unlock_irqrestore(&pcdev->lock, flags);
+}
+
+static irqreturn_t mx25_camera_irq(int irq_csi, void *data)
+{
+       struct mx2_camera_dev *pcdev = data;
+       u32 status = readl(pcdev->base_csi + CSISR);
+
+       if (status & CSISR_DMA_TSF_FB1_INT)
+               mx25_camera_frame_done(pcdev, 1, VIDEOBUF_DONE);
+       else if (status & CSISR_DMA_TSF_FB2_INT)
+               mx25_camera_frame_done(pcdev, 2, VIDEOBUF_DONE);
+
+       /* FIXME: handle CSISR_RFF_OR_INT */
+
+       writel(status, pcdev->base_csi + CSISR);
+
+       return IRQ_HANDLED;
+}
+
+/*
+ *  Videobuf operations
+ */
+static int mx2_videobuf_setup(struct videobuf_queue *vq, unsigned int *count,
+                             unsigned int *size)
+{
+       struct soc_camera_device *icd = vq->priv_data;
+       int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
+                       icd->current_fmt->host_fmt);
+
+       dev_dbg(&icd->dev, "count=%d, size=%d\n", *count, *size);
+
+       if (bytes_per_line < 0)
+               return bytes_per_line;
+
+       *size = bytes_per_line * icd->user_height;
+
+       if (0 == *count)
+               *count = 32;
+       if (*size * *count > MAX_VIDEO_MEM * 1024 * 1024)
+               *count = (MAX_VIDEO_MEM * 1024 * 1024) / *size;
+
+       return 0;
+}
+
+static void free_buffer(struct videobuf_queue *vq, struct mx2_buffer *buf)
+{
+       struct soc_camera_device *icd = vq->priv_data;
+       struct videobuf_buffer *vb = &buf->vb;
+
+       dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+               vb, vb->baddr, vb->bsize);
+
+       /*
+        * This waits until this buffer is out of danger, i.e., until it is no
+        * longer in STATE_QUEUED or STATE_ACTIVE
+        */
+       videobuf_waiton(vb, 0, 0);
+
+       videobuf_dma_contig_free(vq, vb);
+       dev_dbg(&icd->dev, "%s freed\n", __func__);
+
+       vb->state = VIDEOBUF_NEEDS_INIT;
+}
+
+static int mx2_videobuf_prepare(struct videobuf_queue *vq,
+               struct videobuf_buffer *vb, enum v4l2_field field)
+{
+       struct soc_camera_device *icd = vq->priv_data;
+       struct mx2_buffer *buf = container_of(vb, struct mx2_buffer, vb);
+       int bytes_per_line = soc_mbus_bytes_per_line(icd->user_width,
+                       icd->current_fmt->host_fmt);
+       int ret = 0;
+
+       dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+               vb, vb->baddr, vb->bsize);
+
+       if (bytes_per_line < 0)
+               return bytes_per_line;
+
+#ifdef DEBUG
+       /*
+        * This can be useful if you want to see if we actually fill
+        * the buffer with something
+        */
+       memset((void *)vb->baddr, 0xaa, vb->bsize);
+#endif
+
+       if (buf->code   != icd->current_fmt->code ||
+           vb->width   != icd->user_width ||
+           vb->height  != icd->user_height ||
+           vb->field   != field) {
+               buf->code       = icd->current_fmt->code;
+               vb->width       = icd->user_width;
+               vb->height      = icd->user_height;
+               vb->field       = field;
+               vb->state       = VIDEOBUF_NEEDS_INIT;
+       }
+
+       vb->size = bytes_per_line * vb->height;
+       if (vb->baddr && vb->bsize < vb->size) {
+               ret = -EINVAL;
+               goto out;
+       }
+
+       if (vb->state == VIDEOBUF_NEEDS_INIT) {
+               ret = videobuf_iolock(vq, vb, NULL);
+               if (ret)
+                       goto fail;
+
+               vb->state = VIDEOBUF_PREPARED;
+       }
+
+       return 0;
+
+fail:
+       free_buffer(vq, buf);
+out:
+       return ret;
+}
+
+static void mx2_videobuf_queue(struct videobuf_queue *vq,
+                              struct videobuf_buffer *vb)
+{
+       struct soc_camera_device *icd = vq->priv_data;
+       struct soc_camera_host *ici =
+               to_soc_camera_host(icd->dev.parent);
+       struct mx2_camera_dev *pcdev = ici->priv;
+       struct mx2_buffer *buf = container_of(vb, struct mx2_buffer, vb);
+       unsigned long flags;
+
+       dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+               vb, vb->baddr, vb->bsize);
+
+       spin_lock_irqsave(&pcdev->lock, flags);
+
+       vb->state = VIDEOBUF_QUEUED;
+       list_add_tail(&vb->queue, &pcdev->capture);
+
+       if (mx27_camera_emma(pcdev)) {
+               goto out;
+#ifdef CONFIG_MACH_MX27
+       } else if (cpu_is_mx27()) {
+               int ret;
+
+               if (pcdev->active == NULL) {
+                       ret = imx_dma_setup_single(pcdev->dma,
+                                       videobuf_to_dma_contig(vb), vb->size,
+                                       (u32)pcdev->base_dma + 0x10,
+                                       DMA_MODE_READ);
+                       if (ret) {
+                               vb->state = VIDEOBUF_ERROR;
+                               wake_up(&vb->done);
+                               goto out;
+                       }
+
+                       vb->state = VIDEOBUF_ACTIVE;
+                       pcdev->active = buf;
+               }
+#endif
+       } else { /* cpu_is_mx25() */
+               u32 csicr3, dma_inten = 0;
+
+               if (pcdev->fb1_active == NULL) {
+                       writel(videobuf_to_dma_contig(vb),
+                                       pcdev->base_csi + CSIDMASA_FB1);
+                       pcdev->fb1_active = buf;
+                       dma_inten = CSICR1_FB1_DMA_INTEN;
+               } else if (pcdev->fb2_active == NULL) {
+                       writel(videobuf_to_dma_contig(vb),
+                                       pcdev->base_csi + CSIDMASA_FB2);
+                       pcdev->fb2_active = buf;
+                       dma_inten = CSICR1_FB2_DMA_INTEN;
+               }
+
+               if (dma_inten) {
+                       list_del(&vb->queue);
+                       vb->state = VIDEOBUF_ACTIVE;
+
+                       csicr3 = readl(pcdev->base_csi + CSICR3);
+
+                       /* Reflash DMA */
+                       writel(csicr3 | CSICR3_DMA_REFLASH_RFF,
+                                       pcdev->base_csi + CSICR3);
+
+                       /* clear & enable interrupts */
+                       writel(dma_inten, pcdev->base_csi + CSISR);
+                       pcdev->csicr1 |= dma_inten;
+                       writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
+
+                       /* enable DMA */
+                       csicr3 |= CSICR3_DMA_REQ_EN_RFF | CSICR3_RXFF_LEVEL(1);
+                       writel(csicr3, pcdev->base_csi + CSICR3);
+               }
+       }
+
+out:
+       spin_unlock_irqrestore(&pcdev->lock, flags);
+}
+
+static void mx2_videobuf_release(struct videobuf_queue *vq,
+                                struct videobuf_buffer *vb)
+{
+       struct soc_camera_device *icd = vq->priv_data;
+       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct mx2_camera_dev *pcdev = ici->priv;
+       struct mx2_buffer *buf = container_of(vb, struct mx2_buffer, vb);
+       unsigned long flags;
+
+#ifdef DEBUG
+       dev_dbg(&icd->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+               vb, vb->baddr, vb->bsize);
+
+       switch (vb->state) {
+       case VIDEOBUF_ACTIVE:
+               dev_info(&icd->dev, "%s (active)\n", __func__);
+               break;
+       case VIDEOBUF_QUEUED:
+               dev_info(&icd->dev, "%s (queued)\n", __func__);
+               break;
+       case VIDEOBUF_PREPARED:
+               dev_info(&icd->dev, "%s (prepared)\n", __func__);
+               break;
+       default:
+               dev_info(&icd->dev, "%s (unknown) %d\n", __func__,
+                               vb->state);
+               break;
+       }
+#endif
+
+       /*
+        * Terminate only queued but inactive buffers. Active buffers are
+        * released when they become inactive after videobuf_waiton().
+        *
+        * FIXME: implement forced termination of active buffers, so that the
+        * user won't get stuck in an uninterruptible state. This requires a
+        * specific handling for each of the three DMA types that this driver
+        * supports.
+        */
+       spin_lock_irqsave(&pcdev->lock, flags);
+       if (vb->state == VIDEOBUF_QUEUED) {
+               list_del(&vb->queue);
+               vb->state = VIDEOBUF_ERROR;
+       }
+       spin_unlock_irqrestore(&pcdev->lock, flags);
+
+       free_buffer(vq, buf);
+}
+
+static struct videobuf_queue_ops mx2_videobuf_ops = {
+       .buf_setup      = mx2_videobuf_setup,
+       .buf_prepare    = mx2_videobuf_prepare,
+       .buf_queue      = mx2_videobuf_queue,
+       .buf_release    = mx2_videobuf_release,
+};
+
+static void mx2_camera_init_videobuf(struct videobuf_queue *q,
+                             struct soc_camera_device *icd)
+{
+       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct mx2_camera_dev *pcdev = ici->priv;
+
+       videobuf_queue_dma_contig_init(q, &mx2_videobuf_ops, pcdev->dev,
+                       &pcdev->lock, V4L2_BUF_TYPE_VIDEO_CAPTURE,
+                       V4L2_FIELD_NONE, sizeof(struct mx2_buffer), icd);
+}
+
+#define MX2_BUS_FLAGS  (SOCAM_DATAWIDTH_8 | \
+                       SOCAM_MASTER | \
+                       SOCAM_VSYNC_ACTIVE_HIGH | \
+                       SOCAM_VSYNC_ACTIVE_LOW | \
+                       SOCAM_HSYNC_ACTIVE_HIGH | \
+                       SOCAM_HSYNC_ACTIVE_LOW | \
+                       SOCAM_PCLK_SAMPLE_RISING | \
+                       SOCAM_PCLK_SAMPLE_FALLING | \
+                       SOCAM_DATA_ACTIVE_HIGH | \
+                       SOCAM_DATA_ACTIVE_LOW)
+
+static int mx27_camera_emma_prp_reset(struct mx2_camera_dev *pcdev)
+{
+       u32 cntl;
+       int count = 0;
+
+       cntl = readl(pcdev->base_emma + PRP_CNTL);
+       writel(PRP_CNTL_SWRST, pcdev->base_emma + PRP_CNTL);
+       while (count++ < 100) {
+               if (!(readl(pcdev->base_emma + PRP_CNTL) & PRP_CNTL_SWRST))
+                       return 0;
+               barrier();
+               udelay(1);
+       }
+
+       return -ETIMEDOUT;
+}
+
+static void mx27_camera_emma_buf_init(struct soc_camera_device *icd,
+               int bytesperline)
+{
+       struct soc_camera_host *ici =
+               to_soc_camera_host(icd->dev.parent);
+       struct mx2_camera_dev *pcdev = ici->priv;
+
+       writel(pcdev->discard_buffer_dma,
+                       pcdev->base_emma + PRP_DEST_RGB1_PTR);
+       writel(pcdev->discard_buffer_dma,
+                       pcdev->base_emma + PRP_DEST_RGB2_PTR);
+
+       /*
+        * We only use the EMMA engine to get rid of the broken
+        * DMA Engine. No color space consversion at the moment.
+        * We adjust incoming and outgoing pixelformat to rgb16
+        * and adjust the bytesperline accordingly.
+        */
+       writel(PRP_CNTL_CH1EN |
+                       PRP_CNTL_CSIEN |
+                       PRP_CNTL_DATA_IN_RGB16 |
+                       PRP_CNTL_CH1_OUT_RGB16 |
+                       PRP_CNTL_CH1_LEN |
+                       PRP_CNTL_CH1BYP |
+                       PRP_CNTL_CH1_TSKIP(0) |
+                       PRP_CNTL_IN_TSKIP(0),
+                       pcdev->base_emma + PRP_CNTL);
+
+       writel(((bytesperline >> 1) << 16) | icd->user_height,
+                       pcdev->base_emma + PRP_SRC_FRAME_SIZE);
+       writel(((bytesperline >> 1) << 16) | icd->user_height,
+                       pcdev->base_emma + PRP_CH1_OUT_IMAGE_SIZE);
+       writel(bytesperline,
+                       pcdev->base_emma + PRP_DEST_CH1_LINE_STRIDE);
+       writel(0x2ca00565, /* RGB565 */
+                       pcdev->base_emma + PRP_SRC_PIXEL_FORMAT_CNTL);
+       writel(0x2ca00565, /* RGB565 */
+                       pcdev->base_emma + PRP_CH1_PIXEL_FORMAT_CNTL);
+
+       /* Enable interrupts */
+       writel(PRP_INTR_RDERR |
+                       PRP_INTR_CH1WERR |
+                       PRP_INTR_CH2WERR |
+                       PRP_INTR_CH1FC |
+                       PRP_INTR_CH2FC |
+                       PRP_INTR_LBOVF |
+                       PRP_INTR_CH2OVF,
+                       pcdev->base_emma + PRP_INTR_CNTL);
+}
+
+static int mx2_camera_set_bus_param(struct soc_camera_device *icd,
+               __u32 pixfmt)
+{
+       struct soc_camera_host *ici =
+               to_soc_camera_host(icd->dev.parent);
+       struct mx2_camera_dev *pcdev = ici->priv;
+       unsigned long camera_flags, common_flags;
+       int ret = 0;
+       int bytesperline;
+       u32 csicr1 = pcdev->csicr1;
+
+       camera_flags = icd->ops->query_bus_param(icd);
+
+       common_flags = soc_camera_bus_param_compatible(camera_flags,
+                               MX2_BUS_FLAGS);
+       if (!common_flags)
+               return -EINVAL;
+
+       if ((common_flags & SOCAM_HSYNC_ACTIVE_HIGH) &&
+           (common_flags & SOCAM_HSYNC_ACTIVE_LOW)) {
+               if (pcdev->platform_flags & MX2_CAMERA_HSYNC_HIGH)
+                       common_flags &= ~SOCAM_HSYNC_ACTIVE_LOW;
+               else
+                       common_flags &= ~SOCAM_HSYNC_ACTIVE_HIGH;
+       }
+
+       if ((common_flags & SOCAM_PCLK_SAMPLE_RISING) &&
+           (common_flags & SOCAM_PCLK_SAMPLE_FALLING)) {
+               if (pcdev->platform_flags & MX2_CAMERA_PCLK_SAMPLE_RISING)
+                       common_flags &= ~SOCAM_PCLK_SAMPLE_FALLING;
+               else
+                       common_flags &= ~SOCAM_PCLK_SAMPLE_RISING;
+       }
+
+       ret = icd->ops->set_bus_param(icd, common_flags);
+       if (ret < 0)
+               return ret;
+
+       if (common_flags & SOCAM_PCLK_SAMPLE_FALLING)
+               csicr1 |= CSICR1_INV_PCLK;
+       if (common_flags & SOCAM_VSYNC_ACTIVE_HIGH)
+               csicr1 |= CSICR1_SOF_POL;
+       if (common_flags & SOCAM_HSYNC_ACTIVE_HIGH)
+               csicr1 |= CSICR1_HSYNC_POL;
+       if (pcdev->platform_flags & MX2_CAMERA_SWAP16)
+               csicr1 |= CSICR1_SWAP16_EN;
+       if (pcdev->platform_flags & MX2_CAMERA_EXT_VSYNC)
+               csicr1 |= CSICR1_EXT_VSYNC;
+       if (pcdev->platform_flags & MX2_CAMERA_CCIR)
+               csicr1 |= CSICR1_CCIR_EN;
+       if (pcdev->platform_flags & MX2_CAMERA_CCIR_INTERLACE)
+               csicr1 |= CSICR1_CCIR_MODE;
+       if (pcdev->platform_flags & MX2_CAMERA_GATED_CLOCK)
+               csicr1 |= CSICR1_GCLK_MODE;
+       if (pcdev->platform_flags & MX2_CAMERA_INV_DATA)
+               csicr1 |= CSICR1_INV_DATA;
+       if (pcdev->platform_flags & MX2_CAMERA_PACK_DIR_MSB)
+               csicr1 |= CSICR1_PACK_DIR;
+
+       pcdev->csicr1 = csicr1;
+
+       bytesperline = soc_mbus_bytes_per_line(icd->user_width,
+                       icd->current_fmt->host_fmt);
+       if (bytesperline < 0)
+               return bytesperline;
+
+       if (mx27_camera_emma(pcdev)) {
+               ret = mx27_camera_emma_prp_reset(pcdev);
+               if (ret)
+                       return ret;
+
+               if (pcdev->discard_buffer)
+                       dma_free_coherent(ici->v4l2_dev.dev,
+                               pcdev->discard_size, pcdev->discard_buffer,
+                               pcdev->discard_buffer_dma);
+
+               /*
+                * I didn't manage to properly enable/disable the prp
+                * on a per frame basis during running transfers,
+                * thus we allocate a buffer here and use it to
+                * discard frames when no buffer is available.
+                * Feel free to work on this ;)
+                */
+               pcdev->discard_size = icd->user_height * bytesperline;
+               pcdev->discard_buffer = dma_alloc_coherent(ici->v4l2_dev.dev,
+                               pcdev->discard_size, &pcdev->discard_buffer_dma,
+                               GFP_KERNEL);
+               if (!pcdev->discard_buffer)
+                       return -ENOMEM;
+
+               mx27_camera_emma_buf_init(icd, bytesperline);
+       } else if (cpu_is_mx25()) {
+               writel((bytesperline * icd->user_height) >> 2,
+                               pcdev->base_csi + CSIRXCNT);
+               writel((bytesperline << 16) | icd->user_height,
+                               pcdev->base_csi + CSIIMAG_PARA);
+       }
+
+       writel(pcdev->csicr1, pcdev->base_csi + CSICR1);
+
+       return 0;
+}
+
+static int mx2_camera_set_crop(struct soc_camera_device *icd,
+                               struct v4l2_crop *a)
+{
+       struct v4l2_rect *rect = &a->c;
+       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+       struct v4l2_mbus_framefmt mf;
+       int ret;
+
+       soc_camera_limit_side(&rect->left, &rect->width, 0, 2, 4096);
+       soc_camera_limit_side(&rect->top, &rect->height, 0, 2, 4096);
+
+       ret = v4l2_subdev_call(sd, video, s_crop, a);
+       if (ret < 0)
+               return ret;
+
+       /* The capture device might have changed its output  */
+       ret = v4l2_subdev_call(sd, video, g_mbus_fmt, &mf);
+       if (ret < 0)
+               return ret;
+
+       dev_dbg(icd->dev.parent, "Sensor cropped %dx%d\n",
+               mf.width, mf.height);
+
+       icd->user_width         = mf.width;
+       icd->user_height        = mf.height;
+
+       return ret;
+}
+
+static int mx2_camera_set_fmt(struct soc_camera_device *icd,
+                              struct v4l2_format *f)
+{
+       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct mx2_camera_dev *pcdev = ici->priv;
+       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+       const struct soc_camera_format_xlate *xlate;
+       struct v4l2_pix_format *pix = &f->fmt.pix;
+       struct v4l2_mbus_framefmt mf;
+       int ret;
+
+       xlate = soc_camera_xlate_by_fourcc(icd, pix->pixelformat);
+       if (!xlate) {
+               dev_warn(icd->dev.parent, "Format %x not found\n",
+                               pix->pixelformat);
+               return -EINVAL;
+       }
+
+       /* eMMA can only do RGB565 */
+       if (mx27_camera_emma(pcdev) && pix->pixelformat != V4L2_PIX_FMT_RGB565)
+               return -EINVAL;
+
+       mf.width        = pix->width;
+       mf.height       = pix->height;
+       mf.field        = pix->field;
+       mf.colorspace   = pix->colorspace;
+       mf.code         = xlate->code;
+
+       ret = v4l2_subdev_call(sd, video, s_mbus_fmt, &mf);
+       if (ret < 0 && ret != -ENOIOCTLCMD)
+               return ret;
+
+       if (mf.code != xlate->code)
+               return -EINVAL;
+
+       pix->width              = mf.width;
+       pix->height             = mf.height;
+       pix->field              = mf.field;
+       pix->colorspace         = mf.colorspace;
+       icd->current_fmt        = xlate;
+
+       return 0;
+}
+
+static int mx2_camera_try_fmt(struct soc_camera_device *icd,
+                                 struct v4l2_format *f)
+{
+       struct soc_camera_host *ici = to_soc_camera_host(icd->dev.parent);
+       struct mx2_camera_dev *pcdev = ici->priv;
+       struct v4l2_subdev *sd = soc_camera_to_subdev(icd);
+       const struct soc_camera_format_xlate *xlate;
+       struct v4l2_pix_format *pix = &f->fmt.pix;
+       struct v4l2_mbus_framefmt mf;
+       __u32 pixfmt = pix->pixelformat;
+       unsigned int width_limit;
+       int ret;
+
+       xlate = soc_camera_xlate_by_fourcc(icd, pixfmt);
+       if (pixfmt && !xlate) {
+               dev_warn(icd->dev.parent, "Format %x not found\n", pixfmt);
+               return -EINVAL;
+       }
+
+       /* FIXME: implement MX27 limits */
+
+       /* eMMA can only do RGB565 */
+       if (mx27_camera_emma(pcdev) && pixfmt != V4L2_PIX_FMT_RGB565)
+               return -EINVAL;
+
+       /* limit to MX25 hardware capabilities */
+       if (cpu_is_mx25()) {
+               if (xlate->host_fmt->bits_per_sample <= 8)
+                       width_limit = 0xffff * 4;
+               else
+                       width_limit = 0xffff * 2;
+               /* CSIIMAG_PARA limit */
+               if (pix->width > width_limit)
+                       pix->width = width_limit;
+               if (pix->height > 0xffff)
+                       pix->height = 0xffff;
+
+               pix->bytesperline = soc_mbus_bytes_per_line(pix->width,
+                               xlate->host_fmt);
+               if (pix->bytesperline < 0)
+                       return pix->bytesperline;
+               pix->sizeimage = pix->height * pix->bytesperline;
+               if (pix->sizeimage > (4 * 0x3ffff)) { /* CSIRXCNT limit */
+                       dev_warn(icd->dev.parent,
+                                       "Image size (%u) above limit\n",
+                                       pix->sizeimage);
+                       return -EINVAL;
+               }
+       }
+
+       /* limit to sensor capabilities */
+       mf.width        = pix->width;
+       mf.height       = pix->height;
+       mf.field        = pix->field;
+       mf.colorspace   = pix->colorspace;
+       mf.code         = xlate->code;
+
+       ret = v4l2_subdev_call(sd, video, try_mbus_fmt, &mf);
+       if (ret < 0)
+               return ret;
+
+       if (mf.field == V4L2_FIELD_ANY)
+               mf.field = V4L2_FIELD_NONE;
+       if (mf.field != V4L2_FIELD_NONE) {
+               dev_err(icd->dev.parent, "Field type %d unsupported.\n",
+                               mf.field);
+               return -EINVAL;
+       }
+
+       pix->width      = mf.width;
+       pix->height     = mf.height;
+       pix->field      = mf.field;
+       pix->colorspace = mf.colorspace;
+
+       return 0;
+}
+
+static int mx2_camera_querycap(struct soc_camera_host *ici,
+                              struct v4l2_capability *cap)
+{
+       /* cap->name is set by the friendly caller:-> */
+       strlcpy(cap->card, MX2_CAM_DRIVER_DESCRIPTION, sizeof(cap->card));
+       cap->version = MX2_CAM_VERSION_CODE;
+       cap->capabilities = V4L2_CAP_VIDEO_CAPTURE | V4L2_CAP_STREAMING;
+
+       return 0;
+}
+
+static int mx2_camera_reqbufs(struct soc_camera_file *icf,
+                             struct v4l2_requestbuffers *p)
+{
+       int i;
+
+       for (i = 0; i < p->count; i++) {
+               struct mx2_buffer *buf = container_of(icf->vb_vidq.bufs[i],
+                                                     struct mx2_buffer, vb);
+               INIT_LIST_HEAD(&buf->vb.queue);
+       }
+
+       return 0;
+}
+
+#ifdef CONFIG_MACH_MX27
+static void mx27_camera_frame_done(struct mx2_camera_dev *pcdev, int state)
+{
+       struct videobuf_buffer *vb;
+       struct mx2_buffer *buf;
+       unsigned long flags;
+       int ret;
+
+       spin_lock_irqsave(&pcdev->lock, flags);
+
+       if (!pcdev->active) {
+               dev_err(pcdev->dev, "%s called with no active buffer!\n",
+                               __func__);
+               goto out;
+       }
+
+       vb = &pcdev->active->vb;
+       buf = container_of(vb, struct mx2_buffer, vb);
+       WARN_ON(list_empty(&vb->queue));
+       dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__,
+               vb, vb->baddr, vb->bsize);
+
+       /* _init is used to debug races, see comment in pxa_camera_reqbufs() */
+       list_del_init(&vb->queue);
+       vb->state = state;
+       do_gettimeofday(&vb->ts);
+       vb->field_count++;
+
+       wake_up(&vb->done);
+
+       if (list_empty(&pcdev->capture)) {
+               pcdev->active = NULL;
+               goto out;
+       }
+
+       pcdev->active = list_entry(pcdev->capture.next,
+                       struct mx2_buffer, vb.queue);
+
+       vb = &pcdev->active->vb;
+       vb->state = VIDEOBUF_ACTIVE;
+
+       ret = imx_dma_setup_single(pcdev->dma, videobuf_to_dma_contig(vb),
+                       vb->size, (u32)pcdev->base_dma + 0x10, DMA_MODE_READ);
+
+       if (ret) {
+               vb->state = VIDEOBUF_ERROR;
+               pcdev->active = NULL;
+               wake_up(&vb->done);
+       }
+
+out:
+       spin_unlock_irqrestore(&pcdev->lock, flags);
+}
+
+static void mx27_camera_dma_err_callback(int channel, void *data, int err)
+{
+       struct mx2_camera_dev *pcdev = data;
+
+       mx27_camera_frame_done(pcdev, VIDEOBUF_ERROR);
+}
+
+static void mx27_camera_dma_callback(int channel, void *data)
+{
+       struct mx2_camera_dev *pcdev = data;
+
+       mx27_camera_frame_done(pcdev, VIDEOBUF_DONE);
+}
+
+#define DMA_REQ_CSI_RX          31 /* FIXME: Add this to a resource */
+
+static int __devinit mx27_camera_dma_init(struct platform_device *pdev,
+               struct mx2_camera_dev *pcdev)
+{
+       int err;
+
+       pcdev->dma = imx_dma_request_by_prio("CSI RX DMA", DMA_PRIO_HIGH);
+       if (pcdev->dma < 0) {
+               dev_err(&pdev->dev, "%s failed to request DMA channel\n",
+                               __func__);
+               return pcdev->dma;
+       }
+
+       err = imx_dma_setup_handlers(pcdev->dma, mx27_camera_dma_callback,
+                                       mx27_camera_dma_err_callback, pcdev);
+       if (err) {
+               dev_err(&pdev->dev, "%s failed to set DMA callback\n",
+                               __func__);
+               goto err_out;
+       }
+
+       err = imx_dma_config_channel(pcdev->dma,
+                       IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_FIFO,
+                       IMX_DMA_MEMSIZE_32 | IMX_DMA_TYPE_LINEAR,
+                       DMA_REQ_CSI_RX, 1);
+       if (err) {
+               dev_err(&pdev->dev, "%s failed to config DMA channel\n",
+                               __func__);
+               goto err_out;
+       }
+
+       imx_dma_config_burstlen(pcdev->dma, 64);
+
+       return 0;
+
+err_out:
+       imx_dma_free(pcdev->dma);
+
+       return err;
+}
+#endif /* CONFIG_MACH_MX27 */
+
+static unsigned int mx2_camera_poll(struct file *file, poll_table *pt)
+{
+       struct soc_camera_file *icf = file->private_data;
+
+       return videobuf_poll_stream(file, &icf->vb_vidq, pt);
+}
+
+static struct soc_camera_host_ops mx2_soc_camera_host_ops = {
+       .owner          = THIS_MODULE,
+       .add            = mx2_camera_add_device,
+       .remove         = mx2_camera_remove_device,
+       .set_fmt        = mx2_camera_set_fmt,
+       .set_crop       = mx2_camera_set_crop,
+       .try_fmt        = mx2_camera_try_fmt,
+       .init_videobuf  = mx2_camera_init_videobuf,
+       .reqbufs        = mx2_camera_reqbufs,
+       .poll           = mx2_camera_poll,
+       .querycap       = mx2_camera_querycap,
+       .set_bus_param  = mx2_camera_set_bus_param,
+};
+
+static void mx27_camera_frame_done_emma(struct mx2_camera_dev *pcdev,
+               int bufnum, int state)
+{
+       struct mx2_buffer *buf;
+       struct videobuf_buffer *vb;
+       unsigned long phys;
+
+       if (!list_empty(&pcdev->active_bufs)) {
+               buf = list_entry(pcdev->active_bufs.next,
+                       struct mx2_buffer, vb.queue);
+
+               BUG_ON(buf->bufnum != bufnum);
+
+               vb = &buf->vb;
+#ifdef DEBUG
+               phys = videobuf_to_dma_contig(vb);
+               if (readl(pcdev->base_emma + PRP_DEST_RGB1_PTR + 4 * bufnum)
+                               != phys) {
+                       dev_err(pcdev->dev, "%p != %p\n", phys,
+                                       readl(pcdev->base_emma +
+                                               PRP_DEST_RGB1_PTR +
+                                               4 * bufnum));
+               }
+#endif
+               dev_dbg(pcdev->dev, "%s (vb=0x%p) 0x%08lx %d\n", __func__, vb,
+                               vb->baddr, vb->bsize);
+
+               list_del(&vb->queue);
+               vb->state = state;
+               do_gettimeofday(&vb->ts);
+               vb->field_count++;
+
+               wake_up(&vb->done);
+       }
+
+       if (list_empty(&pcdev->capture)) {
+               writel(pcdev->discard_buffer_dma, pcdev->base_emma +
+                               PRP_DEST_RGB1_PTR + 4 * bufnum);
+               return;
+       }
+
+       buf = list_entry(pcdev->capture.next,
+                       struct mx2_buffer, vb.queue);
+
+       buf->bufnum = bufnum;
+
+       list_move_tail(pcdev->capture.next, &pcdev->active_bufs);
+
+       vb = &buf->vb;
+       vb->state = VIDEOBUF_ACTIVE;
+
+       phys = videobuf_to_dma_contig(vb);
+       writel(phys, pcdev->base_emma + PRP_DEST_RGB1_PTR + 4 * bufnum);
+}
+
+static irqreturn_t mx27_camera_emma_irq(int irq_emma, void *data)
+{
+       struct mx2_camera_dev *pcdev = data;
+       unsigned int status = readl(pcdev->base_emma + PRP_INTRSTATUS);
+       struct mx2_buffer *buf;
+
+       if (status & (1 << 7)) { /* overflow */
+               u32 cntl;
+               /*
+                * We only disable channel 1 here since this is the only
+                * enabled channel
+                *
+                * FIXME: the correct DMA overflow handling should be resetting
+                * the buffer, returning an error frame, and continuing with
+                * the next one.
+                */
+               cntl = readl(pcdev->base_emma + PRP_CNTL);
+               writel(cntl & ~PRP_CNTL_CH1EN, pcdev->base_emma + PRP_CNTL);
+               writel(cntl, pcdev->base_emma + PRP_CNTL);
+       }
+       if ((status & (3 << 5)) == (3 << 5)
+                       && !list_empty(&pcdev->active_bufs)) {
+               /*
+                * Both buffers have triggered, process the one we're expecting
+                * to first
+                */
+               buf = list_entry(pcdev->active_bufs.next,
+                       struct mx2_buffer, vb.queue);
+               mx27_camera_frame_done_emma(pcdev, buf->bufnum, VIDEOBUF_DONE);
+               status &= ~(1 << (6 - buf->bufnum)); /* mark processed */
+       }
+       if (status & (1 << 6))
+               mx27_camera_frame_done_emma(pcdev, 0, VIDEOBUF_DONE);
+       if (status & (1 << 5))
+               mx27_camera_frame_done_emma(pcdev, 1, VIDEOBUF_DONE);
+
+       writel(status, pcdev->base_emma + PRP_INTRSTATUS);
+
+       return IRQ_HANDLED;
+}
+
+static int __devinit mx27_camera_emma_init(struct mx2_camera_dev *pcdev)
+{
+       struct resource *res_emma = pcdev->res_emma;
+       int err = 0;
+
+       if (!request_mem_region(res_emma->start, resource_size(res_emma),
+                               MX2_CAM_DRV_NAME)) {
+               err = -EBUSY;
+               goto out;
+       }
+
+       pcdev->base_emma = ioremap(res_emma->start, resource_size(res_emma));
+       if (!pcdev->base_emma) {
+               err = -ENOMEM;
+               goto exit_release;
+       }
+
+       err = request_irq(pcdev->irq_emma, mx27_camera_emma_irq, 0,
+                       MX2_CAM_DRV_NAME, pcdev);
+       if (err) {
+               dev_err(pcdev->dev, "Camera EMMA interrupt register failed \n");
+               goto exit_iounmap;
+       }
+
+       pcdev->clk_emma = clk_get(NULL, "emma");
+       if (IS_ERR(pcdev->clk_emma)) {
+               err = PTR_ERR(pcdev->clk_emma);
+               goto exit_free_irq;
+       }
+
+       clk_enable(pcdev->clk_emma);
+
+       err = mx27_camera_emma_prp_reset(pcdev);
+       if (err)
+               goto exit_clk_emma_put;
+
+       return err;
+
+exit_clk_emma_put:
+       clk_disable(pcdev->clk_emma);
+       clk_put(pcdev->clk_emma);
+exit_free_irq:
+       free_irq(pcdev->irq_emma, pcdev);
+exit_iounmap:
+       iounmap(pcdev->base_emma);
+exit_release:
+       release_mem_region(res_emma->start, resource_size(res_emma));
+out:
+       return err;
+}
+
+static int __devinit mx2_camera_probe(struct platform_device *pdev)
+{
+       struct mx2_camera_dev *pcdev;
+       struct resource *res_csi, *res_emma;
+       void __iomem *base_csi;
+       int irq_csi, irq_emma;
+       irq_handler_t mx2_cam_irq_handler = cpu_is_mx25() ? mx25_camera_irq
+               : mx27_camera_irq;
+       int err = 0;
+
+       dev_dbg(&pdev->dev, "initialising\n");
+
+       res_csi = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       irq_csi = platform_get_irq(pdev, 0);
+       if (res_csi == NULL || irq_csi < 0) {
+               dev_err(&pdev->dev, "Missing platform resources data\n");
+               err = -ENODEV;
+               goto exit;
+       }
+
+       pcdev = kzalloc(sizeof(*pcdev), GFP_KERNEL);
+       if (!pcdev) {
+               dev_err(&pdev->dev, "Could not allocate pcdev\n");
+               err = -ENOMEM;
+               goto exit;
+       }
+
+       pcdev->clk_csi = clk_get(&pdev->dev, NULL);
+       if (IS_ERR(pcdev->clk_csi)) {
+               err = PTR_ERR(pcdev->clk_csi);
+               goto exit_kfree;
+       }
+
+       dev_dbg(&pdev->dev, "Camera clock frequency: %ld\n",
+                       clk_get_rate(pcdev->clk_csi));
+
+       /* Initialize DMA */
+#ifdef CONFIG_MACH_MX27
+       if (cpu_is_mx27()) {
+               err = mx27_camera_dma_init(pdev, pcdev);
+               if (err)
+                       goto exit_clk_put;
+       }
+#endif /* CONFIG_MACH_MX27 */
+
+       pcdev->res_csi = res_csi;
+       pcdev->pdata = pdev->dev.platform_data;
+       if (pcdev->pdata) {
+               long rate;
+
+               pcdev->platform_flags = pcdev->pdata->flags;
+
+               rate = clk_round_rate(pcdev->clk_csi, pcdev->pdata->clk * 2);
+               if (rate <= 0) {
+                       err = -ENODEV;
+                       goto exit_dma_free;
+               }
+               err = clk_set_rate(pcdev->clk_csi, rate);
+               if (err < 0)
+                       goto exit_dma_free;
+       }
+
+       INIT_LIST_HEAD(&pcdev->capture);
+       INIT_LIST_HEAD(&pcdev->active_bufs);
+       spin_lock_init(&pcdev->lock);
+
+       /*
+        * Request the regions.
+        */
+       if (!request_mem_region(res_csi->start, resource_size(res_csi),
+                               MX2_CAM_DRV_NAME)) {
+               err = -EBUSY;
+               goto exit_dma_free;
+       }
+
+       base_csi = ioremap(res_csi->start, resource_size(res_csi));
+       if (!base_csi) {
+               err = -ENOMEM;
+               goto exit_release;
+       }
+       pcdev->irq_csi = irq_csi;
+       pcdev->base_csi = base_csi;
+       pcdev->base_dma = res_csi->start;
+       pcdev->dev = &pdev->dev;
+
+       err = request_irq(pcdev->irq_csi, mx2_cam_irq_handler, 0,
+                       MX2_CAM_DRV_NAME, pcdev);
+       if (err) {
+               dev_err(pcdev->dev, "Camera interrupt register failed \n");
+               goto exit_iounmap;
+       }
+
+       if (cpu_is_mx27()) {
+               /* EMMA support */
+               res_emma = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+               irq_emma = platform_get_irq(pdev, 1);
+
+               if (res_emma && irq_emma >= 0) {
+                       dev_info(&pdev->dev, "Using EMMA\n");
+                       pcdev->use_emma = 1;
+                       pcdev->res_emma = res_emma;
+                       pcdev->irq_emma = irq_emma;
+                       if (mx27_camera_emma_init(pcdev))
+                               goto exit_free_irq;
+               }
+       }
+
+       pcdev->soc_host.drv_name        = MX2_CAM_DRV_NAME,
+       pcdev->soc_host.ops             = &mx2_soc_camera_host_ops,
+       pcdev->soc_host.priv            = pcdev;
+       pcdev->soc_host.v4l2_dev.dev    = &pdev->dev;
+       pcdev->soc_host.nr              = pdev->id;
+       err = soc_camera_host_register(&pcdev->soc_host);
+       if (err)
+               goto exit_free_emma;
+
+       return 0;
+
+exit_free_emma:
+       if (mx27_camera_emma(pcdev)) {
+               free_irq(pcdev->irq_emma, pcdev);
+               clk_disable(pcdev->clk_emma);
+               clk_put(pcdev->clk_emma);
+               iounmap(pcdev->base_emma);
+               release_mem_region(res_emma->start, resource_size(res_emma));
+       }
+exit_free_irq:
+       free_irq(pcdev->irq_csi, pcdev);
+exit_iounmap:
+       iounmap(base_csi);
+exit_release:
+       release_mem_region(res_csi->start, resource_size(res_csi));
+exit_dma_free:
+#ifdef CONFIG_MACH_MX27
+       if (cpu_is_mx27())
+               imx_dma_free(pcdev->dma);
+exit_clk_put:
+       clk_put(pcdev->clk_csi);
+#endif /* CONFIG_MACH_MX27 */
+exit_kfree:
+       kfree(pcdev);
+exit:
+       return err;
+}
+
+static int __devexit mx2_camera_remove(struct platform_device *pdev)
+{
+       struct soc_camera_host *soc_host = to_soc_camera_host(&pdev->dev);
+       struct mx2_camera_dev *pcdev = container_of(soc_host,
+                       struct mx2_camera_dev, soc_host);
+       struct resource *res;
+
+       clk_put(pcdev->clk_csi);
+#ifdef CONFIG_MACH_MX27
+       if (cpu_is_mx27())
+               imx_dma_free(pcdev->dma);
+#endif /* CONFIG_MACH_MX27 */
+       free_irq(pcdev->irq_csi, pcdev);
+       if (mx27_camera_emma(pcdev))
+               free_irq(pcdev->irq_emma, pcdev);
+
+       soc_camera_host_unregister(&pcdev->soc_host);
+
+       iounmap(pcdev->base_csi);
+
+       if (mx27_camera_emma(pcdev)) {
+               clk_disable(pcdev->clk_emma);
+               clk_put(pcdev->clk_emma);
+               iounmap(pcdev->base_emma);
+               res = pcdev->res_emma;
+               release_mem_region(res->start, resource_size(res));
+       }
+
+       res = pcdev->res_csi;
+       release_mem_region(res->start, resource_size(res));
+
+       kfree(pcdev);
+
+       dev_info(&pdev->dev, "MX2 Camera driver unloaded\n");
+
+       return 0;
+}
+
+static struct platform_driver mx2_camera_driver = {
+       .driver         = {
+               .name   = MX2_CAM_DRV_NAME,
+       },
+       .remove         = __devexit_p(mx2_camera_remove),
+};
+
+
+static int __init mx2_camera_init(void)
+{
+       return platform_driver_probe(&mx2_camera_driver, &mx2_camera_probe);
+}
+
+static void __exit mx2_camera_exit(void)
+{
+       return platform_driver_unregister(&mx2_camera_driver);
+}
+
+module_init(mx2_camera_init);
+module_exit(mx2_camera_exit);
+
+MODULE_DESCRIPTION("i.MX27/i.MX25 SoC Camera Host driver");
+MODULE_AUTHOR("Sascha Hauer <sha@pengutronix.de>");
+MODULE_LICENSE("GPL");
index 26386a92f5aafbb614c3308d7c03c05f638cfc15..9b089dfb173ef987f5220d38bce0336c66b92a0f 100644 (file)
@@ -353,6 +353,16 @@ config VMWARE_BALLOON
          To compile this driver as a module, choose M here: the
          module will be called vmware_balloon.
 
+config ARM_CHARLCD
+       bool "ARM Ltd. Character LCD Driver"
+       depends on PLAT_VERSATILE
+       help
+         This is a driver for the character LCD found on the ARM Ltd.
+         Versatile and RealView Platform Baseboards. It doesn't do
+         very much more than display the text "ARM Linux" on the first
+         line and the Linux version on the second line, but that's
+         still useful.
+
 source "drivers/misc/c2port/Kconfig"
 source "drivers/misc/eeprom/Kconfig"
 source "drivers/misc/cb710/Kconfig"
index 6ed06a19474acc23de3b93b732ecce25b9a55c40..67552d6e932784b2e8c19e8f0c840483a52faa65 100644 (file)
@@ -31,3 +31,4 @@ obj-$(CONFIG_IWMC3200TOP)      += iwmc3200top/
 obj-y                          += eeprom/
 obj-y                          += cb710/
 obj-$(CONFIG_VMWARE_BALLOON)   += vmware_balloon.o
+obj-$(CONFIG_ARM_CHARLCD)      += arm-charlcd.o
diff --git a/drivers/misc/arm-charlcd.c b/drivers/misc/arm-charlcd.c
new file mode 100644 (file)
index 0000000..9e3879e
--- /dev/null
@@ -0,0 +1,396 @@
+/*
+ * Driver for the on-board character LCD found on some ARM reference boards
+ * This is basically an Hitachi HD44780 LCD with a custom IP block to drive it
+ * http://en.wikipedia.org/wiki/HD44780_Character_LCD
+ * Currently it will just display the text "ARM Linux" and the linux version
+ *
+ * License terms: GNU General Public License (GPL) version 2
+ * Author: Linus Walleij <triad@df.lth.se>
+ */
+#include <linux/init.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/platform_device.h>
+#include <linux/completion.h>
+#include <linux/delay.h>
+#include <linux/io.h>
+#include <linux/slab.h>
+#include <linux/workqueue.h>
+#include <generated/utsrelease.h>
+
+#define DRIVERNAME "arm-charlcd"
+#define CHARLCD_TIMEOUT (msecs_to_jiffies(1000))
+
+/* Offsets to registers */
+#define CHAR_COM       0x00U
+#define CHAR_DAT       0x04U
+#define CHAR_RD                0x08U
+#define CHAR_RAW       0x0CU
+#define CHAR_MASK      0x10U
+#define CHAR_STAT      0x14U
+
+#define CHAR_RAW_CLEAR 0x00000000U
+#define CHAR_RAW_VALID 0x00000100U
+
+/* Hitachi HD44780 display commands */
+#define HD_CLEAR                       0x01U
+#define HD_HOME                                0x02U
+#define HD_ENTRYMODE                   0x04U
+#define HD_ENTRYMODE_INCREMENT         0x02U
+#define HD_ENTRYMODE_SHIFT             0x01U
+#define HD_DISPCTRL                    0x08U
+#define HD_DISPCTRL_ON                 0x04U
+#define HD_DISPCTRL_CURSOR_ON          0x02U
+#define HD_DISPCTRL_CURSOR_BLINK       0x01U
+#define HD_CRSR_SHIFT                  0x10U
+#define HD_CRSR_SHIFT_DISPLAY          0x08U
+#define HD_CRSR_SHIFT_DISPLAY_RIGHT    0x04U
+#define HD_FUNCSET                     0x20U
+#define HD_FUNCSET_8BIT                        0x10U
+#define HD_FUNCSET_2_LINES             0x08U
+#define HD_FUNCSET_FONT_5X10           0x04U
+#define HD_SET_CGRAM                   0x40U
+#define HD_SET_DDRAM                   0x80U
+#define HD_BUSY_FLAG                   0x80U
+
+/**
+ * @dev: a pointer back to containing device
+ * @phybase: the offset to the controller in physical memory
+ * @physize: the size of the physical page
+ * @virtbase: the offset to the controller in virtual memory
+ * @irq: reserved interrupt number
+ * @complete: completion structure for the last LCD command
+ */
+struct charlcd {
+       struct device *dev;
+       u32 phybase;
+       u32 physize;
+       void __iomem *virtbase;
+       int irq;
+       struct completion complete;
+       struct delayed_work init_work;
+};
+
+static irqreturn_t charlcd_interrupt(int irq, void *data)
+{
+       struct charlcd *lcd = data;
+       u8 status;
+
+       status = readl(lcd->virtbase + CHAR_STAT) & 0x01;
+       /* Clear IRQ */
+       writel(CHAR_RAW_CLEAR, lcd->virtbase + CHAR_RAW);
+       if (status)
+               complete(&lcd->complete);
+       else
+               dev_info(lcd->dev, "Spurious IRQ (%02x)\n", status);
+       return IRQ_HANDLED;
+}
+
+
+static void charlcd_wait_complete_irq(struct charlcd *lcd)
+{
+       int ret;
+
+       ret = wait_for_completion_interruptible_timeout(&lcd->complete,
+                                                       CHARLCD_TIMEOUT);
+       /* Disable IRQ after completion */
+       writel(0x00, lcd->virtbase + CHAR_MASK);
+
+       if (ret < 0) {
+               dev_err(lcd->dev,
+                       "wait_for_completion_interruptible_timeout() "
+                       "returned %d waiting for ready\n", ret);
+               return;
+       }
+
+       if (ret == 0) {
+               dev_err(lcd->dev, "charlcd controller timed out "
+                       "waiting for ready\n");
+               return;
+       }
+}
+
+static u8 charlcd_4bit_read_char(struct charlcd *lcd)
+{
+       u8 data;
+       u32 val;
+       int i;
+
+       /* If we can, use an IRQ to wait for the data, else poll */
+       if (lcd->irq >= 0)
+               charlcd_wait_complete_irq(lcd);
+       else {
+               i = 0;
+               val = 0;
+               while (!(val & CHAR_RAW_VALID) && i < 10) {
+                       udelay(100);
+                       val = readl(lcd->virtbase + CHAR_RAW);
+                       i++;
+               }
+
+               writel(CHAR_RAW_CLEAR, lcd->virtbase + CHAR_RAW);
+       }
+       msleep(1);
+
+       /* Read the 4 high bits of the data */
+       data = readl(lcd->virtbase + CHAR_RD) & 0xf0;
+
+       /*
+        * The second read for the low bits does not trigger an IRQ
+        * so in this case we have to poll for the 4 lower bits
+        */
+       i = 0;
+       val = 0;
+       while (!(val & CHAR_RAW_VALID) && i < 10) {
+               udelay(100);
+               val = readl(lcd->virtbase + CHAR_RAW);
+               i++;
+       }
+       writel(CHAR_RAW_CLEAR, lcd->virtbase + CHAR_RAW);
+       msleep(1);
+
+       /* Read the 4 low bits of the data */
+       data |= (readl(lcd->virtbase + CHAR_RD) >> 4) & 0x0f;
+
+       return data;
+}
+
+static bool charlcd_4bit_read_bf(struct charlcd *lcd)
+{
+       if (lcd->irq >= 0) {
+               /*
+                * If we'll use IRQs to wait for the busyflag, clear any
+                * pending flag and enable IRQ
+                */
+               writel(CHAR_RAW_CLEAR, lcd->virtbase + CHAR_RAW);
+               init_completion(&lcd->complete);
+               writel(0x01, lcd->virtbase + CHAR_MASK);
+       }
+       readl(lcd->virtbase + CHAR_COM);
+       return charlcd_4bit_read_char(lcd) & HD_BUSY_FLAG ? true : false;
+}
+
+static void charlcd_4bit_wait_busy(struct charlcd *lcd)
+{
+       int retries = 50;
+
+       udelay(100);
+       while (charlcd_4bit_read_bf(lcd) && retries)
+               retries--;
+       if (!retries)
+               dev_err(lcd->dev, "timeout waiting for busyflag\n");
+}
+
+static void charlcd_4bit_command(struct charlcd *lcd, u8 cmd)
+{
+       u32 cmdlo = (cmd << 4) & 0xf0;
+       u32 cmdhi = (cmd & 0xf0);
+
+       writel(cmdhi, lcd->virtbase + CHAR_COM);
+       udelay(10);
+       writel(cmdlo, lcd->virtbase + CHAR_COM);
+       charlcd_4bit_wait_busy(lcd);
+}
+
+static void charlcd_4bit_char(struct charlcd *lcd, u8 ch)
+{
+       u32 chlo = (ch << 4) & 0xf0;
+       u32 chhi = (ch & 0xf0);
+
+       writel(chhi, lcd->virtbase + CHAR_DAT);
+       udelay(10);
+       writel(chlo, lcd->virtbase + CHAR_DAT);
+       charlcd_4bit_wait_busy(lcd);
+}
+
+static void charlcd_4bit_print(struct charlcd *lcd, int line, const char *str)
+{
+       u8 offset;
+       int i;
+
+       /*
+        * We support line 0, 1
+        * Line 1 runs from 0x00..0x27
+        * Line 2 runs from 0x28..0x4f
+        */
+       if (line == 0)
+               offset = 0;
+       else if (line == 1)
+               offset = 0x28;
+       else
+               return;
+
+       /* Set offset */
+       charlcd_4bit_command(lcd, HD_SET_DDRAM | offset);
+
+       /* Send string */
+       for (i = 0; i < strlen(str) && i < 0x28; i++)
+               charlcd_4bit_char(lcd, str[i]);
+}
+
+static void charlcd_4bit_init(struct charlcd *lcd)
+{
+       /* These commands cannot be checked with the busy flag */
+       writel(HD_FUNCSET | HD_FUNCSET_8BIT, lcd->virtbase + CHAR_COM);
+       msleep(5);
+       writel(HD_FUNCSET | HD_FUNCSET_8BIT, lcd->virtbase + CHAR_COM);
+       udelay(100);
+       writel(HD_FUNCSET | HD_FUNCSET_8BIT, lcd->virtbase + CHAR_COM);
+       udelay(100);
+       /* Go to 4bit mode */
+       writel(HD_FUNCSET, lcd->virtbase + CHAR_COM);
+       udelay(100);
+       /*
+        * 4bit mode, 2 lines, 5x8 font, after this the number of lines
+        * and the font cannot be changed until the next initialization sequence
+        */
+       charlcd_4bit_command(lcd, HD_FUNCSET | HD_FUNCSET_2_LINES);
+       charlcd_4bit_command(lcd, HD_DISPCTRL | HD_DISPCTRL_ON);
+       charlcd_4bit_command(lcd, HD_ENTRYMODE | HD_ENTRYMODE_INCREMENT);
+       charlcd_4bit_command(lcd, HD_CLEAR);
+       charlcd_4bit_command(lcd, HD_HOME);
+       /* Put something useful in the display */
+       charlcd_4bit_print(lcd, 0, "ARM Linux");
+       charlcd_4bit_print(lcd, 1, UTS_RELEASE);
+}
+
+static void charlcd_init_work(struct work_struct *work)
+{
+       struct charlcd *lcd =
+               container_of(work, struct charlcd, init_work.work);
+
+       charlcd_4bit_init(lcd);
+}
+
+static int __init charlcd_probe(struct platform_device *pdev)
+{
+       int ret;
+       struct charlcd *lcd;
+       struct resource *res;
+
+       lcd = kzalloc(sizeof(struct charlcd), GFP_KERNEL);
+       if (!lcd)
+               return -ENOMEM;
+
+       lcd->dev = &pdev->dev;
+
+       res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+       if (!res) {
+               ret = -ENOENT;
+               goto out_no_resource;
+       }
+       lcd->phybase = res->start;
+       lcd->physize = resource_size(res);
+
+       if (request_mem_region(lcd->phybase, lcd->physize,
+                              DRIVERNAME) == NULL) {
+               ret = -EBUSY;
+               goto out_no_memregion;
+       }
+
+       lcd->virtbase = ioremap(lcd->phybase, lcd->physize);
+       if (!lcd->virtbase) {
+               ret = -ENOMEM;
+               goto out_no_remap;
+       }
+
+       lcd->irq = platform_get_irq(pdev, 0);
+       /* If no IRQ is supplied, we'll survive without it */
+       if (lcd->irq >= 0) {
+               if (request_irq(lcd->irq, charlcd_interrupt, IRQF_DISABLED,
+                               DRIVERNAME, lcd)) {
+                       ret = -EIO;
+                       goto out_no_irq;
+               }
+       }
+
+       platform_set_drvdata(pdev, lcd);
+
+       /*
+        * Initialize the display in a delayed work, because
+        * it is VERY slow and would slow down the boot of the system.
+        */
+       INIT_DELAYED_WORK(&lcd->init_work, charlcd_init_work);
+       schedule_delayed_work(&lcd->init_work, 0);
+
+       dev_info(&pdev->dev, "initalized ARM character LCD at %08x\n",
+               lcd->phybase);
+
+       return 0;
+
+out_no_irq:
+       iounmap(lcd->virtbase);
+out_no_remap:
+       platform_set_drvdata(pdev, NULL);
+out_no_memregion:
+       release_mem_region(lcd->phybase, SZ_4K);
+out_no_resource:
+       kfree(lcd);
+       return ret;
+}
+
+static int __exit charlcd_remove(struct platform_device *pdev)
+{
+       struct charlcd *lcd = platform_get_drvdata(pdev);
+
+       if (lcd) {
+               free_irq(lcd->irq, lcd);
+               iounmap(lcd->virtbase);
+               release_mem_region(lcd->phybase, lcd->physize);
+               platform_set_drvdata(pdev, NULL);
+               kfree(lcd);
+       }
+
+       return 0;
+}
+
+static int charlcd_suspend(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct charlcd *lcd = platform_get_drvdata(pdev);
+
+       /* Power the display off */
+       charlcd_4bit_command(lcd, HD_DISPCTRL);
+       return 0;
+}
+
+static int charlcd_resume(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       struct charlcd *lcd = platform_get_drvdata(pdev);
+
+       /* Turn the display back on */
+       charlcd_4bit_command(lcd, HD_DISPCTRL | HD_DISPCTRL_ON);
+       return 0;
+}
+
+static const struct dev_pm_ops charlcd_pm_ops = {
+       .suspend = charlcd_suspend,
+       .resume = charlcd_resume,
+};
+
+static struct platform_driver charlcd_driver = {
+       .driver = {
+               .name = DRIVERNAME,
+               .owner = THIS_MODULE,
+               .pm = &charlcd_pm_ops,
+       },
+       .remove = __exit_p(charlcd_remove),
+};
+
+static int __init charlcd_init(void)
+{
+       return platform_driver_probe(&charlcd_driver, charlcd_probe);
+}
+
+static void __exit charlcd_exit(void)
+{
+       platform_driver_unregister(&charlcd_driver);
+}
+
+module_init(charlcd_init);
+module_exit(charlcd_exit);
+
+MODULE_AUTHOR("Linus Walleij <triad@df.lth.se>");
+MODULE_DESCRIPTION("ARM Character LCD Driver");
+MODULE_LICENSE("GPL v2");
index 2ed435bd4b6c18c426640140cf39908b1d065574..840b301b567142b4e264924a14feb91c5cb54003 100644 (file)
@@ -26,7 +26,6 @@
 #include <linux/amba/mmci.h>
 #include <linux/regulator/consumer.h>
 
-#include <asm/cacheflush.h>
 #include <asm/div64.h>
 #include <asm/io.h>
 #include <asm/sizes.h>
 
 static unsigned int fmax = 515633;
 
+/**
+ * struct variant_data - MMCI variant-specific quirks
+ * @clkreg: default value for MCICLOCK register
+ * @clkreg_enable: enable value for MMCICLOCK register
+ * @datalength_bits: number of bits in the MMCIDATALENGTH register
+ */
+struct variant_data {
+       unsigned int            clkreg;
+       unsigned int            clkreg_enable;
+       unsigned int            datalength_bits;
+};
+
+static struct variant_data variant_arm = {
+       .datalength_bits        = 16,
+};
+
+static struct variant_data variant_u300 = {
+       .clkreg_enable          = 1 << 13, /* HWFCEN */
+       .datalength_bits        = 16,
+};
+
+static struct variant_data variant_ux500 = {
+       .clkreg                 = MCI_CLK_ENABLE,
+       .clkreg_enable          = 1 << 14, /* HWFCEN */
+       .datalength_bits        = 24,
+};
 /*
  * This must be called with host->lock held
  */
 static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired)
 {
-       u32 clk = 0;
+       struct variant_data *variant = host->variant;
+       u32 clk = variant->clkreg;
 
        if (desired) {
                if (desired >= host->mclk) {
@@ -54,8 +80,8 @@ static void mmci_set_clkreg(struct mmci_host *host, unsigned int desired)
                                clk = 255;
                        host->cclk = host->mclk / (2 * (clk + 1));
                }
-               if (host->hw_designer == AMBA_VENDOR_ST)
-                       clk |= MCI_ST_FCEN; /* Bug fix in ST IP block */
+
+               clk |= variant->clkreg_enable;
                clk |= MCI_CLK_ENABLE;
                /* This hasn't proven to be worthwhile */
                /* clk |= MCI_CLK_PWRSAVE; */
@@ -98,6 +124,18 @@ static void mmci_stop_data(struct mmci_host *host)
        host->data = NULL;
 }
 
+static void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
+{
+       unsigned int flags = SG_MITER_ATOMIC;
+
+       if (data->flags & MMC_DATA_READ)
+               flags |= SG_MITER_TO_SG;
+       else
+               flags |= SG_MITER_FROM_SG;
+
+       sg_miter_start(&host->sg_miter, data->sg, data->sg_len, flags);
+}
+
 static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
 {
        unsigned int datactrl, timeout, irqmask;
@@ -109,7 +147,7 @@ static void mmci_start_data(struct mmci_host *host, struct mmc_data *data)
                data->blksz, data->blocks, data->flags);
 
        host->data = data;
-       host->size = data->blksz;
+       host->size = data->blksz * data->blocks;
        host->data_xfered = 0;
 
        mmci_init_sg(host, data);
@@ -210,8 +248,17 @@ mmci_data_irq(struct mmci_host *host, struct mmc_data *data,
                 * We hit an error condition.  Ensure that any data
                 * partially written to a page is properly coherent.
                 */
-               if (host->sg_len && data->flags & MMC_DATA_READ)
-                       flush_dcache_page(sg_page(host->sg_ptr));
+               if (data->flags & MMC_DATA_READ) {
+                       struct sg_mapping_iter *sg_miter = &host->sg_miter;
+                       unsigned long flags;
+
+                       local_irq_save(flags);
+                       if (sg_miter_next(sg_miter)) {
+                               flush_dcache_page(sg_miter->page);
+                               sg_miter_stop(sg_miter);
+                       }
+                       local_irq_restore(flags);
+               }
        }
        if (status & MCI_DATAEND) {
                mmci_stop_data(host);
@@ -314,15 +361,18 @@ static int mmci_pio_write(struct mmci_host *host, char *buffer, unsigned int rem
 static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
 {
        struct mmci_host *host = dev_id;
+       struct sg_mapping_iter *sg_miter = &host->sg_miter;
        void __iomem *base = host->base;
+       unsigned long flags;
        u32 status;
 
        status = readl(base + MMCISTATUS);
 
        dev_dbg(mmc_dev(host->mmc), "irq1 (pio) %08x\n", status);
 
+       local_irq_save(flags);
+
        do {
-               unsigned long flags;
                unsigned int remain, len;
                char *buffer;
 
@@ -336,11 +386,11 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
                if (!(status & (MCI_TXFIFOHALFEMPTY|MCI_RXDATAAVLBL)))
                        break;
 
-               /*
-                * Map the current scatter buffer.
-                */
-               buffer = mmci_kmap_atomic(host, &flags) + host->sg_off;
-               remain = host->sg_ptr->length - host->sg_off;
+               if (!sg_miter_next(sg_miter))
+                       break;
+
+               buffer = sg_miter->addr;
+               remain = sg_miter->length;
 
                len = 0;
                if (status & MCI_RXACTIVE)
@@ -348,31 +398,24 @@ static irqreturn_t mmci_pio_irq(int irq, void *dev_id)
                if (status & MCI_TXACTIVE)
                        len = mmci_pio_write(host, buffer, remain, status);
 
-               /*
-                * Unmap the buffer.
-                */
-               mmci_kunmap_atomic(host, buffer, &flags);
+               sg_miter->consumed = len;
 
-               host->sg_off += len;
                host->size -= len;
                remain -= len;
 
                if (remain)
                        break;
 
-               /*
-                * If we were reading, and we have completed this
-                * page, ensure that the data cache is coherent.
-                */
                if (status & MCI_RXACTIVE)
-                       flush_dcache_page(sg_page(host->sg_ptr));
-
-               if (!mmci_next_sg(host))
-                       break;
+                       flush_dcache_page(sg_miter->page);
 
                status = readl(base + MMCISTATUS);
        } while (1);
 
+       sg_miter_stop(sg_miter);
+
+       local_irq_restore(flags);
+
        /*
         * If we're nearing the end of the read, switch to
         * "any data available" mode.
@@ -477,16 +520,9 @@ static void mmci_set_ios(struct mmc_host *mmc, struct mmc_ios *ios)
                        /* This implicitly enables the regulator */
                        mmc_regulator_set_ocr(host->vcc, ios->vdd);
 #endif
-               /*
-                * The translate_vdd function is not used if you have
-                * an external regulator, or your design is really weird.
-                * Using it would mean sending in power control BOTH using
-                * a regulator AND the 4 MMCIPWR bits. If we don't have
-                * a regulator, we might have some other platform specific
-                * power control behind this translate function.
-                */
-               if (!host->vcc && host->plat->translate_vdd)
-                       pwr |= host->plat->translate_vdd(mmc_dev(mmc), ios->vdd);
+               if (host->plat->vdd_handler)
+                       pwr |= host->plat->vdd_handler(mmc_dev(mmc), ios->vdd,
+                                                      ios->power_mode);
                /* The ST version does not have this, fall through to POWER_ON */
                if (host->hw_designer != AMBA_VENDOR_ST) {
                        pwr |= MCI_PWR_UP;
@@ -555,21 +591,10 @@ static const struct mmc_host_ops mmci_ops = {
        .get_cd         = mmci_get_cd,
 };
 
-static void mmci_check_status(unsigned long data)
-{
-       struct mmci_host *host = (struct mmci_host *)data;
-       unsigned int status = mmci_get_cd(host->mmc);
-
-       if (status ^ host->oldstat)
-               mmc_detect_change(host->mmc, 0);
-
-       host->oldstat = status;
-       mod_timer(&host->timer, jiffies + HZ);
-}
-
 static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
 {
        struct mmci_platform_data *plat = dev->dev.platform_data;
+       struct variant_data *variant = id->data;
        struct mmci_host *host;
        struct mmc_host *mmc;
        int ret;
@@ -613,6 +638,7 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
                goto clk_free;
 
        host->plat = plat;
+       host->variant = variant;
        host->mclk = clk_get_rate(host->clk);
        /*
         * According to the spec, mclk is max 100 MHz,
@@ -673,6 +699,7 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
        if (host->vcc == NULL)
                mmc->ocr_avail = plat->ocr_mask;
        mmc->caps = plat->capabilities;
+       mmc->caps |= MMC_CAP_NEEDS_POLL;
 
        /*
         * We can do SGIO
@@ -681,10 +708,11 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
        mmc->max_phys_segs = NR_SG;
 
        /*
-        * Since we only have a 16-bit data length register, we must
-        * ensure that we don't exceed 2^16-1 bytes in a single request.
+        * Since only a certain number of bits are valid in the data length
+        * register, we must ensure that we don't exceed 2^num-1 bytes in a
+        * single request.
         */
-       mmc->max_req_size = 65535;
+       mmc->max_req_size = (1 << variant->datalength_bits) - 1;
 
        /*
         * Set the maximum segment size.  Since we aren't doing DMA
@@ -738,7 +766,6 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
        writel(MCI_IRQENABLE, host->base + MMCIMASK0);
 
        amba_set_drvdata(dev, mmc);
-       host->oldstat = mmci_get_cd(host->mmc);
 
        mmc_add_host(mmc);
 
@@ -746,12 +773,6 @@ static int __devinit mmci_probe(struct amba_device *dev, struct amba_id *id)
                mmc_hostname(mmc), amba_rev(dev), amba_config(dev),
                (unsigned long long)dev->res.start, dev->irq[0], dev->irq[1]);
 
-       init_timer(&host->timer);
-       host->timer.data = (unsigned long)host;
-       host->timer.function = mmci_check_status;
-       host->timer.expires = jiffies + HZ;
-       add_timer(&host->timer);
-
        return 0;
 
  irq0_free:
@@ -785,8 +806,6 @@ static int __devexit mmci_remove(struct amba_device *dev)
        if (mmc) {
                struct mmci_host *host = mmc_priv(mmc);
 
-               del_timer_sync(&host->timer);
-
                mmc_remove_host(mmc);
 
                writel(0, host->base + MMCIMASK0);
@@ -860,19 +879,28 @@ static struct amba_id mmci_ids[] = {
        {
                .id     = 0x00041180,
                .mask   = 0x000fffff,
+               .data   = &variant_arm,
        },
        {
                .id     = 0x00041181,
                .mask   = 0x000fffff,
+               .data   = &variant_arm,
        },
        /* ST Micro variants */
        {
                .id     = 0x00180180,
                .mask   = 0x00ffffff,
+               .data   = &variant_u300,
        },
        {
                .id     = 0x00280180,
                .mask   = 0x00ffffff,
+               .data   = &variant_u300,
+       },
+       {
+               .id     = 0x00480180,
+               .mask   = 0x00ffffff,
+               .data   = &variant_ux500,
        },
        { 0, 0 },
 };
index d77062e5e3af5425b15d31c6609aafa784ddeff3..68970cfb81e1396ca9f5a3f817e4c7ede777d6ea 100644 (file)
@@ -28,8 +28,6 @@
 #define MCI_4BIT_BUS           (1 << 11)
 /* 8bit wide buses supported in ST Micro versions */
 #define MCI_ST_8BIT_BUS                (1 << 12)
-/* HW flow control on the ST Micro version */
-#define MCI_ST_FCEN            (1 << 13)
 
 #define MMCIARGUMENT           0x008
 #define MMCICOMMAND            0x00c
 #define NR_SG          16
 
 struct clk;
+struct variant_data;
 
 struct mmci_host {
        void __iomem            *base;
@@ -164,6 +163,7 @@ struct mmci_host {
        unsigned int            cclk;
        u32                     pwr;
        struct mmci_platform_data *plat;
+       struct variant_data     *variant;
 
        u8                      hw_designer;
        u8                      hw_revision:4;
@@ -171,42 +171,9 @@ struct mmci_host {
        struct timer_list       timer;
        unsigned int            oldstat;
 
-       unsigned int            sg_len;
-
        /* pio stuff */
-       struct scatterlist      *sg_ptr;
-       unsigned int            sg_off;
+       struct sg_mapping_iter  sg_miter;
        unsigned int            size;
        struct regulator        *vcc;
 };
 
-static inline void mmci_init_sg(struct mmci_host *host, struct mmc_data *data)
-{
-       /*
-        * Ideally, we want the higher levels to pass us a scatter list.
-        */
-       host->sg_len = data->sg_len;
-       host->sg_ptr = data->sg;
-       host->sg_off = 0;
-}
-
-static inline int mmci_next_sg(struct mmci_host *host)
-{
-       host->sg_ptr++;
-       host->sg_off = 0;
-       return --host->sg_len;
-}
-
-static inline char *mmci_kmap_atomic(struct mmci_host *host, unsigned long *flags)
-{
-       struct scatterlist *sg = host->sg_ptr;
-
-       local_irq_save(*flags);
-       return kmap_atomic(sg_page(sg), KM_BIO_SRC_IRQ) + sg->offset;
-}
-
-static inline void mmci_kunmap_atomic(struct mmci_host *host, void *buffer, unsigned long *flags)
-{
-       kunmap_atomic(buffer, KM_BIO_SRC_IRQ);
-       local_irq_restore(*flags);
-}
index d9d4a72e0ec792d42386d21afcf327fa5b59f69c..350f78e8624511cfd1378c4b8365a2d6d956a4ae 100644 (file)
@@ -119,6 +119,7 @@ struct mxcmci_host {
        int                     detect_irq;
        int                     dma;
        int                     do_dma;
+       int                     default_irq_mask;
        int                     use_sdio;
        unsigned int            power_mode;
        struct imxmmc_platform_data *pdata;
@@ -228,7 +229,7 @@ static int mxcmci_setup_data(struct mxcmci_host *host, struct mmc_data *data)
 static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd,
                unsigned int cmdat)
 {
-       u32 int_cntr;
+       u32 int_cntr = host->default_irq_mask;
        unsigned long flags;
 
        WARN_ON(host->cmd != NULL);
@@ -275,7 +276,7 @@ static int mxcmci_start_cmd(struct mxcmci_host *host, struct mmc_command *cmd,
 static void mxcmci_finish_request(struct mxcmci_host *host,
                struct mmc_request *req)
 {
-       u32 int_cntr = 0;
+       u32 int_cntr = host->default_irq_mask;
        unsigned long flags;
 
        spin_lock_irqsave(&host->lock, flags);
@@ -585,6 +586,9 @@ static irqreturn_t mxcmci_irq(int irq, void *devid)
                  (stat & (STATUS_DATA_TRANS_DONE | STATUS_WRITE_OP_DONE)))
                mxcmci_data_done(host, stat);
 #endif
+       if (host->default_irq_mask &&
+                 (stat & (STATUS_CARD_INSERTION | STATUS_CARD_REMOVAL)))
+               mmc_detect_change(host->mmc, msecs_to_jiffies(200));
        return IRQ_HANDLED;
 }
 
@@ -809,6 +813,12 @@ static int mxcmci_probe(struct platform_device *pdev)
        else
                mmc->ocr_avail = MMC_VDD_32_33 | MMC_VDD_33_34;
 
+       if (host->pdata && host->pdata->dat3_card_detect)
+               host->default_irq_mask =
+                       INT_CARD_INSERTION_EN | INT_CARD_REMOVAL_EN;
+       else
+               host->default_irq_mask = 0;
+
        host->res = r;
        host->irq = irq;
 
@@ -835,7 +845,7 @@ static int mxcmci_probe(struct platform_device *pdev)
        /* recommended in data sheet */
        writew(0x2db4, host->base + MMC_REG_READ_TO);
 
-       writel(0, host->base + MMC_REG_INT_CNTR);
+       writel(host->default_irq_mask, host->base + MMC_REG_INT_CNTR);
 
 #ifdef HAS_DMA
        host->dma = imx_dma_request_by_prio(DRIVER_NAME, DMA_PRIO_LOW);
@@ -926,43 +936,47 @@ static int mxcmci_remove(struct platform_device *pdev)
 }
 
 #ifdef CONFIG_PM
-static int mxcmci_suspend(struct platform_device *dev, pm_message_t state)
+static int mxcmci_suspend(struct device *dev)
 {
-       struct mmc_host *mmc = platform_get_drvdata(dev);
+       struct mmc_host *mmc = dev_get_drvdata(dev);
+       struct mxcmci_host *host = mmc_priv(mmc);
        int ret = 0;
 
        if (mmc)
                ret = mmc_suspend_host(mmc);
+       clk_disable(host->clk);
 
        return ret;
 }
 
-static int mxcmci_resume(struct platform_device *dev)
+static int mxcmci_resume(struct device *dev)
 {
-       struct mmc_host *mmc = platform_get_drvdata(dev);
-       struct mxcmci_host *host;
+       struct mmc_host *mmc = dev_get_drvdata(dev);
+       struct mxcmci_host *host = mmc_priv(mmc);
        int ret = 0;
 
-       if (mmc) {
-               host = mmc_priv(mmc);
+       clk_enable(host->clk);
+       if (mmc)
                ret = mmc_resume_host(mmc);
-       }
 
        return ret;
 }
-#else
-#define mxcmci_suspend  NULL
-#define mxcmci_resume   NULL
-#endif /* CONFIG_PM */
+
+static const struct dev_pm_ops mxcmci_pm_ops = {
+       .suspend        = mxcmci_suspend,
+       .resume         = mxcmci_resume,
+};
+#endif
 
 static struct platform_driver mxcmci_driver = {
        .probe          = mxcmci_probe,
        .remove         = mxcmci_remove,
-       .suspend        = mxcmci_suspend,
-       .resume         = mxcmci_resume,
        .driver         = {
                .name           = DRIVER_NAME,
                .owner          = THIS_MODULE,
+#ifdef CONFIG_PM
+               .pm     = &mxcmci_pm_ops,
+#endif
        }
 };
 
index 82e94389824e74e2c8ca6b8007da09475dc5b1da..0d76b169482f47afff1bbb4f09696c771e3f829e 100644 (file)
@@ -623,8 +623,7 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
                else
                        host->buf_start = column + mtd->writesize;
 
-               if (mtd->writesize > 512)
-                       command = NAND_CMD_READ0; /* only READ0 is valid */
+               command = NAND_CMD_READ0; /* only READ0 is valid */
 
                send_cmd(host, command, false);
                mxc_do_addr_cycle(mtd, column, page_addr);
@@ -639,31 +638,11 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
                break;
 
        case NAND_CMD_SEQIN:
-               if (column >= mtd->writesize) {
-                       /*
-                        * FIXME: before send SEQIN command for write OOB,
-                        * We must read one page out.
-                        * For K9F1GXX has no READ1 command to set current HW
-                        * pointer to spare area, we must write the whole page
-                        * including OOB together.
-                        */
-                       if (mtd->writesize > 512)
-                               /* call ourself to read a page */
-                               mxc_nand_command(mtd, NAND_CMD_READ0, 0,
-                                               page_addr);
-
-                       host->buf_start = column;
-
-                       /* Set program pointer to spare region */
-                       if (mtd->writesize == 512)
-                               send_cmd(host, NAND_CMD_READOOB, false);
-               } else {
-                       host->buf_start = column;
+               if (column >= mtd->writesize)
+                       /* call ourself to read a page */
+                       mxc_nand_command(mtd, NAND_CMD_READ0, 0, page_addr);
 
-                       /* Set program pointer to page start */
-                       if (mtd->writesize == 512)
-                               send_cmd(host, NAND_CMD_READ0, false);
-               }
+               host->buf_start = column;
 
                send_cmd(host, command, false);
                mxc_do_addr_cycle(mtd, column, page_addr);
@@ -853,6 +832,8 @@ static int __init mxcnd_probe(struct platform_device *pdev)
            parse_mtd_partitions(mtd, part_probes, &host->parts, 0);
        if (nr_parts > 0)
                add_mtd_partitions(mtd, host->parts, nr_parts);
+       else if (pdata->parts)
+               add_mtd_partitions(mtd, pdata->parts, pdata->nr_parts);
        else
 #endif
        {
index 13b05cb33b085fbb063a1024f30feb239a82c9de..78ae89488a4fbc54550bf4a7dd54877035b295ec 100644 (file)
@@ -593,6 +593,7 @@ static int attach_by_scanning(struct ubi_device *ubi)
        ubi->good_peb_count = ubi->peb_count - ubi->bad_peb_count;
        ubi->max_ec = si->max_ec;
        ubi->mean_ec = si->mean_ec;
+       ubi_msg("max. sequence number:       %llu", si->max_sqnum);
 
        err = ubi_read_volume_table(ubi, si);
        if (err)
@@ -981,7 +982,7 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num, int vid_hdr_offset)
        ubi_msg("number of PEBs reserved for bad PEB handling: %d",
                ubi->beb_rsvd_pebs);
        ubi_msg("max/mean erase counter: %d/%d", ubi->max_ec, ubi->mean_ec);
-       ubi_msg("image sequence number: %d", ubi->image_seq);
+       ubi_msg("image sequence number:  %d", ubi->image_seq);
 
        /*
         * The below lock makes sure we do not race with 'ubi_thread()' which
index 9f87c99189a99cca2e30dbe35b2a7441203a663e..fe74749e0dae734271b9a6b9e780f11e5cbb021c 100644 (file)
@@ -418,7 +418,8 @@ retry:
                                 * may try to recover data. FIXME: but this is
                                 * not implemented.
                                 */
-                               if (err == UBI_IO_BAD_VID_HDR) {
+                               if (err == UBI_IO_BAD_HDR_READ ||
+                                   err == UBI_IO_BAD_HDR) {
                                        ubi_warn("corrupted VID header at PEB "
                                                 "%d, LEB %d:%d", pnum, vol_id,
                                                 lnum);
@@ -961,8 +962,8 @@ write_error:
  */
 static int is_error_sane(int err)
 {
-       if (err == -EIO || err == -ENOMEM || err == UBI_IO_BAD_VID_HDR ||
-           err == -ETIMEDOUT)
+       if (err == -EIO || err == -ENOMEM || err == UBI_IO_BAD_HDR ||
+           err == UBI_IO_BAD_HDR_READ || err == -ETIMEDOUT)
                return 0;
        return 1;
 }
@@ -1164,6 +1165,44 @@ out_unlock_leb:
        return err;
 }
 
+/**
+ * print_rsvd_warning - warn about not having enough reserved PEBs.
+ * @ubi: UBI device description object
+ *
+ * This is a helper function for 'ubi_eba_init_scan()' which is called when UBI
+ * cannot reserve enough PEBs for bad block handling. This function makes a
+ * decision whether we have to print a warning or not. The algorithm is as
+ * follows:
+ *   o if this is a new UBI image, then just print the warning
+ *   o if this is an UBI image which has already been used for some time, print
+ *     a warning only if we can reserve less than 10% of the expected amount of
+ *     the reserved PEB.
+ *
+ * The idea is that when UBI is used, PEBs become bad, and the reserved pool
+ * of PEBs becomes smaller, which is normal and we do not want to scare users
+ * with a warning every time they attach the MTD device. This was an issue
+ * reported by real users.
+ */
+static void print_rsvd_warning(struct ubi_device *ubi,
+                              struct ubi_scan_info *si)
+{
+       /*
+        * The 1 << 18 (256KiB) number is picked randomly, just a reasonably
+        * large number to distinguish between newly flashed and used images.
+        */
+       if (si->max_sqnum > (1 << 18)) {
+               int min = ubi->beb_rsvd_level / 10;
+
+               if (!min)
+                       min = 1;
+               if (ubi->beb_rsvd_pebs > min)
+                       return;
+       }
+
+       ubi_warn("cannot reserve enough PEBs for bad PEB handling, reserved %d,"
+                " need %d", ubi->beb_rsvd_pebs, ubi->beb_rsvd_level);
+}
+
 /**
  * ubi_eba_init_scan - initialize the EBA sub-system using scanning information.
  * @ubi: UBI device description object
@@ -1236,9 +1275,7 @@ int ubi_eba_init_scan(struct ubi_device *ubi, struct ubi_scan_info *si)
                if (ubi->avail_pebs < ubi->beb_rsvd_level) {
                        /* No enough free physical eraseblocks */
                        ubi->beb_rsvd_pebs = ubi->avail_pebs;
-                       ubi_warn("cannot reserve enough PEBs for bad PEB "
-                                "handling, reserved %d, need %d",
-                                ubi->beb_rsvd_pebs, ubi->beb_rsvd_level);
+                       print_rsvd_warning(ubi, si);
                } else
                        ubi->beb_rsvd_pebs = ubi->beb_rsvd_level;
 
index 4b979e34b159a7f5e7e397404ff89c0cc3421648..332f992f13d982e4d1d46164f673a4f67914ce87 100644 (file)
@@ -150,6 +150,8 @@ int ubi_io_read(const struct ubi_device *ubi, void *buf, int pnum, int offset,
 retry:
        err = ubi->mtd->read(ubi->mtd, addr, len, &read, buf);
        if (err) {
+               const char *errstr = (err == -EBADMSG) ? " (ECC error)" : "";
+
                if (err == -EUCLEAN) {
                        /*
                         * -EUCLEAN is reported if there was a bit-flip which
@@ -165,15 +167,15 @@ retry:
                }
 
                if (read != len && retries++ < UBI_IO_RETRIES) {
-                       dbg_io("error %d while reading %d bytes from PEB %d:%d,"
+                       dbg_io("error %d%s while reading %d bytes from PEB %d:%d,"
                               " read only %zd bytes, retry",
-                              err, len, pnum, offset, read);
+                              err, errstr, len, pnum, offset, read);
                        yield();
                        goto retry;
                }
 
-               ubi_err("error %d while reading %d bytes from PEB %d:%d, "
-                       "read %zd bytes", err, len, pnum, offset, read);
+               ubi_err("error %d%s while reading %d bytes from PEB %d:%d, "
+                       "read %zd bytes", err, errstr, len, pnum, offset, read);
                ubi_dbg_dump_stack();
 
                /*
@@ -515,7 +517,7 @@ static int nor_erase_prepare(struct ubi_device *ubi, int pnum)
         * In this case we probably anyway have garbage in this PEB.
         */
        err1 = ubi_io_read_vid_hdr(ubi, pnum, &vid_hdr, 0);
-       if (err1 == UBI_IO_BAD_VID_HDR)
+       if (err1 == UBI_IO_BAD_HDR_READ || err1 == UBI_IO_BAD_HDR)
                /*
                 * The VID header is corrupted, so we can safely erase this
                 * PEB and not afraid that it will be treated as a valid PEB in
@@ -709,7 +711,7 @@ bad:
  * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected
  *   and corrected by the flash driver; this is harmless but may indicate that
  *   this eraseblock may become bad soon (but may be not);
- * o %UBI_IO_BAD_EC_HDR if the erase counter header is corrupted (a CRC error);
+ * o %UBI_IO_BAD_HDR if the erase counter header is corrupted (a CRC error);
  * o %UBI_IO_PEB_EMPTY if the physical eraseblock is empty;
  * o a negative error code in case of failure.
  */
@@ -736,23 +738,21 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
                 * header is still OK, we just report this as there was a
                 * bit-flip.
                 */
-               read_err = err;
+               if (err == -EBADMSG)
+                       read_err = UBI_IO_BAD_HDR_READ;
        }
 
        magic = be32_to_cpu(ec_hdr->magic);
        if (magic != UBI_EC_HDR_MAGIC) {
+               if (read_err)
+                       return read_err;
+
                /*
                 * The magic field is wrong. Let's check if we have read all
                 * 0xFF. If yes, this physical eraseblock is assumed to be
                 * empty.
-                *
-                * But if there was a read error, we do not test it for all
-                * 0xFFs. Even if it does contain all 0xFFs, this error
-                * indicates that something is still wrong with this physical
-                * eraseblock and we anyway cannot treat it as empty.
                 */
-               if (read_err != -EBADMSG &&
-                   check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) {
+               if (check_pattern(ec_hdr, 0xFF, UBI_EC_HDR_SIZE)) {
                        /* The physical eraseblock is supposedly empty */
                        if (verbose)
                                ubi_warn("no EC header found at PEB %d, "
@@ -774,7 +774,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
                } else if (UBI_IO_DEBUG)
                        dbg_msg("bad magic number at PEB %d: %08x instead of "
                                "%08x", pnum, magic, UBI_EC_HDR_MAGIC);
-               return UBI_IO_BAD_EC_HDR;
+               return UBI_IO_BAD_HDR;
        }
 
        crc = crc32(UBI_CRC32_INIT, ec_hdr, UBI_EC_HDR_SIZE_CRC);
@@ -788,7 +788,7 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
                } else if (UBI_IO_DEBUG)
                        dbg_msg("bad EC header CRC at PEB %d, calculated "
                                "%#08x, read %#08x", pnum, crc, hdr_crc);
-               return UBI_IO_BAD_EC_HDR;
+               return read_err ?: UBI_IO_BAD_HDR;
        }
 
        /* And of course validate what has just been read from the media */
@@ -798,6 +798,10 @@ int ubi_io_read_ec_hdr(struct ubi_device *ubi, int pnum,
                return -EINVAL;
        }
 
+       /*
+        * If there was %-EBADMSG, but the header CRC is still OK, report about
+        * a bit-flip to force scrubbing on this PEB.
+        */
        return read_err ? UBI_IO_BITFLIPS : 0;
 }
 
@@ -977,7 +981,7 @@ bad:
  * o %UBI_IO_BITFLIPS if the CRC is correct, but bit-flips were detected
  *   and corrected by the flash driver; this is harmless but may indicate that
  *   this eraseblock may become bad soon;
- * o %UBI_IO_BAD_VID_HDR if the volume identifier header is corrupted (a CRC
+ * o %UBI_IO_BAD_HDR if the volume identifier header is corrupted (a CRC
  *   error detected);
  * o %UBI_IO_PEB_FREE if the physical eraseblock is free (i.e., there is no VID
  *   header there);
@@ -1008,22 +1012,20 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
                 * CRC check-sum and we will identify this. If the VID header is
                 * still OK, we just report this as there was a bit-flip.
                 */
-               read_err = err;
+               if (err == -EBADMSG)
+                       read_err = UBI_IO_BAD_HDR_READ;
        }
 
        magic = be32_to_cpu(vid_hdr->magic);
        if (magic != UBI_VID_HDR_MAGIC) {
+               if (read_err)
+                       return read_err;
+
                /*
                 * If we have read all 0xFF bytes, the VID header probably does
                 * not exist and the physical eraseblock is assumed to be free.
-                *
-                * But if there was a read error, we do not test the data for
-                * 0xFFs. Even if it does contain all 0xFFs, this error
-                * indicates that something is still wrong with this physical
-                * eraseblock and it cannot be regarded as free.
                 */
-               if (read_err != -EBADMSG &&
-                   check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
+               if (check_pattern(vid_hdr, 0xFF, UBI_VID_HDR_SIZE)) {
                        /* The physical eraseblock is supposedly free */
                        if (verbose)
                                ubi_warn("no VID header found at PEB %d, "
@@ -1045,7 +1047,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
                } else if (UBI_IO_DEBUG)
                        dbg_msg("bad magic number at PEB %d: %08x instead of "
                                "%08x", pnum, magic, UBI_VID_HDR_MAGIC);
-               return UBI_IO_BAD_VID_HDR;
+               return UBI_IO_BAD_HDR;
        }
 
        crc = crc32(UBI_CRC32_INIT, vid_hdr, UBI_VID_HDR_SIZE_CRC);
@@ -1059,7 +1061,7 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
                } else if (UBI_IO_DEBUG)
                        dbg_msg("bad CRC at PEB %d, calculated %#08x, "
                                "read %#08x", pnum, crc, hdr_crc);
-               return UBI_IO_BAD_VID_HDR;
+               return read_err ?: UBI_IO_BAD_HDR;
        }
 
        /* Validate the VID header that we have just read */
@@ -1069,6 +1071,10 @@ int ubi_io_read_vid_hdr(struct ubi_device *ubi, int pnum,
                return -EINVAL;
        }
 
+       /*
+        * If there was a read error (%-EBADMSG), but the header CRC is still
+        * OK, report about a bit-flip to force scrubbing on this PEB.
+        */
        return read_err ? UBI_IO_BITFLIPS : 0;
 }
 
index aed19f33b8f3ec1685fd40acf121df738c2c77d4..372a15ac9995a64c7fc8f8084c75cb59ba4251d1 100644 (file)
@@ -44,6 +44,7 @@
 #include <linux/slab.h>
 #include <linux/crc32.h>
 #include <linux/math64.h>
+#include <linux/random.h>
 #include "ubi.h"
 
 #ifdef CONFIG_MTD_UBI_DEBUG_PARANOID
@@ -72,16 +73,19 @@ static int add_to_list(struct ubi_scan_info *si, int pnum, int ec,
 {
        struct ubi_scan_leb *seb;
 
-       if (list == &si->free)
+       if (list == &si->free) {
                dbg_bld("add to free: PEB %d, EC %d", pnum, ec);
-       else if (list == &si->erase)
+               si->free_peb_count += 1;
+       } else if (list == &si->erase) {
                dbg_bld("add to erase: PEB %d, EC %d", pnum, ec);
-       else if (list == &si->corr) {
+               si->erase_peb_count += 1;
+       } else if (list == &si->corr) {
                dbg_bld("add to corrupted: PEB %d, EC %d", pnum, ec);
-               si->corr_count += 1;
-       } else if (list == &si->alien)
+               si->corr_peb_count += 1;
+       } else if (list == &si->alien) {
                dbg_bld("add to alien: PEB %d, EC %d", pnum, ec);
-       else
+               si->alien_peb_count += 1;
+       } else
                BUG();
 
        seb = kmalloc(sizeof(struct ubi_scan_leb), GFP_KERNEL);
@@ -517,6 +521,7 @@ int ubi_scan_add_used(struct ubi_device *ubi, struct ubi_scan_info *si,
        sv->leb_count += 1;
        rb_link_node(&seb->u.rb, parent, p);
        rb_insert_color(&seb->u.rb, &sv->root);
+       si->used_peb_count += 1;
        return 0;
 }
 
@@ -745,19 +750,17 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
                bitflips = 1;
        else if (err == UBI_IO_PEB_EMPTY)
                return add_to_list(si, pnum, UBI_SCAN_UNKNOWN_EC, &si->erase);
-       else if (err == UBI_IO_BAD_EC_HDR) {
+       else if (err == UBI_IO_BAD_HDR_READ || err == UBI_IO_BAD_HDR) {
                /*
                 * We have to also look at the VID header, possibly it is not
                 * corrupted. Set %bitflips flag in order to make this PEB be
                 * moved and EC be re-created.
                 */
-               ec_corr = 1;
+               ec_corr = err;
                ec = UBI_SCAN_UNKNOWN_EC;
                bitflips = 1;
        }
 
-       si->is_empty = 0;
-
        if (!ec_corr) {
                int image_seq;
 
@@ -813,9 +816,12 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
                return err;
        else if (err == UBI_IO_BITFLIPS)
                bitflips = 1;
-       else if (err == UBI_IO_BAD_VID_HDR ||
+       else if (err == UBI_IO_BAD_HDR_READ || err == UBI_IO_BAD_HDR ||
                 (err == UBI_IO_PEB_FREE && ec_corr)) {
                /* VID header is corrupted */
+               if (err == UBI_IO_BAD_HDR_READ ||
+                   ec_corr == UBI_IO_BAD_HDR_READ)
+                       si->read_err_count += 1;
                err = add_to_list(si, pnum, ec, &si->corr);
                if (err)
                        return err;
@@ -836,11 +842,11 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
                switch (vidh->compat) {
                case UBI_COMPAT_DELETE:
                        ubi_msg("\"delete\" compatible internal volume %d:%d"
-                               " found, remove it", vol_id, lnum);
+                               " found, will remove it", vol_id, lnum);
                        err = add_to_list(si, pnum, ec, &si->corr);
                        if (err)
                                return err;
-                       break;
+                       return 0;
 
                case UBI_COMPAT_RO:
                        ubi_msg("read-only compatible internal volume %d:%d"
@@ -855,7 +861,6 @@ static int process_eb(struct ubi_device *ubi, struct ubi_scan_info *si,
                        err = add_to_list(si, pnum, ec, &si->alien);
                        if (err)
                                return err;
-                       si->alien_peb_count += 1;
                        return 0;
 
                case UBI_COMPAT_REJECT:
@@ -885,6 +890,85 @@ adjust_mean_ec:
        return 0;
 }
 
+/**
+ * check_what_we_have - check what PEB were found by scanning.
+ * @ubi: UBI device description object
+ * @si: scanning information
+ *
+ * This is a helper function which takes a look what PEBs were found by
+ * scanning, and decides whether the flash is empty and should be formatted and
+ * whether there are too many corrupted PEBs and we should not attach this
+ * MTD device. Returns zero if we should proceed with attaching the MTD device,
+ * and %-EINVAL if we should not.
+ */
+static int check_what_we_have(struct ubi_device *ubi, struct ubi_scan_info *si)
+{
+       struct ubi_scan_leb *seb;
+       int max_corr;
+
+       max_corr = ubi->peb_count - si->bad_peb_count - si->alien_peb_count;
+       max_corr = max_corr / 20 ?: 8;
+
+       /*
+        * Few corrupted PEBs are not a problem and may be just a result of
+        * unclean reboots. However, many of them may indicate some problems
+        * with the flash HW or driver.
+        */
+       if (si->corr_peb_count >= 8) {
+               ubi_warn("%d PEBs are corrupted", si->corr_peb_count);
+               printk(KERN_WARNING "corrupted PEBs are:");
+               list_for_each_entry(seb, &si->corr, u.list)
+                       printk(KERN_CONT " %d", seb->pnum);
+               printk(KERN_CONT "\n");
+
+               /*
+                * If too many PEBs are corrupted, we refuse attaching,
+                * otherwise, only print a warning.
+                */
+               if (si->corr_peb_count >= max_corr) {
+                       ubi_err("too many corrupted PEBs, refusing this device");
+                       return -EINVAL;
+               }
+       }
+
+       if (si->free_peb_count + si->used_peb_count +
+           si->alien_peb_count == 0) {
+               /* No UBI-formatted eraseblocks were found */
+               if (si->corr_peb_count == si->read_err_count &&
+                   si->corr_peb_count < 8) {
+                       /* No or just few corrupted PEBs, and all of them had a
+                        * read error. We assume that those are bad PEBs, which
+                        * were just not marked as bad so far.
+                        *
+                        * This piece of code basically tries to distinguish
+                        * between the following 2 situations:
+                        *
+                        * 1. Flash is empty, but there are few bad PEBs, which
+                        *    are not marked as bad so far, and which were read
+                        *    with error. We want to go ahead and format this
+                        *    flash. While formating, the faulty PEBs will
+                        *    probably be marked as bad.
+                        *
+                        * 2. Flash probably contains non-UBI data and we do
+                        * not want to format it and destroy possibly needed
+                        * data (e.g., consider the case when the bootloader
+                        * MTD partition was accidentally fed to UBI).
+                        */
+                       si->is_empty = 1;
+                       ubi_msg("empty MTD device detected");
+                       get_random_bytes(&ubi->image_seq, sizeof(ubi->image_seq));
+               } else {
+                       ubi_err("MTD device possibly contains non-UBI data, "
+                               "refusing it");
+                       return -EINVAL;
+               }
+       }
+
+       if (si->corr_peb_count > 0)
+               ubi_msg("corrupted PEBs will be formatted");
+       return 0;
+}
+
 /**
  * ubi_scan - scan an MTD device.
  * @ubi: UBI device description object
@@ -909,7 +993,6 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
        INIT_LIST_HEAD(&si->erase);
        INIT_LIST_HEAD(&si->alien);
        si->volumes = RB_ROOT;
-       si->is_empty = 1;
 
        err = -ENOMEM;
        ech = kzalloc(ubi->ec_hdr_alsize, GFP_KERNEL);
@@ -935,21 +1018,9 @@ struct ubi_scan_info *ubi_scan(struct ubi_device *ubi)
        if (si->ec_count)
                si->mean_ec = div_u64(si->ec_sum, si->ec_count);
 
-       if (si->is_empty)
-               ubi_msg("empty MTD device detected");
-
-       /*
-        * Few corrupted PEBs are not a problem and may be just a result of
-        * unclean reboots. However, many of them may indicate some problems
-        * with the flash HW or driver. Print a warning in this case.
-        */
-       if (si->corr_count >= 8 || si->corr_count >= ubi->peb_count / 4) {
-               ubi_warn("%d PEBs are corrupted", si->corr_count);
-               printk(KERN_WARNING "corrupted PEBs are:");
-               list_for_each_entry(seb, &si->corr, u.list)
-                       printk(KERN_CONT " %d", seb->pnum);
-               printk(KERN_CONT "\n");
-       }
+       err = check_what_we_have(ubi, si);
+       if (err)
+               goto out_vidh;
 
        /*
         * In case of unknown erase counter we use the mean erase counter
index ff179ad7ca55965ed4a710c1910721e47f6c36e6..2576a8d1532b700d659391bbe6d3e1364acbcaef 100644 (file)
@@ -91,10 +91,16 @@ struct ubi_scan_volume {
  * @erase: list of physical eraseblocks which have to be erased
  * @alien: list of physical eraseblocks which should not be used by UBI (e.g.,
  *         those belonging to "preserve"-compatible internal volumes)
+ * @used_peb_count: count of used PEBs
+ * @corr_peb_count: count of PEBs in the @corr list
+ * @read_err_count: count of PEBs read with error (%UBI_IO_BAD_HDR_READ was
+ *                  returned)
+ * @free_peb_count: count of PEBs in the @free list
+ * @erase_peb_count: count of PEBs in the @erase list
+ * @alien_peb_count: count of PEBs in the @alien list
  * @bad_peb_count: count of bad physical eraseblocks
  * @vols_found: number of volumes found during scanning
  * @highest_vol_id: highest volume ID
- * @alien_peb_count: count of physical eraseblocks in the @alien list
  * @is_empty: flag indicating whether the MTD device is empty or not
  * @min_ec: lowest erase counter value
  * @max_ec: highest erase counter value
@@ -102,7 +108,6 @@ struct ubi_scan_volume {
  * @mean_ec: mean erase counter value
  * @ec_sum: a temporary variable used when calculating @mean_ec
  * @ec_count: a temporary variable used when calculating @mean_ec
- * @corr_count: count of corrupted PEBs
  *
  * This data structure contains the result of scanning and may be used by other
  * UBI sub-systems to build final UBI data structures, further error-recovery
@@ -114,10 +119,15 @@ struct ubi_scan_info {
        struct list_head free;
        struct list_head erase;
        struct list_head alien;
+       int used_peb_count;
+       int corr_peb_count;
+       int read_err_count;
+       int free_peb_count;
+       int erase_peb_count;
+       int alien_peb_count;
        int bad_peb_count;
        int vols_found;
        int highest_vol_id;
-       int alien_peb_count;
        int is_empty;
        int min_ec;
        int max_ec;
@@ -125,7 +135,6 @@ struct ubi_scan_info {
        int mean_ec;
        uint64_t ec_sum;
        int ec_count;
-       int corr_count;
 };
 
 struct ubi_device;
@@ -135,7 +144,7 @@ struct ubi_vid_hdr;
  * ubi_scan_move_to_list - move a PEB from the volume tree to a list.
  *
  * @sv: volume scanning information
- * @seb: scanning eraseblock infprmation
+ * @seb: scanning eraseblock information
  * @list: the list to move to
  */
 static inline void ubi_scan_move_to_list(struct ubi_scan_volume *sv,
index a637f0283add2fd98d006228b18a3bff3c8b79be..0359e0cce4827ea7dd778d188b5ff7d6dde5b9d3 100644 (file)
  *                   %0xFF bytes
  * UBI_IO_PEB_FREE: the physical eraseblock is free, i.e. it contains only a
  *                  valid erase counter header, and the rest are %0xFF bytes
- * UBI_IO_BAD_EC_HDR: the erase counter header is corrupted (bad magic or CRC)
- * UBI_IO_BAD_VID_HDR: the volume identifier header is corrupted (bad magic or
- *                     CRC)
+ * UBI_IO_BAD_HDR: the EC or VID header is corrupted (bad magic or CRC)
+ * UBI_IO_BAD_HDR_READ: the same as %UBI_IO_BAD_HDR, but also there was a read
+ *                     error reported by the flash driver
  * UBI_IO_BITFLIPS: bit-flips were detected and corrected
  */
 enum {
        UBI_IO_PEB_EMPTY = 1,
        UBI_IO_PEB_FREE,
-       UBI_IO_BAD_EC_HDR,
-       UBI_IO_BAD_VID_HDR,
+       UBI_IO_BAD_HDR,
+       UBI_IO_BAD_HDR_READ,
        UBI_IO_BITFLIPS
 };
 
index 78b74e83ce5df7f242fe579676f7623c8d84e6f3..5a1bd5db2a93b3bfc3540e5cd81b76d05b553e0e 100644 (file)
@@ -29,6 +29,7 @@
 #include <linux/mii.h>
 #include <linux/ethtool.h>
 #include <linux/phy.h>
+#include <linux/marvell_phy.h>
 
 #include <asm/io.h>
 #include <asm/irq.h>
@@ -48,8 +49,6 @@
 #define MII_M1145_RGMII_RX_DELAY       0x0080
 #define MII_M1145_RGMII_TX_DELAY       0x0002
 
-#define M1145_DEV_FLAGS_RESISTANCE     0x00000001
-
 #define MII_M1111_PHY_LED_CONTROL      0x18
 #define MII_M1111_PHY_LED_DIRECT       0x4100
 #define MII_M1111_PHY_LED_COMBINE      0x411c
@@ -350,7 +349,10 @@ static int m88e1118_config_init(struct phy_device *phydev)
                return err;
 
        /* Adjust LED Control */
-       err = phy_write(phydev, 0x10, 0x021e);
+       if (phydev->dev_flags & MARVELL_PHY_M1118_DNS323_LEDS)
+               err = phy_write(phydev, 0x10, 0x1100);
+       else
+               err = phy_write(phydev, 0x10, 0x021e);
        if (err < 0)
                return err;
 
@@ -398,7 +400,7 @@ static int m88e1145_config_init(struct phy_device *phydev)
                if (err < 0)
                        return err;
 
-               if (phydev->dev_flags & M1145_DEV_FLAGS_RESISTANCE) {
+               if (phydev->dev_flags & MARVELL_PHY_M1145_FLAGS_RESISTANCE) {
                        err = phy_write(phydev, 0x1d, 0x0012);
                        if (err < 0)
                                return err;
@@ -529,8 +531,8 @@ static int m88e1121_did_interrupt(struct phy_device *phydev)
 
 static struct phy_driver marvell_drivers[] = {
        {
-               .phy_id = 0x01410c60,
-               .phy_id_mask = 0xfffffff0,
+               .phy_id = MARVELL_PHY_ID_88E1101,
+               .phy_id_mask = MARVELL_PHY_ID_MASK,
                .name = "Marvell 88E1101",
                .features = PHY_GBIT_FEATURES,
                .flags = PHY_HAS_INTERRUPT,
@@ -541,8 +543,8 @@ static struct phy_driver marvell_drivers[] = {
                .driver = { .owner = THIS_MODULE },
        },
        {
-               .phy_id = 0x01410c90,
-               .phy_id_mask = 0xfffffff0,
+               .phy_id = MARVELL_PHY_ID_88E1112,
+               .phy_id_mask = MARVELL_PHY_ID_MASK,
                .name = "Marvell 88E1112",
                .features = PHY_GBIT_FEATURES,
                .flags = PHY_HAS_INTERRUPT,
@@ -554,8 +556,8 @@ static struct phy_driver marvell_drivers[] = {
                .driver = { .owner = THIS_MODULE },
        },
        {
-               .phy_id = 0x01410cc0,
-               .phy_id_mask = 0xfffffff0,
+               .phy_id = MARVELL_PHY_ID_88E1111,
+               .phy_id_mask = MARVELL_PHY_ID_MASK,
                .name = "Marvell 88E1111",
                .features = PHY_GBIT_FEATURES,
                .flags = PHY_HAS_INTERRUPT,
@@ -567,8 +569,8 @@ static struct phy_driver marvell_drivers[] = {
                .driver = { .owner = THIS_MODULE },
        },
        {
-               .phy_id = 0x01410e10,
-               .phy_id_mask = 0xfffffff0,
+               .phy_id = MARVELL_PHY_ID_88E1118,
+               .phy_id_mask = MARVELL_PHY_ID_MASK,
                .name = "Marvell 88E1118",
                .features = PHY_GBIT_FEATURES,
                .flags = PHY_HAS_INTERRUPT,
@@ -580,8 +582,8 @@ static struct phy_driver marvell_drivers[] = {
                .driver = {.owner = THIS_MODULE,},
        },
        {
-               .phy_id = 0x01410cb0,
-               .phy_id_mask = 0xfffffff0,
+               .phy_id = MARVELL_PHY_ID_88E1121R,
+               .phy_id_mask = MARVELL_PHY_ID_MASK,
                .name = "Marvell 88E1121R",
                .features = PHY_GBIT_FEATURES,
                .flags = PHY_HAS_INTERRUPT,
@@ -593,8 +595,8 @@ static struct phy_driver marvell_drivers[] = {
                .driver = { .owner = THIS_MODULE },
        },
        {
-               .phy_id = 0x01410cd0,
-               .phy_id_mask = 0xfffffff0,
+               .phy_id = MARVELL_PHY_ID_88E1145,
+               .phy_id_mask = MARVELL_PHY_ID_MASK,
                .name = "Marvell 88E1145",
                .features = PHY_GBIT_FEATURES,
                .flags = PHY_HAS_INTERRUPT,
@@ -606,8 +608,8 @@ static struct phy_driver marvell_drivers[] = {
                .driver = { .owner = THIS_MODULE },
        },
        {
-               .phy_id = 0x01410e30,
-               .phy_id_mask = 0xfffffff0,
+               .phy_id = MARVELL_PHY_ID_88E1240,
+               .phy_id_mask = MARVELL_PHY_ID_MASK,
                .name = "Marvell 88E1240",
                .features = PHY_GBIT_FEATURES,
                .flags = PHY_HAS_INTERRUPT,
index 188bc8496a264feb05758e36cd7c2e23dea37b63..d02be78a41386b2ecb94c249cff8da11776ecb4a 100644 (file)
@@ -176,16 +176,18 @@ static ssize_t led_proc_write(struct file *file, const char *buf,
        size_t count, loff_t *pos)
 {
        void *data = PDE(file->f_path.dentry->d_inode)->data;
-       char *cur, lbuf[count + 1];
+       char *cur, lbuf[32];
        int d;
 
        if (!capable(CAP_SYS_ADMIN))
                return -EACCES;
 
-       memset(lbuf, 0, count + 1);
+       if (count >= sizeof(lbuf))
+               count = sizeof(lbuf)-1;
 
        if (copy_from_user(lbuf, buf, count))
                return -EFAULT;
+       lbuf[count] = 0;
 
        cur = lbuf;
 
index 3587d9922f2895832059f1ea1163e715750dd19a..71bbefc3544ee7782539083ace3ca2ea11931a1e 100644 (file)
@@ -456,7 +456,7 @@ static struct rtc_class_ops stv2_pl031_ops = {
        .irq_set_freq = pl031_irq_set_freq,
 };
 
-static struct amba_id pl031_ids[] __initdata = {
+static struct amba_id pl031_ids[] = {
        {
                .id = 0x00041031,
                .mask = 0x000fffff,
index b09a638d051fde98c37e52a58eb2cb9a25756663..50441ffe8e3856592dbfdae368e9891b64078d50 100644 (file)
@@ -782,7 +782,7 @@ static int pl010_resume(struct amba_device *dev)
        return 0;
 }
 
-static struct amba_id pl010_ids[] __initdata = {
+static struct amba_id pl010_ids[] = {
        {
                .id     = 0x00041010,
                .mask   = 0x000fffff,
index eb4cb480b93e9be344f9f84bbd574c68fe3ec8e6..6ca7a44f29c205ef37c95318253e2592efaa459b 100644 (file)
 struct uart_amba_port {
        struct uart_port        port;
        struct clk              *clk;
-       unsigned int            im;     /* interrupt mask */
+       unsigned int            im;             /* interrupt mask */
        unsigned int            old_status;
-       unsigned int            ifls;   /* vendor-specific */
+       unsigned int            ifls;           /* vendor-specific */
+       unsigned int            lcrh_tx;        /* vendor-specific */
+       unsigned int            lcrh_rx;        /* vendor-specific */
+       bool                    oversampling;   /* vendor-specific */
        bool                    autorts;
 };
 
@@ -79,16 +82,25 @@ struct uart_amba_port {
 struct vendor_data {
        unsigned int            ifls;
        unsigned int            fifosize;
+       unsigned int            lcrh_tx;
+       unsigned int            lcrh_rx;
+       bool                    oversampling;
 };
 
 static struct vendor_data vendor_arm = {
        .ifls                   = UART011_IFLS_RX4_8|UART011_IFLS_TX4_8,
        .fifosize               = 16,
+       .lcrh_tx                = UART011_LCRH,
+       .lcrh_rx                = UART011_LCRH,
+       .oversampling           = false,
 };
 
 static struct vendor_data vendor_st = {
        .ifls                   = UART011_IFLS_RX_HALF|UART011_IFLS_TX_HALF,
        .fifosize               = 64,
+       .lcrh_tx                = ST_UART011_LCRH_TX,
+       .lcrh_rx                = ST_UART011_LCRH_RX,
+       .oversampling           = true,
 };
 
 static void pl011_stop_tx(struct uart_port *port)
@@ -327,12 +339,12 @@ static void pl011_break_ctl(struct uart_port *port, int break_state)
        unsigned int lcr_h;
 
        spin_lock_irqsave(&uap->port.lock, flags);
-       lcr_h = readw(uap->port.membase + UART011_LCRH);
+       lcr_h = readw(uap->port.membase + uap->lcrh_tx);
        if (break_state == -1)
                lcr_h |= UART01x_LCRH_BRK;
        else
                lcr_h &= ~UART01x_LCRH_BRK;
-       writew(lcr_h, uap->port.membase + UART011_LCRH);
+       writew(lcr_h, uap->port.membase + uap->lcrh_tx);
        spin_unlock_irqrestore(&uap->port.lock, flags);
 }
 
@@ -393,7 +405,17 @@ static int pl011_startup(struct uart_port *port)
        writew(cr, uap->port.membase + UART011_CR);
        writew(0, uap->port.membase + UART011_FBRD);
        writew(1, uap->port.membase + UART011_IBRD);
-       writew(0, uap->port.membase + UART011_LCRH);
+       writew(0, uap->port.membase + uap->lcrh_rx);
+       if (uap->lcrh_tx != uap->lcrh_rx) {
+               int i;
+               /*
+                * Wait 10 PCLKs before writing LCRH_TX register,
+                * to get this delay write read only register 10 times
+                */
+               for (i = 0; i < 10; ++i)
+                       writew(0xff, uap->port.membase + UART011_MIS);
+               writew(0, uap->port.membase + uap->lcrh_tx);
+       }
        writew(0, uap->port.membase + UART01x_DR);
        while (readw(uap->port.membase + UART01x_FR) & UART01x_FR_BUSY)
                barrier();
@@ -422,10 +444,19 @@ static int pl011_startup(struct uart_port *port)
        return retval;
 }
 
+static void pl011_shutdown_channel(struct uart_amba_port *uap,
+                                       unsigned int lcrh)
+{
+      unsigned long val;
+
+      val = readw(uap->port.membase + lcrh);
+      val &= ~(UART01x_LCRH_BRK | UART01x_LCRH_FEN);
+      writew(val, uap->port.membase + lcrh);
+}
+
 static void pl011_shutdown(struct uart_port *port)
 {
        struct uart_amba_port *uap = (struct uart_amba_port *)port;
-       unsigned long val;
 
        /*
         * disable all interrupts
@@ -450,9 +481,9 @@ static void pl011_shutdown(struct uart_port *port)
        /*
         * disable break condition and fifos
         */
-       val = readw(uap->port.membase + UART011_LCRH);
-       val &= ~(UART01x_LCRH_BRK | UART01x_LCRH_FEN);
-       writew(val, uap->port.membase + UART011_LCRH);
+       pl011_shutdown_channel(uap, uap->lcrh_rx);
+       if (uap->lcrh_rx != uap->lcrh_tx)
+               pl011_shutdown_channel(uap, uap->lcrh_tx);
 
        /*
         * Shut down the clock producer
@@ -472,8 +503,13 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios,
        /*
         * Ask the core to calculate the divisor for us.
         */
-       baud = uart_get_baud_rate(port, termios, old, 0, port->uartclk/16);
-       quot = port->uartclk * 4 / baud;
+       baud = uart_get_baud_rate(port, termios, old, 0,
+                                 port->uartclk/(uap->oversampling ? 8 : 16));
+
+       if (baud > port->uartclk/16)
+               quot = DIV_ROUND_CLOSEST(port->uartclk * 8, baud);
+       else
+               quot = DIV_ROUND_CLOSEST(port->uartclk * 4, baud);
 
        switch (termios->c_cflag & CSIZE) {
        case CS5:
@@ -552,6 +588,13 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios,
                uap->autorts = false;
        }
 
+       if (uap->oversampling) {
+               if (baud > port->uartclk/16)
+                       old_cr |= ST_UART011_CR_OVSFACT;
+               else
+                       old_cr &= ~ST_UART011_CR_OVSFACT;
+       }
+
        /* Set baud rate */
        writew(quot & 0x3f, port->membase + UART011_FBRD);
        writew(quot >> 6, port->membase + UART011_IBRD);
@@ -561,7 +604,17 @@ pl011_set_termios(struct uart_port *port, struct ktermios *termios,
         * NOTE: MUST BE WRITTEN AFTER UARTLCR_M & UARTLCR_L
         * ----------^----------^----------^----------^-----
         */
-       writew(lcr_h, port->membase + UART011_LCRH);
+       writew(lcr_h, port->membase + uap->lcrh_rx);
+       if (uap->lcrh_rx != uap->lcrh_tx) {
+               int i;
+               /*
+                * Wait 10 PCLKs before writing LCRH_TX register,
+                * to get this delay write read only register 10 times
+                */
+               for (i = 0; i < 10; ++i)
+                       writew(0xff, uap->port.membase + UART011_MIS);
+               writew(lcr_h, port->membase + uap->lcrh_tx);
+       }
        writew(old_cr, port->membase + UART011_CR);
 
        spin_unlock_irqrestore(&port->lock, flags);
@@ -688,7 +741,7 @@ pl011_console_get_options(struct uart_amba_port *uap, int *baud,
        if (readw(uap->port.membase + UART011_CR) & UART01x_CR_UARTEN) {
                unsigned int lcr_h, ibrd, fbrd;
 
-               lcr_h = readw(uap->port.membase + UART011_LCRH);
+               lcr_h = readw(uap->port.membase + uap->lcrh_tx);
 
                *parity = 'n';
                if (lcr_h & UART01x_LCRH_PEN) {
@@ -707,6 +760,12 @@ pl011_console_get_options(struct uart_amba_port *uap, int *baud,
                fbrd = readw(uap->port.membase + UART011_FBRD);
 
                *baud = uap->port.uartclk * 4 / (64 * ibrd + fbrd);
+
+               if (uap->oversampling) {
+                       if (readw(uap->port.membase + UART011_CR)
+                                 & ST_UART011_CR_OVSFACT)
+                               *baud *= 2;
+               }
        }
 }
 
@@ -800,6 +859,9 @@ static int pl011_probe(struct amba_device *dev, struct amba_id *id)
        }
 
        uap->ifls = vendor->ifls;
+       uap->lcrh_rx = vendor->lcrh_rx;
+       uap->lcrh_tx = vendor->lcrh_tx;
+       uap->oversampling = vendor->oversampling;
        uap->port.dev = &dev->dev;
        uap->port.mapbase = dev->res.start;
        uap->port.membase = base;
@@ -868,7 +930,7 @@ static int pl011_resume(struct amba_device *dev)
 }
 #endif
 
-static struct amba_id pl011_ids[] __initdata = {
+static struct amba_id pl011_ids[] = {
        {
                .id     = 0x00041011,
                .mask   = 0x000fffff,
index eaa79c8a9b8c2bee44fdce43f2963d19087213a3..93ead19507b632c20095980fd5b0350d6407d23d 100644 (file)
 static const char driver_name [] = "at91_udc";
 static const char ep0name[] = "ep0";
 
+#define VBUS_POLL_TIMEOUT      msecs_to_jiffies(1000)
 
-#define at91_udp_read(dev, reg) \
-       __raw_readl((dev)->udp_baseaddr + (reg))
-#define at91_udp_write(dev, reg, val) \
-       __raw_writel((val), (dev)->udp_baseaddr + (reg))
+#define at91_udp_read(udc, reg) \
+       __raw_readl((udc)->udp_baseaddr + (reg))
+#define at91_udp_write(udc, reg, val) \
+       __raw_writel((val), (udc)->udp_baseaddr + (reg))
 
 /*-------------------------------------------------------------------------*/
 
@@ -102,8 +103,9 @@ static void proc_ep_show(struct seq_file *s, struct at91_ep *ep)
        u32                     csr;
        struct at91_request     *req;
        unsigned long   flags;
+       struct at91_udc *udc = ep->udc;
 
-       local_irq_save(flags);
+       spin_lock_irqsave(&udc->lock, flags);
 
        csr = __raw_readl(ep->creg);
 
@@ -147,7 +149,7 @@ static void proc_ep_show(struct seq_file *s, struct at91_ep *ep)
                                &req->req, length,
                                req->req.length, req->req.buf);
        }
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&udc->lock, flags);
 }
 
 static void proc_irq_show(struct seq_file *s, const char *label, u32 mask)
@@ -272,7 +274,9 @@ static void done(struct at91_ep *ep, struct at91_request *req, int status)
                VDBG("%s done %p, status %d\n", ep->ep.name, req, status);
 
        ep->stopped = 1;
+       spin_unlock(&udc->lock);
        req->req.complete(&ep->ep, &req->req);
+       spin_lock(&udc->lock);
        ep->stopped = stopped;
 
        /* ep0 is always ready; other endpoints need a non-empty queue */
@@ -472,7 +476,7 @@ static int at91_ep_enable(struct usb_ep *_ep,
                                const struct usb_endpoint_descriptor *desc)
 {
        struct at91_ep  *ep = container_of(_ep, struct at91_ep, ep);
-       struct at91_udc *dev = ep->udc;
+       struct at91_udc *udc = ep->udc;
        u16             maxpacket;
        u32             tmp;
        unsigned long   flags;
@@ -487,7 +491,7 @@ static int at91_ep_enable(struct usb_ep *_ep,
                return -EINVAL;
        }
 
-       if (!dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
+       if (!udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
                DBG("bogus device state\n");
                return -ESHUTDOWN;
        }
@@ -521,7 +525,7 @@ bogus_max:
        }
 
 ok:
-       local_irq_save(flags);
+       spin_lock_irqsave(&udc->lock, flags);
 
        /* initialize endpoint to match this descriptor */
        ep->is_in = usb_endpoint_dir_in(desc);
@@ -540,10 +544,10 @@ ok:
         * reset/init endpoint fifo.  NOTE:  leaves fifo_bank alone,
         * since endpoint resets don't reset hw pingpong state.
         */
-       at91_udp_write(dev, AT91_UDP_RST_EP, ep->int_mask);
-       at91_udp_write(dev, AT91_UDP_RST_EP, 0);
+       at91_udp_write(udc, AT91_UDP_RST_EP, ep->int_mask);
+       at91_udp_write(udc, AT91_UDP_RST_EP, 0);
 
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&udc->lock, flags);
        return 0;
 }
 
@@ -556,7 +560,7 @@ static int at91_ep_disable (struct usb_ep * _ep)
        if (ep == &ep->udc->ep[0])
                return -EINVAL;
 
-       local_irq_save(flags);
+       spin_lock_irqsave(&udc->lock, flags);
 
        nuke(ep, -ESHUTDOWN);
 
@@ -571,7 +575,7 @@ static int at91_ep_disable (struct usb_ep * _ep)
                __raw_writel(0, ep->creg);
        }
 
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&udc->lock, flags);
        return 0;
 }
 
@@ -607,7 +611,7 @@ static int at91_ep_queue(struct usb_ep *_ep,
 {
        struct at91_request     *req;
        struct at91_ep          *ep;
-       struct at91_udc         *dev;
+       struct at91_udc         *udc;
        int                     status;
        unsigned long           flags;
 
@@ -625,9 +629,9 @@ static int at91_ep_queue(struct usb_ep *_ep,
                return -EINVAL;
        }
 
-       dev = ep->udc;
+       udc = ep->udc;
 
-       if (!dev || !dev->driver || dev->gadget.speed == USB_SPEED_UNKNOWN) {
+       if (!udc || !udc->driver || udc->gadget.speed == USB_SPEED_UNKNOWN) {
                DBG("invalid device\n");
                return -EINVAL;
        }
@@ -635,7 +639,7 @@ static int at91_ep_queue(struct usb_ep *_ep,
        _req->status = -EINPROGRESS;
        _req->actual = 0;
 
-       local_irq_save(flags);
+       spin_lock_irqsave(&udc->lock, flags);
 
        /* try to kickstart any empty and idle queue */
        if (list_empty(&ep->queue) && !ep->stopped) {
@@ -653,7 +657,7 @@ static int at91_ep_queue(struct usb_ep *_ep,
                if (is_ep0) {
                        u32     tmp;
 
-                       if (!dev->req_pending) {
+                       if (!udc->req_pending) {
                                status = -EINVAL;
                                goto done;
                        }
@@ -662,11 +666,11 @@ static int at91_ep_queue(struct usb_ep *_ep,
                         * defer changing CONFG until after the gadget driver
                         * reconfigures the endpoints.
                         */
-                       if (dev->wait_for_config_ack) {
-                               tmp = at91_udp_read(dev, AT91_UDP_GLB_STAT);
+                       if (udc->wait_for_config_ack) {
+                               tmp = at91_udp_read(udc, AT91_UDP_GLB_STAT);
                                tmp ^= AT91_UDP_CONFG;
                                VDBG("toggle config\n");
-                               at91_udp_write(dev, AT91_UDP_GLB_STAT, tmp);
+                               at91_udp_write(udc, AT91_UDP_GLB_STAT, tmp);
                        }
                        if (req->req.length == 0) {
 ep0_in_status:
@@ -676,7 +680,7 @@ ep0_in_status:
                                tmp &= ~SET_FX;
                                tmp |= CLR_FX | AT91_UDP_TXPKTRDY;
                                __raw_writel(tmp, ep->creg);
-                               dev->req_pending = 0;
+                               udc->req_pending = 0;
                                goto done;
                        }
                }
@@ -695,31 +699,40 @@ ep0_in_status:
 
        if (req && !status) {
                list_add_tail (&req->queue, &ep->queue);
-               at91_udp_write(dev, AT91_UDP_IER, ep->int_mask);
+               at91_udp_write(udc, AT91_UDP_IER, ep->int_mask);
        }
 done:
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&udc->lock, flags);
        return (status < 0) ? status : 0;
 }
 
 static int at91_ep_dequeue(struct usb_ep *_ep, struct usb_request *_req)
 {
-       struct at91_ep  *ep;
+       struct at91_ep          *ep;
        struct at91_request     *req;
+       unsigned long           flags;
+       struct at91_udc         *udc;
 
        ep = container_of(_ep, struct at91_ep, ep);
        if (!_ep || ep->ep.name == ep0name)
                return -EINVAL;
 
+       udc = ep->udc;
+
+       spin_lock_irqsave(&udc->lock, flags);
+
        /* make sure it's actually queued on this endpoint */
        list_for_each_entry (req, &ep->queue, queue) {
                if (&req->req == _req)
                        break;
        }
-       if (&req->req != _req)
+       if (&req->req != _req) {
+               spin_unlock_irqrestore(&udc->lock, flags);
                return -EINVAL;
+       }
 
        done(ep, req, -ECONNRESET);
+       spin_unlock_irqrestore(&udc->lock, flags);
        return 0;
 }
 
@@ -736,7 +749,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
                return -EINVAL;
 
        creg = ep->creg;
-       local_irq_save(flags);
+       spin_lock_irqsave(&udc->lock, flags);
 
        csr = __raw_readl(creg);
 
@@ -761,7 +774,7 @@ static int at91_ep_set_halt(struct usb_ep *_ep, int value)
                __raw_writel(csr, creg);
        }
 
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&udc->lock, flags);
        return status;
 }
 
@@ -795,7 +808,7 @@ static int at91_wakeup(struct usb_gadget *gadget)
        unsigned long   flags;
 
        DBG("%s\n", __func__ );
-       local_irq_save(flags);
+       spin_lock_irqsave(&udc->lock, flags);
 
        if (!udc->clocked || !udc->suspended)
                goto done;
@@ -809,7 +822,7 @@ static int at91_wakeup(struct usb_gadget *gadget)
        at91_udp_write(udc, AT91_UDP_GLB_STAT, glbstate);
 
 done:
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&udc->lock, flags);
        return status;
 }
 
@@ -851,8 +864,11 @@ static void stop_activity(struct at91_udc *udc)
                ep->stopped = 1;
                nuke(ep, -ESHUTDOWN);
        }
-       if (driver)
+       if (driver) {
+               spin_unlock(&udc->lock);
                driver->disconnect(&udc->gadget);
+               spin_lock(&udc->lock);
+       }
 
        udc_reinit(udc);
 }
@@ -935,13 +951,13 @@ static int at91_vbus_session(struct usb_gadget *gadget, int is_active)
        unsigned long   flags;
 
        // VDBG("vbus %s\n", is_active ? "on" : "off");
-       local_irq_save(flags);
+       spin_lock_irqsave(&udc->lock, flags);
        udc->vbus = (is_active != 0);
        if (udc->driver)
                pullup(udc, is_active);
        else
                pullup(udc, 0);
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&udc->lock, flags);
        return 0;
 }
 
@@ -950,10 +966,10 @@ static int at91_pullup(struct usb_gadget *gadget, int is_on)
        struct at91_udc *udc = to_udc(gadget);
        unsigned long   flags;
 
-       local_irq_save(flags);
+       spin_lock_irqsave(&udc->lock, flags);
        udc->enabled = is_on = !!is_on;
        pullup(udc, is_on);
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&udc->lock, flags);
        return 0;
 }
 
@@ -962,9 +978,9 @@ static int at91_set_selfpowered(struct usb_gadget *gadget, int is_on)
        struct at91_udc *udc = to_udc(gadget);
        unsigned long   flags;
 
-       local_irq_save(flags);
+       spin_lock_irqsave(&udc->lock, flags);
        udc->selfpowered = (is_on != 0);
-       local_irq_restore(flags);
+       spin_unlock_irqrestore(&udc->lock, flags);
        return 0;
 }
 
@@ -1226,8 +1242,11 @@ static void handle_setup(struct at91_udc *udc, struct at91_ep *ep, u32 csr)
 #undef w_length
 
        /* pass request up to the gadget driver */
-       if (udc->driver)
+       if (udc->driver) {
+               spin_unlock(&udc->lock);
                status = udc->driver->setup(&udc->gadget, &pkt.r);
+               spin_lock(&udc->lock);
+       }
        else
                status = -ENODEV;
        if (status < 0) {
@@ -1378,6 +1397,9 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
        struct at91_udc         *udc = _udc;
        u32                     rescans = 5;
        int                     disable_clock = 0;
+       unsigned long           flags;
+
+       spin_lock_irqsave(&udc->lock, flags);
 
        if (!udc->clocked) {
                clk_on(udc);
@@ -1433,8 +1455,11 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
                         * and then into standby to avoid drawing more than
                         * 500uA power (2500uA for some high-power configs).
                         */
-                       if (udc->driver && udc->driver->suspend)
+                       if (udc->driver && udc->driver->suspend) {
+                               spin_unlock(&udc->lock);
                                udc->driver->suspend(&udc->gadget);
+                               spin_lock(&udc->lock);
+                       }
 
                /* host initiated resume */
                } else if (status & AT91_UDP_RXRSM) {
@@ -1451,8 +1476,11 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
                         * would normally want to switch out of slow clock
                         * mode into normal mode.
                         */
-                       if (udc->driver && udc->driver->resume)
+                       if (udc->driver && udc->driver->resume) {
+                               spin_unlock(&udc->lock);
                                udc->driver->resume(&udc->gadget);
+                               spin_lock(&udc->lock);
+                       }
 
                /* endpoint IRQs are cleared by handling them */
                } else {
@@ -1474,6 +1502,8 @@ static irqreturn_t at91_udc_irq (int irq, void *_udc)
        if (disable_clock)
                clk_off(udc);
 
+       spin_unlock_irqrestore(&udc->lock, flags);
+
        return IRQ_HANDLED;
 }
 
@@ -1556,24 +1586,53 @@ static struct at91_udc controller = {
        /* ep6 and ep7 are also reserved (custom silicon might use them) */
 };
 
+static void at91_vbus_update(struct at91_udc *udc, unsigned value)
+{
+       value ^= udc->board.vbus_active_low;
+       if (value != udc->vbus)
+               at91_vbus_session(&udc->gadget, value);
+}
+
 static irqreturn_t at91_vbus_irq(int irq, void *_udc)
 {
        struct at91_udc *udc = _udc;
-       unsigned        value;
 
        /* vbus needs at least brief debouncing */
        udelay(10);
-       value = gpio_get_value(udc->board.vbus_pin);
-       if (value != udc->vbus)
-               at91_vbus_session(&udc->gadget, value);
+       at91_vbus_update(udc, gpio_get_value(udc->board.vbus_pin));
 
        return IRQ_HANDLED;
 }
 
+static void at91_vbus_timer_work(struct work_struct *work)
+{
+       struct at91_udc *udc = container_of(work, struct at91_udc,
+                                           vbus_timer_work);
+
+       at91_vbus_update(udc, gpio_get_value_cansleep(udc->board.vbus_pin));
+
+       if (!timer_pending(&udc->vbus_timer))
+               mod_timer(&udc->vbus_timer, jiffies + VBUS_POLL_TIMEOUT);
+}
+
+static void at91_vbus_timer(unsigned long data)
+{
+       struct at91_udc *udc = (struct at91_udc *)data;
+
+       /*
+        * If we are polling vbus it is likely that the gpio is on an
+        * bus such as i2c or spi which may sleep, so schedule some work
+        * to read the vbus gpio
+        */
+       if (!work_pending(&udc->vbus_timer_work))
+               schedule_work(&udc->vbus_timer_work);
+}
+
 int usb_gadget_register_driver (struct usb_gadget_driver *driver)
 {
        struct at91_udc *udc = &controller;
        int             retval;
+       unsigned long   flags;
 
        if (!driver
                        || driver->speed < USB_SPEED_FULL
@@ -1605,9 +1664,9 @@ int usb_gadget_register_driver (struct usb_gadget_driver *driver)
                return retval;
        }
 
-       local_irq_disable();
+       spin_lock_irqsave(&udc->lock, flags);
        pullup(udc, 1);
-       local_irq_enable();
+       spin_unlock_irqrestore(&udc->lock, flags);
 
        DBG("bound to %s\n", driver->driver.name);
        return 0;
@@ -1617,15 +1676,16 @@ EXPORT_SYMBOL (usb_gadget_register_driver);
 int usb_gadget_unregister_driver (struct usb_gadget_driver *driver)
 {
        struct at91_udc *udc = &controller;
+       unsigned long   flags;
 
        if (!driver || driver != udc->driver || !driver->unbind)
                return -EINVAL;
 
-       local_irq_disable();
+       spin_lock_irqsave(&udc->lock, flags);
        udc->enabled = 0;
        at91_udp_write(udc, AT91_UDP_IDR, ~0);
        pullup(udc, 0);
-       local_irq_enable();
+       spin_unlock_irqrestore(&udc->lock, flags);
 
        driver->unbind(&udc->gadget);
        udc->gadget.dev.driver = NULL;
@@ -1641,8 +1701,13 @@ EXPORT_SYMBOL (usb_gadget_unregister_driver);
 
 static void at91udc_shutdown(struct platform_device *dev)
 {
+       struct at91_udc *udc = platform_get_drvdata(dev);
+       unsigned long   flags;
+
        /* force disconnect on reboot */
+       spin_lock_irqsave(&udc->lock, flags);
        pullup(platform_get_drvdata(dev), 0);
+       spin_unlock_irqrestore(&udc->lock, flags);
 }
 
 static int __init at91udc_probe(struct platform_device *pdev)
@@ -1683,6 +1748,7 @@ static int __init at91udc_probe(struct platform_device *pdev)
        udc->board = *(struct at91_udc_data *) dev->platform_data;
        udc->pdev = pdev;
        udc->enabled = 0;
+       spin_lock_init(&udc->lock);
 
        /* rm9200 needs manual D+ pullup; off by default */
        if (cpu_is_at91rm9200()) {
@@ -1763,13 +1829,23 @@ static int __init at91udc_probe(struct platform_device *pdev)
                 * Get the initial state of VBUS - we cannot expect
                 * a pending interrupt.
                 */
-               udc->vbus = gpio_get_value(udc->board.vbus_pin);
-               if (request_irq(udc->board.vbus_pin, at91_vbus_irq,
-                               IRQF_DISABLED, driver_name, udc)) {
-                       DBG("request vbus irq %d failed\n",
-                                       udc->board.vbus_pin);
-                       retval = -EBUSY;
-                       goto fail3;
+               udc->vbus = gpio_get_value_cansleep(udc->board.vbus_pin) ^
+                       udc->board.vbus_active_low;
+
+               if (udc->board.vbus_polled) {
+                       INIT_WORK(&udc->vbus_timer_work, at91_vbus_timer_work);
+                       setup_timer(&udc->vbus_timer, at91_vbus_timer,
+                                   (unsigned long)udc);
+                       mod_timer(&udc->vbus_timer,
+                                 jiffies + VBUS_POLL_TIMEOUT);
+               } else {
+                       if (request_irq(udc->board.vbus_pin, at91_vbus_irq,
+                                       IRQF_DISABLED, driver_name, udc)) {
+                               DBG("request vbus irq %d failed\n",
+                                   udc->board.vbus_pin);
+                               retval = -EBUSY;
+                               goto fail3;
+                       }
                }
        } else {
                DBG("no VBUS detection, assuming always-on\n");
@@ -1804,13 +1880,16 @@ static int __exit at91udc_remove(struct platform_device *pdev)
 {
        struct at91_udc *udc = platform_get_drvdata(pdev);
        struct resource *res;
+       unsigned long   flags;
 
        DBG("remove\n");
 
        if (udc->driver)
                return -EBUSY;
 
+       spin_lock_irqsave(&udc->lock, flags);
        pullup(udc, 0);
+       spin_unlock_irqrestore(&udc->lock, flags);
 
        device_init_wakeup(&pdev->dev, 0);
        remove_debug_file(udc);
@@ -1840,6 +1919,7 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
 {
        struct at91_udc *udc = platform_get_drvdata(pdev);
        int             wake = udc->driver && device_may_wakeup(&pdev->dev);
+       unsigned long   flags;
 
        /* Unless we can act normally to the host (letting it wake us up
         * whenever it has work for us) force disconnect.  Wakeup requires
@@ -1849,13 +1929,15 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
        if ((!udc->suspended && udc->addr)
                        || !wake
                        || at91_suspend_entering_slow_clock()) {
+               spin_lock_irqsave(&udc->lock, flags);
                pullup(udc, 0);
                wake = 0;
+               spin_unlock_irqrestore(&udc->lock, flags);
        } else
                enable_irq_wake(udc->udp_irq);
 
        udc->active_suspend = wake;
-       if (udc->board.vbus_pin > 0 && wake)
+       if (udc->board.vbus_pin > 0 && !udc->board.vbus_polled && wake)
                enable_irq_wake(udc->board.vbus_pin);
        return 0;
 }
@@ -1863,15 +1945,20 @@ static int at91udc_suspend(struct platform_device *pdev, pm_message_t mesg)
 static int at91udc_resume(struct platform_device *pdev)
 {
        struct at91_udc *udc = platform_get_drvdata(pdev);
+       unsigned long   flags;
 
-       if (udc->board.vbus_pin > 0 && udc->active_suspend)
+       if (udc->board.vbus_pin > 0 && !udc->board.vbus_polled &&
+           udc->active_suspend)
                disable_irq_wake(udc->board.vbus_pin);
 
        /* maybe reconnect to host; if so, clocks on */
        if (udc->active_suspend)
                disable_irq_wake(udc->udp_irq);
-       else
+       else {
+               spin_lock_irqsave(&udc->lock, flags);
                pullup(udc, 1);
+               spin_unlock_irqrestore(&udc->lock, flags);
+       }
        return 0;
 }
 #else
index c65d62295890e94584045ab9f0cc4b872ab29711..108ca54f9092ff4d01679292cd5acf0d221e81a1 100644 (file)
@@ -144,6 +144,9 @@ struct at91_udc {
        struct proc_dir_entry           *pde;
        void __iomem                    *udp_baseaddr;
        int                             udp_irq;
+       spinlock_t                      lock;
+       struct timer_list               vbus_timer;
+       struct work_struct              vbus_timer_work;
 };
 
 static inline struct at91_udc *to_udc(struct usb_gadget *g)
index d0b8bde59e59effdff3df5e5d84b5a79a817903d..eafa6d2c5ed734b278eaf1d34c69ab8f3290e383 100644 (file)
@@ -30,7 +30,7 @@ int fsl_udc_clk_init(struct platform_device *pdev)
 
        pdata = pdev->dev.platform_data;
 
-       if (!cpu_is_mx35()) {
+       if (!cpu_is_mx35() && !cpu_is_mx25()) {
                mxc_ahb_clk = clk_get(&pdev->dev, "usb_ahb");
                if (IS_ERR(mxc_ahb_clk))
                        return PTR_ERR(mxc_ahb_clk);
index bd4027745aa7039e5cfcdd6b1bf4057ad8569d85..a8ad8ac120a2bfe733eaa2d151ad528afc15685d 100644 (file)
@@ -182,7 +182,7 @@ static int ehci_mxc_drv_probe(struct platform_device *pdev)
        }
        clk_enable(priv->usbclk);
 
-       if (!cpu_is_mx35()) {
+       if (!cpu_is_mx35() && !cpu_is_mx25()) {
                priv->ahbclk = clk_get(dev, "usb_ahb");
                if (IS_ERR(priv->ahbclk)) {
                        ret = PTR_ERR(priv->ahbclk);
index b4b6deceed153ae1b11bab3384249113359ec2c0..43f0639b1c10b7a7ede287df51b0ab28277031c1 100644 (file)
@@ -175,6 +175,7 @@ struct imxfb_info {
 
        struct imx_fb_videomode *mode;
        int                     num_modes;
+       struct backlight_device *bl;
 
        void (*lcd_power)(int);
        void (*backlight_power)(int);
@@ -449,6 +450,73 @@ static int imxfb_set_par(struct fb_info *info)
        return 0;
 }
 
+
+
+static int imxfb_bl_get_brightness(struct backlight_device *bl)
+{
+       struct imxfb_info *fbi = bl_get_data(bl);
+
+       return readl(fbi->regs + LCDC_PWMR) & 0xFF;
+}
+
+static int imxfb_bl_update_status(struct backlight_device *bl)
+{
+       struct imxfb_info *fbi = bl_get_data(bl);
+       int brightness = bl->props.brightness;
+
+       if (bl->props.power != FB_BLANK_UNBLANK)
+               brightness = 0;
+       if (bl->props.fb_blank != FB_BLANK_UNBLANK)
+               brightness = 0;
+
+       fbi->pwmr = (fbi->pwmr & ~0xFF) | brightness;
+
+       if (bl->props.fb_blank != FB_BLANK_UNBLANK)
+               clk_enable(fbi->clk);
+       writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
+       if (bl->props.fb_blank != FB_BLANK_UNBLANK)
+               clk_disable(fbi->clk);
+
+       return 0;
+}
+
+static const struct backlight_ops imxfb_lcdc_bl_ops = {
+       .update_status = imxfb_bl_update_status,
+       .get_brightness = imxfb_bl_get_brightness,
+};
+
+static void imxfb_init_backlight(struct imxfb_info *fbi)
+{
+       struct backlight_properties props;
+       struct backlight_device *bl;
+
+       if (fbi->bl)
+               return;
+
+       memset(&props, 0, sizeof(struct backlight_properties));
+       props.max_brightness = 0xff;
+       writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
+
+       bl = backlight_device_register("imxfb-bl", &fbi->pdev->dev, fbi,
+                                      &imxfb_lcdc_bl_ops, &props);
+       if (IS_ERR(bl)) {
+               dev_err(&fbi->pdev->dev, "error %ld on backlight register\n",
+                               PTR_ERR(bl));
+               return;
+       }
+
+       fbi->bl = bl;
+       bl->props.power = FB_BLANK_UNBLANK;
+       bl->props.fb_blank = FB_BLANK_UNBLANK;
+       bl->props.brightness = imxfb_bl_get_brightness(bl);
+}
+
+static void imxfb_exit_backlight(struct imxfb_info *fbi)
+{
+       if (fbi->bl)
+               backlight_device_unregister(fbi->bl);
+}
+
 static void imxfb_enable_controller(struct imxfb_info *fbi)
 {
        pr_debug("Enabling LCD controller\n");
@@ -579,7 +647,6 @@ static int imxfb_activate_var(struct fb_var_screeninfo *var, struct fb_info *inf
                        fbi->regs + LCDC_SIZE);
 
        writel(fbi->pcr, fbi->regs + LCDC_PCR);
-       writel(fbi->pwmr, fbi->regs + LCDC_PWMR);
        writel(fbi->lscr1, fbi->regs + LCDC_LSCR1);
        writel(fbi->dmacr, fbi->regs + LCDC_DMACR);
 
@@ -779,6 +846,8 @@ static int __init imxfb_probe(struct platform_device *pdev)
        }
 
        imxfb_enable_controller(fbi);
+       fbi->pdev = pdev;
+       imxfb_init_backlight(fbi);
 
        return 0;
 
@@ -816,6 +885,7 @@ static int __devexit imxfb_remove(struct platform_device *pdev)
 
        imxfb_disable_controller(fbi);
 
+       imxfb_exit_backlight(fbi);
        unregister_framebuffer(info);
 
        pdata = pdev->dev.platform_data;
index 3b1237ad85ed384a3adba6dfe07451d2a732ed11..f6fdc2085f3e20147a4e9b0ae8ab4080c4fa4728 100644 (file)
@@ -25,7 +25,7 @@
 #include <linux/list.h>
 #include <linux/slab.h>
 #include <linux/seq_file.h>
-#include <linux/bootmem.h>
+#include <linux/memblock.h>
 #include <linux/completion.h>
 #include <linux/debugfs.h>
 #include <linux/jiffies.h>
@@ -525,10 +525,8 @@ early_param("vram", omap_vram_early_vram);
  * Called from map_io. We need to call to this early enough so that we
  * can reserve the fixed SDRAM regions before VM could get hold of them.
  */
-void __init omap_vram_reserve_sdram(void)
+void __init omap_vram_reserve_sdram_memblock(void)
 {
-       struct bootmem_data     *bdata;
-       unsigned long           sdram_start, sdram_size;
        u32 paddr;
        u32 size = 0;
 
@@ -555,29 +553,28 @@ void __init omap_vram_reserve_sdram(void)
 
        size = PAGE_ALIGN(size);
 
-       bdata = NODE_DATA(0)->bdata;
-       sdram_start = bdata->node_min_pfn << PAGE_SHIFT;
-       sdram_size = (bdata->node_low_pfn << PAGE_SHIFT) - sdram_start;
-
        if (paddr) {
-               if ((paddr & ~PAGE_MASK) || paddr < sdram_start ||
-                               paddr + size > sdram_start + sdram_size) {
+               struct memblock_property res;
+
+               res.base = paddr;
+               res.size = size;
+               if ((paddr & ~PAGE_MASK) || memblock_find(&res) ||
+                   res.base != paddr || res.size != size) {
                        pr_err("Illegal SDRAM region for VRAM\n");
                        return;
                }
 
-               if (reserve_bootmem(paddr, size, BOOTMEM_EXCLUSIVE) < 0) {
-                       pr_err("FB: failed to reserve VRAM\n");
+               if (memblock_is_region_reserved(paddr, size)) {
+                       pr_err("FB: failed to reserve VRAM - busy\n");
                        return;
                }
-       } else {
-               if (size > sdram_size) {
-                       pr_err("Illegal SDRAM size for VRAM\n");
+
+               if (memblock_reserve(paddr, size) < 0) {
+                       pr_err("FB: failed to reserve VRAM - no memory\n");
                        return;
                }
-
-               paddr = virt_to_phys(alloc_bootmem_pages(size));
-               BUG_ON(paddr & ~PAGE_MASK);
+       } else {
+               paddr = memblock_alloc_base(size, PAGE_SIZE, MEMBLOCK_REAL_LIMIT);
        }
 
        omap_vram_add_region(paddr, size);
index 1a940ec7af611859aa01b012e866c66fdc8cf9e0..91fba025fcbea22cceeabd19c979bd2281dd040a 100644 (file)
@@ -8,6 +8,8 @@ obj-$(CONFIG_9P_FS) := 9p.o
        vfs_dir.o \
        vfs_dentry.o \
        v9fs.o \
-       fid.o
+       fid.o  \
+       xattr.o \
+       xattr_user.o
 
 9p-$(CONFIG_9P_FSCACHE) += cache.o
index 7317b39b28159b2e712de1eec7bed5fce2312b3a..358563689064df61c9b81713ad8bb8911c6518bd 100644 (file)
@@ -97,6 +97,34 @@ static struct p9_fid *v9fs_fid_find(struct dentry *dentry, u32 uid, int any)
        return ret;
 }
 
+/*
+ * We need to hold v9ses->rename_sem as long as we hold references
+ * to returned path array. Array element contain pointers to
+ * dentry names.
+ */
+static int build_path_from_dentry(struct v9fs_session_info *v9ses,
+                                 struct dentry *dentry, char ***names)
+{
+       int n = 0, i;
+       char **wnames;
+       struct dentry *ds;
+
+       for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent)
+               n++;
+
+       wnames = kmalloc(sizeof(char *) * n, GFP_KERNEL);
+       if (!wnames)
+               goto err_out;
+
+       for (ds = dentry, i = (n-1); i >= 0; i--, ds = ds->d_parent)
+               wnames[i] = (char  *)ds->d_name.name;
+
+       *names = wnames;
+       return n;
+err_out:
+       return -ENOMEM;
+}
+
 /**
  * v9fs_fid_lookup - lookup for a fid, try to walk if not found
  * @dentry: dentry to look for fid in
@@ -112,7 +140,7 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
        int i, n, l, clone, any, access;
        u32 uid;
        struct p9_fid *fid, *old_fid = NULL;
-       struct dentry *d, *ds;
+       struct dentry *ds;
        struct v9fs_session_info *v9ses;
        char **wnames, *uname;
 
@@ -139,49 +167,62 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
        fid = v9fs_fid_find(dentry, uid, any);
        if (fid)
                return fid;
-
+       /*
+        * we don't have a matching fid. To do a TWALK we need
+        * parent fid. We need to prevent rename when we want to
+        * look at the parent.
+        */
+       down_read(&v9ses->rename_sem);
        ds = dentry->d_parent;
        fid = v9fs_fid_find(ds, uid, any);
-       if (!fid) { /* walk from the root */
-               n = 0;
-               for (ds = dentry; !IS_ROOT(ds); ds = ds->d_parent)
-                       n++;
+       if (fid) {
+               /* Found the parent fid do a lookup with that */
+               fid = p9_client_walk(fid, 1, (char **)&dentry->d_name.name, 1);
+               goto fid_out;
+       }
+       up_read(&v9ses->rename_sem);
 
-               fid = v9fs_fid_find(ds, uid, any);
-               if (!fid) { /* the user is not attached to the fs yet */
-                       if (access == V9FS_ACCESS_SINGLE)
-                               return ERR_PTR(-EPERM);
+       /* start from the root and try to do a lookup */
+       fid = v9fs_fid_find(dentry->d_sb->s_root, uid, any);
+       if (!fid) {
+               /* the user is not attached to the fs yet */
+               if (access == V9FS_ACCESS_SINGLE)
+                       return ERR_PTR(-EPERM);
 
-                       if (v9fs_proto_dotu(v9ses))
+               if (v9fs_proto_dotu(v9ses) || v9fs_proto_dotl(v9ses))
                                uname = NULL;
-                       else
-                               uname = v9ses->uname;
+               else
+                       uname = v9ses->uname;
 
-                       fid = p9_client_attach(v9ses->clnt, NULL, uname, uid,
-                               v9ses->aname);
-
-                       if (IS_ERR(fid))
-                               return fid;
-
-                       v9fs_fid_add(ds, fid);
-               }
-       } else /* walk from the parent */
-               n = 1;
+               fid = p9_client_attach(v9ses->clnt, NULL, uname, uid,
+                                      v9ses->aname);
+               if (IS_ERR(fid))
+                       return fid;
 
-       if (ds == dentry)
+               v9fs_fid_add(dentry->d_sb->s_root, fid);
+       }
+       /* If we are root ourself just return that */
+       if (dentry->d_sb->s_root == dentry)
                return fid;
-
-       wnames = kmalloc(sizeof(char *) * n, GFP_KERNEL);
-       if (!wnames)
-               return ERR_PTR(-ENOMEM);
-
-       for (d = dentry, i = (n-1); i >= 0; i--, d = d->d_parent)
-               wnames[i] = (char *) d->d_name.name;
-
+       /*
+        * Do a multipath walk with attached root.
+        * When walking parent we need to make sure we
+        * don't have a parallel rename happening
+        */
+       down_read(&v9ses->rename_sem);
+       n  = build_path_from_dentry(v9ses, dentry, &wnames);
+       if (n < 0) {
+               fid = ERR_PTR(n);
+               goto err_out;
+       }
        clone = 1;
        i = 0;
        while (i < n) {
                l = min(n - i, P9_MAXWELEM);
+               /*
+                * We need to hold rename lock when doing a multipath
+                * walk to ensure none of the patch component change
+                */
                fid = p9_client_walk(fid, l, &wnames[i], clone);
                if (IS_ERR(fid)) {
                        if (old_fid) {
@@ -193,15 +234,17 @@ struct p9_fid *v9fs_fid_lookup(struct dentry *dentry)
                                p9_client_clunk(old_fid);
                        }
                        kfree(wnames);
-                       return fid;
+                       goto err_out;
                }
                old_fid = fid;
                i += l;
                clone = 0;
        }
-
        kfree(wnames);
+fid_out:
        v9fs_fid_add(dentry, fid);
+err_out:
+       up_read(&v9ses->rename_sem);
        return fid;
 }
 
index f8b86e92cd660ef9da7e026be6a06fb7de4863fb..38dc0e0675998413dd205d13674412eff054ec4e 100644 (file)
@@ -237,6 +237,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
                __putname(v9ses->uname);
                return ERR_PTR(-ENOMEM);
        }
+       init_rwsem(&v9ses->rename_sem);
 
        rc = bdi_setup_and_register(&v9ses->bdi, "9p", BDI_CAP_MAP_COPY);
        if (rc) {
@@ -278,7 +279,7 @@ struct p9_fid *v9fs_session_init(struct v9fs_session_info *v9ses,
        v9ses->maxdata = v9ses->clnt->msize - P9_IOHDRSZ;
 
        /* for legacy mode, fall back to V9FS_ACCESS_ANY */
-       if (!v9fs_proto_dotu(v9ses) &&
+       if (!(v9fs_proto_dotu(v9ses) || v9fs_proto_dotl(v9ses)) &&
                ((v9ses->flags&V9FS_ACCESS_MASK) == V9FS_ACCESS_USER)) {
 
                v9ses->flags &= ~V9FS_ACCESS_MASK;
index bec4d0bcb4585d1f41c89406ef9eeb9eb6421115..4c963c9fc41fdf17107604354b17c4dfd06f0fae 100644 (file)
@@ -104,6 +104,7 @@ struct v9fs_session_info {
        struct p9_client *clnt; /* 9p client */
        struct list_head slist; /* list of sessions registered with v9fs */
        struct backing_dev_info bdi;
+       struct rw_semaphore rename_sem;
 };
 
 struct p9_fid *v9fs_session_init(struct v9fs_session_info *, const char *,
index 32ef4009d030063328d9811a9bcaf7daaf5e762d..f47c6bbb01b308115eedf8cb228e5dc694fe6560 100644 (file)
@@ -55,6 +55,7 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode);
 void v9fs_clear_inode(struct inode *inode);
 ino_t v9fs_qid2ino(struct p9_qid *qid);
 void v9fs_stat2inode(struct p9_wstat *, struct inode *, struct super_block *);
+void v9fs_stat2inode_dotl(struct p9_stat_dotl *, struct inode *);
 int v9fs_dir_release(struct inode *inode, struct file *filp);
 int v9fs_file_open(struct inode *inode, struct file *file);
 void v9fs_inode2stat(struct inode *inode, struct p9_wstat *stat);
index 36d961f342af5b95e4e79c42f4a82b5893a73823..16c8a2a98c1bb6b93fbc8634cb1986cf555bad0e 100644 (file)
@@ -87,29 +87,19 @@ static void p9stat_init(struct p9_wstat *stbuf)
 }
 
 /**
- * v9fs_dir_readdir - read a directory
+ * v9fs_alloc_rdir_buf - Allocate buffer used for read and readdir
  * @filp: opened file structure
- * @dirent: directory structure ???
- * @filldir: function to populate directory structure ???
+ * @buflen: Length in bytes of buffer to allocate
  *
  */
 
-static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+static int v9fs_alloc_rdir_buf(struct file *filp, int buflen)
 {
-       int over;
-       struct p9_wstat st;
-       int err = 0;
-       struct p9_fid *fid;
-       int buflen;
-       int reclen = 0;
        struct p9_rdir *rdir;
+       struct p9_fid *fid;
+       int err = 0;
 
-       P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
        fid = filp->private_data;
-
-       buflen = fid->clnt->msize - P9_IOHDRSZ;
-
-       /* allocate rdir on demand */
        if (!fid->rdir) {
                rdir = kmalloc(sizeof(struct p9_rdir) + buflen, GFP_KERNEL);
 
@@ -128,6 +118,36 @@ static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
                spin_unlock(&filp->f_dentry->d_lock);
                kfree(rdir);
        }
+exit:
+       return err;
+}
+
+/**
+ * v9fs_dir_readdir - read a directory
+ * @filp: opened file structure
+ * @dirent: directory structure ???
+ * @filldir: function to populate directory structure ???
+ *
+ */
+
+static int v9fs_dir_readdir(struct file *filp, void *dirent, filldir_t filldir)
+{
+       int over;
+       struct p9_wstat st;
+       int err = 0;
+       struct p9_fid *fid;
+       int buflen;
+       int reclen = 0;
+       struct p9_rdir *rdir;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
+       fid = filp->private_data;
+
+       buflen = fid->clnt->msize - P9_IOHDRSZ;
+
+       err = v9fs_alloc_rdir_buf(filp, buflen);
+       if (err)
+               goto exit;
        rdir = (struct p9_rdir *) fid->rdir;
 
        err = mutex_lock_interruptible(&rdir->mutex);
@@ -176,6 +196,88 @@ exit:
        return err;
 }
 
+/**
+ * v9fs_dir_readdir_dotl - read a directory
+ * @filp: opened file structure
+ * @dirent: buffer to fill dirent structures
+ * @filldir: function to populate dirent structures
+ *
+ */
+static int v9fs_dir_readdir_dotl(struct file *filp, void *dirent,
+                                               filldir_t filldir)
+{
+       int over;
+       int err = 0;
+       struct p9_fid *fid;
+       int buflen;
+       struct p9_rdir *rdir;
+       struct p9_dirent curdirent;
+       u64 oldoffset = 0;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", filp->f_path.dentry->d_name.name);
+       fid = filp->private_data;
+
+       buflen = fid->clnt->msize - P9_READDIRHDRSZ;
+
+       err = v9fs_alloc_rdir_buf(filp, buflen);
+       if (err)
+               goto exit;
+       rdir = (struct p9_rdir *) fid->rdir;
+
+       err = mutex_lock_interruptible(&rdir->mutex);
+       if (err)
+               return err;
+
+       while (err == 0) {
+               if (rdir->tail == rdir->head) {
+                       err = p9_client_readdir(fid, rdir->buf, buflen,
+                                                               filp->f_pos);
+                       if (err <= 0)
+                               goto unlock_and_exit;
+
+                       rdir->head = 0;
+                       rdir->tail = err;
+               }
+
+               while (rdir->head < rdir->tail) {
+
+                       err = p9dirent_read(rdir->buf + rdir->head,
+                                               buflen - rdir->head, &curdirent,
+                                               fid->clnt->proto_version);
+                       if (err < 0) {
+                               P9_DPRINTK(P9_DEBUG_VFS, "returned %d\n", err);
+                               err = -EIO;
+                               goto unlock_and_exit;
+                       }
+
+                       /* d_off in dirent structure tracks the offset into
+                        * the next dirent in the dir. However, filldir()
+                        * expects offset into the current dirent. Hence
+                        * while calling filldir send the offset from the
+                        * previous dirent structure.
+                        */
+                       over = filldir(dirent, curdirent.d_name,
+                                       strlen(curdirent.d_name),
+                                       oldoffset, v9fs_qid2ino(&curdirent.qid),
+                                       curdirent.d_type);
+                       oldoffset = curdirent.d_off;
+
+                       if (over) {
+                               err = 0;
+                               goto unlock_and_exit;
+                       }
+
+                       filp->f_pos = curdirent.d_off;
+                       rdir->head += err;
+               }
+       }
+
+unlock_and_exit:
+       mutex_unlock(&rdir->mutex);
+exit:
+       return err;
+}
+
 
 /**
  * v9fs_dir_release - close a directory
@@ -207,7 +309,7 @@ const struct file_operations v9fs_dir_operations = {
 const struct file_operations v9fs_dir_operations_dotl = {
        .read = generic_read_dir,
        .llseek = generic_file_llseek,
-       .readdir = v9fs_dir_readdir,
+       .readdir = v9fs_dir_readdir_dotl,
        .open = v9fs_file_open,
        .release = v9fs_dir_release,
 };
index 2bedc6c94fc2c805f407e4fb5ad7970e36f27a83..e97c92bd6f16d51c38fa3f98909e62ff9225e2b6 100644 (file)
@@ -59,9 +59,13 @@ int v9fs_file_open(struct inode *inode, struct file *file)
        struct p9_fid *fid;
        int omode;
 
-       P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p \n", inode, file);
+       P9_DPRINTK(P9_DEBUG_VFS, "inode: %p file: %p\n", inode, file);
        v9ses = v9fs_inode2v9ses(inode);
-       omode = v9fs_uflags2omode(file->f_flags, v9fs_proto_dotu(v9ses));
+       if (v9fs_proto_dotl(v9ses))
+               omode = file->f_flags;
+       else
+               omode = v9fs_uflags2omode(file->f_flags,
+                                       v9fs_proto_dotu(v9ses));
        fid = file->private_data;
        if (!fid) {
                fid = v9fs_fid_clone(file->f_path.dentry);
@@ -73,11 +77,12 @@ int v9fs_file_open(struct inode *inode, struct file *file)
                        p9_client_clunk(fid);
                        return err;
                }
-               if (omode & P9_OTRUNC) {
+               if (file->f_flags & O_TRUNC) {
                        i_size_write(inode, 0);
                        inode->i_blocks = 0;
                }
-               if ((file->f_flags & O_APPEND) && (!v9fs_proto_dotu(v9ses)))
+               if ((file->f_flags & O_APPEND) &&
+                       (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses)))
                        generic_file_llseek(file, 0, SEEK_END);
        }
 
@@ -139,7 +144,7 @@ ssize_t
 v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count,
               u64 offset)
 {
-       int n, total;
+       int n, total, size;
        struct p9_fid *fid = filp->private_data;
 
        P9_DPRINTK(P9_DEBUG_VFS, "fid %d offset %llu count %d\n", fid->fid,
@@ -147,6 +152,7 @@ v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count,
 
        n = 0;
        total = 0;
+       size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ;
        do {
                n = p9_client_read(fid, data, udata, offset, count);
                if (n <= 0)
@@ -160,7 +166,7 @@ v9fs_file_readn(struct file *filp, char *data, char __user *udata, u32 count,
                offset += n;
                count -= n;
                total += n;
-       } while (count > 0 && n == (fid->clnt->msize - P9_IOHDRSZ));
+       } while (count > 0 && n == size);
 
        if (n < 0)
                total = n;
@@ -183,11 +189,13 @@ v9fs_file_read(struct file *filp, char __user *udata, size_t count,
 {
        int ret;
        struct p9_fid *fid;
+       size_t size;
 
        P9_DPRINTK(P9_DEBUG_VFS, "count %zu offset %lld\n", count, *offset);
        fid = filp->private_data;
 
-       if (count > (fid->clnt->msize - P9_IOHDRSZ))
+       size = fid->iounit ? fid->iounit : fid->clnt->msize - P9_IOHDRSZ;
+       if (count > size)
                ret = v9fs_file_readn(filp, NULL, udata, count, *offset);
        else
                ret = p9_client_read(fid, NULL, udata, *offset, count);
@@ -224,9 +232,7 @@ v9fs_file_write(struct file *filp, const char __user * data,
        fid = filp->private_data;
        clnt = fid->clnt;
 
-       rsize = fid->iounit;
-       if (!rsize || rsize > clnt->msize-P9_IOHDRSZ)
-               rsize = clnt->msize - P9_IOHDRSZ;
+       rsize = fid->iounit ? fid->iounit : clnt->msize - P9_IOHDRSZ;
 
        do {
                if (count < rsize)
index 4331b3b5ee1c978a8a7b4b719ed6da14ede32cff..6e94f3247cec5fb7e354583c31ded72254a3b623 100644 (file)
@@ -35,6 +35,7 @@
 #include <linux/idr.h>
 #include <linux/sched.h>
 #include <linux/slab.h>
+#include <linux/xattr.h>
 #include <net/9p/9p.h>
 #include <net/9p/client.h>
 
@@ -42,6 +43,7 @@
 #include "v9fs_vfs.h"
 #include "fid.h"
 #include "cache.h"
+#include "xattr.h"
 
 static const struct inode_operations v9fs_dir_inode_operations;
 static const struct inode_operations v9fs_dir_inode_operations_dotu;
@@ -235,6 +237,41 @@ void v9fs_destroy_inode(struct inode *inode)
 }
 #endif
 
+/**
+ * v9fs_get_fsgid_for_create - Helper function to get the gid for creating a
+ * new file system object. This checks the S_ISGID to determine the owning
+ * group of the new file system object.
+ */
+
+static gid_t v9fs_get_fsgid_for_create(struct inode *dir_inode)
+{
+       BUG_ON(dir_inode == NULL);
+
+       if (dir_inode->i_mode & S_ISGID) {
+               /* set_gid bit is set.*/
+               return dir_inode->i_gid;
+       }
+       return current_fsgid();
+}
+
+/**
+ * v9fs_dentry_from_dir_inode - helper function to get the dentry from
+ * dir inode.
+ *
+ */
+
+static struct dentry *v9fs_dentry_from_dir_inode(struct inode *inode)
+{
+       struct dentry *dentry;
+
+       spin_lock(&dcache_lock);
+       /* Directory should have only one entry. */
+       BUG_ON(S_ISDIR(inode->i_mode) && !list_is_singular(&inode->i_dentry));
+       dentry = list_entry(inode->i_dentry.next, struct dentry, d_alias);
+       spin_unlock(&dcache_lock);
+       return dentry;
+}
+
 /**
  * v9fs_get_inode - helper function to setup an inode
  * @sb: superblock
@@ -267,7 +304,13 @@ struct inode *v9fs_get_inode(struct super_block *sb, int mode)
        case S_IFBLK:
        case S_IFCHR:
        case S_IFSOCK:
-               if (!v9fs_proto_dotu(v9ses)) {
+               if (v9fs_proto_dotl(v9ses)) {
+                       inode->i_op = &v9fs_file_inode_operations_dotl;
+                       inode->i_fop = &v9fs_file_operations_dotl;
+               } else if (v9fs_proto_dotu(v9ses)) {
+                       inode->i_op = &v9fs_file_inode_operations;
+                       inode->i_fop = &v9fs_file_operations;
+               } else {
                        P9_DPRINTK(P9_DEBUG_ERROR,
                                   "special files without extended mode\n");
                        err = -EINVAL;
@@ -396,23 +439,14 @@ void v9fs_clear_inode(struct inode *inode)
 #endif
 }
 
-/**
- * v9fs_inode_from_fid - populate an inode by issuing a attribute request
- * @v9ses: session information
- * @fid: fid to issue attribute request for
- * @sb: superblock on which to create inode
- *
- */
-
 static struct inode *
-v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
+v9fs_inode(struct v9fs_session_info *v9ses, struct p9_fid *fid,
        struct super_block *sb)
 {
        int err, umode;
-       struct inode *ret;
+       struct inode *ret = NULL;
        struct p9_wstat *st;
 
-       ret = NULL;
        st = p9_client_stat(fid);
        if (IS_ERR(st))
                return ERR_CAST(st);
@@ -433,15 +467,62 @@ v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
 #endif
        p9stat_free(st);
        kfree(st);
-
        return ret;
-
 error:
        p9stat_free(st);
        kfree(st);
        return ERR_PTR(err);
 }
 
+static struct inode *
+v9fs_inode_dotl(struct v9fs_session_info *v9ses, struct p9_fid *fid,
+       struct super_block *sb)
+{
+       struct inode *ret = NULL;
+       int err;
+       struct p9_stat_dotl *st;
+
+       st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
+       if (IS_ERR(st))
+               return ERR_CAST(st);
+
+       ret = v9fs_get_inode(sb, st->st_mode);
+       if (IS_ERR(ret)) {
+               err = PTR_ERR(ret);
+               goto error;
+       }
+
+       v9fs_stat2inode_dotl(st, ret);
+       ret->i_ino = v9fs_qid2ino(&st->qid);
+#ifdef CONFIG_9P_FSCACHE
+       v9fs_vcookie_set_qid(ret, &st->qid);
+       v9fs_cache_inode_get_cookie(ret);
+#endif
+       kfree(st);
+       return ret;
+error:
+       kfree(st);
+       return ERR_PTR(err);
+}
+
+/**
+ * v9fs_inode_from_fid - Helper routine to populate an inode by
+ * issuing a attribute request
+ * @v9ses: session information
+ * @fid: fid to issue attribute request for
+ * @sb: superblock on which to create inode
+ *
+ */
+static inline struct inode *
+v9fs_inode_from_fid(struct v9fs_session_info *v9ses, struct p9_fid *fid,
+                       struct super_block *sb)
+{
+       if (v9fs_proto_dotl(v9ses))
+               return v9fs_inode_dotl(v9ses, fid, sb);
+       else
+               return v9fs_inode(v9ses, fid, sb);
+}
+
 /**
  * v9fs_remove - helper function to remove files and directories
  * @dir: directory inode that is being deleted
@@ -562,6 +643,118 @@ error:
        return ERR_PTR(err);
 }
 
+/**
+ * v9fs_vfs_create_dotl - VFS hook to create files for 9P2000.L protocol.
+ * @dir: directory inode that is being created
+ * @dentry:  dentry that is being deleted
+ * @mode: create permissions
+ * @nd: path information
+ *
+ */
+
+static int
+v9fs_vfs_create_dotl(struct inode *dir, struct dentry *dentry, int mode,
+               struct nameidata *nd)
+{
+       int err = 0;
+       char *name = NULL;
+       gid_t gid;
+       int flags;
+       struct v9fs_session_info *v9ses;
+       struct p9_fid *fid = NULL;
+       struct p9_fid *dfid, *ofid;
+       struct file *filp;
+       struct p9_qid qid;
+       struct inode *inode;
+
+       v9ses = v9fs_inode2v9ses(dir);
+       if (nd && nd->flags & LOOKUP_OPEN)
+               flags = nd->intent.open.flags - 1;
+       else
+               flags = O_RDWR;
+
+       name = (char *) dentry->d_name.name;
+       P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_create_dotl: name:%s flags:0x%x "
+                       "mode:0x%x\n", name, flags, mode);
+
+       dfid = v9fs_fid_lookup(dentry->d_parent);
+       if (IS_ERR(dfid)) {
+               err = PTR_ERR(dfid);
+               P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
+               return err;
+       }
+
+       /* clone a fid to use for creation */
+       ofid = p9_client_walk(dfid, 0, NULL, 1);
+       if (IS_ERR(ofid)) {
+               err = PTR_ERR(ofid);
+               P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
+               return err;
+       }
+
+       gid = v9fs_get_fsgid_for_create(dir);
+       err = p9_client_create_dotl(ofid, name, flags, mode, gid, &qid);
+       if (err < 0) {
+               P9_DPRINTK(P9_DEBUG_VFS,
+                               "p9_client_open_dotl failed in creat %d\n",
+                               err);
+               goto error;
+       }
+
+       /* No need to populate the inode if we are not opening the file AND
+        * not in cached mode.
+        */
+       if (!v9ses->cache && !(nd && nd->flags & LOOKUP_OPEN)) {
+               /* Not in cached mode. No need to populate inode with stat */
+               dentry->d_op = &v9fs_dentry_operations;
+               p9_client_clunk(ofid);
+               d_instantiate(dentry, NULL);
+               return 0;
+       }
+
+       /* Now walk from the parent so we can get an unopened fid. */
+       fid = p9_client_walk(dfid, 1, &name, 1);
+       if (IS_ERR(fid)) {
+               err = PTR_ERR(fid);
+               P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n", err);
+               fid = NULL;
+               goto error;
+       }
+
+       /* instantiate inode and assign the unopened fid to dentry */
+       inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
+       if (IS_ERR(inode)) {
+               err = PTR_ERR(inode);
+               P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n", err);
+               goto error;
+       }
+       dentry->d_op = &v9fs_cached_dentry_operations;
+       d_instantiate(dentry, inode);
+       err = v9fs_fid_add(dentry, fid);
+       if (err < 0)
+               goto error;
+
+       /* if we are opening a file, assign the open fid to the file */
+       if (nd && nd->flags & LOOKUP_OPEN) {
+               filp = lookup_instantiate_filp(nd, dentry, v9fs_open_created);
+               if (IS_ERR(filp)) {
+                       p9_client_clunk(ofid);
+                       return PTR_ERR(filp);
+               }
+               filp->private_data = ofid;
+       } else
+               p9_client_clunk(ofid);
+
+       return 0;
+
+error:
+       if (ofid)
+               p9_client_clunk(ofid);
+       if (fid)
+               p9_client_clunk(fid);
+       return err;
+}
+
 /**
  * v9fs_vfs_create - VFS hook to create files
  * @dir: directory inode that is being created
@@ -652,6 +845,83 @@ static int v9fs_vfs_mkdir(struct inode *dir, struct dentry *dentry, int mode)
        return err;
 }
 
+
+/**
+ * v9fs_vfs_mkdir_dotl - VFS mkdir hook to create a directory
+ * @dir:  inode that is being unlinked
+ * @dentry: dentry that is being unlinked
+ * @mode: mode for new directory
+ *
+ */
+
+static int v9fs_vfs_mkdir_dotl(struct inode *dir, struct dentry *dentry,
+                                       int mode)
+{
+       int err;
+       struct v9fs_session_info *v9ses;
+       struct p9_fid *fid = NULL, *dfid = NULL;
+       gid_t gid;
+       char *name;
+       struct inode *inode;
+       struct p9_qid qid;
+       struct dentry *dir_dentry;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "name %s\n", dentry->d_name.name);
+       err = 0;
+       v9ses = v9fs_inode2v9ses(dir);
+
+       mode |= S_IFDIR;
+       dir_dentry = v9fs_dentry_from_dir_inode(dir);
+       dfid = v9fs_fid_lookup(dir_dentry);
+       if (IS_ERR(dfid)) {
+               err = PTR_ERR(dfid);
+               P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
+               dfid = NULL;
+               goto error;
+       }
+
+       gid = v9fs_get_fsgid_for_create(dir);
+       if (gid < 0) {
+               P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n");
+               goto error;
+       }
+
+       name = (char *) dentry->d_name.name;
+       err = p9_client_mkdir_dotl(dfid, name, mode, gid, &qid);
+       if (err < 0)
+               goto error;
+
+       /* instantiate inode and assign the unopened fid to the dentry */
+       if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+               fid = p9_client_walk(dfid, 1, &name, 1);
+               if (IS_ERR(fid)) {
+                       err = PTR_ERR(fid);
+                       P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
+                               err);
+                       fid = NULL;
+                       goto error;
+               }
+
+               inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
+               if (IS_ERR(inode)) {
+                       err = PTR_ERR(inode);
+                       P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
+                               err);
+                       goto error;
+               }
+               dentry->d_op = &v9fs_cached_dentry_operations;
+               d_instantiate(dentry, inode);
+               err = v9fs_fid_add(dentry, fid);
+               if (err < 0)
+                       goto error;
+               fid = NULL;
+       }
+error:
+       if (fid)
+               p9_client_clunk(fid);
+       return err;
+}
+
 /**
  * v9fs_vfs_lookup - VFS lookup hook to "walk" to a new inode
  * @dir:  inode that is being walked from
@@ -678,6 +948,7 @@ static struct dentry *v9fs_vfs_lookup(struct inode *dir, struct dentry *dentry,
 
        sb = dir->i_sb;
        v9ses = v9fs_inode2v9ses(dir);
+       /* We can walk d_parent because we hold the dir->i_mutex */
        dfid = v9fs_fid_lookup(dentry->d_parent);
        if (IS_ERR(dfid))
                return ERR_CAST(dfid);
@@ -785,27 +1056,33 @@ v9fs_vfs_rename(struct inode *old_dir, struct dentry *old_dentry,
                goto clunk_olddir;
        }
 
+       down_write(&v9ses->rename_sem);
        if (v9fs_proto_dotl(v9ses)) {
                retval = p9_client_rename(oldfid, newdirfid,
                                        (char *) new_dentry->d_name.name);
                if (retval != -ENOSYS)
                        goto clunk_newdir;
        }
+       if (old_dentry->d_parent != new_dentry->d_parent) {
+               /*
+                * 9P .u can only handle file rename in the same directory
+                */
 
-       /* 9P can only handle file rename in the same directory */
-       if (memcmp(&olddirfid->qid, &newdirfid->qid, sizeof(newdirfid->qid))) {
                P9_DPRINTK(P9_DEBUG_ERROR,
                                "old dir and new dir are different\n");
                retval = -EXDEV;
                goto clunk_newdir;
        }
-
        v9fs_blank_wstat(&wstat);
        wstat.muid = v9ses->uname;
        wstat.name = (char *) new_dentry->d_name.name;
        retval = p9_client_wstat(oldfid, &wstat);
 
 clunk_newdir:
+       if (!retval)
+               /* successful rename */
+               d_move(old_dentry, new_dentry);
+       up_write(&v9ses->rename_sem);
        p9_client_clunk(newdirfid);
 
 clunk_olddir:
@@ -853,6 +1130,42 @@ v9fs_vfs_getattr(struct vfsmount *mnt, struct dentry *dentry,
        return 0;
 }
 
+static int
+v9fs_vfs_getattr_dotl(struct vfsmount *mnt, struct dentry *dentry,
+                struct kstat *stat)
+{
+       int err;
+       struct v9fs_session_info *v9ses;
+       struct p9_fid *fid;
+       struct p9_stat_dotl *st;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "dentry: %p\n", dentry);
+       err = -EPERM;
+       v9ses = v9fs_inode2v9ses(dentry->d_inode);
+       if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE)
+               return simple_getattr(mnt, dentry, stat);
+
+       fid = v9fs_fid_lookup(dentry);
+       if (IS_ERR(fid))
+               return PTR_ERR(fid);
+
+       /* Ask for all the fields in stat structure. Server will return
+        * whatever it supports
+        */
+
+       st = p9_client_getattr_dotl(fid, P9_STATS_ALL);
+       if (IS_ERR(st))
+               return PTR_ERR(st);
+
+       v9fs_stat2inode_dotl(st, dentry->d_inode);
+       generic_fillattr(dentry->d_inode, stat);
+       /* Change block size to what the server returned */
+       stat->blksize = st->st_blksize;
+
+       kfree(st);
+       return 0;
+}
+
 /**
  * v9fs_vfs_setattr - set file metadata
  * @dentry: file whose metadata to set
@@ -902,6 +1215,49 @@ static int v9fs_vfs_setattr(struct dentry *dentry, struct iattr *iattr)
        return retval;
 }
 
+/**
+ * v9fs_vfs_setattr_dotl - set file metadata
+ * @dentry: file whose metadata to set
+ * @iattr: metadata assignment structure
+ *
+ */
+
+static int v9fs_vfs_setattr_dotl(struct dentry *dentry, struct iattr *iattr)
+{
+       int retval;
+       struct v9fs_session_info *v9ses;
+       struct p9_fid *fid;
+       struct p9_iattr_dotl p9attr;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "\n");
+
+       retval = inode_change_ok(dentry->d_inode, iattr);
+       if (retval)
+               return retval;
+
+       p9attr.valid = iattr->ia_valid;
+       p9attr.mode = iattr->ia_mode;
+       p9attr.uid = iattr->ia_uid;
+       p9attr.gid = iattr->ia_gid;
+       p9attr.size = iattr->ia_size;
+       p9attr.atime_sec = iattr->ia_atime.tv_sec;
+       p9attr.atime_nsec = iattr->ia_atime.tv_nsec;
+       p9attr.mtime_sec = iattr->ia_mtime.tv_sec;
+       p9attr.mtime_nsec = iattr->ia_mtime.tv_nsec;
+
+       retval = -EPERM;
+       v9ses = v9fs_inode2v9ses(dentry->d_inode);
+       fid = v9fs_fid_lookup(dentry);
+       if (IS_ERR(fid))
+               return PTR_ERR(fid);
+
+       retval = p9_client_setattr(fid, &p9attr);
+       if (retval >= 0)
+               retval = inode_setattr(dentry->d_inode, iattr);
+
+       return retval;
+}
+
 /**
  * v9fs_stat2inode - populate an inode structure with mistat info
  * @stat: Plan 9 metadata (mistat) structure
@@ -979,6 +1335,77 @@ v9fs_stat2inode(struct p9_wstat *stat, struct inode *inode,
        inode->i_blocks = (i_size_read(inode) + 512 - 1) >> 9;
 }
 
+/**
+ * v9fs_stat2inode_dotl - populate an inode structure with stat info
+ * @stat: stat structure
+ * @inode: inode to populate
+ * @sb: superblock of filesystem
+ *
+ */
+
+void
+v9fs_stat2inode_dotl(struct p9_stat_dotl *stat, struct inode *inode)
+{
+
+       if ((stat->st_result_mask & P9_STATS_BASIC) == P9_STATS_BASIC) {
+               inode->i_atime.tv_sec = stat->st_atime_sec;
+               inode->i_atime.tv_nsec = stat->st_atime_nsec;
+               inode->i_mtime.tv_sec = stat->st_mtime_sec;
+               inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
+               inode->i_ctime.tv_sec = stat->st_ctime_sec;
+               inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
+               inode->i_uid = stat->st_uid;
+               inode->i_gid = stat->st_gid;
+               inode->i_nlink = stat->st_nlink;
+               inode->i_mode = stat->st_mode;
+               inode->i_rdev = new_decode_dev(stat->st_rdev);
+
+               if ((S_ISBLK(inode->i_mode)) || (S_ISCHR(inode->i_mode)))
+                       init_special_inode(inode, inode->i_mode, inode->i_rdev);
+
+               i_size_write(inode, stat->st_size);
+               inode->i_blocks = stat->st_blocks;
+       } else {
+               if (stat->st_result_mask & P9_STATS_ATIME) {
+                       inode->i_atime.tv_sec = stat->st_atime_sec;
+                       inode->i_atime.tv_nsec = stat->st_atime_nsec;
+               }
+               if (stat->st_result_mask & P9_STATS_MTIME) {
+                       inode->i_mtime.tv_sec = stat->st_mtime_sec;
+                       inode->i_mtime.tv_nsec = stat->st_mtime_nsec;
+               }
+               if (stat->st_result_mask & P9_STATS_CTIME) {
+                       inode->i_ctime.tv_sec = stat->st_ctime_sec;
+                       inode->i_ctime.tv_nsec = stat->st_ctime_nsec;
+               }
+               if (stat->st_result_mask & P9_STATS_UID)
+                       inode->i_uid = stat->st_uid;
+               if (stat->st_result_mask & P9_STATS_GID)
+                       inode->i_gid = stat->st_gid;
+               if (stat->st_result_mask & P9_STATS_NLINK)
+                       inode->i_nlink = stat->st_nlink;
+               if (stat->st_result_mask & P9_STATS_MODE) {
+                       inode->i_mode = stat->st_mode;
+                       if ((S_ISBLK(inode->i_mode)) ||
+                                               (S_ISCHR(inode->i_mode)))
+                               init_special_inode(inode, inode->i_mode,
+                                                               inode->i_rdev);
+               }
+               if (stat->st_result_mask & P9_STATS_RDEV)
+                       inode->i_rdev = new_decode_dev(stat->st_rdev);
+               if (stat->st_result_mask & P9_STATS_SIZE)
+                       i_size_write(inode, stat->st_size);
+               if (stat->st_result_mask & P9_STATS_BLOCKS)
+                       inode->i_blocks = stat->st_blocks;
+       }
+       if (stat->st_result_mask & P9_STATS_GEN)
+                       inode->i_generation = stat->st_gen;
+
+       /* Currently we don't support P9_STATS_BTIME and P9_STATS_DATA_VERSION
+        * because the inode structure does not have fields for them.
+        */
+}
+
 /**
  * v9fs_qid2ino - convert qid into inode number
  * @qid: qid to hash
@@ -1022,7 +1449,7 @@ static int v9fs_readlink(struct dentry *dentry, char *buffer, int buflen)
        if (IS_ERR(fid))
                return PTR_ERR(fid);
 
-       if (!v9fs_proto_dotu(v9ses))
+       if (!v9fs_proto_dotu(v9ses) && !v9fs_proto_dotl(v9ses))
                return -EBADF;
 
        st = p9_client_stat(fid);
@@ -1127,6 +1554,99 @@ static int v9fs_vfs_mkspecial(struct inode *dir, struct dentry *dentry,
        return 0;
 }
 
+/**
+ * v9fs_vfs_symlink_dotl - helper function to create symlinks
+ * @dir: directory inode containing symlink
+ * @dentry: dentry for symlink
+ * @symname: symlink data
+ *
+ * See Also: 9P2000.L RFC for more information
+ *
+ */
+
+static int
+v9fs_vfs_symlink_dotl(struct inode *dir, struct dentry *dentry,
+               const char *symname)
+{
+       struct v9fs_session_info *v9ses;
+       struct p9_fid *dfid;
+       struct p9_fid *fid = NULL;
+       struct inode *inode;
+       struct p9_qid qid;
+       char *name;
+       int err;
+       gid_t gid;
+
+       name = (char *) dentry->d_name.name;
+       P9_DPRINTK(P9_DEBUG_VFS, "v9fs_vfs_symlink_dotl : %lu,%s,%s\n",
+                       dir->i_ino, name, symname);
+       v9ses = v9fs_inode2v9ses(dir);
+
+       dfid = v9fs_fid_lookup(dentry->d_parent);
+       if (IS_ERR(dfid)) {
+               err = PTR_ERR(dfid);
+               P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
+               return err;
+       }
+
+       gid = v9fs_get_fsgid_for_create(dir);
+
+       if (gid < 0) {
+               P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_egid failed %d\n", gid);
+               goto error;
+       }
+
+       /* Server doesn't alter fid on TSYMLINK. Hence no need to clone it. */
+       err = p9_client_symlink(dfid, name, (char *)symname, gid, &qid);
+
+       if (err < 0) {
+               P9_DPRINTK(P9_DEBUG_VFS, "p9_client_symlink failed %d\n", err);
+               goto error;
+       }
+
+       if (v9ses->cache) {
+               /* Now walk from the parent so we can get an unopened fid. */
+               fid = p9_client_walk(dfid, 1, &name, 1);
+               if (IS_ERR(fid)) {
+                       err = PTR_ERR(fid);
+                       P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
+                                       err);
+                       fid = NULL;
+                       goto error;
+               }
+
+               /* instantiate inode and assign the unopened fid to dentry */
+               inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
+               if (IS_ERR(inode)) {
+                       err = PTR_ERR(inode);
+                       P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
+                                       err);
+                       goto error;
+               }
+               dentry->d_op = &v9fs_cached_dentry_operations;
+               d_instantiate(dentry, inode);
+               err = v9fs_fid_add(dentry, fid);
+               if (err < 0)
+                       goto error;
+               fid = NULL;
+       } else {
+               /* Not in cached mode. No need to populate inode with stat */
+               inode = v9fs_get_inode(dir->i_sb, S_IFLNK);
+               if (IS_ERR(inode)) {
+                       err = PTR_ERR(inode);
+                       goto error;
+               }
+               dentry->d_op = &v9fs_dentry_operations;
+               d_instantiate(dentry, inode);
+       }
+
+error:
+       if (fid)
+               p9_client_clunk(fid);
+
+       return err;
+}
+
 /**
  * v9fs_vfs_symlink - helper function to create symlinks
  * @dir: directory inode containing symlink
@@ -1185,6 +1705,76 @@ clunk_fid:
        return retval;
 }
 
+/**
+ * v9fs_vfs_link_dotl - create a hardlink for dotl
+ * @old_dentry: dentry for file to link to
+ * @dir: inode destination for new link
+ * @dentry: dentry for link
+ *
+ */
+
+static int
+v9fs_vfs_link_dotl(struct dentry *old_dentry, struct inode *dir,
+               struct dentry *dentry)
+{
+       int err;
+       struct p9_fid *dfid, *oldfid;
+       char *name;
+       struct v9fs_session_info *v9ses;
+       struct dentry *dir_dentry;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "dir ino: %lu, old_name: %s, new_name: %s\n",
+                       dir->i_ino, old_dentry->d_name.name,
+                       dentry->d_name.name);
+
+       v9ses = v9fs_inode2v9ses(dir);
+       dir_dentry = v9fs_dentry_from_dir_inode(dir);
+       dfid = v9fs_fid_lookup(dir_dentry);
+       if (IS_ERR(dfid))
+               return PTR_ERR(dfid);
+
+       oldfid = v9fs_fid_lookup(old_dentry);
+       if (IS_ERR(oldfid))
+               return PTR_ERR(oldfid);
+
+       name = (char *) dentry->d_name.name;
+
+       err = p9_client_link(dfid, oldfid, (char *)dentry->d_name.name);
+
+       if (err < 0) {
+               P9_DPRINTK(P9_DEBUG_VFS, "p9_client_link failed %d\n", err);
+               return err;
+       }
+
+       if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+               /* Get the latest stat info from server. */
+               struct p9_fid *fid;
+               struct p9_stat_dotl *st;
+
+               fid = v9fs_fid_lookup(old_dentry);
+               if (IS_ERR(fid))
+                       return PTR_ERR(fid);
+
+               st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
+               if (IS_ERR(st))
+                       return PTR_ERR(st);
+
+               v9fs_stat2inode_dotl(st, old_dentry->d_inode);
+
+               kfree(st);
+       } else {
+               /* Caching disabled. No need to get upto date stat info.
+                * This dentry will be released immediately. So, just i_count++
+                */
+               atomic_inc(&old_dentry->d_inode->i_count);
+       }
+
+       dentry->d_op = old_dentry->d_op;
+       d_instantiate(dentry, old_dentry->d_inode);
+
+       return err;
+}
+
 /**
  * v9fs_vfs_mknod - create a special file
  * @dir: inode destination for new link
@@ -1230,6 +1820,100 @@ v9fs_vfs_mknod(struct inode *dir, struct dentry *dentry, int mode, dev_t rdev)
        return retval;
 }
 
+/**
+ * v9fs_vfs_mknod_dotl - create a special file
+ * @dir: inode destination for new link
+ * @dentry: dentry for file
+ * @mode: mode for creation
+ * @rdev: device associated with special file
+ *
+ */
+static int
+v9fs_vfs_mknod_dotl(struct inode *dir, struct dentry *dentry, int mode,
+               dev_t rdev)
+{
+       int err;
+       char *name;
+       struct v9fs_session_info *v9ses;
+       struct p9_fid *fid = NULL, *dfid = NULL;
+       struct inode *inode;
+       gid_t gid;
+       struct p9_qid qid;
+       struct dentry *dir_dentry;
+
+       P9_DPRINTK(P9_DEBUG_VFS,
+               " %lu,%s mode: %x MAJOR: %u MINOR: %u\n", dir->i_ino,
+               dentry->d_name.name, mode, MAJOR(rdev), MINOR(rdev));
+
+       if (!new_valid_dev(rdev))
+               return -EINVAL;
+
+       v9ses = v9fs_inode2v9ses(dir);
+       dir_dentry = v9fs_dentry_from_dir_inode(dir);
+       dfid = v9fs_fid_lookup(dir_dentry);
+       if (IS_ERR(dfid)) {
+               err = PTR_ERR(dfid);
+               P9_DPRINTK(P9_DEBUG_VFS, "fid lookup failed %d\n", err);
+               dfid = NULL;
+               goto error;
+       }
+
+       gid = v9fs_get_fsgid_for_create(dir);
+       if (gid < 0) {
+               P9_DPRINTK(P9_DEBUG_VFS, "v9fs_get_fsgid_for_create failed\n");
+               goto error;
+       }
+
+       name = (char *) dentry->d_name.name;
+
+       err = p9_client_mknod_dotl(dfid, name, mode, rdev, gid, &qid);
+       if (err < 0)
+               goto error;
+
+       /* instantiate inode and assign the unopened fid to the dentry */
+       if (v9ses->cache == CACHE_LOOSE || v9ses->cache == CACHE_FSCACHE) {
+               fid = p9_client_walk(dfid, 1, &name, 1);
+               if (IS_ERR(fid)) {
+                       err = PTR_ERR(fid);
+                       P9_DPRINTK(P9_DEBUG_VFS, "p9_client_walk failed %d\n",
+                               err);
+                       fid = NULL;
+                       goto error;
+               }
+
+               inode = v9fs_inode_from_fid(v9ses, fid, dir->i_sb);
+               if (IS_ERR(inode)) {
+                       err = PTR_ERR(inode);
+                       P9_DPRINTK(P9_DEBUG_VFS, "inode creation failed %d\n",
+                               err);
+                       goto error;
+               }
+               dentry->d_op = &v9fs_cached_dentry_operations;
+               d_instantiate(dentry, inode);
+               err = v9fs_fid_add(dentry, fid);
+               if (err < 0)
+                       goto error;
+               fid = NULL;
+       } else {
+               /*
+                * Not in cached mode. No need to populate inode with stat.
+                * socket syscall returns a fd, so we need instantiate
+                */
+               inode = v9fs_get_inode(dir->i_sb, mode);
+               if (IS_ERR(inode)) {
+                       err = PTR_ERR(inode);
+                       goto error;
+               }
+               dentry->d_op = &v9fs_dentry_operations;
+               d_instantiate(dentry, inode);
+       }
+
+error:
+       if (fid)
+               p9_client_clunk(fid);
+       return err;
+}
+
 static const struct inode_operations v9fs_dir_inode_operations_dotu = {
        .create = v9fs_vfs_create,
        .lookup = v9fs_vfs_lookup,
@@ -1238,24 +1922,29 @@ static const struct inode_operations v9fs_dir_inode_operations_dotu = {
        .unlink = v9fs_vfs_unlink,
        .mkdir = v9fs_vfs_mkdir,
        .rmdir = v9fs_vfs_rmdir,
-       .mknod = v9fs_vfs_mknod,
+       .mknod = v9fs_vfs_mknod_dotl,
        .rename = v9fs_vfs_rename,
        .getattr = v9fs_vfs_getattr,
        .setattr = v9fs_vfs_setattr,
 };
 
 static const struct inode_operations v9fs_dir_inode_operations_dotl = {
-       .create = v9fs_vfs_create,
+       .create = v9fs_vfs_create_dotl,
        .lookup = v9fs_vfs_lookup,
-       .symlink = v9fs_vfs_symlink,
-       .link = v9fs_vfs_link,
+       .link = v9fs_vfs_link_dotl,
+       .symlink = v9fs_vfs_symlink_dotl,
        .unlink = v9fs_vfs_unlink,
-       .mkdir = v9fs_vfs_mkdir,
+       .mkdir = v9fs_vfs_mkdir_dotl,
        .rmdir = v9fs_vfs_rmdir,
-       .mknod = v9fs_vfs_mknod,
+       .mknod = v9fs_vfs_mknod_dotl,
        .rename = v9fs_vfs_rename,
-       .getattr = v9fs_vfs_getattr,
-       .setattr = v9fs_vfs_setattr,
+       .getattr = v9fs_vfs_getattr_dotl,
+       .setattr = v9fs_vfs_setattr_dotl,
+       .setxattr = generic_setxattr,
+       .getxattr = generic_getxattr,
+       .removexattr = generic_removexattr,
+       .listxattr = v9fs_listxattr,
+
 };
 
 static const struct inode_operations v9fs_dir_inode_operations = {
@@ -1276,8 +1965,12 @@ static const struct inode_operations v9fs_file_inode_operations = {
 };
 
 static const struct inode_operations v9fs_file_inode_operations_dotl = {
-       .getattr = v9fs_vfs_getattr,
-       .setattr = v9fs_vfs_setattr,
+       .getattr = v9fs_vfs_getattr_dotl,
+       .setattr = v9fs_vfs_setattr_dotl,
+       .setxattr = generic_setxattr,
+       .getxattr = generic_getxattr,
+       .removexattr = generic_removexattr,
+       .listxattr = v9fs_listxattr,
 };
 
 static const struct inode_operations v9fs_symlink_inode_operations = {
@@ -1292,6 +1985,10 @@ static const struct inode_operations v9fs_symlink_inode_operations_dotl = {
        .readlink = generic_readlink,
        .follow_link = v9fs_vfs_follow_link,
        .put_link = v9fs_vfs_put_link,
-       .getattr = v9fs_vfs_getattr,
-       .setattr = v9fs_vfs_setattr,
+       .getattr = v9fs_vfs_getattr_dotl,
+       .setattr = v9fs_vfs_setattr_dotl,
+       .setxattr = generic_setxattr,
+       .getxattr = generic_getxattr,
+       .removexattr = generic_removexattr,
+       .listxattr = v9fs_listxattr,
 };
index be74d020436e2d7badad70f6e89e430d12f9d6e8..4b9ede0b41b71f94fb1ae00031c7b5417cf37683 100644 (file)
@@ -45,6 +45,7 @@
 #include "v9fs.h"
 #include "v9fs_vfs.h"
 #include "fid.h"
+#include "xattr.h"
 
 static const struct super_operations v9fs_super_ops, v9fs_super_ops_dotl;
 
@@ -77,9 +78,10 @@ v9fs_fill_super(struct super_block *sb, struct v9fs_session_info *v9ses,
        sb->s_blocksize_bits = fls(v9ses->maxdata - 1);
        sb->s_blocksize = 1 << sb->s_blocksize_bits;
        sb->s_magic = V9FS_MAGIC;
-       if (v9fs_proto_dotl(v9ses))
+       if (v9fs_proto_dotl(v9ses)) {
                sb->s_op = &v9fs_super_ops_dotl;
-       else
+               sb->s_xattr = v9fs_xattr_handlers;
+       } else
                sb->s_op = &v9fs_super_ops;
        sb->s_bdi = &v9ses->bdi;
 
@@ -107,7 +109,6 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
        struct inode *inode = NULL;
        struct dentry *root = NULL;
        struct v9fs_session_info *v9ses = NULL;
-       struct p9_wstat *st = NULL;
        int mode = S_IRWXUGO | S_ISVTX;
        struct p9_fid *fid;
        int retval = 0;
@@ -124,16 +125,10 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
                goto close_session;
        }
 
-       st = p9_client_stat(fid);
-       if (IS_ERR(st)) {
-               retval = PTR_ERR(st);
-               goto clunk_fid;
-       }
-
        sb = sget(fs_type, NULL, v9fs_set_super, v9ses);
        if (IS_ERR(sb)) {
                retval = PTR_ERR(sb);
-               goto free_stat;
+               goto clunk_fid;
        }
        v9fs_fill_super(sb, v9ses, flags, data);
 
@@ -151,22 +146,38 @@ static int v9fs_get_sb(struct file_system_type *fs_type, int flags,
        }
 
        sb->s_root = root;
-       root->d_inode->i_ino = v9fs_qid2ino(&st->qid);
 
-       v9fs_stat2inode(st, root->d_inode, sb);
+       if (v9fs_proto_dotl(v9ses)) {
+               struct p9_stat_dotl *st = NULL;
+               st = p9_client_getattr_dotl(fid, P9_STATS_BASIC);
+               if (IS_ERR(st)) {
+                       retval = PTR_ERR(st);
+                       goto clunk_fid;
+               }
+
+               v9fs_stat2inode_dotl(st, root->d_inode);
+               kfree(st);
+       } else {
+               struct p9_wstat *st = NULL;
+               st = p9_client_stat(fid);
+               if (IS_ERR(st)) {
+                       retval = PTR_ERR(st);
+                       goto clunk_fid;
+               }
+
+               root->d_inode->i_ino = v9fs_qid2ino(&st->qid);
+               v9fs_stat2inode(st, root->d_inode, sb);
+
+               p9stat_free(st);
+               kfree(st);
+       }
 
        v9fs_fid_add(root, fid);
-       p9stat_free(st);
-       kfree(st);
 
 P9_DPRINTK(P9_DEBUG_VFS, " simple set mount, return 0\n");
        simple_set_mnt(mnt, sb);
        return 0;
 
-free_stat:
-       p9stat_free(st);
-       kfree(st);
-
 clunk_fid:
        p9_client_clunk(fid);
 
@@ -176,8 +187,6 @@ close_session:
        return retval;
 
 release_sb:
-       p9stat_free(st);
-       kfree(st);
        deactivate_locked_super(sb);
        return retval;
 }
@@ -278,4 +287,5 @@ struct file_system_type v9fs_fs_type = {
        .get_sb = v9fs_get_sb,
        .kill_sb = v9fs_kill_super,
        .owner = THIS_MODULE,
+       .fs_flags = FS_RENAME_DOES_D_MOVE,
 };
diff --git a/fs/9p/xattr.c b/fs/9p/xattr.c
new file mode 100644 (file)
index 0000000..f88e5c2
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ * Copyright IBM Corporation, 2010
+ * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
+
+#include <linux/module.h>
+#include <linux/fs.h>
+#include <linux/sched.h>
+#include <net/9p/9p.h>
+#include <net/9p/client.h>
+
+#include "fid.h"
+#include "xattr.h"
+
+/*
+ * v9fs_xattr_get()
+ *
+ * Copy an extended attribute into the buffer
+ * provided, or compute the buffer size required.
+ * Buffer is NULL to compute the size of the buffer required.
+ *
+ * Returns a negative error number on failure, or the number of bytes
+ * used / required on success.
+ */
+ssize_t v9fs_xattr_get(struct dentry *dentry, const char *name,
+                      void *buffer, size_t buffer_size)
+{
+       ssize_t retval;
+       int msize, read_count;
+       u64 offset = 0, attr_size;
+       struct p9_fid *fid, *attr_fid;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "%s: name = %s value_len = %zu\n",
+               __func__, name, buffer_size);
+
+       fid = v9fs_fid_lookup(dentry);
+       if (IS_ERR(fid))
+               return PTR_ERR(fid);
+
+       attr_fid = p9_client_xattrwalk(fid, name, &attr_size);
+       if (IS_ERR(attr_fid)) {
+               retval = PTR_ERR(attr_fid);
+               P9_DPRINTK(P9_DEBUG_VFS,
+                       "p9_client_attrwalk failed %zd\n", retval);
+               attr_fid = NULL;
+               goto error;
+       }
+       if (!buffer_size) {
+               /* request to get the attr_size */
+               retval = attr_size;
+               goto error;
+       }
+       if (attr_size > buffer_size) {
+               retval = -ERANGE;
+               goto error;
+       }
+       msize = attr_fid->clnt->msize;
+       while (attr_size) {
+               if (attr_size > (msize - P9_IOHDRSZ))
+                       read_count = msize - P9_IOHDRSZ;
+               else
+                       read_count = attr_size;
+               read_count = p9_client_read(attr_fid, ((char *)buffer)+offset,
+                                       NULL, offset, read_count);
+               if (read_count < 0) {
+                       /* error in xattr read */
+                       retval = read_count;
+                       goto error;
+               }
+               offset += read_count;
+               attr_size -= read_count;
+       }
+       /* Total read xattr bytes */
+       retval = offset;
+error:
+       if (attr_fid)
+               p9_client_clunk(attr_fid);
+       return retval;
+
+}
+
+/*
+ * v9fs_xattr_set()
+ *
+ * Create, replace or remove an extended attribute for this inode. Buffer
+ * is NULL to remove an existing extended attribute, and non-NULL to
+ * either replace an existing extended attribute, or create a new extended
+ * attribute. The flags XATTR_REPLACE and XATTR_CREATE
+ * specify that an extended attribute must exist and must not exist
+ * previous to the call, respectively.
+ *
+ * Returns 0, or a negative error number on failure.
+ */
+int v9fs_xattr_set(struct dentry *dentry, const char *name,
+                  const void *value, size_t value_len, int flags)
+{
+       u64 offset = 0;
+       int retval, msize, write_count;
+       struct p9_fid *fid = NULL;
+
+       P9_DPRINTK(P9_DEBUG_VFS, "%s: name = %s value_len = %zu flags = %d\n",
+               __func__, name, value_len, flags);
+
+       fid = v9fs_fid_clone(dentry);
+       if (IS_ERR(fid)) {
+               retval = PTR_ERR(fid);
+               fid = NULL;
+               goto error;
+       }
+       /*
+        * On success fid points to xattr
+        */
+       retval = p9_client_xattrcreate(fid, name, value_len, flags);
+       if (retval < 0) {
+               P9_DPRINTK(P9_DEBUG_VFS,
+                       "p9_client_xattrcreate failed %d\n", retval);
+               goto error;
+       }
+       msize = fid->clnt->msize;;
+       while (value_len) {
+               if (value_len > (msize - P9_IOHDRSZ))
+                       write_count = msize - P9_IOHDRSZ;
+               else
+                       write_count = value_len;
+               write_count = p9_client_write(fid, ((char *)value)+offset,
+                                       NULL, offset, write_count);
+               if (write_count < 0) {
+                       /* error in xattr write */
+                       retval = write_count;
+                       goto error;
+               }
+               offset += write_count;
+               value_len -= write_count;
+       }
+       /* Total read xattr bytes */
+       retval = offset;
+error:
+       if (fid)
+               retval = p9_client_clunk(fid);
+       return retval;
+}
+
+ssize_t v9fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
+{
+       return v9fs_xattr_get(dentry, NULL, buffer, buffer_size);
+}
+
+const struct xattr_handler *v9fs_xattr_handlers[] = {
+       &v9fs_xattr_user_handler,
+       NULL
+};
diff --git a/fs/9p/xattr.h b/fs/9p/xattr.h
new file mode 100644 (file)
index 0000000..9ddf672
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * Copyright IBM Corporation, 2010
+ * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
+#ifndef FS_9P_XATTR_H
+#define FS_9P_XATTR_H
+
+#include <linux/xattr.h>
+
+extern const struct xattr_handler *v9fs_xattr_handlers[];
+extern struct xattr_handler v9fs_xattr_user_handler;
+
+extern ssize_t v9fs_xattr_get(struct dentry *, const char *,
+                             void *, size_t);
+extern int v9fs_xattr_set(struct dentry *, const char *,
+                         const void *, size_t, int);
+extern ssize_t v9fs_listxattr(struct dentry *, char *, size_t);
+#endif /* FS_9P_XATTR_H */
diff --git a/fs/9p/xattr_user.c b/fs/9p/xattr_user.c
new file mode 100644 (file)
index 0000000..d0b701b
--- /dev/null
@@ -0,0 +1,80 @@
+/*
+ * Copyright IBM Corporation, 2010
+ * Author Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of version 2.1 of the GNU Lesser General Public License
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it would be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+ *
+ */
+
+
+#include <linux/module.h>
+#include <linux/string.h>
+#include <linux/fs.h>
+#include <linux/slab.h>
+#include "xattr.h"
+
+static int v9fs_xattr_user_get(struct dentry *dentry, const char *name,
+                       void *buffer, size_t size, int type)
+{
+       int retval;
+       char *full_name;
+       size_t name_len;
+       size_t prefix_len = XATTR_USER_PREFIX_LEN;
+
+       if (name == NULL)
+               return -EINVAL;
+
+       if (strcmp(name, "") == 0)
+               return -EINVAL;
+
+       name_len = strlen(name);
+       full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
+       if (!full_name)
+               return -ENOMEM;
+       memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
+       memcpy(full_name+prefix_len, name, name_len);
+       full_name[prefix_len + name_len] = '\0';
+
+       retval = v9fs_xattr_get(dentry, full_name, buffer, size);
+       kfree(full_name);
+       return retval;
+}
+
+static int v9fs_xattr_user_set(struct dentry *dentry, const char *name,
+                       const void *value, size_t size, int flags, int type)
+{
+       int retval;
+       char *full_name;
+       size_t name_len;
+       size_t prefix_len = XATTR_USER_PREFIX_LEN;
+
+       if (name == NULL)
+               return -EINVAL;
+
+       if (strcmp(name, "") == 0)
+               return -EINVAL;
+
+       name_len = strlen(name);
+       full_name = kmalloc(prefix_len + name_len + 1 , GFP_KERNEL);
+       if (!full_name)
+               return -ENOMEM;
+       memcpy(full_name, XATTR_USER_PREFIX, prefix_len);
+       memcpy(full_name + prefix_len, name, name_len);
+       full_name[prefix_len + name_len] = '\0';
+
+       retval = v9fs_xattr_set(dentry, full_name, value, size, flags);
+       kfree(full_name);
+       return retval;
+}
+
+struct xattr_handler v9fs_xattr_user_handler = {
+       .prefix = XATTR_USER_PREFIX,
+       .get    = v9fs_xattr_user_get,
+       .set    = v9fs_xattr_user_set,
+};
index 80f352596807a43f08235209d0434998a8ae07a6..5739fd7f88b4996698f6768f8aa9b955177d127a 100644 (file)
@@ -131,6 +131,15 @@ config CIFS_DFS_UPCALL
            IP addresses) which is needed for implicit mounts of DFS junction
            points. If unsure, say N.
 
+config CIFS_FSCACHE
+         bool "Provide CIFS client caching support (EXPERIMENTAL)"
+         depends on EXPERIMENTAL
+         depends on CIFS=m && FSCACHE || CIFS=y && FSCACHE=y
+         help
+           Makes CIFS FS-Cache capable. Say Y here if you want your CIFS data
+           to be cached locally on disk through the general filesystem cache
+           manager. If unsure, say N.
+
 config CIFS_EXPERIMENTAL
          bool "CIFS Experimental Features (EXPERIMENTAL)"
          depends on CIFS && EXPERIMENTAL
index 9948c0030e86df5ad020785341f514b814fed5ee..adefa60a9bdc10108ec9c802e4cbe1ea26f3f6e0 100644 (file)
@@ -11,3 +11,5 @@ cifs-y := cifsfs.o cifssmb.o cifs_debug.o connect.o dir.o file.o inode.o \
 cifs-$(CONFIG_CIFS_UPCALL) += cifs_spnego.o
 
 cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o
+
+cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o
diff --git a/fs/cifs/cache.c b/fs/cifs/cache.c
new file mode 100644 (file)
index 0000000..224d7bb
--- /dev/null
@@ -0,0 +1,331 @@
+/*
+ *   fs/cifs/cache.c - CIFS filesystem cache index structure definitions
+ *
+ *   Copyright (c) 2010 Novell, Inc.
+ *   Authors(s): Suresh Jayaraman (sjayaraman@suse.de>
+ *
+ *   This library is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published
+ *   by the Free Software Foundation; either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This library 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 Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include "fscache.h"
+#include "cifs_debug.h"
+
+/*
+ * CIFS filesystem definition for FS-Cache
+ */
+struct fscache_netfs cifs_fscache_netfs = {
+       .name = "cifs",
+       .version = 0,
+};
+
+/*
+ * Register CIFS for caching with FS-Cache
+ */
+int cifs_fscache_register(void)
+{
+       return fscache_register_netfs(&cifs_fscache_netfs);
+}
+
+/*
+ * Unregister CIFS for caching
+ */
+void cifs_fscache_unregister(void)
+{
+       fscache_unregister_netfs(&cifs_fscache_netfs);
+}
+
+/*
+ * Key layout of CIFS server cache index object
+ */
+struct cifs_server_key {
+       uint16_t        family;         /* address family */
+       uint16_t        port;           /* IP port */
+       union {
+               struct in_addr  ipv4_addr;
+               struct in6_addr ipv6_addr;
+       } addr[0];
+};
+
+/*
+ * Server object keyed by {IPaddress,port,family} tuple
+ */
+static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
+                                  void *buffer, uint16_t maxbuf)
+{
+       const struct TCP_Server_Info *server = cookie_netfs_data;
+       const struct sockaddr *sa = (struct sockaddr *) &server->addr.sockAddr;
+       struct cifs_server_key *key = buffer;
+       uint16_t key_len = sizeof(struct cifs_server_key);
+
+       memset(key, 0, key_len);
+
+       /*
+        * Should not be a problem as sin_family/sin6_family overlays
+        * sa_family field
+        */
+       switch (sa->sa_family) {
+       case AF_INET:
+               key->family = server->addr.sockAddr.sin_family;
+               key->port = server->addr.sockAddr.sin_port;
+               key->addr[0].ipv4_addr = server->addr.sockAddr.sin_addr;
+               key_len += sizeof(key->addr[0].ipv4_addr);
+               break;
+
+       case AF_INET6:
+               key->family = server->addr.sockAddr6.sin6_family;
+               key->port = server->addr.sockAddr6.sin6_port;
+               key->addr[0].ipv6_addr = server->addr.sockAddr6.sin6_addr;
+               key_len += sizeof(key->addr[0].ipv6_addr);
+               break;
+
+       default:
+               cERROR(1, "CIFS: Unknown network family '%d'", sa->sa_family);
+               key_len = 0;
+               break;
+       }
+
+       return key_len;
+}
+
+/*
+ * Server object for FS-Cache
+ */
+const struct fscache_cookie_def cifs_fscache_server_index_def = {
+       .name = "CIFS.server",
+       .type = FSCACHE_COOKIE_TYPE_INDEX,
+       .get_key = cifs_server_get_key,
+};
+
+/*
+ * Auxiliary data attached to CIFS superblock within the cache
+ */
+struct cifs_fscache_super_auxdata {
+       u64     resource_id;            /* unique server resource id */
+};
+
+static char *extract_sharename(const char *treename)
+{
+       const char *src;
+       char *delim, *dst;
+       int len;
+
+       /* skip double chars at the beginning */
+       src = treename + 2;
+
+       /* share name is always preceded by '\\' now */
+       delim = strchr(src, '\\');
+       if (!delim)
+               return ERR_PTR(-EINVAL);
+       delim++;
+       len = strlen(delim);
+
+       /* caller has to free the memory */
+       dst = kstrndup(delim, len, GFP_KERNEL);
+       if (!dst)
+               return ERR_PTR(-ENOMEM);
+
+       return dst;
+}
+
+/*
+ * Superblock object currently keyed by share name
+ */
+static uint16_t cifs_super_get_key(const void *cookie_netfs_data, void *buffer,
+                                  uint16_t maxbuf)
+{
+       const struct cifsTconInfo *tcon = cookie_netfs_data;
+       char *sharename;
+       uint16_t len;
+
+       sharename = extract_sharename(tcon->treeName);
+       if (IS_ERR(sharename)) {
+               cFYI(1, "CIFS: couldn't extract sharename\n");
+               sharename = NULL;
+               return 0;
+       }
+
+       len = strlen(sharename);
+       if (len > maxbuf)
+               return 0;
+
+       memcpy(buffer, sharename, len);
+
+       kfree(sharename);
+
+       return len;
+}
+
+static uint16_t
+cifs_fscache_super_get_aux(const void *cookie_netfs_data, void *buffer,
+                          uint16_t maxbuf)
+{
+       struct cifs_fscache_super_auxdata auxdata;
+       const struct cifsTconInfo *tcon = cookie_netfs_data;
+
+       memset(&auxdata, 0, sizeof(auxdata));
+       auxdata.resource_id = tcon->resource_id;
+
+       if (maxbuf > sizeof(auxdata))
+               maxbuf = sizeof(auxdata);
+
+       memcpy(buffer, &auxdata, maxbuf);
+
+       return maxbuf;
+}
+
+static enum
+fscache_checkaux cifs_fscache_super_check_aux(void *cookie_netfs_data,
+                                             const void *data,
+                                             uint16_t datalen)
+{
+       struct cifs_fscache_super_auxdata auxdata;
+       const struct cifsTconInfo *tcon = cookie_netfs_data;
+
+       if (datalen != sizeof(auxdata))
+               return FSCACHE_CHECKAUX_OBSOLETE;
+
+       memset(&auxdata, 0, sizeof(auxdata));
+       auxdata.resource_id = tcon->resource_id;
+
+       if (memcmp(data, &auxdata, datalen) != 0)
+               return FSCACHE_CHECKAUX_OBSOLETE;
+
+       return FSCACHE_CHECKAUX_OKAY;
+}
+
+/*
+ * Superblock object for FS-Cache
+ */
+const struct fscache_cookie_def cifs_fscache_super_index_def = {
+       .name = "CIFS.super",
+       .type = FSCACHE_COOKIE_TYPE_INDEX,
+       .get_key = cifs_super_get_key,
+       .get_aux = cifs_fscache_super_get_aux,
+       .check_aux = cifs_fscache_super_check_aux,
+};
+
+/*
+ * Auxiliary data attached to CIFS inode within the cache
+ */
+struct cifs_fscache_inode_auxdata {
+       struct timespec last_write_time;
+       struct timespec last_change_time;
+       u64             eof;
+};
+
+static uint16_t cifs_fscache_inode_get_key(const void *cookie_netfs_data,
+                                          void *buffer, uint16_t maxbuf)
+{
+       const struct cifsInodeInfo *cifsi = cookie_netfs_data;
+       uint16_t keylen;
+
+       /* use the UniqueId as the key */
+       keylen = sizeof(cifsi->uniqueid);
+       if (keylen > maxbuf)
+               keylen = 0;
+       else
+               memcpy(buffer, &cifsi->uniqueid, keylen);
+
+       return keylen;
+}
+
+static void
+cifs_fscache_inode_get_attr(const void *cookie_netfs_data, uint64_t *size)
+{
+       const struct cifsInodeInfo *cifsi = cookie_netfs_data;
+
+       *size = cifsi->vfs_inode.i_size;
+}
+
+static uint16_t
+cifs_fscache_inode_get_aux(const void *cookie_netfs_data, void *buffer,
+                          uint16_t maxbuf)
+{
+       struct cifs_fscache_inode_auxdata auxdata;
+       const struct cifsInodeInfo *cifsi = cookie_netfs_data;
+
+       memset(&auxdata, 0, sizeof(auxdata));
+       auxdata.eof = cifsi->server_eof;
+       auxdata.last_write_time = cifsi->vfs_inode.i_mtime;
+       auxdata.last_change_time = cifsi->vfs_inode.i_ctime;
+
+       if (maxbuf > sizeof(auxdata))
+               maxbuf = sizeof(auxdata);
+
+       memcpy(buffer, &auxdata, maxbuf);
+
+       return maxbuf;
+}
+
+static enum
+fscache_checkaux cifs_fscache_inode_check_aux(void *cookie_netfs_data,
+                                             const void *data,
+                                             uint16_t datalen)
+{
+       struct cifs_fscache_inode_auxdata auxdata;
+       struct cifsInodeInfo *cifsi = cookie_netfs_data;
+
+       if (datalen != sizeof(auxdata))
+               return FSCACHE_CHECKAUX_OBSOLETE;
+
+       memset(&auxdata, 0, sizeof(auxdata));
+       auxdata.eof = cifsi->server_eof;
+       auxdata.last_write_time = cifsi->vfs_inode.i_mtime;
+       auxdata.last_change_time = cifsi->vfs_inode.i_ctime;
+
+       if (memcmp(data, &auxdata, datalen) != 0)
+               return FSCACHE_CHECKAUX_OBSOLETE;
+
+       return FSCACHE_CHECKAUX_OKAY;
+}
+
+static void cifs_fscache_inode_now_uncached(void *cookie_netfs_data)
+{
+       struct cifsInodeInfo *cifsi = cookie_netfs_data;
+       struct pagevec pvec;
+       pgoff_t first;
+       int loop, nr_pages;
+
+       pagevec_init(&pvec, 0);
+       first = 0;
+
+       cFYI(1, "cifs inode 0x%p now uncached", cifsi);
+
+       for (;;) {
+               nr_pages = pagevec_lookup(&pvec,
+                                         cifsi->vfs_inode.i_mapping, first,
+                                         PAGEVEC_SIZE - pagevec_count(&pvec));
+               if (!nr_pages)
+                       break;
+
+               for (loop = 0; loop < nr_pages; loop++)
+                       ClearPageFsCache(pvec.pages[loop]);
+
+               first = pvec.pages[nr_pages - 1]->index + 1;
+
+               pvec.nr = nr_pages;
+               pagevec_release(&pvec);
+               cond_resched();
+       }
+}
+
+const struct fscache_cookie_def cifs_fscache_inode_object_def = {
+       .name           = "CIFS.uniqueid",
+       .type           = FSCACHE_COOKIE_TYPE_DATAFILE,
+       .get_key        = cifs_fscache_inode_get_key,
+       .get_attr       = cifs_fscache_inode_get_attr,
+       .get_aux        = cifs_fscache_inode_get_aux,
+       .check_aux      = cifs_fscache_inode_check_aux,
+       .now_uncached   = cifs_fscache_inode_now_uncached,
+};
index ac19a6f3dae079c3b1caa34d0157e3536e609ba8..dc1ed50ea06e2ad7b23e7a547e793b1f48718b21 100644 (file)
@@ -230,28 +230,22 @@ compose_mount_options_err:
        goto compose_mount_options_out;
 }
 
-
-static struct vfsmount *cifs_dfs_do_refmount(const struct vfsmount *mnt_parent,
-               struct dentry *dentry, const struct dfs_info3_param *ref)
+/**
+ * cifs_dfs_do_refmount - mounts specified path using provided refferal
+ * @cifs_sb:           parent/root superblock
+ * @fullpath:          full path in UNC format
+ * @ref:               server's referral
+ */
+static struct vfsmount *cifs_dfs_do_refmount(struct cifs_sb_info *cifs_sb,
+               const char *fullpath, const struct dfs_info3_param *ref)
 {
-       struct cifs_sb_info *cifs_sb;
        struct vfsmount *mnt;
        char *mountdata;
        char *devname = NULL;
-       char *fullpath;
-
-       cifs_sb = CIFS_SB(dentry->d_inode->i_sb);
-       /*
-        * this function gives us a path with a double backslash prefix. We
-        * require a single backslash for DFS.
-        */
-       fullpath = build_path_from_dentry(dentry);
-       if (!fullpath)
-               return ERR_PTR(-ENOMEM);
 
+       /* strip first '\' from fullpath */
        mountdata = cifs_compose_mount_options(cifs_sb->mountdata,
                        fullpath + 1, ref, &devname);
-       kfree(fullpath);
 
        if (IS_ERR(mountdata))
                return (struct vfsmount *)mountdata;
@@ -357,8 +351,8 @@ cifs_dfs_follow_mountpoint(struct dentry *dentry, struct nameidata *nd)
                        rc = -EINVAL;
                        goto out_err;
                }
-               mnt = cifs_dfs_do_refmount(nd->path.mnt,
-                               nd->path.dentry, referrals + i);
+               mnt = cifs_dfs_do_refmount(cifs_sb,
+                               full_path, referrals + i);
                cFYI(1, "%s: cifs_dfs_do_refmount:%s , mnt:%p", __func__,
                                        referrals[i].node_name, mnt);
 
index 246a167cb91354e39455e11dacd84b25f22ec0a9..9e771450c3b8eba5230ffa16c30cb95a73151868 100644 (file)
@@ -35,6 +35,7 @@
 #define CIFS_MOUNT_DYNPERM      0x1000 /* allow in-memory only mode setting   */
 #define CIFS_MOUNT_NOPOSIXBRL   0x2000 /* mandatory not posix byte range lock */
 #define CIFS_MOUNT_NOSSYNC      0x4000 /* don't do slow SMBflush on every sync*/
+#define CIFS_MOUNT_FSCACHE     0x8000 /* local caching enabled */
 
 struct cifs_sb_info {
        struct cifsTconInfo *tcon;      /* primary mount */
index 379bd7d9c05f8ade3045f6c19a17f81b089c7a5a..6effccff85a50d742c23122ea155087c63191909 100644 (file)
@@ -143,6 +143,9 @@ cifs_get_spnego_key(struct cifsSesInfo *sesInfo)
        dp = description + strlen(description);
        sprintf(dp, ";uid=0x%x", sesInfo->linux_uid);
 
+       dp = description + strlen(description);
+       sprintf(dp, ";creduid=0x%x", sesInfo->cred_uid);
+
        dp = description + strlen(description);
        sprintf(dp, ";user=%s", sesInfo->userName);
 
index 2cb1a70214d7298070266840bb97ad7bf2c98a57..8a2cf129e535a21a8cd8bf7bc9116e2bbbd025da 100644 (file)
@@ -47,6 +47,7 @@
 #include <linux/key-type.h>
 #include "dns_resolve.h"
 #include "cifs_spnego.h"
+#include "fscache.h"
 #define CIFS_MAGIC_NUMBER 0xFF534D42   /* the first four bytes of SMB PDUs */
 
 int cifsFYI = 0;
@@ -328,6 +329,12 @@ cifs_destroy_inode(struct inode *inode)
        kmem_cache_free(cifs_inode_cachep, CIFS_I(inode));
 }
 
+static void
+cifs_clear_inode(struct inode *inode)
+{
+       cifs_fscache_release_inode_cookie(inode);
+}
+
 static void
 cifs_show_address(struct seq_file *s, struct TCP_Server_Info *server)
 {
@@ -489,6 +496,7 @@ static const struct super_operations cifs_super_ops = {
        .alloc_inode = cifs_alloc_inode,
        .destroy_inode = cifs_destroy_inode,
        .drop_inode     = cifs_drop_inode,
+       .clear_inode    = cifs_clear_inode,
 /*     .delete_inode   = cifs_delete_inode,  */  /* Do not need above
        function unless later we add lazy close of inodes or unless the
        kernel forgets to call us with the same number of releases (closes)
@@ -902,6 +910,10 @@ init_cifs(void)
                cFYI(1, "cifs_max_pending set to max of 256");
        }
 
+       rc = cifs_fscache_register();
+       if (rc)
+               goto out;
+
        rc = cifs_init_inodecache();
        if (rc)
                goto out_clean_proc;
@@ -951,6 +963,8 @@ init_cifs(void)
        cifs_destroy_inodecache();
  out_clean_proc:
        cifs_proc_clean();
+       cifs_fscache_unregister();
+ out:
        return rc;
 }
 
@@ -959,6 +973,7 @@ exit_cifs(void)
 {
        cFYI(DBG2, "exit_cifs");
        cifs_proc_clean();
+       cifs_fscache_unregister();
 #ifdef CONFIG_CIFS_DFS_UPCALL
        cifs_dfs_release_automount_timer();
        cifs_exit_dns_resolver();
index a7eb65c84b1c16725110b8732163968bc9caef24..d82f5fb4761e252511028b7380e78509c4b7f50a 100644 (file)
@@ -114,5 +114,5 @@ extern long cifs_ioctl(struct file *filep, unsigned int cmd, unsigned long arg);
 extern const struct export_operations cifs_export_ops;
 #endif /* EXPERIMENTAL */
 
-#define CIFS_VERSION   "1.64"
+#define CIFS_VERSION   "1.65"
 #endif                         /* _CIFSFS_H */
index a88479ceaad59602919d3d6d1a1c7a01855d69ac..59906146ad3634e89eb403530d2d592e3ac0216b 100644 (file)
@@ -16,6 +16,9 @@
  *   the GNU Lesser General Public License for more details.
  *
  */
+#ifndef _CIFS_GLOB_H
+#define _CIFS_GLOB_H
+
 #include <linux/in.h>
 #include <linux/in6.h>
 #include <linux/slab.h>
@@ -34,7 +37,7 @@
 #define MAX_SHARE_SIZE  64     /* used to be 20, this should still be enough */
 #define MAX_USERNAME_SIZE 32   /* 32 is to allow for 15 char names + null
                                   termination then *2 for unicode versions */
-#define MAX_PASSWORD_SIZE 16
+#define MAX_PASSWORD_SIZE 512  /* max for windows seems to be 256 wide chars */
 
 #define CIFS_MIN_RCV_POOL 4
 
@@ -80,8 +83,7 @@ enum statusEnum {
 };
 
 enum securityEnum {
-       PLAINTXT = 0,           /* Legacy with Plaintext passwords */
-       LANMAN,                 /* Legacy LANMAN auth */
+       LANMAN = 0,                     /* Legacy LANMAN auth */
        NTLM,                   /* Legacy NTLM012 auth with NTLM hash */
        NTLMv2,                 /* Legacy NTLM auth with NTLMv2 hash */
        RawNTLMSSP,             /* NTLMSSP without SPNEGO, NTLMv2 hash */
@@ -142,7 +144,6 @@ struct TCP_Server_Info {
        struct list_head pending_mid_q;
        void *Server_NlsInfo;   /* BB - placeholder for future NLS info  */
        unsigned short server_codepage; /* codepage for the server    */
-       unsigned long ip_address;       /* IP addr for the server if known */
        enum protocolEnum protocolType;
        char versionMajor;
        char versionMinor;
@@ -190,19 +191,9 @@ struct TCP_Server_Info {
        bool    sec_mskerberos;         /* supports legacy MS Kerberos */
        bool    sec_kerberosu2u;        /* supports U2U Kerberos */
        bool    sec_ntlmssp;            /* supports NTLMSSP */
-};
-
-/*
- * The following is our shortcut to user information.  We surface the uid,
- * and name. We always get the password on the fly in case it
- * has changed. We also hang a list of sessions owned by this user off here.
- */
-struct cifsUidInfo {
-       struct list_head userList;
-       struct list_head sessionList; /* SMB sessions for this user */
-       uid_t linux_uid;
-       char user[MAX_USERNAME_SIZE + 1];       /* ascii name of user */
-       /* BB may need ptr or callback for PAM or WinBind info */
+#ifdef CONFIG_CIFS_FSCACHE
+       struct fscache_cookie   *fscache; /* client index cache cookie */
+#endif
 };
 
 /*
@@ -212,9 +203,6 @@ struct cifsSesInfo {
        struct list_head smb_ses_list;
        struct list_head tcon_list;
        struct mutex session_mutex;
-#if 0
-       struct cifsUidInfo *uidInfo;    /* pointer to user info */
-#endif
        struct TCP_Server_Info *server; /* pointer to server info */
        int ses_count;          /* reference counter */
        enum statusEnum status;
@@ -226,7 +214,8 @@ struct cifsSesInfo {
        char *serverNOS;        /* name of network operating system of server */
        char *serverDomain;     /* security realm of server */
        int Suid;               /* remote smb uid  */
-       uid_t linux_uid;        /* local Linux uid */
+       uid_t linux_uid;        /* overriding owner of files on the mount */
+       uid_t cred_uid;         /* owner of credentials */
        int capabilities;
        char serverName[SERVER_NAME_LEN_WITH_NULL * 2]; /* BB make bigger for
                                TCP names - will ipv6 and sctp addresses fit? */
@@ -311,6 +300,10 @@ struct cifsTconInfo {
        bool local_lease:1; /* check leases (only) on local system not remote */
        bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */
        bool need_reconnect:1; /* connection reset, tid now invalid */
+#ifdef CONFIG_CIFS_FSCACHE
+       u64 resource_id;                /* server resource id */
+       struct fscache_cookie *fscache; /* cookie for share */
+#endif
        /* BB add field for back pointer to sb struct(s)? */
 };
 
@@ -398,6 +391,9 @@ struct cifsInodeInfo {
        bool invalid_mapping:1;         /* pagecache is invalid */
        u64  server_eof;                /* current file size on server */
        u64  uniqueid;                  /* server inode number */
+#ifdef CONFIG_CIFS_FSCACHE
+       struct fscache_cookie *fscache;
+#endif
        struct inode vfs_inode;
 };
 
@@ -733,3 +729,5 @@ GLOBAL_EXTERN unsigned int cifs_min_small;  /* min size of small buf pool */
 GLOBAL_EXTERN unsigned int cifs_max_pending; /* MAX requests at once to server*/
 
 extern const struct slow_work_ops cifs_oplock_break_ops;
+
+#endif /* _CIFS_GLOB_H */
index fb6318b81509801a218d8a2248542e427b9516ce..2eaebbd31132f8118d3afb347433eca50846e417 100644 (file)
@@ -86,7 +86,9 @@ extern unsigned int smbCalcSize(struct smb_hdr *ptr);
 extern unsigned int smbCalcSize_LE(struct smb_hdr *ptr);
 extern int decode_negTokenInit(unsigned char *security_blob, int length,
                        struct TCP_Server_Info *server);
-extern int cifs_convert_address(char *src, void *dst);
+extern int cifs_convert_address(struct sockaddr *dst, char *src);
+extern int cifs_fill_sockaddr(struct sockaddr *dst, char *src,
+                               unsigned short int port);
 extern int map_smb_to_linux_error(struct smb_hdr *smb, int logErr);
 extern void header_assemble(struct smb_hdr *, char /* command */ ,
                            const struct cifsTconInfo *, int /* length of
index 2208f06e4c45ec17d1908b5435ee556be54d6dbe..2a43a0aca965424bf0fb66234560e3a1fbabb08a 100644 (file)
@@ -48,6 +48,7 @@
 #include "nterr.h"
 #include "rfc1002pdu.h"
 #include "cn_cifs.h"
+#include "fscache.h"
 
 #define CIFS_PORT 445
 #define RFC1001_PORT 139
@@ -66,6 +67,7 @@ struct smb_vol {
        char *iocharset;  /* local code page for mapping to and from Unicode */
        char source_rfc1001_name[16]; /* netbios name of client */
        char target_rfc1001_name[16]; /* netbios name of server for Win9x/ME */
+       uid_t cred_uid;
        uid_t linux_uid;
        gid_t linux_gid;
        mode_t file_mode;
@@ -97,6 +99,7 @@ struct smb_vol {
        bool noblocksnd:1;
        bool noautotune:1;
        bool nostrictsync:1; /* do not force expensive SMBflush on every sync */
+       bool fsc:1;     /* enable fscache */
        unsigned int rsize;
        unsigned int wsize;
        bool sockopt_tcp_nodelay:1;
@@ -830,7 +833,8 @@ cifs_parse_mount_options(char *options, const char *devname,
        /* null target name indicates to use *SMBSERVR default called name
           if we end up sending RFC1001 session initialize */
        vol->target_rfc1001_name[0] = 0;
-       vol->linux_uid = current_uid();  /* use current_euid() instead? */
+       vol->cred_uid = current_uid();
+       vol->linux_uid = current_uid();
        vol->linux_gid = current_gid();
 
        /* default to only allowing write access to owner of the mount */
@@ -1257,6 +1261,12 @@ cifs_parse_mount_options(char *options, const char *devname,
                } else if ((strnicmp(data, "nocase", 6) == 0) ||
                           (strnicmp(data, "ignorecase", 10)  == 0)) {
                        vol->nocase = 1;
+               } else if (strnicmp(data, "mand", 4) == 0) {
+                       /* ignore */
+               } else if (strnicmp(data, "nomand", 6) == 0) {
+                       /* ignore */
+               } else if (strnicmp(data, "_netdev", 7) == 0) {
+                       /* ignore */
                } else if (strnicmp(data, "brl", 3) == 0) {
                        vol->nobrl =  0;
                } else if ((strnicmp(data, "nobrl", 5) == 0) ||
@@ -1331,6 +1341,8 @@ cifs_parse_mount_options(char *options, const char *devname,
                        printk(KERN_WARNING "CIFS: Mount option noac not "
                                "supported. Instead set "
                                "/proc/fs/cifs/LookupCacheEnabled to 0\n");
+               } else if (strnicmp(data, "fsc", 3) == 0) {
+                       vol->fsc = true;
                } else
                        printk(KERN_WARNING "CIFS: Unknown mount option %s\n",
                                                data);
@@ -1380,18 +1392,92 @@ cifs_parse_mount_options(char *options, const char *devname,
        return 0;
 }
 
+static bool
+match_address(struct TCP_Server_Info *server, struct sockaddr *addr)
+{
+       struct sockaddr_in *addr4 = (struct sockaddr_in *)addr;
+       struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)addr;
+
+       switch (addr->sa_family) {
+       case AF_INET:
+               if (addr4->sin_addr.s_addr !=
+                   server->addr.sockAddr.sin_addr.s_addr)
+                       return false;
+               if (addr4->sin_port &&
+                   addr4->sin_port != server->addr.sockAddr.sin_port)
+                       return false;
+               break;
+       case AF_INET6:
+               if (!ipv6_addr_equal(&addr6->sin6_addr,
+                                    &server->addr.sockAddr6.sin6_addr))
+                       return false;
+               if (addr6->sin6_scope_id !=
+                   server->addr.sockAddr6.sin6_scope_id)
+                       return false;
+               if (addr6->sin6_port &&
+                   addr6->sin6_port != server->addr.sockAddr6.sin6_port)
+                       return false;
+               break;
+       }
+
+       return true;
+}
+
+static bool
+match_security(struct TCP_Server_Info *server, struct smb_vol *vol)
+{
+       unsigned int secFlags;
+
+       if (vol->secFlg & (~(CIFSSEC_MUST_SIGN | CIFSSEC_MUST_SEAL)))
+               secFlags = vol->secFlg;
+       else
+               secFlags = global_secflags | vol->secFlg;
+
+       switch (server->secType) {
+       case LANMAN:
+               if (!(secFlags & (CIFSSEC_MAY_LANMAN|CIFSSEC_MAY_PLNTXT)))
+                       return false;
+               break;
+       case NTLMv2:
+               if (!(secFlags & CIFSSEC_MAY_NTLMV2))
+                       return false;
+               break;
+       case NTLM:
+               if (!(secFlags & CIFSSEC_MAY_NTLM))
+                       return false;
+               break;
+       case Kerberos:
+               if (!(secFlags & CIFSSEC_MAY_KRB5))
+                       return false;
+               break;
+       case RawNTLMSSP:
+               if (!(secFlags & CIFSSEC_MAY_NTLMSSP))
+                       return false;
+               break;
+       default:
+               /* shouldn't happen */
+               return false;
+       }
+
+       /* now check if signing mode is acceptible */
+       if ((secFlags & CIFSSEC_MAY_SIGN) == 0 &&
+           (server->secMode & SECMODE_SIGN_REQUIRED))
+                       return false;
+       else if (((secFlags & CIFSSEC_MUST_SIGN) == CIFSSEC_MUST_SIGN) &&
+                (server->secMode &
+                 (SECMODE_SIGN_ENABLED|SECMODE_SIGN_REQUIRED)) == 0)
+                       return false;
+
+       return true;
+}
+
 static struct TCP_Server_Info *
-cifs_find_tcp_session(struct sockaddr_storage *addr, unsigned short int port)
+cifs_find_tcp_session(struct sockaddr *addr, struct smb_vol *vol)
 {
-       struct list_head *tmp;
        struct TCP_Server_Info *server;
-       struct sockaddr_in *addr4 = (struct sockaddr_in *) addr;
-       struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *) addr;
 
        write_lock(&cifs_tcp_ses_lock);
-       list_for_each(tmp, &cifs_tcp_ses_list) {
-               server = list_entry(tmp, struct TCP_Server_Info,
-                                   tcp_ses_list);
+       list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
                /*
                 * the demux thread can exit on its own while still in CifsNew
                 * so don't accept any sockets in that state. Since the
@@ -1401,37 +1487,11 @@ cifs_find_tcp_session(struct sockaddr_storage *addr, unsigned short int port)
                if (server->tcpStatus == CifsNew)
                        continue;
 
-               switch (addr->ss_family) {
-               case AF_INET:
-                       if (addr4->sin_addr.s_addr ==
-                           server->addr.sockAddr.sin_addr.s_addr) {
-                               addr4->sin_port = htons(port);
-                               /* user overrode default port? */
-                               if (addr4->sin_port) {
-                                       if (addr4->sin_port !=
-                                           server->addr.sockAddr.sin_port)
-                                               continue;
-                               }
-                               break;
-                       } else
-                               continue;
+               if (!match_address(server, addr))
+                       continue;
 
-               case AF_INET6:
-                       if (ipv6_addr_equal(&addr6->sin6_addr,
-                           &server->addr.sockAddr6.sin6_addr) &&
-                           (addr6->sin6_scope_id ==
-                           server->addr.sockAddr6.sin6_scope_id)) {
-                               addr6->sin6_port = htons(port);
-                               /* user overrode default port? */
-                               if (addr6->sin6_port) {
-                                       if (addr6->sin6_port !=
-                                          server->addr.sockAddr6.sin6_port)
-                                               continue;
-                               }
-                               break;
-                       } else
-                               continue;
-               }
+               if (!match_security(server, vol))
+                       continue;
 
                ++server->srv_count;
                write_unlock(&cifs_tcp_ses_lock);
@@ -1460,6 +1520,8 @@ cifs_put_tcp_session(struct TCP_Server_Info *server)
        server->tcpStatus = CifsExiting;
        spin_unlock(&GlobalMid_Lock);
 
+       cifs_fscache_release_client_cookie(server);
+
        task = xchg(&server->tsk, NULL);
        if (task)
                force_sig(SIGKILL, task);
@@ -1479,7 +1541,9 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
        cFYI(1, "UNC: %s ip: %s", volume_info->UNC, volume_info->UNCip);
 
        if (volume_info->UNCip && volume_info->UNC) {
-               rc = cifs_convert_address(volume_info->UNCip, &addr);
+               rc = cifs_fill_sockaddr((struct sockaddr *)&addr,
+                                       volume_info->UNCip,
+                                       volume_info->port);
                if (!rc) {
                        /* we failed translating address */
                        rc = -EINVAL;
@@ -1499,7 +1563,7 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
        }
 
        /* see if we already have a matching tcp_ses */
-       tcp_ses = cifs_find_tcp_session(&addr, volume_info->port);
+       tcp_ses = cifs_find_tcp_session((struct sockaddr *)&addr, volume_info);
        if (tcp_ses)
                return tcp_ses;
 
@@ -1543,12 +1607,10 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
                cFYI(1, "attempting ipv6 connect");
                /* BB should we allow ipv6 on port 139? */
                /* other OS never observed in Wild doing 139 with v6 */
-               sin_server6->sin6_port = htons(volume_info->port);
                memcpy(&tcp_ses->addr.sockAddr6, sin_server6,
                        sizeof(struct sockaddr_in6));
                rc = ipv6_connect(tcp_ses);
        } else {
-               sin_server->sin_port = htons(volume_info->port);
                memcpy(&tcp_ses->addr.sockAddr, sin_server,
                        sizeof(struct sockaddr_in));
                rc = ipv4_connect(tcp_ses);
@@ -1577,6 +1639,8 @@ cifs_get_tcp_session(struct smb_vol *volume_info)
        list_add(&tcp_ses->tcp_ses_list, &cifs_tcp_ses_list);
        write_unlock(&cifs_tcp_ses_lock);
 
+       cifs_fscache_get_client_cookie(tcp_ses);
+
        return tcp_ses;
 
 out_err:
@@ -1591,17 +1655,27 @@ out_err:
 }
 
 static struct cifsSesInfo *
-cifs_find_smb_ses(struct TCP_Server_Info *server, char *username)
+cifs_find_smb_ses(struct TCP_Server_Info *server, struct smb_vol *vol)
 {
-       struct list_head *tmp;
        struct cifsSesInfo *ses;
 
        write_lock(&cifs_tcp_ses_lock);
-       list_for_each(tmp, &server->smb_ses_list) {
-               ses = list_entry(tmp, struct cifsSesInfo, smb_ses_list);
-               if (strncmp(ses->userName, username, MAX_USERNAME_SIZE))
-                       continue;
-
+       list_for_each_entry(ses, &server->smb_ses_list, smb_ses_list) {
+               switch (server->secType) {
+               case Kerberos:
+                       if (vol->cred_uid != ses->cred_uid)
+                               continue;
+                       break;
+               default:
+                       /* anything else takes username/password */
+                       if (strncmp(ses->userName, vol->username,
+                                   MAX_USERNAME_SIZE))
+                               continue;
+                       if (strlen(vol->username) != 0 &&
+                           strncmp(ses->password, vol->password,
+                                   MAX_PASSWORD_SIZE))
+                               continue;
+               }
                ++ses->ses_count;
                write_unlock(&cifs_tcp_ses_lock);
                return ses;
@@ -1643,7 +1717,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
 
        xid = GetXid();
 
-       ses = cifs_find_smb_ses(server, volume_info->username);
+       ses = cifs_find_smb_ses(server, volume_info);
        if (ses) {
                cFYI(1, "Existing smb sess found (status=%d)", ses->status);
 
@@ -1706,6 +1780,7 @@ cifs_get_smb_ses(struct TCP_Server_Info *server, struct smb_vol *volume_info)
                if (ses->domainName)
                        strcpy(ses->domainName, volume_info->domainname);
        }
+       ses->cred_uid = volume_info->cred_uid;
        ses->linux_uid = volume_info->linux_uid;
        ses->overrideSecFlg = volume_info->secFlg;
 
@@ -1773,6 +1848,7 @@ cifs_put_tcon(struct cifsTconInfo *tcon)
        CIFSSMBTDis(xid, tcon);
        _FreeXid(xid);
 
+       cifs_fscache_release_super_cookie(tcon);
        tconInfoFree(tcon);
        cifs_put_smb_ses(ses);
 }
@@ -1843,6 +1919,8 @@ cifs_get_tcon(struct cifsSesInfo *ses, struct smb_vol *volume_info)
        list_add(&tcon->tcon_list, &ses->tcon_list);
        write_unlock(&cifs_tcp_ses_lock);
 
+       cifs_fscache_get_super_cookie(tcon);
+
        return tcon;
 
 out_fail:
@@ -2397,6 +2475,8 @@ static void setup_cifs_sb(struct smb_vol *pvolume_info,
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_OVERR_GID;
        if (pvolume_info->dynperm)
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DYNPERM;
+       if (pvolume_info->fsc)
+               cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_FSCACHE;
        if (pvolume_info->direct_io) {
                cFYI(1, "mounting share using direct i/o");
                cifs_sb->mnt_cifs_flags |= CIFS_MOUNT_DIRECT_IO;
index e7ae78b66fa15b89162b18a12d76c90f48b8b508..a7de5e9fff11f166b23dd472149277bf059c50fa 100644 (file)
@@ -130,12 +130,6 @@ cifs_bp_rename_retry:
        return full_path;
 }
 
-/*
- * When called with struct file pointer set to NULL, there is no way we could
- * update file->private_data, but getting it stuck on openFileList provides a
- * way to access it from cifs_fill_filedata and thereby set file->private_data
- * from cifs_open.
- */
 struct cifsFileInfo *
 cifs_new_fileinfo(struct inode *newinode, __u16 fileHandle,
                  struct file *file, struct vfsmount *mnt, unsigned int oflags)
index 853a968e82d74731b0c93083b238bca1ef5c96a1..3ad7f4300c45049ad7384a2251203dfe2f30c087 100644 (file)
@@ -44,7 +44,7 @@ is_ip(char *name)
 {
        struct sockaddr_storage ss;
 
-       return cifs_convert_address(name, &ss);
+       return cifs_convert_address((struct sockaddr *)&ss, name);
 }
 
 static int
index 409e4f523e61e56aae0e1b892c2a9021ebe3728d..fa04a00d126dc5787850f905e195b41d7b310b5c 100644 (file)
@@ -40,6 +40,7 @@
 #include "cifs_unicode.h"
 #include "cifs_debug.h"
 #include "cifs_fs_sb.h"
+#include "fscache.h"
 
 static inline int cifs_convert_flags(unsigned int flags)
 {
@@ -282,6 +283,9 @@ int cifs_open(struct inode *inode, struct file *file)
                                CIFSSMBClose(xid, tcon, netfid);
                                rc = -ENOMEM;
                        }
+
+                       cifs_fscache_set_inode_cookie(inode, file);
+
                        goto out;
                } else if ((rc == -EINVAL) || (rc == -EOPNOTSUPP)) {
                        if (tcon->ses->serverNOS)
@@ -373,6 +377,8 @@ int cifs_open(struct inode *inode, struct file *file)
                goto out;
        }
 
+       cifs_fscache_set_inode_cookie(inode, file);
+
        if (oplock & CIFS_CREATE_ACTION) {
                /* time to set mode which we can not set earlier due to
                   problems creating new read-only files */
@@ -427,7 +433,7 @@ static int cifs_reopen_file(struct file *file, bool can_flush)
        __u16 netfid;
 
        if (file->private_data)
-               pCifsFile = (struct cifsFileInfo *)file->private_data;
+               pCifsFile = file->private_data;
        else
                return -EBADF;
 
@@ -565,8 +571,7 @@ int cifs_close(struct inode *inode, struct file *file)
        int xid, timeout;
        struct cifs_sb_info *cifs_sb;
        struct cifsTconInfo *pTcon;
-       struct cifsFileInfo *pSMBFile =
-               (struct cifsFileInfo *)file->private_data;
+       struct cifsFileInfo *pSMBFile = file->private_data;
 
        xid = GetXid();
 
@@ -641,8 +646,7 @@ int cifs_closedir(struct inode *inode, struct file *file)
 {
        int rc = 0;
        int xid;
-       struct cifsFileInfo *pCFileStruct =
-           (struct cifsFileInfo *)file->private_data;
+       struct cifsFileInfo *pCFileStruct = file->private_data;
        char *ptmp;
 
        cFYI(1, "Closedir inode = 0x%p", inode);
@@ -863,8 +867,7 @@ int cifs_lock(struct file *file, int cmd, struct file_lock *pfLock)
                                      length, pfLock,
                                      posix_lock_type, wait_flag);
        } else {
-               struct cifsFileInfo *fid =
-                       (struct cifsFileInfo *)file->private_data;
+               struct cifsFileInfo *fid = file->private_data;
 
                if (numLock) {
                        rc = CIFSSMBLock(xid, tcon, netfid, length,
@@ -965,7 +968,7 @@ ssize_t cifs_user_write(struct file *file, const char __user *write_data,
 
        if (file->private_data == NULL)
                return -EBADF;
-       open_file = (struct cifsFileInfo *) file->private_data;
+       open_file = file->private_data;
 
        rc = generic_write_checks(file, poffset, &write_size, 0);
        if (rc)
@@ -1067,7 +1070,7 @@ static ssize_t cifs_write(struct file *file, const char *write_data,
 
        if (file->private_data == NULL)
                return -EBADF;
-       open_file = (struct cifsFileInfo *)file->private_data;
+       open_file = file->private_data;
 
        xid = GetXid();
 
@@ -1651,8 +1654,7 @@ int cifs_fsync(struct file *file, int datasync)
        int xid;
        int rc = 0;
        struct cifsTconInfo *tcon;
-       struct cifsFileInfo *smbfile =
-               (struct cifsFileInfo *)file->private_data;
+       struct cifsFileInfo *smbfile = file->private_data;
        struct inode *inode = file->f_path.dentry->d_inode;
 
        xid = GetXid();
@@ -1756,7 +1758,7 @@ ssize_t cifs_user_read(struct file *file, char __user *read_data,
                FreeXid(xid);
                return rc;
        }
-       open_file = (struct cifsFileInfo *)file->private_data;
+       open_file = file->private_data;
 
        if ((file->f_flags & O_ACCMODE) == O_WRONLY)
                cFYI(1, "attempting read on write only file instance");
@@ -1837,7 +1839,7 @@ static ssize_t cifs_read(struct file *file, char *read_data, size_t read_size,
                FreeXid(xid);
                return rc;
        }
-       open_file = (struct cifsFileInfo *)file->private_data;
+       open_file = file->private_data;
 
        if ((file->f_flags & O_ACCMODE) == O_WRONLY)
                cFYI(1, "attempting read on write only file instance");
@@ -1942,6 +1944,9 @@ static void cifs_copy_cache_pages(struct address_space *mapping,
                SetPageUptodate(page);
                unlock_page(page);
                data += PAGE_CACHE_SIZE;
+
+               /* add page to FS-Cache */
+               cifs_readpage_to_fscache(mapping->host, page);
        }
        return;
 }
@@ -1968,10 +1973,19 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
                FreeXid(xid);
                return rc;
        }
-       open_file = (struct cifsFileInfo *)file->private_data;
+       open_file = file->private_data;
        cifs_sb = CIFS_SB(file->f_path.dentry->d_sb);
        pTcon = cifs_sb->tcon;
 
+       /*
+        * Reads as many pages as possible from fscache. Returns -ENOBUFS
+        * immediately if the cookie is negative
+        */
+       rc = cifs_readpages_from_fscache(mapping->host, mapping, page_list,
+                                        &num_pages);
+       if (rc == 0)
+               goto read_complete;
+
        cFYI(DBG2, "rpages: num pages %d", num_pages);
        for (i = 0; i < num_pages; ) {
                unsigned contig_pages;
@@ -2082,6 +2096,7 @@ static int cifs_readpages(struct file *file, struct address_space *mapping,
                smb_read_data = NULL;
        }
 
+read_complete:
        FreeXid(xid);
        return rc;
 }
@@ -2092,6 +2107,11 @@ static int cifs_readpage_worker(struct file *file, struct page *page,
        char *read_data;
        int rc;
 
+       /* Is the page cached? */
+       rc = cifs_readpage_from_fscache(file->f_path.dentry->d_inode, page);
+       if (rc == 0)
+               goto read_complete;
+
        page_cache_get(page);
        read_data = kmap(page);
        /* for reads over a certain size could initiate async read ahead */
@@ -2111,11 +2131,17 @@ static int cifs_readpage_worker(struct file *file, struct page *page,
 
        flush_dcache_page(page);
        SetPageUptodate(page);
+
+       /* send this page to the cache */
+       cifs_readpage_to_fscache(file->f_path.dentry->d_inode, page);
+
        rc = 0;
 
 io_error:
        kunmap(page);
        page_cache_release(page);
+
+read_complete:
        return rc;
 }
 
@@ -2265,6 +2291,22 @@ out:
        return rc;
 }
 
+static int cifs_release_page(struct page *page, gfp_t gfp)
+{
+       if (PagePrivate(page))
+               return 0;
+
+       return cifs_fscache_release_page(page, gfp);
+}
+
+static void cifs_invalidate_page(struct page *page, unsigned long offset)
+{
+       struct cifsInodeInfo *cifsi = CIFS_I(page->mapping->host);
+
+       if (offset == 0)
+               cifs_fscache_invalidate_page(page, &cifsi->vfs_inode);
+}
+
 static void
 cifs_oplock_break(struct slow_work *work)
 {
@@ -2338,6 +2380,8 @@ const struct address_space_operations cifs_addr_ops = {
        .write_begin = cifs_write_begin,
        .write_end = cifs_write_end,
        .set_page_dirty = __set_page_dirty_nobuffers,
+       .releasepage = cifs_release_page,
+       .invalidatepage = cifs_invalidate_page,
        /* .sync_page = cifs_sync_page, */
        /* .direct_IO = */
 };
@@ -2354,6 +2398,8 @@ const struct address_space_operations cifs_addr_ops_smallbuf = {
        .write_begin = cifs_write_begin,
        .write_end = cifs_write_end,
        .set_page_dirty = __set_page_dirty_nobuffers,
+       .releasepage = cifs_release_page,
+       .invalidatepage = cifs_invalidate_page,
        /* .sync_page = cifs_sync_page, */
        /* .direct_IO = */
 };
diff --git a/fs/cifs/fscache.c b/fs/cifs/fscache.c
new file mode 100644 (file)
index 0000000..9f3f5c4
--- /dev/null
@@ -0,0 +1,236 @@
+/*
+ *   fs/cifs/fscache.c - CIFS filesystem cache interface
+ *
+ *   Copyright (c) 2010 Novell, Inc.
+ *   Author(s): Suresh Jayaraman (sjayaraman@suse.de>
+ *
+ *   This library is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published
+ *   by the Free Software Foundation; either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This library 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 Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include "fscache.h"
+#include "cifsglob.h"
+#include "cifs_debug.h"
+#include "cifs_fs_sb.h"
+
+void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server)
+{
+       server->fscache =
+               fscache_acquire_cookie(cifs_fscache_netfs.primary_index,
+                               &cifs_fscache_server_index_def, server);
+       cFYI(1, "CIFS: get client cookie (0x%p/0x%p)", server,
+                               server->fscache);
+}
+
+void cifs_fscache_release_client_cookie(struct TCP_Server_Info *server)
+{
+       cFYI(1, "CIFS: release client cookie (0x%p/0x%p)", server,
+                               server->fscache);
+       fscache_relinquish_cookie(server->fscache, 0);
+       server->fscache = NULL;
+}
+
+void cifs_fscache_get_super_cookie(struct cifsTconInfo *tcon)
+{
+       struct TCP_Server_Info *server = tcon->ses->server;
+
+       tcon->fscache =
+               fscache_acquire_cookie(server->fscache,
+                               &cifs_fscache_super_index_def, tcon);
+       cFYI(1, "CIFS: get superblock cookie (0x%p/0x%p)",
+                               server->fscache, tcon->fscache);
+}
+
+void cifs_fscache_release_super_cookie(struct cifsTconInfo *tcon)
+{
+       cFYI(1, "CIFS: releasing superblock cookie (0x%p)", tcon->fscache);
+       fscache_relinquish_cookie(tcon->fscache, 0);
+       tcon->fscache = NULL;
+}
+
+static void cifs_fscache_enable_inode_cookie(struct inode *inode)
+{
+       struct cifsInodeInfo *cifsi = CIFS_I(inode);
+       struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
+
+       if (cifsi->fscache)
+               return;
+
+       cifsi->fscache = fscache_acquire_cookie(cifs_sb->tcon->fscache,
+                               &cifs_fscache_inode_object_def,
+                               cifsi);
+       cFYI(1, "CIFS: got FH cookie (0x%p/0x%p)",
+                       cifs_sb->tcon->fscache, cifsi->fscache);
+}
+
+void cifs_fscache_release_inode_cookie(struct inode *inode)
+{
+       struct cifsInodeInfo *cifsi = CIFS_I(inode);
+
+       if (cifsi->fscache) {
+               cFYI(1, "CIFS releasing inode cookie (0x%p)",
+                               cifsi->fscache);
+               fscache_relinquish_cookie(cifsi->fscache, 0);
+               cifsi->fscache = NULL;
+       }
+}
+
+static void cifs_fscache_disable_inode_cookie(struct inode *inode)
+{
+       struct cifsInodeInfo *cifsi = CIFS_I(inode);
+
+       if (cifsi->fscache) {
+               cFYI(1, "CIFS disabling inode cookie (0x%p)",
+                               cifsi->fscache);
+               fscache_relinquish_cookie(cifsi->fscache, 1);
+               cifsi->fscache = NULL;
+       }
+}
+
+void cifs_fscache_set_inode_cookie(struct inode *inode, struct file *filp)
+{
+       if ((filp->f_flags & O_ACCMODE) != O_RDONLY)
+               cifs_fscache_disable_inode_cookie(inode);
+       else {
+               cifs_fscache_enable_inode_cookie(inode);
+               cFYI(1, "CIFS: fscache inode cookie set");
+       }
+}
+
+void cifs_fscache_reset_inode_cookie(struct inode *inode)
+{
+       struct cifsInodeInfo *cifsi = CIFS_I(inode);
+       struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
+       struct fscache_cookie *old = cifsi->fscache;
+
+       if (cifsi->fscache) {
+               /* retire the current fscache cache and get a new one */
+               fscache_relinquish_cookie(cifsi->fscache, 1);
+
+               cifsi->fscache = fscache_acquire_cookie(cifs_sb->tcon->fscache,
+                                       &cifs_fscache_inode_object_def,
+                                       cifsi);
+               cFYI(1, "CIFS: new cookie 0x%p oldcookie 0x%p",
+                               cifsi->fscache, old);
+       }
+}
+
+int cifs_fscache_release_page(struct page *page, gfp_t gfp)
+{
+       if (PageFsCache(page)) {
+               struct inode *inode = page->mapping->host;
+               struct cifsInodeInfo *cifsi = CIFS_I(inode);
+
+               cFYI(1, "CIFS: fscache release page (0x%p/0x%p)",
+                               page, cifsi->fscache);
+               if (!fscache_maybe_release_page(cifsi->fscache, page, gfp))
+                       return 0;
+       }
+
+       return 1;
+}
+
+static void cifs_readpage_from_fscache_complete(struct page *page, void *ctx,
+                                               int error)
+{
+       cFYI(1, "CFS: readpage_from_fscache_complete (0x%p/%d)",
+                       page, error);
+       if (!error)
+               SetPageUptodate(page);
+       unlock_page(page);
+}
+
+/*
+ * Retrieve a page from FS-Cache
+ */
+int __cifs_readpage_from_fscache(struct inode *inode, struct page *page)
+{
+       int ret;
+
+       cFYI(1, "CIFS: readpage_from_fscache(fsc:%p, p:%p, i:0x%p",
+                       CIFS_I(inode)->fscache, page, inode);
+       ret = fscache_read_or_alloc_page(CIFS_I(inode)->fscache, page,
+                                        cifs_readpage_from_fscache_complete,
+                                        NULL,
+                                        GFP_KERNEL);
+       switch (ret) {
+
+       case 0: /* page found in fscache, read submitted */
+               cFYI(1, "CIFS: readpage_from_fscache: submitted");
+               return ret;
+       case -ENOBUFS:  /* page won't be cached */
+       case -ENODATA:  /* page not in cache */
+               cFYI(1, "CIFS: readpage_from_fscache %d", ret);
+               return 1;
+
+       default:
+               cERROR(1, "unknown error ret = %d", ret);
+       }
+       return ret;
+}
+
+/*
+ * Retrieve a set of pages from FS-Cache
+ */
+int __cifs_readpages_from_fscache(struct inode *inode,
+                               struct address_space *mapping,
+                               struct list_head *pages,
+                               unsigned *nr_pages)
+{
+       int ret;
+
+       cFYI(1, "CIFS: __cifs_readpages_from_fscache (0x%p/%u/0x%p)",
+                       CIFS_I(inode)->fscache, *nr_pages, inode);
+       ret = fscache_read_or_alloc_pages(CIFS_I(inode)->fscache, mapping,
+                                         pages, nr_pages,
+                                         cifs_readpage_from_fscache_complete,
+                                         NULL,
+                                         mapping_gfp_mask(mapping));
+       switch (ret) {
+       case 0: /* read submitted to the cache for all pages */
+               cFYI(1, "CIFS: readpages_from_fscache: submitted");
+               return ret;
+
+       case -ENOBUFS:  /* some pages are not cached and can't be */
+       case -ENODATA:  /* some pages are not cached */
+               cFYI(1, "CIFS: readpages_from_fscache: no page");
+               return 1;
+
+       default:
+               cFYI(1, "unknown error ret = %d", ret);
+       }
+
+       return ret;
+}
+
+void __cifs_readpage_to_fscache(struct inode *inode, struct page *page)
+{
+       int ret;
+
+       cFYI(1, "CIFS: readpage_to_fscache(fsc: %p, p: %p, i: %p",
+                       CIFS_I(inode)->fscache, page, inode);
+       ret = fscache_write_page(CIFS_I(inode)->fscache, page, GFP_KERNEL);
+       if (ret != 0)
+               fscache_uncache_page(CIFS_I(inode)->fscache, page);
+}
+
+void __cifs_fscache_invalidate_page(struct page *page, struct inode *inode)
+{
+       struct cifsInodeInfo *cifsi = CIFS_I(inode);
+       struct fscache_cookie *cookie = cifsi->fscache;
+
+       cFYI(1, "CIFS: fscache invalidatepage (0x%p/0x%p)", page, cookie);
+       fscache_wait_on_page_write(cookie, page);
+       fscache_uncache_page(cookie, page);
+}
+
diff --git a/fs/cifs/fscache.h b/fs/cifs/fscache.h
new file mode 100644 (file)
index 0000000..31b88ec
--- /dev/null
@@ -0,0 +1,136 @@
+/*
+ *   fs/cifs/fscache.h - CIFS filesystem cache interface definitions
+ *
+ *   Copyright (c) 2010 Novell, Inc.
+ *   Authors(s): Suresh Jayaraman (sjayaraman@suse.de>
+ *
+ *   This library is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published
+ *   by the Free Software Foundation; either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This library 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 Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#ifndef _CIFS_FSCACHE_H
+#define _CIFS_FSCACHE_H
+
+#include <linux/fscache.h>
+
+#include "cifsglob.h"
+
+#ifdef CONFIG_CIFS_FSCACHE
+
+extern struct fscache_netfs cifs_fscache_netfs;
+extern const struct fscache_cookie_def cifs_fscache_server_index_def;
+extern const struct fscache_cookie_def cifs_fscache_super_index_def;
+extern const struct fscache_cookie_def cifs_fscache_inode_object_def;
+
+extern int cifs_fscache_register(void);
+extern void cifs_fscache_unregister(void);
+
+/*
+ * fscache.c
+ */
+extern void cifs_fscache_get_client_cookie(struct TCP_Server_Info *);
+extern void cifs_fscache_release_client_cookie(struct TCP_Server_Info *);
+extern void cifs_fscache_get_super_cookie(struct cifsTconInfo *);
+extern void cifs_fscache_release_super_cookie(struct cifsTconInfo *);
+
+extern void cifs_fscache_release_inode_cookie(struct inode *);
+extern void cifs_fscache_set_inode_cookie(struct inode *, struct file *);
+extern void cifs_fscache_reset_inode_cookie(struct inode *);
+
+extern void __cifs_fscache_invalidate_page(struct page *, struct inode *);
+extern int cifs_fscache_release_page(struct page *page, gfp_t gfp);
+extern int __cifs_readpage_from_fscache(struct inode *, struct page *);
+extern int __cifs_readpages_from_fscache(struct inode *,
+                                        struct address_space *,
+                                        struct list_head *,
+                                        unsigned *);
+
+extern void __cifs_readpage_to_fscache(struct inode *, struct page *);
+
+static inline void cifs_fscache_invalidate_page(struct page *page,
+                                              struct inode *inode)
+{
+       if (PageFsCache(page))
+               __cifs_fscache_invalidate_page(page, inode);
+}
+
+static inline int cifs_readpage_from_fscache(struct inode *inode,
+                                            struct page *page)
+{
+       if (CIFS_I(inode)->fscache)
+               return __cifs_readpage_from_fscache(inode, page);
+
+       return -ENOBUFS;
+}
+
+static inline int cifs_readpages_from_fscache(struct inode *inode,
+                                             struct address_space *mapping,
+                                             struct list_head *pages,
+                                             unsigned *nr_pages)
+{
+       if (CIFS_I(inode)->fscache)
+               return __cifs_readpages_from_fscache(inode, mapping, pages,
+                                                    nr_pages);
+       return -ENOBUFS;
+}
+
+static inline void cifs_readpage_to_fscache(struct inode *inode,
+                                           struct page *page)
+{
+       if (PageFsCache(page))
+               __cifs_readpage_to_fscache(inode, page);
+}
+
+#else /* CONFIG_CIFS_FSCACHE */
+static inline int cifs_fscache_register(void) { return 0; }
+static inline void cifs_fscache_unregister(void) {}
+
+static inline void
+cifs_fscache_get_client_cookie(struct TCP_Server_Info *server) {}
+static inline void
+cifs_fscache_release_client_cookie(struct TCP_Server_Info *server) {}
+static inline void cifs_fscache_get_super_cookie(struct cifsTconInfo *tcon) {}
+static inline void
+cifs_fscache_release_super_cookie(struct cifsTconInfo *tcon) {}
+
+static inline void cifs_fscache_release_inode_cookie(struct inode *inode) {}
+static inline void cifs_fscache_set_inode_cookie(struct inode *inode,
+                                                struct file *filp) {}
+static inline void cifs_fscache_reset_inode_cookie(struct inode *inode) {}
+static inline int cifs_fscache_release_page(struct page *page, gfp_t gfp)
+{
+       return 1; /* May release page */
+}
+
+static inline void cifs_fscache_invalidate_page(struct page *page,
+                       struct inode *inode) {}
+static inline int
+cifs_readpage_from_fscache(struct inode *inode, struct page *page)
+{
+       return -ENOBUFS;
+}
+
+static inline int cifs_readpages_from_fscache(struct inode *inode,
+                                             struct address_space *mapping,
+                                             struct list_head *pages,
+                                             unsigned *nr_pages)
+{
+       return -ENOBUFS;
+}
+
+static inline void cifs_readpage_to_fscache(struct inode *inode,
+                       struct page *page) {}
+
+#endif /* CONFIG_CIFS_FSCACHE */
+
+#endif /* _CIFS_FSCACHE_H */
index 6f0683c689523894cb6fae3edd79181876084d42..a15b3a9bbff40af95532b152a5bbf993a44bac99 100644 (file)
@@ -29,6 +29,7 @@
 #include "cifsproto.h"
 #include "cifs_debug.h"
 #include "cifs_fs_sb.h"
+#include "fscache.h"
 
 
 static void cifs_set_ops(struct inode *inode, const bool is_dfs_referral)
@@ -288,7 +289,7 @@ int cifs_get_file_info_unix(struct file *filp)
        struct inode *inode = filp->f_path.dentry->d_inode;
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct cifsTconInfo *tcon = cifs_sb->tcon;
-       struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data;
+       struct cifsFileInfo *cfile = filp->private_data;
 
        xid = GetXid();
        rc = CIFSSMBUnixQFileInfo(xid, tcon, cfile->netfid, &find_data);
@@ -515,7 +516,7 @@ int cifs_get_file_info(struct file *filp)
        struct inode *inode = filp->f_path.dentry->d_inode;
        struct cifs_sb_info *cifs_sb = CIFS_SB(inode->i_sb);
        struct cifsTconInfo *tcon = cifs_sb->tcon;
-       struct cifsFileInfo *cfile = (struct cifsFileInfo *) filp->private_data;
+       struct cifsFileInfo *cfile = filp->private_data;
 
        xid = GetXid();
        rc = CIFSSMBQFileInfo(xid, tcon, cfile->netfid, &find_data);
@@ -723,9 +724,14 @@ cifs_find_inode(struct inode *inode, void *opaque)
 {
        struct cifs_fattr *fattr = (struct cifs_fattr *) opaque;
 
+       /* don't match inode with different uniqueid */
        if (CIFS_I(inode)->uniqueid != fattr->cf_uniqueid)
                return 0;
 
+       /* don't match inode of different type */
+       if ((inode->i_mode & S_IFMT) != (fattr->cf_mode & S_IFMT))
+               return 0;
+
        /*
         * uh oh -- it's a directory. We can't use it since hardlinked dirs are
         * verboten. Disable serverino and return it as if it were found, the
@@ -776,6 +782,10 @@ retry_iget5_locked:
                        inode->i_flags |= S_NOATIME | S_NOCMTIME;
                if (inode->i_state & I_NEW) {
                        inode->i_ino = hash;
+#ifdef CONFIG_CIFS_FSCACHE
+                       /* initialize per-inode cache cookie pointer */
+                       CIFS_I(inode)->fscache = NULL;
+#endif
                        unlock_new_inode(inode);
                }
        }
@@ -807,6 +817,11 @@ struct inode *cifs_root_iget(struct super_block *sb, unsigned long ino)
        if (!inode)
                return ERR_PTR(-ENOMEM);
 
+#ifdef CONFIG_CIFS_FSCACHE
+       /* populate tcon->resource_id */
+       cifs_sb->tcon->resource_id = CIFS_I(inode)->uniqueid;
+#endif
+
        if (rc && cifs_sb->tcon->ipc) {
                cFYI(1, "ipc connection - fake read inode");
                inode->i_mode |= S_IFDIR;
@@ -1568,6 +1583,7 @@ cifs_invalidate_mapping(struct inode *inode)
                        cifs_i->write_behind_rc = rc;
        }
        invalidate_remote_inode(inode);
+       cifs_fscache_reset_inode_cookie(inode);
 }
 
 int cifs_revalidate_file(struct file *filp)
index 505926f1ee6b99d9f3388fb2bb8208dc1f498758..9d38a71c8e1449561f625d5762c2337714d31563 100644 (file)
@@ -41,8 +41,7 @@ long cifs_ioctl(struct file *filep, unsigned int command, unsigned long arg)
        __u64   ExtAttrMask = 0;
        __u64   caps;
        struct cifsTconInfo *tcon;
-       struct cifsFileInfo *pSMBFile =
-               (struct cifsFileInfo *)filep->private_data;
+       struct cifsFileInfo *pSMBFile = filep->private_data;
 #endif /* CONFIG_CIFS_POSIX */
 
        xid = GetXid();
index d35d52889cb54a57e62b99b6e6d6e31e4cb19dd0..c6721ee26dbcb77aca9acf528efb1226de9eebea 100644 (file)
@@ -61,6 +61,7 @@ static const struct smb_to_posix_error mapping_table_ERRDOS[] = {
        {ERRremcd, -EACCES},
        {ERRdiffdevice, -EXDEV},
        {ERRnofiles, -ENOENT},
+       {ERRwriteprot, -EROFS},
        {ERRbadshare, -ETXTBSY},
        {ERRlock, -EACCES},
        {ERRunsup, -EINVAL},
@@ -164,7 +165,7 @@ cifs_inet_pton(const int address_family, const char *cp, void *dst)
  * Returns 0 on failure.
  */
 int
-cifs_convert_address(char *src, void *dst)
+cifs_convert_address(struct sockaddr *dst, char *src)
 {
        int rc;
        char *pct, *endp;
@@ -201,6 +202,27 @@ cifs_convert_address(char *src, void *dst)
        return rc;
 }
 
+int
+cifs_fill_sockaddr(struct sockaddr *dst, char *src,
+                  const unsigned short int port)
+{
+       if (!cifs_convert_address(dst, src))
+               return 0;
+
+       switch (dst->sa_family) {
+       case AF_INET:
+               ((struct sockaddr_in *)dst)->sin_port = htons(port);
+               break;
+       case AF_INET6:
+               ((struct sockaddr_in6 *)dst)->sin6_port = htons(port);
+               break;
+       default:
+               return 0;
+       }
+
+       return 1;
+}
+
 /*****************************************************************************
 convert a NT status code to a dos class/code
  *****************************************************************************/
index daf1753af674584e2f83f5c1c974da7762097801..d5e591fab4753bf48bde4e9d7883f1051d2dc280 100644 (file)
@@ -847,6 +847,11 @@ int cifs_readdir(struct file *file, void *direntry, filldir_t filldir)
                end_of_smb = cifsFile->srch_inf.ntwrk_buf_start + max_len;
 
                tmp_buf = kmalloc(UNICODE_NAME_MAX, GFP_KERNEL);
+               if (tmp_buf == NULL) {
+                       rc = -ENOMEM;
+                       break;
+               }
+
                for (i = 0; (i < num_to_fill) && (rc == 0); i++) {
                        if (current_entry == NULL) {
                                /* evaluate whether this case is an error */
index c5084d27db7c10ab28dd6e8903d8f8d201046c2b..7f16cb825fe59d654639177dac63ec5382bf361c 100644 (file)
@@ -76,6 +76,7 @@
 #define ERRnofiles             18      /* A File Search command can find no
                                           more files matching the specified
                                           criteria. */
+#define ERRwriteprot           19      /* media is write protected */
 #define ERRgeneral             31
 #define ERRbadshare            32      /* The sharing mode specified for an
                                           Open conflicts with existing FIDs on
index 7600aacf531dc8ed16ccfb727878d13834a16503..a10cb91cadea04ac68ff5ce0db34d6d07bdd6371 100644 (file)
@@ -218,7 +218,7 @@ static struct page *dio_get_page(struct dio *dio)
  * filesystems can use it to hold additional state between get_block calls and
  * dio_complete.
  */
-static int dio_complete(struct dio *dio, loff_t offset, int ret)
+static int dio_complete(struct dio *dio, loff_t offset, int ret, bool is_async)
 {
        ssize_t transferred = 0;
 
@@ -239,14 +239,6 @@ static int dio_complete(struct dio *dio, loff_t offset, int ret)
                        transferred = dio->i_size - offset;
        }
 
-       if (dio->end_io && dio->result)
-               dio->end_io(dio->iocb, offset, transferred,
-                           dio->map_bh.b_private);
-
-       if (dio->flags & DIO_LOCKING)
-               /* lockdep: non-owner release */
-               up_read_non_owner(&dio->inode->i_alloc_sem);
-
        if (ret == 0)
                ret = dio->page_errors;
        if (ret == 0)
@@ -254,6 +246,17 @@ static int dio_complete(struct dio *dio, loff_t offset, int ret)
        if (ret == 0)
                ret = transferred;
 
+       if (dio->end_io && dio->result) {
+               dio->end_io(dio->iocb, offset, transferred,
+                           dio->map_bh.b_private, ret, is_async);
+       } else if (is_async) {
+               aio_complete(dio->iocb, ret, 0);
+       }
+
+       if (dio->flags & DIO_LOCKING)
+               /* lockdep: non-owner release */
+               up_read_non_owner(&dio->inode->i_alloc_sem);
+
        return ret;
 }
 
@@ -277,8 +280,7 @@ static void dio_bio_end_aio(struct bio *bio, int error)
        spin_unlock_irqrestore(&dio->bio_lock, flags);
 
        if (remaining == 0) {
-               int ret = dio_complete(dio, dio->iocb->ki_pos, 0);
-               aio_complete(dio->iocb, ret, 0);
+               dio_complete(dio, dio->iocb->ki_pos, 0, true);
                kfree(dio);
        }
 }
@@ -1126,7 +1128,7 @@ direct_io_worker(int rw, struct kiocb *iocb, struct inode *inode,
        spin_unlock_irqrestore(&dio->bio_lock, flags);
 
        if (ret2 == 0) {
-               ret = dio_complete(dio, offset, ret);
+               ret = dio_complete(dio, offset, ret, false);
                kfree(dio);
        } else
                BUG_ON(ret != -EIOCBQUEUED);
index 42272d67955a413cdd17a53980fe5dac410cceff..0afc8c1d8cf3597bf075ecb731a16accb67687ad 100644 (file)
@@ -3775,7 +3775,8 @@ static ext4_io_end_t *ext4_init_io_end (struct inode *inode, gfp_t flags)
 }
 
 static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
-                           ssize_t size, void *private)
+                           ssize_t size, void *private, int ret,
+                           bool is_async)
 {
         ext4_io_end_t *io_end = iocb->private;
        struct workqueue_struct *wq;
@@ -3784,7 +3785,7 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
 
        /* if not async direct IO or dio with 0 bytes write, just return */
        if (!io_end || !size)
-               return;
+               goto out;
 
        ext_debug("ext4_end_io_dio(): io_end 0x%p"
                  "for inode %lu, iocb 0x%p, offset %llu, size %llu\n",
@@ -3795,7 +3796,7 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
        if (io_end->flag != EXT4_IO_UNWRITTEN){
                ext4_free_io_end(io_end);
                iocb->private = NULL;
-               return;
+               goto out;
        }
 
        io_end->offset = offset;
@@ -3812,6 +3813,9 @@ static void ext4_end_io_dio(struct kiocb *iocb, loff_t offset,
        list_add_tail(&io_end->list, &ei->i_completed_io_list);
        spin_unlock_irqrestore(&ei->i_completed_io_lock, flags);
        iocb->private = NULL;
+out:
+       if (is_async)
+               aio_complete(iocb, ret, 0);
 }
 
 static void ext4_end_io_buffer_write(struct buffer_head *bh, int uptodate)
index 3cdc5f78a406357a7e4bcbffe5783facd35c7236..431be0795b6bdf27c43ca34a093c52ca127a77af 100644 (file)
@@ -1016,7 +1016,7 @@ static int fuse_permission(struct inode *inode, int mask)
                   exist.  So if permissions are revoked this won't be
                   noticed immediately, only after the attribute
                   timeout has expired */
-       } else if (mask & MAY_ACCESS) {
+       } else if (mask & (MAY_ACCESS | MAY_CHDIR)) {
                err = fuse_access(inode, mask);
        } else if ((mask & MAY_EXEC) && S_ISREG(inode->i_mode)) {
                if (!(inode->i_mode & S_IXUGO)) {
index 9f8b52500d63551c4111370bc59b357cb177f60a..5e96cbd8a454a532c058a0880fec8a6b38571ddf 100644 (file)
@@ -136,10 +136,7 @@ static int gfs2_writeback_writepage(struct page *page,
        if (ret <= 0)
                return ret;
 
-       ret = mpage_writepage(page, gfs2_get_block_noalloc, wbc);
-       if (ret == -EAGAIN)
-               ret = block_write_full_page(page, gfs2_get_block_noalloc, wbc);
-       return ret;
+       return nobh_writepage(page, gfs2_get_block_noalloc, wbc);
 }
 
 /**
@@ -637,9 +634,7 @@ static int gfs2_write_begin(struct file *file, struct address_space *mapping,
                }
        }
 
-       error = gfs2_write_alloc_required(ip, pos, len, &alloc_required);
-       if (error)
-               goto out_unlock;
+       alloc_required = gfs2_write_alloc_required(ip, pos, len);
 
        if (alloc_required || gfs2_is_jdata(ip))
                gfs2_write_calc_reserv(ip, len, &data_blocks, &ind_blocks);
index 84da64b551b2c1170f4e68550ead612ed6fd7b41..6f482809d1a35b4787e9cb62357958d532aeaa30 100644 (file)
@@ -1040,7 +1040,7 @@ static int trunc_start(struct gfs2_inode *ip, u64 size)
                goto out;
 
        if (gfs2_is_stuffed(ip)) {
-               u64 dsize = size + sizeof(struct gfs2_inode);
+               u64 dsize = size + sizeof(struct gfs2_dinode);
                ip->i_disksize = size;
                ip->i_inode.i_mtime = ip->i_inode.i_ctime = CURRENT_TIME;
                gfs2_trans_add_bh(ip->i_gl, dibh, 1);
@@ -1244,13 +1244,12 @@ int gfs2_file_dealloc(struct gfs2_inode *ip)
  * @ip: the file being written to
  * @offset: the offset to write to
  * @len: the number of bytes being written
- * @alloc_required: set to 1 if an alloc is required, 0 otherwise
  *
- * Returns: errno
+ * Returns: 1 if an alloc is required, 0 otherwise
  */
 
 int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
-                             unsigned int len, int *alloc_required)
+                             unsigned int len)
 {
        struct gfs2_sbd *sdp = GFS2_SB(&ip->i_inode);
        struct buffer_head bh;
@@ -1258,26 +1257,23 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
        u64 lblock, lblock_stop, size;
        u64 end_of_file;
 
-       *alloc_required = 0;
-
        if (!len)
                return 0;
 
        if (gfs2_is_stuffed(ip)) {
                if (offset + len >
                    sdp->sd_sb.sb_bsize - sizeof(struct gfs2_dinode))
-                       *alloc_required = 1;
+                       return 1;
                return 0;
        }
 
-       *alloc_required = 1;
        shift = sdp->sd_sb.sb_bsize_shift;
        BUG_ON(gfs2_is_dir(ip));
        end_of_file = (ip->i_disksize + sdp->sd_sb.sb_bsize - 1) >> shift;
        lblock = offset >> shift;
        lblock_stop = (offset + len + sdp->sd_sb.sb_bsize - 1) >> shift;
        if (lblock_stop > end_of_file)
-               return 0;
+               return 1;
 
        size = (lblock_stop - lblock) << shift;
        do {
@@ -1285,12 +1281,11 @@ int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
                bh.b_size = size;
                gfs2_block_map(&ip->i_inode, lblock, &bh, 0);
                if (!buffer_mapped(&bh))
-                       return 0;
+                       return 1;
                size -= bh.b_size;
                lblock += (bh.b_size >> ip->i_inode.i_blkbits);
        } while(size > 0);
 
-       *alloc_required = 0;
        return 0;
 }
 
index c983177e05ac2401887115781891c9a50f0972ba..a20a5213135a50ae9293da676eb533e9c04063db 100644 (file)
@@ -52,6 +52,6 @@ int gfs2_truncatei(struct gfs2_inode *ip, u64 size);
 int gfs2_truncatei_resume(struct gfs2_inode *ip);
 int gfs2_file_dealloc(struct gfs2_inode *ip);
 int gfs2_write_alloc_required(struct gfs2_inode *ip, u64 offset,
-                             unsigned int len, int *alloc_required);
+                             unsigned int len);
 
 #endif /* __BMAP_DOT_H__ */
index 6b48d7c268b24b65fae281e606fa32080490cf78..b9dd88a78dd47073e3af1645a1e0fa3bcb94d1bb 100644 (file)
@@ -955,7 +955,12 @@ static int dir_split_leaf(struct inode *inode, const struct qstr *name)
        /* Change the pointers.
           Don't bother distinguishing stuffed from non-stuffed.
           This code is complicated enough already. */
-       lp = kmalloc(half_len * sizeof(__be64), GFP_NOFS | __GFP_NOFAIL);
+       lp = kmalloc(half_len * sizeof(__be64), GFP_NOFS);
+       if (!lp) {
+               error = -ENOMEM;
+               goto fail_brelse;
+       }
+
        /*  Change the pointers  */
        for (x = 0; x < half_len; x++)
                lp[x] = cpu_to_be64(bn);
@@ -1063,7 +1068,9 @@ static int dir_double_exhash(struct gfs2_inode *dip)
 
        /*  Allocate both the "from" and "to" buffers in one big chunk  */
 
-       buf = kcalloc(3, sdp->sd_hash_bsize, GFP_NOFS | __GFP_NOFAIL);
+       buf = kcalloc(3, sdp->sd_hash_bsize, GFP_NOFS);
+       if (!buf)
+               return -ENOMEM;
 
        for (block = dip->i_disksize >> sdp->sd_hash_bsize_shift; block--;) {
                error = gfs2_dir_read_data(dip, (char *)buf,
index ed9a94f0ef159c369b6bd3a3598e1cd4d42fb697..4edd662c8232b2c24d1f1767b937f258071f8211 100644 (file)
@@ -351,7 +351,6 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
        unsigned long last_index;
        u64 pos = page->index << PAGE_CACHE_SHIFT;
        unsigned int data_blocks, ind_blocks, rblocks;
-       int alloc_required = 0;
        struct gfs2_holder gh;
        struct gfs2_alloc *al;
        int ret;
@@ -364,8 +363,7 @@ static int gfs2_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
        set_bit(GLF_DIRTY, &ip->i_gl->gl_flags);
        set_bit(GIF_SW_PAGED, &ip->i_flags);
 
-       ret = gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE, &alloc_required);
-       if (ret || !alloc_required)
+       if (!gfs2_write_alloc_required(ip, pos, PAGE_CACHE_SIZE))
                goto out_unlock;
        ret = -ENOMEM;
        al = gfs2_alloc_get(ip);
index 0898f3ec8212e5599df8c547d7d106aeb15d6c86..9adf8f924e08991c32d12938702e570f163c3215 100644 (file)
@@ -327,6 +327,30 @@ static void gfs2_holder_wake(struct gfs2_holder *gh)
        wake_up_bit(&gh->gh_iflags, HIF_WAIT);
 }
 
+/**
+ * do_error - Something unexpected has happened during a lock request
+ *
+ */
+
+static inline void do_error(struct gfs2_glock *gl, const int ret)
+{
+       struct gfs2_holder *gh, *tmp;
+
+       list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) {
+               if (test_bit(HIF_HOLDER, &gh->gh_iflags))
+                       continue;
+               if (ret & LM_OUT_ERROR)
+                       gh->gh_error = -EIO;
+               else if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))
+                       gh->gh_error = GLR_TRYFAILED;
+               else
+                       continue;
+               list_del_init(&gh->gh_list);
+               trace_gfs2_glock_queue(gh, 0);
+               gfs2_holder_wake(gh);
+       }
+}
+
 /**
  * do_promote - promote as many requests as possible on the current queue
  * @gl: The glock
@@ -375,35 +399,12 @@ restart:
                }
                if (gh->gh_list.prev == &gl->gl_holders)
                        return 1;
+               do_error(gl, 0);
                break;
        }
        return 0;
 }
 
-/**
- * do_error - Something unexpected has happened during a lock request
- *
- */
-
-static inline void do_error(struct gfs2_glock *gl, const int ret)
-{
-       struct gfs2_holder *gh, *tmp;
-
-       list_for_each_entry_safe(gh, tmp, &gl->gl_holders, gh_list) {
-               if (test_bit(HIF_HOLDER, &gh->gh_iflags))
-                       continue;
-               if (ret & LM_OUT_ERROR)
-                       gh->gh_error = -EIO;
-               else if (gh->gh_flags & (LM_FLAG_TRY | LM_FLAG_TRY_1CB))
-                       gh->gh_error = GLR_TRYFAILED;
-               else
-                       continue;
-               list_del_init(&gh->gh_list);
-               trace_gfs2_glock_queue(gh, 0);
-               gfs2_holder_wake(gh);
-       }
-}
-
 /**
  * find_first_waiter - find the first gh that's waiting for the glock
  * @gl: the glock
@@ -706,18 +707,8 @@ static void glock_work_func(struct work_struct *work)
 {
        unsigned long delay = 0;
        struct gfs2_glock *gl = container_of(work, struct gfs2_glock, gl_work.work);
-       struct gfs2_holder *gh;
        int drop_ref = 0;
 
-       if (unlikely(test_bit(GLF_FROZEN, &gl->gl_flags))) {
-               spin_lock(&gl->gl_spin);
-               gh = find_first_waiter(gl);
-               if (gh && (gh->gh_flags & LM_FLAG_NOEXP) &&
-                   test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))
-                       set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
-               spin_unlock(&gl->gl_spin);
-       }
-
        if (test_and_clear_bit(GLF_REPLY_PENDING, &gl->gl_flags)) {
                finish_xmote(gl, gl->gl_reply);
                drop_ref = 1;
@@ -1072,6 +1063,9 @@ int gfs2_glock_nq(struct gfs2_holder *gh)
 
        spin_lock(&gl->gl_spin);
        add_to_queue(gh);
+       if ((LM_FLAG_NOEXP & gh->gh_flags) &&
+           test_and_clear_bit(GLF_FROZEN, &gl->gl_flags))
+               set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
        run_queue(gl, 1);
        spin_unlock(&gl->gl_spin);
 
@@ -1328,6 +1322,36 @@ void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
                gfs2_glock_put(gl);
 }
 
+/**
+ * gfs2_should_freeze - Figure out if glock should be frozen
+ * @gl: The glock in question
+ *
+ * Glocks are not frozen if (a) the result of the dlm operation is
+ * an error, (b) the locking operation was an unlock operation or
+ * (c) if there is a "noexp" flagged request anywhere in the queue
+ *
+ * Returns: 1 if freezing should occur, 0 otherwise
+ */
+
+static int gfs2_should_freeze(const struct gfs2_glock *gl)
+{
+       const struct gfs2_holder *gh;
+
+       if (gl->gl_reply & ~LM_OUT_ST_MASK)
+               return 0;
+       if (gl->gl_target == LM_ST_UNLOCKED)
+               return 0;
+
+       list_for_each_entry(gh, &gl->gl_holders, gh_list) {
+               if (test_bit(HIF_HOLDER, &gh->gh_iflags))
+                       continue;
+               if (LM_FLAG_NOEXP & gh->gh_flags)
+                       return 0;
+       }
+
+       return 1;
+}
+
 /**
  * gfs2_glock_complete - Callback used by locking
  * @gl: Pointer to the glock
@@ -1338,18 +1362,17 @@ void gfs2_glock_cb(struct gfs2_glock *gl, unsigned int state)
 void gfs2_glock_complete(struct gfs2_glock *gl, int ret)
 {
        struct lm_lockstruct *ls = &gl->gl_sbd->sd_lockstruct;
+
        gl->gl_reply = ret;
+
        if (unlikely(test_bit(DFL_BLOCK_LOCKS, &ls->ls_flags))) {
-               struct gfs2_holder *gh;
                spin_lock(&gl->gl_spin);
-               gh = find_first_waiter(gl);
-               if ((!(gh && (gh->gh_flags & LM_FLAG_NOEXP)) &&
-                    (gl->gl_target != LM_ST_UNLOCKED)) ||
-                   ((ret & ~LM_OUT_ST_MASK) != 0))
+               if (gfs2_should_freeze(gl)) {
                        set_bit(GLF_FROZEN, &gl->gl_flags);
-               spin_unlock(&gl->gl_spin);
-               if (test_bit(GLF_FROZEN, &gl->gl_flags))
+                       spin_unlock(&gl->gl_spin);
                        return;
+               }
+               spin_unlock(&gl->gl_spin);
        }
        set_bit(GLF_REPLY_PENDING, &gl->gl_flags);
        gfs2_glock_hold(gl);
index b5d7363b22da08cdbcaab0c3f5188022c5f7bffe..8fcbce48a128af6414b98afe7f3d48f83dd84ef8 100644 (file)
@@ -460,6 +460,7 @@ enum {
        SDF_NOBARRIERS          = 3,
        SDF_NORECOVERY          = 4,
        SDF_DEMOTE              = 5,
+       SDF_NOJOURNALID         = 6,
 };
 
 #define GFS2_FSNAME_LEN                256
index 3593b3a7290e874b1d3d6a2238a2a83567685b04..45a4a36195d87d0819958399c56601d6702d58c1 100644 (file)
@@ -76,7 +76,7 @@ static struct gfs2_sbd *init_sbd(struct super_block *sb)
 
        sb->s_fs_info = sdp;
        sdp->sd_vfs = sb;
-
+       set_bit(SDF_NOJOURNALID, &sdp->sd_flags);
        gfs2_tune_init(&sdp->sd_tune);
 
        init_waitqueue_head(&sdp->sd_glock_wait);
@@ -1050,7 +1050,8 @@ static int gfs2_lm_mount(struct gfs2_sbd *sdp, int silent)
                        ret = match_int(&tmp[0], &option);
                        if (ret || option < 0) 
                                goto hostdata_error;
-                       ls->ls_jid = option;
+                       if (test_and_clear_bit(SDF_NOJOURNALID, &sdp->sd_flags))
+                               ls->ls_jid = option;
                        break;
                case Opt_id:
                        /* Obsolete, but left for backward compat purposes */
@@ -1102,6 +1103,24 @@ void gfs2_lm_unmount(struct gfs2_sbd *sdp)
                lm->lm_unmount(sdp);
 }
 
+static int gfs2_journalid_wait(void *word)
+{
+       if (signal_pending(current))
+               return -EINTR;
+       schedule();
+       return 0;
+}
+
+static int wait_on_journal(struct gfs2_sbd *sdp)
+{
+       if (sdp->sd_args.ar_spectator)
+               return 0;
+       if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
+               return 0;
+
+       return wait_on_bit(&sdp->sd_flags, SDF_NOJOURNALID, gfs2_journalid_wait, TASK_INTERRUPTIBLE);
+}
+
 void gfs2_online_uevent(struct gfs2_sbd *sdp)
 {
        struct super_block *sb = sdp->sd_vfs;
@@ -1194,6 +1213,10 @@ static int fill_super(struct super_block *sb, struct gfs2_args *args, int silent
        if (error)
                goto fail_locking;
 
+       error = wait_on_journal(sdp);
+       if (error)
+               goto fail_sb;
+
        error = init_inodes(sdp, DO);
        if (error)
                goto fail_sb;
index 8f02d3db8f428fa345062fa50581f1a35c420a0e..8bb643cb2658615cf7c00e7083850c619953875a 100644 (file)
@@ -787,15 +787,9 @@ static int do_sync(unsigned int num_qd, struct gfs2_quota_data **qda)
                goto out;
 
        for (x = 0; x < num_qd; x++) {
-               int alloc_required;
-
                offset = qd2offset(qda[x]);
-               error = gfs2_write_alloc_required(ip, offset,
-                                                 sizeof(struct gfs2_quota),
-                                                 &alloc_required);
-               if (error)
-                       goto out_gunlock;
-               if (alloc_required)
+               if (gfs2_write_alloc_required(ip, offset,
+                                             sizeof(struct gfs2_quota)))
                        nalloc++;
        }
 
@@ -1584,10 +1578,7 @@ static int gfs2_set_dqblk(struct super_block *sb, int type, qid_t id,
                goto out_i;
 
        offset = qd2offset(qd);
-       error = gfs2_write_alloc_required(ip, offset, sizeof(struct gfs2_quota),
-                                         &alloc_required);
-       if (error)
-               goto out_i;
+       alloc_required = gfs2_write_alloc_required(ip, offset, sizeof(struct gfs2_quota));
        if (alloc_required) {
                al = gfs2_alloc_get(ip);
                if (al == NULL)
index 4d1aad38f1b136535ad6b568f3494d8ef3dec4ed..4140811a921cb7dc622a05bfa23b10e245f81daa 100644 (file)
@@ -342,8 +342,6 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd)
 {
        struct gfs2_inode *ip = GFS2_I(jd->jd_inode);
        struct gfs2_sbd *sdp = GFS2_SB(jd->jd_inode);
-       int ar;
-       int error;
 
        if (ip->i_disksize < (8 << 20) || ip->i_disksize > (1 << 30) ||
            (ip->i_disksize & (sdp->sd_sb.sb_bsize - 1))) {
@@ -352,13 +350,12 @@ int gfs2_jdesc_check(struct gfs2_jdesc *jd)
        }
        jd->jd_blocks = ip->i_disksize >> sdp->sd_sb.sb_bsize_shift;
 
-       error = gfs2_write_alloc_required(ip, 0, ip->i_disksize, &ar);
-       if (!error && ar) {
+       if (gfs2_write_alloc_required(ip, 0, ip->i_disksize)) {
                gfs2_consist_inode(ip);
-               error = -EIO;
+               return -EIO;
        }
 
-       return error;
+       return 0;
 }
 
 /**
index 37f5393e68e6e34c96820ebb682fc2b9942e9004..d019d0d55e00eb6a79f5cc24abfaabb2ebcd71d6 100644 (file)
@@ -325,6 +325,30 @@ static ssize_t lkfirst_show(struct gfs2_sbd *sdp, char *buf)
        return sprintf(buf, "%d\n", ls->ls_first);
 }
 
+static ssize_t lkfirst_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
+{
+       unsigned first;
+       int rv;
+
+       rv = sscanf(buf, "%u", &first);
+       if (rv != 1 || first > 1)
+               return -EINVAL;
+       spin_lock(&sdp->sd_jindex_spin);
+       rv = -EBUSY;
+       if (test_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0)
+               goto out;
+       rv = -EINVAL;
+       if (sdp->sd_args.ar_spectator)
+               goto out;
+       if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
+               goto out;
+        sdp->sd_lockstruct.ls_first = first;
+        rv = 0;
+out:
+        spin_unlock(&sdp->sd_jindex_spin);
+        return rv ? rv : len;
+}
+
 static ssize_t first_done_show(struct gfs2_sbd *sdp, char *buf)
 {
        struct lm_lockstruct *ls = &sdp->sd_lockstruct;
@@ -377,14 +401,41 @@ static ssize_t jid_show(struct gfs2_sbd *sdp, char *buf)
        return sprintf(buf, "%u\n", sdp->sd_lockstruct.ls_jid);
 }
 
+static ssize_t jid_store(struct gfs2_sbd *sdp, const char *buf, size_t len)
+{
+        unsigned jid;
+       int rv;
+
+       rv = sscanf(buf, "%u", &jid);
+       if (rv != 1)
+               return -EINVAL;
+
+       spin_lock(&sdp->sd_jindex_spin);
+       rv = -EINVAL;
+       if (sdp->sd_args.ar_spectator)
+               goto out;
+       if (sdp->sd_lockstruct.ls_ops->lm_mount == NULL)
+               goto out;
+       rv = -EBUSY;
+       if (test_and_clear_bit(SDF_NOJOURNALID, &sdp->sd_flags) == 0)
+               goto out;
+       sdp->sd_lockstruct.ls_jid = jid;
+       smp_mb__after_clear_bit();
+       wake_up_bit(&sdp->sd_flags, SDF_NOJOURNALID);
+       rv = 0;
+out:
+       spin_unlock(&sdp->sd_jindex_spin);
+       return rv ? rv : len;
+}
+
 #define GDLM_ATTR(_name,_mode,_show,_store) \
 static struct gfs2_attr gdlm_attr_##_name = __ATTR(_name,_mode,_show,_store)
 
 GDLM_ATTR(proto_name,          0444, proto_name_show,          NULL);
 GDLM_ATTR(block,               0644, block_show,               block_store);
 GDLM_ATTR(withdraw,            0644, withdraw_show,            withdraw_store);
-GDLM_ATTR(jid,                 0444, jid_show,                 NULL);
-GDLM_ATTR(first,               0444, lkfirst_show,             NULL);
+GDLM_ATTR(jid,                 0644, jid_show,                 jid_store);
+GDLM_ATTR(first,               0644, lkfirst_show,             lkfirst_store);
 GDLM_ATTR(first_done,          0444, first_done_show,          NULL);
 GDLM_ATTR(recover,             0600, NULL,                     recover_store);
 GDLM_ATTR(recover_done,                0444, recover_done_show,        NULL);
@@ -564,7 +615,7 @@ static int gfs2_uevent(struct kset *kset, struct kobject *kobj,
 
        add_uevent_var(env, "LOCKTABLE=%s", sdp->sd_table_name);
        add_uevent_var(env, "LOCKPROTO=%s", sdp->sd_proto_name);
-       if (!sdp->sd_args.ar_spectator)
+       if (!test_bit(SDF_NOJOURNALID, &sdp->sd_flags))
                add_uevent_var(env, "JOURNALID=%u", sdp->sd_lockstruct.ls_jid);
        if (gfs2_uuid_valid(uuid))
                add_uevent_var(env, "UUID=%pUB", uuid);
index 868d0cb9d473a92ccdcbe640ac44f4daf24cce62..42d2d28fb827c41f5aad101e0faa340ac2dfa332 100644 (file)
@@ -282,8 +282,7 @@ int inode_permission(struct inode *inode, int mask)
        if (retval)
                return retval;
 
-       return security_inode_permission(inode,
-                       mask & (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND));
+       return security_inode_permission(inode, mask);
 }
 
 /**
@@ -1484,8 +1483,7 @@ static int handle_truncate(struct path *path)
         */
        error = locks_verify_locked(inode);
        if (!error)
-               error = security_path_truncate(path, 0,
-                                      ATTR_MTIME|ATTR_CTIME|ATTR_OPEN);
+               error = security_path_truncate(path);
        if (!error) {
                error = do_truncate(path->dentry, 0,
                                    ATTR_MTIME|ATTR_CTIME|ATTR_OPEN,
index e60416d3f8188b548ec1d55e3438ea7e6f2c926f..832e9e2393248968b793df0302433c4e1f8b052f 100644 (file)
@@ -1953,7 +1953,7 @@ int nfs_permission(struct inode *inode, int mask)
        if ((mask & (MAY_READ | MAY_WRITE | MAY_EXEC)) == 0)
                goto out;
        /* Is this sys_access() ? */
-       if (mask & MAY_ACCESS)
+       if (mask & (MAY_ACCESS | MAY_CHDIR))
                goto force_lookup;
 
        switch (inode->i_mode & S_IFMT) {
index 356e976772bf1adb112aaf3c8b28ddb71b639afb..96337a4fbbdfc3840cffc3a458ee6f37ed0655ce 100644 (file)
@@ -578,7 +578,9 @@ bail:
 static void ocfs2_dio_end_io(struct kiocb *iocb,
                             loff_t offset,
                             ssize_t bytes,
-                            void *private)
+                            void *private,
+                            int ret,
+                            bool is_async)
 {
        struct inode *inode = iocb->ki_filp->f_path.dentry->d_inode;
        int level;
@@ -592,6 +594,9 @@ static void ocfs2_dio_end_io(struct kiocb *iocb,
        if (!level)
                up_read(&inode->i_alloc_sem);
        ocfs2_rw_unlock(inode, level);
+
+       if (is_async)
+               aio_complete(iocb, ret, 0);
 }
 
 /*
index 5463266db9e6312d906082073733c2a04440b40b..0d1fa3dc0efb53f0f42051d4dde9ac4a4503c876 100644 (file)
--- a/fs/open.c
+++ b/fs/open.c
@@ -110,7 +110,7 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
 
        error = locks_verify_truncate(inode, NULL, length);
        if (!error)
-               error = security_path_truncate(&path, length, 0);
+               error = security_path_truncate(&path);
        if (!error)
                error = do_truncate(path.dentry, length, 0, NULL);
 
@@ -165,8 +165,7 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
 
        error = locks_verify_truncate(inode, file, length);
        if (!error)
-               error = security_path_truncate(&file->f_path, length,
-                                              ATTR_MTIME|ATTR_CTIME);
+               error = security_path_truncate(&file->f_path);
        if (!error)
                error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, file);
 out_putf:
@@ -367,7 +366,7 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
        if (error)
                goto out;
 
-       error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_ACCESS);
+       error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
        if (error)
                goto dput_and_out;
 
@@ -396,7 +395,7 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
        if (!S_ISDIR(inode->i_mode))
                goto out_putf;
 
-       error = inode_permission(inode, MAY_EXEC | MAY_ACCESS);
+       error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
        if (!error)
                set_fs_pwd(current->fs, &file->f_path);
 out_putf:
@@ -414,7 +413,7 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
        if (error)
                goto out;
 
-       error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_ACCESS);
+       error = inode_permission(path.dentry->d_inode, MAY_EXEC | MAY_CHDIR);
        if (error)
                goto dput_and_out;
 
index ad7f67b827ea3b568d571685c42dfc50fc721920..0084a33c4c69bba01e8a264bf7a6576ddede3744 100644 (file)
@@ -1457,13 +1457,13 @@ struct ubifs_lprops *ubifs_lpt_lookup(struct ubifs_info *c, int lnum)
                shft -= UBIFS_LPT_FANOUT_SHIFT;
                nnode = ubifs_get_nnode(c, nnode, iip);
                if (IS_ERR(nnode))
-                       return ERR_PTR(PTR_ERR(nnode));
+                       return ERR_CAST(nnode);
        }
        iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1));
        shft -= UBIFS_LPT_FANOUT_SHIFT;
        pnode = ubifs_get_pnode(c, nnode, iip);
        if (IS_ERR(pnode))
-               return ERR_PTR(PTR_ERR(pnode));
+               return ERR_CAST(pnode);
        iip = (i & (UBIFS_LPT_FANOUT - 1));
        dbg_lp("LEB %d, free %d, dirty %d, flags %d", lnum,
               pnode->lprops[iip].free, pnode->lprops[iip].dirty,
@@ -1586,7 +1586,7 @@ struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum)
        nnode = c->nroot;
        nnode = dirty_cow_nnode(c, nnode);
        if (IS_ERR(nnode))
-               return ERR_PTR(PTR_ERR(nnode));
+               return ERR_CAST(nnode);
        i = lnum - c->main_first;
        shft = c->lpt_hght * UBIFS_LPT_FANOUT_SHIFT;
        for (h = 1; h < c->lpt_hght; h++) {
@@ -1594,19 +1594,19 @@ struct ubifs_lprops *ubifs_lpt_lookup_dirty(struct ubifs_info *c, int lnum)
                shft -= UBIFS_LPT_FANOUT_SHIFT;
                nnode = ubifs_get_nnode(c, nnode, iip);
                if (IS_ERR(nnode))
-                       return ERR_PTR(PTR_ERR(nnode));
+                       return ERR_CAST(nnode);
                nnode = dirty_cow_nnode(c, nnode);
                if (IS_ERR(nnode))
-                       return ERR_PTR(PTR_ERR(nnode));
+                       return ERR_CAST(nnode);
        }
        iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1));
        shft -= UBIFS_LPT_FANOUT_SHIFT;
        pnode = ubifs_get_pnode(c, nnode, iip);
        if (IS_ERR(pnode))
-               return ERR_PTR(PTR_ERR(pnode));
+               return ERR_CAST(pnode);
        pnode = dirty_cow_pnode(c, pnode);
        if (IS_ERR(pnode))
-               return ERR_PTR(PTR_ERR(pnode));
+               return ERR_CAST(pnode);
        iip = (i & (UBIFS_LPT_FANOUT - 1));
        dbg_lp("LEB %d, free %d, dirty %d, flags %d", lnum,
               pnode->lprops[iip].free, pnode->lprops[iip].dirty,
index 13cb7a4237bf474fa19a9161edd838c214c07c28..d12535b7fc789dda7c473593aacfc6816afc90be 100644 (file)
@@ -646,7 +646,7 @@ static struct ubifs_pnode *pnode_lookup(struct ubifs_info *c, int i)
                shft -= UBIFS_LPT_FANOUT_SHIFT;
                nnode = ubifs_get_nnode(c, nnode, iip);
                if (IS_ERR(nnode))
-                       return ERR_PTR(PTR_ERR(nnode));
+                       return ERR_CAST(nnode);
        }
        iip = ((i >> shft) & (UBIFS_LPT_FANOUT - 1));
        return ubifs_get_pnode(c, nnode, iip);
index 109c6ea03bb5d0cb86982a42d6ef9030e28b3e55..daae9e1f5382142482490798b0c0ba1aed581221 100644 (file)
@@ -24,7 +24,7 @@
  * This file implements functions needed to recover from unclean un-mounts.
  * When UBIFS is mounted, it checks a flag on the master node to determine if
  * an un-mount was completed successfully. If not, the process of mounting
- * incorparates additional checking and fixing of on-flash data structures.
+ * incorporates additional checking and fixing of on-flash data structures.
  * UBIFS always cleans away all remnants of an unclean un-mount, so that
  * errors do not accumulate. However UBIFS defers recovery if it is mounted
  * read-only, and the flash is not modified in that case.
@@ -1063,8 +1063,21 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c)
        }
        err = ubifs_find_dirty_leb(c, &lp, wbuf->offs, 2);
        if (err) {
-               if (err == -ENOSPC)
-                       dbg_err("could not find a dirty LEB");
+               /*
+                * There are no dirty or empty LEBs subject to here being
+                * enough for the index. Try to use
+                * 'ubifs_find_free_leb_for_idx()', which will return any empty
+                * LEBs (ignoring index requirements). If the index then
+                * doesn't have enough LEBs the recovery commit will fail -
+                * which is the  same result anyway i.e. recovery fails. So
+                * there is no problem ignoring index  requirements and just
+                * grabbing a free LEB since we have already established there
+                * is not a dirty LEB we could have used instead.
+                */
+               if (err == -ENOSPC) {
+                       dbg_rcvry("could not find a dirty LEB");
+                       goto find_free;
+               }
                return err;
        }
        ubifs_assert(!(lp.flags & LPROPS_INDEX));
@@ -1139,8 +1152,8 @@ int ubifs_rcvry_gc_commit(struct ubifs_info *c)
 find_free:
        /*
         * There is no GC head LEB or the free space in the GC head LEB is too
-        * small. Allocate gc_lnum by calling 'ubifs_find_free_leb_for_idx()' so
-        * GC is not run.
+        * small, or there are not dirty LEBs. Allocate gc_lnum by calling
+        * 'ubifs_find_free_leb_for_idx()' so GC is not run.
         */
        lnum = ubifs_find_free_leb_for_idx(c);
        if (lnum < 0) {
index 4d2f2157dd3fa9a70a680baea10a68fba7a56061..5fc5a0988970d15507ef048a6199c5e0f7219d65 100644 (file)
@@ -1307,6 +1307,8 @@ static int mount_ubifs(struct ubifs_info *c)
                        if (err)
                                goto out_orphans;
                        err = ubifs_rcvry_gc_commit(c);
+                       if (err)
+                               goto out_orphans;
                } else {
                        err = take_gc_lnum(c);
                        if (err)
@@ -1318,7 +1320,7 @@ static int mount_ubifs(struct ubifs_info *c)
                         */
                        err = ubifs_leb_unmap(c, c->gc_lnum);
                        if (err)
-                               return err;
+                               goto out_orphans;
                }
 
                err = dbg_check_lprops(c);
index c8fb13f83b3f1f95dc642df019a0d14072ed6d15..0dce969d6cad61840430a40f3972de64a48bfdb0 100644 (file)
@@ -87,11 +87,9 @@ xfs-y                                += xfs_alloc.o \
                                   xfs_trans_buf.o \
                                   xfs_trans_extfree.o \
                                   xfs_trans_inode.o \
-                                  xfs_trans_item.o \
                                   xfs_utils.o \
                                   xfs_vnodeops.o \
-                                  xfs_rw.o \
-                                  xfs_dmops.o
+                                  xfs_rw.o
 
 xfs-$(CONFIG_XFS_TRACE)                += xfs_btree_trace.o
 
index 9f769b5b38fc4c4b41e2b7f356889fd1d5f9a1f6..b2771862fd3df79fbb721b3c5c93865680a8e145 100644 (file)
@@ -225,7 +225,7 @@ xfs_check_acl(struct inode *inode, int mask)
        struct posix_acl *acl;
        int error = -EAGAIN;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_check_acl(ip);
 
        /*
         * If there is no attribute fork no ACL exists on this inode and
index 34640d6dbdcb8e6d5879c50a3acafed0cc819708..d24e78f32f3e3f5f41331c80f1f46e86fb700a9a 100644 (file)
 #include "xfs_inum.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_trans.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_alloc.h"
-#include "xfs_btree.h"
 #include "xfs_error.h"
 #include "xfs_rw.h"
 #include "xfs_iomap.h"
@@ -92,18 +85,15 @@ void
 xfs_count_page_state(
        struct page             *page,
        int                     *delalloc,
-       int                     *unmapped,
        int                     *unwritten)
 {
        struct buffer_head      *bh, *head;
 
-       *delalloc = *unmapped = *unwritten = 0;
+       *delalloc = *unwritten = 0;
 
        bh = head = page_buffers(page);
        do {
-               if (buffer_uptodate(bh) && !buffer_mapped(bh))
-                       (*unmapped) = 1;
-               else if (buffer_unwritten(bh))
+               if (buffer_unwritten(bh))
                        (*unwritten) = 1;
                else if (buffer_delay(bh))
                        (*delalloc) = 1;
@@ -212,23 +202,17 @@ xfs_setfilesize(
 }
 
 /*
- * Schedule IO completion handling on a xfsdatad if this was
- * the final hold on this ioend. If we are asked to wait,
- * flush the workqueue.
+ * Schedule IO completion handling on the final put of an ioend.
  */
 STATIC void
 xfs_finish_ioend(
-       xfs_ioend_t     *ioend,
-       int             wait)
+       struct xfs_ioend        *ioend)
 {
        if (atomic_dec_and_test(&ioend->io_remaining)) {
-               struct workqueue_struct *wq;
-
-               wq = (ioend->io_type == IO_UNWRITTEN) ?
-                       xfsconvertd_workqueue : xfsdatad_workqueue;
-               queue_work(wq, &ioend->io_work);
-               if (wait)
-                       flush_workqueue(wq);
+               if (ioend->io_type == IO_UNWRITTEN)
+                       queue_work(xfsconvertd_workqueue, &ioend->io_work);
+               else
+                       queue_work(xfsdatad_workqueue, &ioend->io_work);
        }
 }
 
@@ -272,11 +256,25 @@ xfs_end_io(
         */
        if (error == EAGAIN) {
                atomic_inc(&ioend->io_remaining);
-               xfs_finish_ioend(ioend, 0);
+               xfs_finish_ioend(ioend);
                /* ensure we don't spin on blocked ioends */
                delay(1);
-       } else
+       } else {
+               if (ioend->io_iocb)
+                       aio_complete(ioend->io_iocb, ioend->io_result, 0);
                xfs_destroy_ioend(ioend);
+       }
+}
+
+/*
+ * Call IO completion handling in caller context on the final put of an ioend.
+ */
+STATIC void
+xfs_finish_ioend_sync(
+       struct xfs_ioend        *ioend)
+{
+       if (atomic_dec_and_test(&ioend->io_remaining))
+               xfs_end_io(&ioend->io_work);
 }
 
 /*
@@ -309,6 +307,8 @@ xfs_alloc_ioend(
        atomic_inc(&XFS_I(ioend->io_inode)->i_iocount);
        ioend->io_offset = 0;
        ioend->io_size = 0;
+       ioend->io_iocb = NULL;
+       ioend->io_result = 0;
 
        INIT_WORK(&ioend->io_work, xfs_end_io);
        return ioend;
@@ -358,7 +358,7 @@ xfs_end_bio(
        bio->bi_end_io = NULL;
        bio_put(bio);
 
-       xfs_finish_ioend(ioend, 0);
+       xfs_finish_ioend(ioend);
 }
 
 STATIC void
@@ -500,7 +500,7 @@ xfs_submit_ioend(
                }
                if (bio)
                        xfs_submit_ioend_bio(wbc, ioend, bio);
-               xfs_finish_ioend(ioend, 0);
+               xfs_finish_ioend(ioend);
        } while ((ioend = next) != NULL);
 }
 
@@ -614,31 +614,30 @@ xfs_map_at_offset(
 STATIC unsigned int
 xfs_probe_page(
        struct page             *page,
-       unsigned int            pg_offset,
-       int                     mapped)
+       unsigned int            pg_offset)
 {
+       struct buffer_head      *bh, *head;
        int                     ret = 0;
 
        if (PageWriteback(page))
                return 0;
+       if (!PageDirty(page))
+               return 0;
+       if (!page->mapping)
+               return 0;
+       if (!page_has_buffers(page))
+               return 0;
 
-       if (page->mapping && PageDirty(page)) {
-               if (page_has_buffers(page)) {
-                       struct buffer_head      *bh, *head;
-
-                       bh = head = page_buffers(page);
-                       do {
-                               if (!buffer_uptodate(bh))
-                                       break;
-                               if (mapped != buffer_mapped(bh))
-                                       break;
-                               ret += bh->b_size;
-                               if (ret >= pg_offset)
-                                       break;
-                       } while ((bh = bh->b_this_page) != head);
-               } else
-                       ret = mapped ? 0 : PAGE_CACHE_SIZE;
-       }
+       bh = head = page_buffers(page);
+       do {
+               if (!buffer_uptodate(bh))
+                       break;
+               if (!buffer_mapped(bh))
+                       break;
+               ret += bh->b_size;
+               if (ret >= pg_offset)
+                       break;
+       } while ((bh = bh->b_this_page) != head);
 
        return ret;
 }
@@ -648,8 +647,7 @@ xfs_probe_cluster(
        struct inode            *inode,
        struct page             *startpage,
        struct buffer_head      *bh,
-       struct buffer_head      *head,
-       int                     mapped)
+       struct buffer_head      *head)
 {
        struct pagevec          pvec;
        pgoff_t                 tindex, tlast, tloff;
@@ -658,7 +656,7 @@ xfs_probe_cluster(
 
        /* First sum forwards in this page */
        do {
-               if (!buffer_uptodate(bh) || (mapped != buffer_mapped(bh)))
+               if (!buffer_uptodate(bh) || !buffer_mapped(bh))
                        return total;
                total += bh->b_size;
        } while ((bh = bh->b_this_page) != head);
@@ -692,7 +690,7 @@ xfs_probe_cluster(
                                pg_offset = PAGE_CACHE_SIZE;
 
                        if (page->index == tindex && trylock_page(page)) {
-                               pg_len = xfs_probe_page(page, pg_offset, mapped);
+                               pg_len = xfs_probe_page(page, pg_offset);
                                unlock_page(page);
                        }
 
@@ -761,7 +759,6 @@ xfs_convert_page(
        struct xfs_bmbt_irec    *imap,
        xfs_ioend_t             **ioendp,
        struct writeback_control *wbc,
-       int                     startio,
        int                     all_bh)
 {
        struct buffer_head      *bh, *head;
@@ -832,19 +829,14 @@ xfs_convert_page(
                        ASSERT(imap->br_startblock != DELAYSTARTBLOCK);
 
                        xfs_map_at_offset(inode, bh, imap, offset);
-                       if (startio) {
-                               xfs_add_to_ioend(inode, bh, offset,
-                                               type, ioendp, done);
-                       } else {
-                               set_buffer_dirty(bh);
-                               unlock_buffer(bh);
-                               mark_buffer_dirty(bh);
-                       }
+                       xfs_add_to_ioend(inode, bh, offset, type,
+                                        ioendp, done);
+
                        page_dirty--;
                        count++;
                } else {
                        type = IO_NEW;
-                       if (buffer_mapped(bh) && all_bh && startio) {
+                       if (buffer_mapped(bh) && all_bh) {
                                lock_buffer(bh);
                                xfs_add_to_ioend(inode, bh, offset,
                                                type, ioendp, done);
@@ -859,14 +851,12 @@ xfs_convert_page(
        if (uptodate && bh == head)
                SetPageUptodate(page);
 
-       if (startio) {
-               if (count) {
-                       wbc->nr_to_write--;
-                       if (wbc->nr_to_write <= 0)
-                               done = 1;
-               }
-               xfs_start_page_writeback(page, !page_dirty, count);
+       if (count) {
+               wbc->nr_to_write--;
+               if (wbc->nr_to_write <= 0)
+                       done = 1;
        }
+       xfs_start_page_writeback(page, !page_dirty, count);
 
        return done;
  fail_unlock_page:
@@ -886,7 +876,6 @@ xfs_cluster_write(
        struct xfs_bmbt_irec    *imap,
        xfs_ioend_t             **ioendp,
        struct writeback_control *wbc,
-       int                     startio,
        int                     all_bh,
        pgoff_t                 tlast)
 {
@@ -902,7 +891,7 @@ xfs_cluster_write(
 
                for (i = 0; i < pagevec_count(&pvec); i++) {
                        done = xfs_convert_page(inode, pvec.pages[i], tindex++,
-                                       imap, ioendp, wbc, startio, all_bh);
+                                       imap, ioendp, wbc, all_bh);
                        if (done)
                                break;
                }
@@ -981,7 +970,7 @@ xfs_aops_discard_page(
                 */
                error = xfs_bmapi(NULL, ip, offset_fsb, 1,
                                XFS_BMAPI_ENTIRE,  NULL, 0, &imap,
-                               &nimaps, NULL, NULL);
+                               &nimaps, NULL);
 
                if (error) {
                        /* something screwed, just bail */
@@ -1009,7 +998,7 @@ xfs_aops_discard_page(
                 */
                xfs_bmap_init(&flist, &firstblock);
                error = xfs_bunmapi(NULL, ip, offset_fsb, 1, 0, 1, &firstblock,
-                                       &flist, NULL, &done);
+                                       &flist, &done);
 
                ASSERT(!flist.xbf_count && !flist.xbf_first);
                if (error) {
@@ -1032,50 +1021,66 @@ out_invalidate:
 }
 
 /*
- * Calling this without startio set means we are being asked to make a dirty
- * page ready for freeing it's buffers.  When called with startio set then
- * we are coming from writepage.
+ * Write out a dirty page.
+ *
+ * For delalloc space on the page we need to allocate space and flush it.
+ * For unwritten space on the page we need to start the conversion to
+ * regular allocated space.
+ * For any other dirty buffer heads on the page we should flush them.
  *
- * When called with startio set it is important that we write the WHOLE
- * page if possible.
- * The bh->b_state's cannot know if any of the blocks or which block for
- * that matter are dirty due to mmap writes, and therefore bh uptodate is
- * only valid if the page itself isn't completely uptodate.  Some layers
- * may clear the page dirty flag prior to calling write page, under the
- * assumption the entire page will be written out; by not writing out the
- * whole page the page can be reused before all valid dirty data is
- * written out.  Note: in the case of a page that has been dirty'd by
- * mapwrite and but partially setup by block_prepare_write the
- * bh->b_states's will not agree and only ones setup by BPW/BCW will have
- * valid state, thus the whole page must be written out thing.
+ * If we detect that a transaction would be required to flush the page, we
+ * have to check the process flags first, if we are already in a transaction
+ * or disk I/O during allocations is off, we need to fail the writepage and
+ * redirty the page.
  */
-
 STATIC int
-xfs_page_state_convert(
-       struct inode    *inode,
-       struct page     *page,
-       struct writeback_control *wbc,
-       int             startio,
-       int             unmapped) /* also implies page uptodate */
+xfs_vm_writepage(
+       struct page             *page,
+       struct writeback_control *wbc)
 {
+       struct inode            *inode = page->mapping->host;
+       int                     delalloc, unwritten;
        struct buffer_head      *bh, *head;
        struct xfs_bmbt_irec    imap;
        xfs_ioend_t             *ioend = NULL, *iohead = NULL;
        loff_t                  offset;
-       unsigned long           p_offset = 0;
        unsigned int            type;
        __uint64_t              end_offset;
        pgoff_t                 end_index, last_index;
        ssize_t                 size, len;
        int                     flags, err, imap_valid = 0, uptodate = 1;
-       int                     page_dirty, count = 0;
-       int                     trylock = 0;
-       int                     all_bh = unmapped;
+       int                     count = 0;
+       int                     all_bh = 0;
 
-       if (startio) {
-               if (wbc->sync_mode == WB_SYNC_NONE && wbc->nonblocking)
-                       trylock |= BMAPI_TRYLOCK;
-       }
+       trace_xfs_writepage(inode, page, 0);
+
+       ASSERT(page_has_buffers(page));
+
+       /*
+        * Refuse to write the page out if we are called from reclaim context.
+        *
+        * This avoids stack overflows when called from deeply used stacks in
+        * random callers for direct reclaim or memcg reclaim.  We explicitly
+        * allow reclaim from kswapd as the stack usage there is relatively low.
+        *
+        * This should really be done by the core VM, but until that happens
+        * filesystems like XFS, btrfs and ext4 have to take care of this
+        * by themselves.
+        */
+       if ((current->flags & (PF_MEMALLOC|PF_KSWAPD)) == PF_MEMALLOC)
+               goto out_fail;
+
+       /*
+        * We need a transaction if there are delalloc or unwritten buffers
+        * on the page.
+        *
+        * If we need a transaction and the process flags say we are already
+        * in a transaction, or no IO is allowed then mark the page dirty
+        * again and leave the page as is.
+        */
+       xfs_count_page_state(page, &delalloc, &unwritten);
+       if ((current->flags & PF_FSTRANS) && (delalloc || unwritten))
+               goto out_fail;
 
        /* Is this page beyond the end of the file? */
        offset = i_size_read(inode);
@@ -1084,50 +1089,33 @@ xfs_page_state_convert(
        if (page->index >= end_index) {
                if ((page->index >= end_index + 1) ||
                    !(i_size_read(inode) & (PAGE_CACHE_SIZE - 1))) {
-                       if (startio)
-                               unlock_page(page);
+                       unlock_page(page);
                        return 0;
                }
        }
 
-       /*
-        * page_dirty is initially a count of buffers on the page before
-        * EOF and is decremented as we move each into a cleanable state.
-        *
-        * Derivation:
-        *
-        * End offset is the highest offset that this page should represent.
-        * If we are on the last page, (end_offset & (PAGE_CACHE_SIZE - 1))
-        * will evaluate non-zero and be less than PAGE_CACHE_SIZE and
-        * hence give us the correct page_dirty count. On any other page,
-        * it will be zero and in that case we need page_dirty to be the
-        * count of buffers on the page.
-        */
        end_offset = min_t(unsigned long long,
-                       (xfs_off_t)(page->index + 1) << PAGE_CACHE_SHIFT, offset);
+                       (xfs_off_t)(page->index + 1) << PAGE_CACHE_SHIFT,
+                       offset);
        len = 1 << inode->i_blkbits;
-       p_offset = min_t(unsigned long, end_offset & (PAGE_CACHE_SIZE - 1),
-                                       PAGE_CACHE_SIZE);
-       p_offset = p_offset ? roundup(p_offset, len) : PAGE_CACHE_SIZE;
-       page_dirty = p_offset / len;
 
        bh = head = page_buffers(page);
        offset = page_offset(page);
        flags = BMAPI_READ;
        type = IO_NEW;
 
-       /* TODO: cleanup count and page_dirty */
-
        do {
                if (offset >= end_offset)
                        break;
                if (!buffer_uptodate(bh))
                        uptodate = 0;
-               if (!(PageUptodate(page) || buffer_uptodate(bh)) && !startio) {
-                       /*
-                        * the iomap is actually still valid, but the ioend
-                        * isn't.  shouldn't happen too often.
-                        */
+
+               /*
+                * A hole may still be marked uptodate because discard_buffer
+                * leaves the flag set.
+                */
+               if (!buffer_mapped(bh) && buffer_uptodate(bh)) {
+                       ASSERT(!buffer_dirty(bh));
                        imap_valid = 0;
                        continue;
                }
@@ -1135,19 +1123,7 @@ xfs_page_state_convert(
                if (imap_valid)
                        imap_valid = xfs_imap_valid(inode, &imap, offset);
 
-               /*
-                * First case, map an unwritten extent and prepare for
-                * extent state conversion transaction on completion.
-                *
-                * Second case, allocate space for a delalloc buffer.
-                * We can return EAGAIN here in the release page case.
-                *
-                * Third case, an unmapped buffer was found, and we are
-                * in a path where we need to write the whole page out.
-                */
-               if (buffer_unwritten(bh) || buffer_delay(bh) ||
-                   ((buffer_uptodate(bh) || PageUptodate(page)) &&
-                    !buffer_mapped(bh) && (unmapped || startio))) {
+               if (buffer_unwritten(bh) || buffer_delay(bh)) {
                        int new_ioend = 0;
 
                        /*
@@ -1161,15 +1137,16 @@ xfs_page_state_convert(
                                flags = BMAPI_WRITE | BMAPI_IGNSTATE;
                        } else if (buffer_delay(bh)) {
                                type = IO_DELAY;
-                               flags = BMAPI_ALLOCATE | trylock;
-                       } else {
-                               type = IO_NEW;
-                               flags = BMAPI_WRITE | BMAPI_MMAP;
+                               flags = BMAPI_ALLOCATE;
+
+                               if (wbc->sync_mode == WB_SYNC_NONE &&
+                                   wbc->nonblocking)
+                                       flags |= BMAPI_TRYLOCK;
                        }
 
                        if (!imap_valid) {
                                /*
-                                * if we didn't have a valid mapping then we
+                                * If we didn't have a valid mapping then we
                                 * need to ensure that we put the new mapping
                                 * in a new ioend structure. This needs to be
                                 * done to ensure that the ioends correctly
@@ -1177,14 +1154,7 @@ xfs_page_state_convert(
                                 * for unwritten extent conversion.
                                 */
                                new_ioend = 1;
-                               if (type == IO_NEW) {
-                                       size = xfs_probe_cluster(inode,
-                                                       page, bh, head, 0);
-                               } else {
-                                       size = len;
-                               }
-
-                               err = xfs_map_blocks(inode, offset, size,
+                               err = xfs_map_blocks(inode, offset, len,
                                                &imap, flags);
                                if (err)
                                        goto error;
@@ -1193,19 +1163,11 @@ xfs_page_state_convert(
                        }
                        if (imap_valid) {
                                xfs_map_at_offset(inode, bh, &imap, offset);
-                               if (startio) {
-                                       xfs_add_to_ioend(inode, bh, offset,
-                                                       type, &ioend,
-                                                       new_ioend);
-                               } else {
-                                       set_buffer_dirty(bh);
-                                       unlock_buffer(bh);
-                                       mark_buffer_dirty(bh);
-                               }
-                               page_dirty--;
+                               xfs_add_to_ioend(inode, bh, offset, type,
+                                                &ioend, new_ioend);
                                count++;
                        }
-               } else if (buffer_uptodate(bh) && startio) {
+               } else if (buffer_uptodate(bh)) {
                        /*
                         * we got here because the buffer is already mapped.
                         * That means it must already have extents allocated
@@ -1213,8 +1175,7 @@ xfs_page_state_convert(
                         */
                        if (!imap_valid || flags != BMAPI_READ) {
                                flags = BMAPI_READ;
-                               size = xfs_probe_cluster(inode, page, bh,
-                                                               head, 1);
+                               size = xfs_probe_cluster(inode, page, bh, head);
                                err = xfs_map_blocks(inode, offset, size,
                                                &imap, flags);
                                if (err)
@@ -1233,18 +1194,16 @@ xfs_page_state_convert(
                         */
                        type = IO_NEW;
                        if (trylock_buffer(bh)) {
-                               ASSERT(buffer_mapped(bh));
                                if (imap_valid)
                                        all_bh = 1;
                                xfs_add_to_ioend(inode, bh, offset, type,
                                                &ioend, !imap_valid);
-                               page_dirty--;
                                count++;
                        } else {
                                imap_valid = 0;
                        }
-               } else if ((buffer_uptodate(bh) || PageUptodate(page)) &&
-                          (unmapped || startio)) {
+               } else if (PageUptodate(page)) {
+                       ASSERT(buffer_mapped(bh));
                        imap_valid = 0;
                }
 
@@ -1256,8 +1215,7 @@ xfs_page_state_convert(
        if (uptodate && bh == head)
                SetPageUptodate(page);
 
-       if (startio)
-               xfs_start_page_writeback(page, 1, count);
+       xfs_start_page_writeback(page, 1, count);
 
        if (ioend && imap_valid) {
                xfs_off_t               end_index;
@@ -1275,131 +1233,27 @@ xfs_page_state_convert(
                        end_index = last_index;
 
                xfs_cluster_write(inode, page->index + 1, &imap, &ioend,
-                                       wbc, startio, all_bh, end_index);
+                                       wbc, all_bh, end_index);
        }
 
        if (iohead)
                xfs_submit_ioend(wbc, iohead);
 
-       return page_dirty;
+       return 0;
 
 error:
        if (iohead)
                xfs_cancel_ioend(iohead);
 
-       /*
-        * If it's delalloc and we have nowhere to put it,
-        * throw it away, unless the lower layers told
-        * us to try again.
-        */
-       if (err != -EAGAIN) {
-               if (!unmapped)
-                       xfs_aops_discard_page(page);
-               ClearPageUptodate(page);
-       }
+       xfs_aops_discard_page(page);
+       ClearPageUptodate(page);
+       unlock_page(page);
        return err;
-}
-
-/*
- * writepage: Called from one of two places:
- *
- * 1. we are flushing a delalloc buffer head.
- *
- * 2. we are writing out a dirty page. Typically the page dirty
- *    state is cleared before we get here. In this case is it
- *    conceivable we have no buffer heads.
- *
- * For delalloc space on the page we need to allocate space and
- * flush it. For unmapped buffer heads on the page we should
- * allocate space if the page is uptodate. For any other dirty
- * buffer heads on the page we should flush them.
- *
- * If we detect that a transaction would be required to flush
- * the page, we have to check the process flags first, if we
- * are already in a transaction or disk I/O during allocations
- * is off, we need to fail the writepage and redirty the page.
- */
-
-STATIC int
-xfs_vm_writepage(
-       struct page             *page,
-       struct writeback_control *wbc)
-{
-       int                     error;
-       int                     need_trans;
-       int                     delalloc, unmapped, unwritten;
-       struct inode            *inode = page->mapping->host;
-
-       trace_xfs_writepage(inode, page, 0);
-
-       /*
-        * Refuse to write the page out if we are called from reclaim context.
-        *
-        * This is primarily to avoid stack overflows when called from deep
-        * used stacks in random callers for direct reclaim, but disabling
-        * reclaim for kswap is a nice side-effect as kswapd causes rather
-        * suboptimal I/O patters, too.
-        *
-        * This should really be done by the core VM, but until that happens
-        * filesystems like XFS, btrfs and ext4 have to take care of this
-        * by themselves.
-        */
-       if (current->flags & PF_MEMALLOC)
-               goto out_fail;
-
-       /*
-        * We need a transaction if:
-        *  1. There are delalloc buffers on the page
-        *  2. The page is uptodate and we have unmapped buffers
-        *  3. The page is uptodate and we have no buffers
-        *  4. There are unwritten buffers on the page
-        */
-
-       if (!page_has_buffers(page)) {
-               unmapped = 1;
-               need_trans = 1;
-       } else {
-               xfs_count_page_state(page, &delalloc, &unmapped, &unwritten);
-               if (!PageUptodate(page))
-                       unmapped = 0;
-               need_trans = delalloc + unmapped + unwritten;
-       }
-
-       /*
-        * If we need a transaction and the process flags say
-        * we are already in a transaction, or no IO is allowed
-        * then mark the page dirty again and leave the page
-        * as is.
-        */
-       if (current_test_flags(PF_FSTRANS) && need_trans)
-               goto out_fail;
-
-       /*
-        * Delay hooking up buffer heads until we have
-        * made our go/no-go decision.
-        */
-       if (!page_has_buffers(page))
-               create_empty_buffers(page, 1 << inode->i_blkbits, 0);
-
-       /*
-        * Convert delayed allocate, unwritten or unmapped space
-        * to real space and flush out to disk.
-        */
-       error = xfs_page_state_convert(inode, page, wbc, 1, unmapped);
-       if (error == -EAGAIN)
-               goto out_fail;
-       if (unlikely(error < 0))
-               goto out_unlock;
-
-       return 0;
 
 out_fail:
        redirty_page_for_writepage(wbc, page);
        unlock_page(page);
        return 0;
-out_unlock:
-       unlock_page(page);
-       return error;
 }
 
 STATIC int
@@ -1413,65 +1267,27 @@ xfs_vm_writepages(
 
 /*
  * Called to move a page into cleanable state - and from there
- * to be released. Possibly the page is already clean. We always
+ * to be released. The page should already be clean. We always
  * have buffer heads in this call.
  *
- * Returns 0 if the page is ok to release, 1 otherwise.
- *
- * Possible scenarios are:
- *
- * 1. We are being called to release a page which has been written
- *    to via regular I/O. buffer heads will be dirty and possibly
- *    delalloc. If no delalloc buffer heads in this case then we
- *    can just return zero.
- *
- * 2. We are called to release a page which has been written via
- *    mmap, all we need to do is ensure there is no delalloc
- *    state in the buffer heads, if not we can let the caller
- *    free them and we should come back later via writepage.
+ * Returns 1 if the page is ok to release, 0 otherwise.
  */
 STATIC int
 xfs_vm_releasepage(
        struct page             *page,
        gfp_t                   gfp_mask)
 {
-       struct inode            *inode = page->mapping->host;
-       int                     dirty, delalloc, unmapped, unwritten;
-       struct writeback_control wbc = {
-               .sync_mode = WB_SYNC_ALL,
-               .nr_to_write = 1,
-       };
+       int                     delalloc, unwritten;
 
-       trace_xfs_releasepage(inode, page, 0);
-
-       if (!page_has_buffers(page))
-               return 0;
+       trace_xfs_releasepage(page->mapping->host, page, 0);
 
-       xfs_count_page_state(page, &delalloc, &unmapped, &unwritten);
-       if (!delalloc && !unwritten)
-               goto free_buffers;
+       xfs_count_page_state(page, &delalloc, &unwritten);
 
-       if (!(gfp_mask & __GFP_FS))
+       if (WARN_ON(delalloc))
                return 0;
-
-       /* If we are already inside a transaction or the thread cannot
-        * do I/O, we cannot release this page.
-        */
-       if (current_test_flags(PF_FSTRANS))
+       if (WARN_ON(unwritten))
                return 0;
 
-       /*
-        * Convert delalloc space to real space, do not flush the
-        * data out to disk, that will be done by the caller.
-        * Never need to allocate space here - we will always
-        * come back to writepage in that case.
-        */
-       dirty = xfs_page_state_convert(inode, page, &wbc, 0, 0);
-       if (dirty == 0 && !unwritten)
-               goto free_buffers;
-       return 0;
-
-free_buffers:
        return try_to_free_buffers(page);
 }
 
@@ -1481,9 +1297,9 @@ __xfs_get_blocks(
        sector_t                iblock,
        struct buffer_head      *bh_result,
        int                     create,
-       int                     direct,
-       bmapi_flags_t           flags)
+       int                     direct)
 {
+       int                     flags = create ? BMAPI_WRITE : BMAPI_READ;
        struct xfs_bmbt_irec    imap;
        xfs_off_t               offset;
        ssize_t                 size;
@@ -1498,8 +1314,11 @@ __xfs_get_blocks(
        if (!create && direct && offset >= i_size_read(inode))
                return 0;
 
-       error = xfs_iomap(XFS_I(inode), offset, size,
-                            create ? flags : BMAPI_READ, &imap, &nimap, &new);
+       if (direct && create)
+               flags |= BMAPI_DIRECT;
+
+       error = xfs_iomap(XFS_I(inode), offset, size, flags, &imap, &nimap,
+                         &new);
        if (error)
                return -error;
        if (nimap == 0)
@@ -1579,8 +1398,7 @@ xfs_get_blocks(
        struct buffer_head      *bh_result,
        int                     create)
 {
-       return __xfs_get_blocks(inode, iblock,
-                               bh_result, create, 0, BMAPI_WRITE);
+       return __xfs_get_blocks(inode, iblock, bh_result, create, 0);
 }
 
 STATIC int
@@ -1590,61 +1408,59 @@ xfs_get_blocks_direct(
        struct buffer_head      *bh_result,
        int                     create)
 {
-       return __xfs_get_blocks(inode, iblock,
-                               bh_result, create, 1, BMAPI_WRITE|BMAPI_DIRECT);
+       return __xfs_get_blocks(inode, iblock, bh_result, create, 1);
 }
 
+/*
+ * Complete a direct I/O write request.
+ *
+ * If the private argument is non-NULL __xfs_get_blocks signals us that we
+ * need to issue a transaction to convert the range from unwritten to written
+ * extents.  In case this is regular synchronous I/O we just call xfs_end_io
+ * to do this and we are done.  But in case this was a successfull AIO
+ * request this handler is called from interrupt context, from which we
+ * can't start transactions.  In that case offload the I/O completion to
+ * the workqueues we also use for buffered I/O completion.
+ */
 STATIC void
-xfs_end_io_direct(
-       struct kiocb    *iocb,
-       loff_t          offset,
-       ssize_t         size,
-       void            *private)
+xfs_end_io_direct_write(
+       struct kiocb            *iocb,
+       loff_t                  offset,
+       ssize_t                 size,
+       void                    *private,
+       int                     ret,
+       bool                    is_async)
 {
-       xfs_ioend_t     *ioend = iocb->private;
+       struct xfs_ioend        *ioend = iocb->private;
 
        /*
-        * Non-NULL private data means we need to issue a transaction to
-        * convert a range from unwritten to written extents.  This needs
-        * to happen from process context but aio+dio I/O completion
-        * happens from irq context so we need to defer it to a workqueue.
-        * This is not necessary for synchronous direct I/O, but we do
-        * it anyway to keep the code uniform and simpler.
-        *
-        * Well, if only it were that simple. Because synchronous direct I/O
-        * requires extent conversion to occur *before* we return to userspace,
-        * we have to wait for extent conversion to complete. Look at the
-        * iocb that has been passed to us to determine if this is AIO or
-        * not. If it is synchronous, tell xfs_finish_ioend() to kick the
-        * workqueue and wait for it to complete.
-        *
-        * The core direct I/O code might be changed to always call the
-        * completion handler in the future, in which case all this can
-        * go away.
+        * blockdev_direct_IO can return an error even after the I/O
+        * completion handler was called.  Thus we need to protect
+        * against double-freeing.
         */
+       iocb->private = NULL;
+
        ioend->io_offset = offset;
        ioend->io_size = size;
-       if (ioend->io_type == IO_READ) {
-               xfs_finish_ioend(ioend, 0);
-       } else if (private && size > 0) {
-               xfs_finish_ioend(ioend, is_sync_kiocb(iocb));
-       } else {
+       if (private && size > 0)
+               ioend->io_type = IO_UNWRITTEN;
+
+       if (is_async) {
                /*
-                * A direct I/O write ioend starts it's life in unwritten
-                * state in case they map an unwritten extent.  This write
-                * didn't map an unwritten extent so switch it's completion
-                * handler.
+                * If we are converting an unwritten extent we need to delay
+                * the AIO completion until after the unwrittent extent
+                * conversion has completed, otherwise do it ASAP.
                 */
-               ioend->io_type = IO_NEW;
-               xfs_finish_ioend(ioend, 0);
+               if (ioend->io_type == IO_UNWRITTEN) {
+                       ioend->io_iocb = iocb;
+                       ioend->io_result = ret;
+               } else {
+                       aio_complete(iocb, ret, 0);
+               }
+               xfs_finish_ioend(ioend);
+       } else {
+               xfs_finish_ioend_sync(ioend);
        }
-
-       /*
-        * blockdev_direct_IO can return an error even after the I/O
-        * completion handler was called.  Thus we need to protect
-        * against double-freeing.
-        */
-       iocb->private = NULL;
 }
 
 STATIC ssize_t
@@ -1655,23 +1471,26 @@ xfs_vm_direct_IO(
        loff_t                  offset,
        unsigned long           nr_segs)
 {
-       struct file     *file = iocb->ki_filp;
-       struct inode    *inode = file->f_mapping->host;
-       struct block_device *bdev;
-       ssize_t         ret;
-
-       bdev = xfs_find_bdev_for_inode(inode);
-
-       iocb->private = xfs_alloc_ioend(inode, rw == WRITE ?
-                                       IO_UNWRITTEN : IO_READ);
-
-       ret = blockdev_direct_IO_no_locking(rw, iocb, inode, bdev, iov,
-                                           offset, nr_segs,
-                                           xfs_get_blocks_direct,
-                                           xfs_end_io_direct);
+       struct inode            *inode = iocb->ki_filp->f_mapping->host;
+       struct block_device     *bdev = xfs_find_bdev_for_inode(inode);
+       ssize_t                 ret;
+
+       if (rw & WRITE) {
+               iocb->private = xfs_alloc_ioend(inode, IO_NEW);
+
+               ret = blockdev_direct_IO_no_locking(rw, iocb, inode, bdev, iov,
+                                                   offset, nr_segs,
+                                                   xfs_get_blocks_direct,
+                                                   xfs_end_io_direct_write);
+               if (ret != -EIOCBQUEUED && iocb->private)
+                       xfs_destroy_ioend(iocb->private);
+       } else {
+               ret = blockdev_direct_IO_no_locking(rw, iocb, inode, bdev, iov,
+                                                   offset, nr_segs,
+                                                   xfs_get_blocks_direct,
+                                                   NULL);
+       }
 
-       if (unlikely(ret != -EIOCBQUEUED && iocb->private))
-               xfs_destroy_ioend(iocb->private);
        return ret;
 }
 
@@ -1686,8 +1505,8 @@ xfs_vm_write_begin(
        void                    **fsdata)
 {
        *pagep = NULL;
-       return block_write_begin(file, mapping, pos, len, flags, pagep, fsdata,
-                                                               xfs_get_blocks);
+       return block_write_begin(file, mapping, pos, len, flags | AOP_FLAG_NOFS,
+                                pagep, fsdata, xfs_get_blocks);
 }
 
 STATIC sector_t
@@ -1698,7 +1517,7 @@ xfs_vm_bmap(
        struct inode            *inode = (struct inode *)mapping->host;
        struct xfs_inode        *ip = XFS_I(inode);
 
-       xfs_itrace_entry(XFS_I(inode));
+       trace_xfs_vm_bmap(XFS_I(inode));
        xfs_ilock(ip, XFS_IOLOCK_SHARED);
        xfs_flush_pages(ip, (xfs_off_t)0, -1, 0, FI_REMAPF);
        xfs_iunlock(ip, XFS_IOLOCK_SHARED);
index 4cfc6ea87df8c4c34564da66ee31aba497dad902..c5057fb6237a2c71bd94b5ad4abe046bf7a37e9e 100644 (file)
@@ -37,6 +37,8 @@ typedef struct xfs_ioend {
        size_t                  io_size;        /* size of the extent */
        xfs_off_t               io_offset;      /* offset in the file */
        struct work_struct      io_work;        /* xfsdatad work queue */
+       struct kiocb            *io_iocb;
+       int                     io_result;
 } xfs_ioend_t;
 
 extern const struct address_space_operations xfs_address_space_operations;
@@ -45,6 +47,6 @@ extern int xfs_get_blocks(struct inode *, sector_t, struct buffer_head *, int);
 extern void xfs_ioend_init(void);
 extern void xfs_ioend_wait(struct xfs_inode *);
 
-extern void xfs_count_page_state(struct page *, int *, int *, int *);
+extern void xfs_count_page_state(struct page *, int *, int *);
 
 #endif /* __XFS_AOPS_H__ */
index 2ee3f7a60163e899e971700aba008a243049726a..ea79072f521012549c4c2673a6210340834202a4 100644 (file)
@@ -39,7 +39,6 @@
 #include "xfs_inum.h"
 #include "xfs_log.h"
 #include "xfs_ag.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_trace.h"
 
@@ -579,9 +578,9 @@ _xfs_buf_read(
                        XBF_READ_AHEAD | _XBF_RUN_QUEUES);
 
        status = xfs_buf_iorequest(bp);
-       if (!status && !(flags & XBF_ASYNC))
-               status = xfs_buf_iowait(bp);
-       return status;
+       if (status || XFS_BUF_ISERROR(bp) || (flags & XBF_ASYNC))
+               return status;
+       return xfs_buf_iowait(bp);
 }
 
 xfs_buf_t *
@@ -897,36 +896,6 @@ xfs_buf_unlock(
        trace_xfs_buf_unlock(bp, _RET_IP_);
 }
 
-
-/*
- *     Pinning Buffer Storage in Memory
- *     Ensure that no attempt to force a buffer to disk will succeed.
- */
-void
-xfs_buf_pin(
-       xfs_buf_t               *bp)
-{
-       trace_xfs_buf_pin(bp, _RET_IP_);
-       atomic_inc(&bp->b_pin_count);
-}
-
-void
-xfs_buf_unpin(
-       xfs_buf_t               *bp)
-{
-       trace_xfs_buf_unpin(bp, _RET_IP_);
-
-       if (atomic_dec_and_test(&bp->b_pin_count))
-               wake_up_all(&bp->b_waiters);
-}
-
-int
-xfs_buf_ispin(
-       xfs_buf_t               *bp)
-{
-       return atomic_read(&bp->b_pin_count);
-}
-
 STATIC void
 xfs_buf_wait_unpin(
        xfs_buf_t               *bp)
@@ -1018,13 +987,12 @@ xfs_bwrite(
 {
        int                     error;
 
-       bp->b_strat = xfs_bdstrat_cb;
        bp->b_mount = mp;
        bp->b_flags |= XBF_WRITE;
        bp->b_flags &= ~(XBF_ASYNC | XBF_READ);
 
        xfs_buf_delwri_dequeue(bp);
-       xfs_buf_iostrategy(bp);
+       xfs_bdstrat_cb(bp);
 
        error = xfs_buf_iowait(bp);
        if (error)
@@ -1040,7 +1008,6 @@ xfs_bdwrite(
 {
        trace_xfs_buf_bdwrite(bp, _RET_IP_);
 
-       bp->b_strat = xfs_bdstrat_cb;
        bp->b_mount = mp;
 
        bp->b_flags &= ~XBF_READ;
@@ -1075,7 +1042,6 @@ xfs_bioerror(
        XFS_BUF_UNDONE(bp);
        XFS_BUF_STALE(bp);
 
-       XFS_BUF_CLR_BDSTRAT_FUNC(bp);
        xfs_biodone(bp);
 
        return EIO;
@@ -1105,7 +1071,6 @@ xfs_bioerror_relse(
        XFS_BUF_DONE(bp);
        XFS_BUF_STALE(bp);
        XFS_BUF_CLR_IODONE_FUNC(bp);
-       XFS_BUF_CLR_BDSTRAT_FUNC(bp);
        if (!(fl & XBF_ASYNC)) {
                /*
                 * Mark b_error and B_ERROR _both_.
@@ -1311,8 +1276,19 @@ submit_io:
                if (size)
                        goto next_chunk;
        } else {
-               bio_put(bio);
+               /*
+                * if we get here, no pages were added to the bio. However,
+                * we can't just error out here - if the pages are locked then
+                * we have to unlock them otherwise we can hang on a later
+                * access to the page.
+                */
                xfs_buf_ioerror(bp, EIO);
+               if (bp->b_flags & _XBF_PAGE_LOCKED) {
+                       int i;
+                       for (i = 0; i < bp->b_page_count; i++)
+                               unlock_page(bp->b_pages[i]);
+               }
+               bio_put(bio);
        }
 }
 
@@ -1804,7 +1780,7 @@ xfs_buf_delwri_split(
                trace_xfs_buf_delwri_split(bp, _RET_IP_);
                ASSERT(bp->b_flags & XBF_DELWRI);
 
-               if (!xfs_buf_ispin(bp) && !xfs_buf_cond_lock(bp)) {
+               if (!XFS_BUF_ISPINNED(bp) && !xfs_buf_cond_lock(bp)) {
                        if (!force &&
                            time_before(jiffies, bp->b_queuetime + age)) {
                                xfs_buf_unlock(bp);
@@ -1889,7 +1865,7 @@ xfsbufd(
                        struct xfs_buf *bp;
                        bp = list_first_entry(&tmp, struct xfs_buf, b_list);
                        list_del_init(&bp->b_list);
-                       xfs_buf_iostrategy(bp);
+                       xfs_bdstrat_cb(bp);
                        count++;
                }
                if (count)
@@ -1936,7 +1912,7 @@ xfs_flush_buftarg(
                        bp->b_flags &= ~XBF_ASYNC;
                        list_add(&bp->b_list, &wait_list);
                }
-               xfs_buf_iostrategy(bp);
+               xfs_bdstrat_cb(bp);
        }
 
        if (wait) {
index 5fbecefa5dfd69a9807cad3a4f4d786e579d0062..d072e5ff923b3e71eac4000bd432cd84d72e0d9b 100644 (file)
@@ -44,57 +44,57 @@ typedef enum {
        XBRW_ZERO = 3,                  /* Zero target memory */
 } xfs_buf_rw_t;
 
-typedef enum {
-       XBF_READ = (1 << 0),    /* buffer intended for reading from device */
-       XBF_WRITE = (1 << 1),   /* buffer intended for writing to device   */
-       XBF_MAPPED = (1 << 2),  /* buffer mapped (b_addr valid)            */
-       XBF_ASYNC = (1 << 4),   /* initiator will not wait for completion  */
-       XBF_DONE = (1 << 5),    /* all pages in the buffer uptodate        */
-       XBF_DELWRI = (1 << 6),  /* buffer has dirty pages                  */
-       XBF_STALE = (1 << 7),   /* buffer has been staled, do not find it  */
-       XBF_FS_MANAGED = (1 << 8),  /* filesystem controls freeing memory  */
-       XBF_ORDERED = (1 << 11),    /* use ordered writes                  */
-       XBF_READ_AHEAD = (1 << 12), /* asynchronous read-ahead             */
-       XBF_LOG_BUFFER = (1 << 13), /* this is a buffer used for the log   */
-
-       /* flags used only as arguments to access routines */
-       XBF_LOCK = (1 << 14),       /* lock requested                      */
-       XBF_TRYLOCK = (1 << 15),    /* lock requested, but do not wait     */
-       XBF_DONT_BLOCK = (1 << 16), /* do not block in current thread      */
-
-       /* flags used only internally */
-       _XBF_PAGE_CACHE = (1 << 17),/* backed by pagecache                 */
-       _XBF_PAGES = (1 << 18),     /* backed by refcounted pages          */
-       _XBF_RUN_QUEUES = (1 << 19),/* run block device task queue         */
-       _XBF_DELWRI_Q = (1 << 21),   /* buffer on delwri queue             */
-
-       /*
-        * Special flag for supporting metadata blocks smaller than a FSB.
-        *
-        * In this case we can have multiple xfs_buf_t on a single page and
-        * need to lock out concurrent xfs_buf_t readers as they only
-        * serialise access to the buffer.
-        *
-        * If the FSB size >= PAGE_CACHE_SIZE case, we have no serialisation
-        * between reads of the page. Hence we can have one thread read the
-        * page and modify it, but then race with another thread that thinks
-        * the page is not up-to-date and hence reads it again.
-        *
-        * The result is that the first modifcation to the page is lost.
-        * This sort of AGF/AGI reading race can happen when unlinking inodes
-        * that require truncation and results in the AGI unlinked list
-        * modifications being lost.
-        */
-       _XBF_PAGE_LOCKED = (1 << 22),
-
-       /*
-        * If we try a barrier write, but it fails we have to communicate
-        * this to the upper layers.  Unfortunately b_error gets overwritten
-        * when the buffer is re-issued so we have to add another flag to
-        * keep this information.
-        */
-       _XFS_BARRIER_FAILED = (1 << 23),
-} xfs_buf_flags_t;
+#define XBF_READ       (1 << 0) /* buffer intended for reading from device */
+#define XBF_WRITE      (1 << 1) /* buffer intended for writing to device */
+#define XBF_MAPPED     (1 << 2) /* buffer mapped (b_addr valid) */
+#define XBF_ASYNC      (1 << 4) /* initiator will not wait for completion */
+#define XBF_DONE       (1 << 5) /* all pages in the buffer uptodate */
+#define XBF_DELWRI     (1 << 6) /* buffer has dirty pages */
+#define XBF_STALE      (1 << 7) /* buffer has been staled, do not find it */
+#define XBF_FS_MANAGED (1 << 8) /* filesystem controls freeing memory */
+#define XBF_ORDERED    (1 << 11)/* use ordered writes */
+#define XBF_READ_AHEAD (1 << 12)/* asynchronous read-ahead */
+#define XBF_LOG_BUFFER (1 << 13)/* this is a buffer used for the log */
+
+/* flags used only as arguments to access routines */
+#define XBF_LOCK       (1 << 14)/* lock requested */
+#define XBF_TRYLOCK    (1 << 15)/* lock requested, but do not wait */
+#define XBF_DONT_BLOCK (1 << 16)/* do not block in current thread */
+
+/* flags used only internally */
+#define _XBF_PAGE_CACHE        (1 << 17)/* backed by pagecache */
+#define _XBF_PAGES     (1 << 18)/* backed by refcounted pages */
+#define        _XBF_RUN_QUEUES (1 << 19)/* run block device task queue */
+#define _XBF_DELWRI_Q  (1 << 21)/* buffer on delwri queue */
+
+/*
+ * Special flag for supporting metadata blocks smaller than a FSB.
+ *
+ * In this case we can have multiple xfs_buf_t on a single page and
+ * need to lock out concurrent xfs_buf_t readers as they only
+ * serialise access to the buffer.
+ *
+ * If the FSB size >= PAGE_CACHE_SIZE case, we have no serialisation
+ * between reads of the page. Hence we can have one thread read the
+ * page and modify it, but then race with another thread that thinks
+ * the page is not up-to-date and hence reads it again.
+ *
+ * The result is that the first modifcation to the page is lost.
+ * This sort of AGF/AGI reading race can happen when unlinking inodes
+ * that require truncation and results in the AGI unlinked list
+ * modifications being lost.
+ */
+#define _XBF_PAGE_LOCKED       (1 << 22)
+
+/*
+ * If we try a barrier write, but it fails we have to communicate
+ * this to the upper layers.  Unfortunately b_error gets overwritten
+ * when the buffer is re-issued so we have to add another flag to
+ * keep this information.
+ */
+#define _XFS_BARRIER_FAILED    (1 << 23)
+
+typedef unsigned int xfs_buf_flags_t;
 
 #define XFS_BUF_FLAGS \
        { XBF_READ,             "READ" }, \
@@ -187,7 +187,6 @@ typedef struct xfs_buf {
        atomic_t                b_io_remaining; /* #outstanding I/O requests */
        xfs_buf_iodone_t        b_iodone;       /* I/O completion function */
        xfs_buf_relse_t         b_relse;        /* releasing function */
-       xfs_buf_bdstrat_t       b_strat;        /* pre-write function */
        struct completion       b_iowait;       /* queue for I/O waiters */
        void                    *b_fspriv;
        void                    *b_fspriv2;
@@ -245,11 +244,6 @@ extern int xfs_buf_iowait(xfs_buf_t *);
 extern void xfs_buf_iomove(xfs_buf_t *, size_t, size_t, void *,
                                xfs_buf_rw_t);
 
-static inline int xfs_buf_iostrategy(xfs_buf_t *bp)
-{
-       return bp->b_strat ? bp->b_strat(bp) : xfs_buf_iorequest(bp);
-}
-
 static inline int xfs_buf_geterror(xfs_buf_t *bp)
 {
        return bp ? bp->b_error : ENOMEM;
@@ -258,11 +252,6 @@ static inline int xfs_buf_geterror(xfs_buf_t *bp)
 /* Buffer Utility Routines */
 extern xfs_caddr_t xfs_buf_offset(xfs_buf_t *, size_t);
 
-/* Pinning Buffer Storage in Memory */
-extern void xfs_buf_pin(xfs_buf_t *);
-extern void xfs_buf_unpin(xfs_buf_t *);
-extern int xfs_buf_ispin(xfs_buf_t *);
-
 /* Delayed Write Buffer Routines */
 extern void xfs_buf_delwri_dequeue(xfs_buf_t *);
 extern void xfs_buf_delwri_promote(xfs_buf_t *);
@@ -326,8 +315,6 @@ extern void xfs_buf_terminate(void);
 #define XFS_BUF_IODONE_FUNC(bp)                        ((bp)->b_iodone)
 #define XFS_BUF_SET_IODONE_FUNC(bp, func)      ((bp)->b_iodone = (func))
 #define XFS_BUF_CLR_IODONE_FUNC(bp)            ((bp)->b_iodone = NULL)
-#define XFS_BUF_SET_BDSTRAT_FUNC(bp, func)     ((bp)->b_strat = (func))
-#define XFS_BUF_CLR_BDSTRAT_FUNC(bp)           ((bp)->b_strat = NULL)
 
 #define XFS_BUF_FSPRIVATE(bp, type)            ((type)(bp)->b_fspriv)
 #define XFS_BUF_SET_FSPRIVATE(bp, val)         ((bp)->b_fspriv = (void*)(val))
@@ -351,7 +338,7 @@ extern void xfs_buf_terminate(void);
 #define XFS_BUF_SET_VTYPE(bp, type)            do { } while (0)
 #define XFS_BUF_SET_REF(bp, ref)               do { } while (0)
 
-#define XFS_BUF_ISPINNED(bp)   xfs_buf_ispin(bp)
+#define XFS_BUF_ISPINNED(bp)   atomic_read(&((bp)->b_pin_count))
 
 #define XFS_BUF_VALUSEMA(bp)   xfs_buf_lock_value(bp)
 #define XFS_BUF_CPSEMA(bp)     (xfs_buf_cond_lock(bp) == 0)
@@ -370,8 +357,6 @@ static inline void xfs_buf_relse(xfs_buf_t *bp)
        xfs_buf_rele(bp);
 }
 
-#define xfs_bpin(bp)           xfs_buf_pin(bp)
-#define xfs_bunpin(bp)         xfs_buf_unpin(bp)
 #define xfs_biodone(bp)                xfs_buf_ioend(bp, 0)
 
 #define xfs_biomove(bp, off, len, data, rw) \
diff --git a/fs/xfs/linux-2.6/xfs_dmapi_priv.h b/fs/xfs/linux-2.6/xfs_dmapi_priv.h
deleted file mode 100644 (file)
index a8b0b16..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Copyright (c) 2000-2006 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * 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.
- *
- * This program is distributed in the hope that it would 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 the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-#ifndef __XFS_DMAPI_PRIV_H__
-#define __XFS_DMAPI_PRIV_H__
-
-/*
- *     Based on IO_ISDIRECT, decide which i_ flag is set.
- */
-#define DM_SEM_FLAG_RD(ioflags) (((ioflags) & IO_ISDIRECT) ? \
-                             DM_FLAGS_IMUX : 0)
-#define DM_SEM_FLAG_WR (DM_FLAGS_IALLOCSEM_WR | DM_FLAGS_IMUX)
-
-#endif /*__XFS_DMAPI_PRIV_H__*/
index e7839ee49e43656d0d1edfa7011ce8d9eb0e97b2..3764d74790ecc5c8dc5301e36dd1605f5af045e8 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_export.h"
 #include "xfs_vnodeops.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
+#include "xfs_trace.h"
 
 /*
  * Note that we only accept fileids which are long enough rather than allow
@@ -132,8 +132,7 @@ xfs_nfs_get_inode(
         * fine and not an indication of a corrupted filesystem as clients can
         * send invalid file handles and we have to handle it gracefully..
         */
-       error = xfs_iget(mp, NULL, ino, XFS_IGET_UNTRUSTED,
-                        XFS_ILOCK_SHARED, &ip);
+       error = xfs_iget(mp, NULL, ino, XFS_IGET_UNTRUSTED, 0, &ip);
        if (error) {
                /*
                 * EINVAL means the inode cluster doesn't exist anymore.
@@ -148,11 +147,10 @@ xfs_nfs_get_inode(
        }
 
        if (ip->i_d.di_gen != generation) {
-               xfs_iput_new(ip, XFS_ILOCK_SHARED);
+               IRELE(ip);
                return ERR_PTR(-ENOENT);
        }
 
-       xfs_iunlock(ip, XFS_ILOCK_SHARED);
        return VFS_I(ip);
 }
 
index 257a56b127cf060013569a211de51efd7f2b1306..ba8ad422a16506fdea605c7a215e572b3b3a8f6a 100644 (file)
 #include "xfs_inum.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_trans.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
 #include "xfs_alloc.h"
-#include "xfs_btree.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dir2_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
 #include "xfs_bmap.h"
 #include "xfs_error.h"
-#include "xfs_rw.h"
 #include "xfs_vnodeops.h"
 #include "xfs_da_btree.h"
 #include "xfs_ioctl.h"
@@ -108,7 +100,7 @@ xfs_file_fsync(
        int                     error = 0;
        int                     log_flushed = 0;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_file_fsync(ip);
 
        if (XFS_FORCED_SHUTDOWN(ip->i_mount))
                return -XFS_ERROR(EIO);
@@ -166,8 +158,7 @@ xfs_file_fsync(
                 * transaction.  So we play it safe and fire off the
                 * transaction anyway.
                 */
-               xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
                xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
                xfs_trans_set_sync(tp);
                error = _xfs_trans_commit(tp, 0, &log_flushed);
@@ -275,20 +266,6 @@ xfs_file_aio_read(
                mutex_lock(&inode->i_mutex);
        xfs_ilock(ip, XFS_IOLOCK_SHARED);
 
-       if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
-               int dmflags = FILP_DELAY_FLAG(file) | DM_SEM_FLAG_RD(ioflags);
-               int iolock = XFS_IOLOCK_SHARED;
-
-               ret = -XFS_SEND_DATA(mp, DM_EVENT_READ, ip, iocb->ki_pos, size,
-                                       dmflags, &iolock);
-               if (ret) {
-                       xfs_iunlock(ip, XFS_IOLOCK_SHARED);
-                       if (unlikely(ioflags & IO_ISDIRECT))
-                               mutex_unlock(&inode->i_mutex);
-                       return ret;
-               }
-       }
-
        if (unlikely(ioflags & IO_ISDIRECT)) {
                if (inode->i_mapping->nrpages) {
                        ret = -xfs_flushinval_pages(ip,
@@ -321,7 +298,6 @@ xfs_file_splice_read(
        unsigned int            flags)
 {
        struct xfs_inode        *ip = XFS_I(infilp->f_mapping->host);
-       struct xfs_mount        *mp = ip->i_mount;
        int                     ioflags = 0;
        ssize_t                 ret;
 
@@ -335,18 +311,6 @@ xfs_file_splice_read(
 
        xfs_ilock(ip, XFS_IOLOCK_SHARED);
 
-       if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) && !(ioflags & IO_INVIS)) {
-               int iolock = XFS_IOLOCK_SHARED;
-               int error;
-
-               error = XFS_SEND_DATA(mp, DM_EVENT_READ, ip, *ppos, count,
-                                       FILP_DELAY_FLAG(infilp), &iolock);
-               if (error) {
-                       xfs_iunlock(ip, XFS_IOLOCK_SHARED);
-                       return -error;
-               }
-       }
-
        trace_xfs_file_splice_read(ip, count, *ppos, ioflags);
 
        ret = generic_file_splice_read(infilp, ppos, pipe, count, flags);
@@ -367,7 +331,6 @@ xfs_file_splice_write(
 {
        struct inode            *inode = outfilp->f_mapping->host;
        struct xfs_inode        *ip = XFS_I(inode);
-       struct xfs_mount        *mp = ip->i_mount;
        xfs_fsize_t             isize, new_size;
        int                     ioflags = 0;
        ssize_t                 ret;
@@ -382,18 +345,6 @@ xfs_file_splice_write(
 
        xfs_ilock(ip, XFS_IOLOCK_EXCL);
 
-       if (DM_EVENT_ENABLED(ip, DM_EVENT_WRITE) && !(ioflags & IO_INVIS)) {
-               int iolock = XFS_IOLOCK_EXCL;
-               int error;
-
-               error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip, *ppos, count,
-                                       FILP_DELAY_FLAG(outfilp), &iolock);
-               if (error) {
-                       xfs_iunlock(ip, XFS_IOLOCK_EXCL);
-                       return -error;
-               }
-       }
-
        new_size = *ppos + count;
 
        xfs_ilock(ip, XFS_ILOCK_EXCL);
@@ -463,7 +414,7 @@ xfs_zero_last_block(
        last_fsb = XFS_B_TO_FSBT(mp, isize);
        nimaps = 1;
        error = xfs_bmapi(NULL, ip, last_fsb, 1, 0, NULL, 0, &imap,
-                         &nimaps, NULL, NULL);
+                         &nimaps, NULL);
        if (error) {
                return error;
        }
@@ -558,7 +509,7 @@ xfs_zero_eof(
                nimaps = 1;
                zero_count_fsb = end_zero_fsb - start_zero_fsb + 1;
                error = xfs_bmapi(NULL, ip, start_zero_fsb, zero_count_fsb,
-                                 0, NULL, 0, &imap, &nimaps, NULL, NULL);
+                                 0, NULL, 0, &imap, &nimaps, NULL);
                if (error) {
                        ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL|XFS_IOLOCK_EXCL));
                        return error;
@@ -627,7 +578,6 @@ xfs_file_aio_write(
        int                     ioflags = 0;
        xfs_fsize_t             isize, new_size;
        int                     iolock;
-       int                     eventsent = 0;
        size_t                  ocount = 0, count;
        int                     need_i_mutex;
 
@@ -673,33 +623,6 @@ start:
                goto out_unlock_mutex;
        }
 
-       if ((DM_EVENT_ENABLED(ip, DM_EVENT_WRITE) &&
-           !(ioflags & IO_INVIS) && !eventsent)) {
-               int             dmflags = FILP_DELAY_FLAG(file);
-
-               if (need_i_mutex)
-                       dmflags |= DM_FLAGS_IMUX;
-
-               xfs_iunlock(ip, XFS_ILOCK_EXCL);
-               error = XFS_SEND_DATA(ip->i_mount, DM_EVENT_WRITE, ip,
-                                     pos, count, dmflags, &iolock);
-               if (error) {
-                       goto out_unlock_internal;
-               }
-               xfs_ilock(ip, XFS_ILOCK_EXCL);
-               eventsent = 1;
-
-               /*
-                * The iolock was dropped and reacquired in XFS_SEND_DATA
-                * so we have to recheck the size when appending.
-                * We will only "goto start;" once, since having sent the
-                * event prevents another call to XFS_SEND_DATA, which is
-                * what allows the size to change in the first place.
-                */
-               if ((file->f_flags & O_APPEND) && pos != ip->i_size)
-                       goto start;
-       }
-
        if (ioflags & IO_ISDIRECT) {
                xfs_buftarg_t   *target =
                        XFS_IS_REALTIME_INODE(ip) ?
@@ -830,22 +753,6 @@ write_retry:
                xfs_iunlock(ip, XFS_ILOCK_EXCL);
        }
 
-       if (ret == -ENOSPC &&
-           DM_EVENT_ENABLED(ip, DM_EVENT_NOSPACE) && !(ioflags & IO_INVIS)) {
-               xfs_iunlock(ip, iolock);
-               if (need_i_mutex)
-                       mutex_unlock(&inode->i_mutex);
-               error = XFS_SEND_NAMESP(ip->i_mount, DM_EVENT_NOSPACE, ip,
-                               DM_RIGHT_NULL, ip, DM_RIGHT_NULL, NULL, NULL,
-                               0, 0, 0); /* Delay flag intentionally  unused */
-               if (need_i_mutex)
-                       mutex_lock(&inode->i_mutex);
-               xfs_ilock(ip, iolock);
-               if (error)
-                       goto out_unlock_internal;
-               goto start;
-       }
-
        error = -ret;
        if (ret <= 0)
                goto out_unlock_internal;
@@ -1014,9 +921,6 @@ const struct file_operations xfs_file_operations = {
        .open           = xfs_file_open,
        .release        = xfs_file_release,
        .fsync          = xfs_file_fsync,
-#ifdef HAVE_FOP_OPEN_EXEC
-       .open_exec      = xfs_file_open_exec,
-#endif
 };
 
 const struct file_operations xfs_dir_file_operations = {
index b6918d76bc7bbdf9740a07955c0e1694a6bf9825..1f279b012f94be7fd4ef2f5fbf084b89921804c1 100644 (file)
 #include "xfs_inode.h"
 #include "xfs_trace.h"
 
-int  fs_noerr(void) { return 0; }
-int  fs_nosys(void) { return ENOSYS; }
-void fs_noval(void) { return; }
-
 /*
  * note: all filemap functions return negative error codes. These
  * need to be inverted before returning to the xfs core functions.
diff --git a/fs/xfs/linux-2.6/xfs_fs_subr.h b/fs/xfs/linux-2.6/xfs_fs_subr.h
deleted file mode 100644 (file)
index 82bb19b..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-/*
- * Copyright (c) 2000,2002,2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * 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.
- *
- * This program is distributed in the hope that it would 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 the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-#ifndef        __XFS_FS_SUBR_H__
-#define __XFS_FS_SUBR_H__
-
-extern int  fs_noerr(void);
-extern int  fs_nosys(void);
-extern void fs_noval(void);
-
-#endif /* __XFS_FS_SUBR_H__ */
index e59a8106283069b24bb9fb4b5f0ea5bec92d8ede..237f5ffb2ee8ca067f6dc81ebc38a6de1f7b36ce 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dir2_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_ioctl.h"
-#include "xfs_btree.h"
-#include "xfs_ialloc.h"
 #include "xfs_rtalloc.h"
 #include "xfs_itable.h"
 #include "xfs_error.h"
-#include "xfs_rw.h"
 #include "xfs_attr.h"
 #include "xfs_bmap.h"
 #include "xfs_buf_item.h"
@@ -908,7 +899,7 @@ xfs_ioctl_setattr(
        struct xfs_dquot        *olddquot = NULL;
        int                     code;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_ioctl_setattr(ip);
 
        if (mp->m_flags & XFS_MOUNT_RDONLY)
                return XFS_ERROR(EROFS);
@@ -1043,8 +1034,7 @@ xfs_ioctl_setattr(
                }
        }
 
-       xfs_trans_ijoin(tp, ip, lock_flags);
-       xfs_trans_ihold(tp, ip);
+       xfs_trans_ijoin(tp, ip);
 
        /*
         * Change file ownership.  Must be the owner or privileged.
@@ -1116,16 +1106,7 @@ xfs_ioctl_setattr(
        xfs_qm_dqrele(udqp);
        xfs_qm_dqrele(gdqp);
 
-       if (code)
-               return code;
-
-       if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE)) {
-               XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL,
-                               NULL, DM_RIGHT_NULL, NULL, NULL, 0, 0,
-                               (mask & FSX_NONBLOCK) ? DM_FLAGS_NDELAY : 0);
-       }
-
-       return 0;
+       return code;
 
  error_return:
        xfs_qm_dqrele(udqp);
@@ -1301,7 +1282,7 @@ xfs_file_ioctl(
        if (filp->f_mode & FMODE_NOCMTIME)
                ioflags |= IO_INVIS;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_file_ioctl(ip);
 
        switch (cmd) {
        case XFS_IOC_ALLOCSP:
index 52ed49e6465cff0eee12844c13b169583cc1411c..6c83f7f62dc99ca29d5597aad61c97b432ec19ed 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dir2_sf.h"
 #include "xfs_vnode.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
@@ -544,7 +540,7 @@ xfs_file_compat_ioctl(
        if (filp->f_mode & FMODE_NOCMTIME)
                ioflags |= IO_INVIS;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_file_compat_ioctl(ip);
 
        switch (cmd) {
        /* No size or alignment issues on any arch */
index 44f0b2de153eb6c4cf77b36c54278f36166d59ba..536b81e63a3d8e397d8e487192f938809ee26923 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_bmap.h"
-#include "xfs_btree.h"
-#include "xfs_ialloc.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
 #include "xfs_itable.h"
@@ -496,7 +488,7 @@ xfs_vn_getattr(
        struct xfs_inode        *ip = XFS_I(inode);
        struct xfs_mount        *mp = ip->i_mount;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_getattr(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
index facfb323a706a914de84de68b504762c82f05d6c..998a9d7fb9c8964d2174f62f935f6fd46b4f2042 100644 (file)
@@ -87,7 +87,6 @@
 #include <xfs_aops.h>
 #include <xfs_super.h>
 #include <xfs_globals.h>
-#include <xfs_fs_subr.h>
 #include <xfs_buf.h>
 
 /*
index 067cafbfc6357fee83a5adbf265e74ab93eeb999..bfd5ac9d1f6f774c49a58588ecc3d6f881bb04aa 100644 (file)
@@ -16,7 +16,6 @@
  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  */
 #include "xfs.h"
-#include "xfs_dmapi.h"
 #include "xfs_sb.h"
 #include "xfs_inum.h"
 #include "xfs_log.h"
index 80938c736c2769861327ea10368cd0c20d4ceb51..758df94690edc7ab8663933b289b6c17e82d7289 100644 (file)
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
@@ -43,7 +40,6 @@
 #include "xfs_error.h"
 #include "xfs_itable.h"
 #include "xfs_fsops.h"
-#include "xfs_rw.h"
 #include "xfs_attr.h"
 #include "xfs_buf_item.h"
 #include "xfs_utils.h"
@@ -94,7 +90,6 @@ mempool_t *xfs_ioend_pool;
 #define MNTOPT_BARRIER "barrier"       /* use writer barriers for log write and
                                         * unwritten extent conversion */
 #define MNTOPT_NOBARRIER "nobarrier"   /* .. disable */
-#define MNTOPT_OSYNCISOSYNC "osyncisosync" /* o_sync is REALLY o_sync */
 #define MNTOPT_64BITINODE   "inode64"  /* inodes can be allocated anywhere */
 #define MNTOPT_IKEEP   "ikeep"         /* do not free empty inode clusters */
 #define MNTOPT_NOIKEEP "noikeep"       /* free empty inode clusters */
@@ -116,9 +111,6 @@ mempool_t *xfs_ioend_pool;
 #define MNTOPT_GQUOTANOENF "gqnoenforce"/* group quota limit enforcement */
 #define MNTOPT_PQUOTANOENF "pqnoenforce"/* project quota limit enforcement */
 #define MNTOPT_QUOTANOENF  "qnoenforce"        /* same as uqnoenforce */
-#define MNTOPT_DMAPI   "dmapi"         /* DMI enabled (DMAPI / XDSM) */
-#define MNTOPT_XDSM    "xdsm"          /* DMI enabled (DMAPI / XDSM) */
-#define MNTOPT_DMI     "dmi"           /* DMI enabled (DMAPI / XDSM) */
 #define MNTOPT_DELAYLOG   "delaylog"   /* Delayed loging enabled */
 #define MNTOPT_NODELAYLOG "nodelaylog" /* Delayed loging disabled */
 
@@ -172,15 +164,13 @@ suffix_strtoul(char *s, char **endp, unsigned int base)
 STATIC int
 xfs_parseargs(
        struct xfs_mount        *mp,
-       char                    *options,
-       char                    **mtpt)
+       char                    *options)
 {
        struct super_block      *sb = mp->m_super;
        char                    *this_char, *value, *eov;
        int                     dsunit = 0;
        int                     dswidth = 0;
        int                     iosize = 0;
-       int                     dmapi_implies_ikeep = 1;
        __uint8_t               iosizelog = 0;
 
        /*
@@ -243,15 +233,10 @@ xfs_parseargs(
                        if (!mp->m_logname)
                                return ENOMEM;
                } else if (!strcmp(this_char, MNTOPT_MTPT)) {
-                       if (!value || !*value) {
-                               cmn_err(CE_WARN,
-                                       "XFS: %s option requires an argument",
-                                       this_char);
-                               return EINVAL;
-                       }
-                       *mtpt = kstrndup(value, MAXNAMELEN, GFP_KERNEL);
-                       if (!*mtpt)
-                               return ENOMEM;
+                       cmn_err(CE_WARN,
+                               "XFS: %s option not allowed on this system",
+                               this_char);
+                       return EINVAL;
                } else if (!strcmp(this_char, MNTOPT_RTDEV)) {
                        if (!value || !*value) {
                                cmn_err(CE_WARN,
@@ -288,8 +273,6 @@ xfs_parseargs(
                        mp->m_flags &= ~XFS_MOUNT_GRPID;
                } else if (!strcmp(this_char, MNTOPT_WSYNC)) {
                        mp->m_flags |= XFS_MOUNT_WSYNC;
-               } else if (!strcmp(this_char, MNTOPT_OSYNCISOSYNC)) {
-                       mp->m_flags |= XFS_MOUNT_OSYNCISOSYNC;
                } else if (!strcmp(this_char, MNTOPT_NORECOVERY)) {
                        mp->m_flags |= XFS_MOUNT_NORECOVERY;
                } else if (!strcmp(this_char, MNTOPT_NOALIGN)) {
@@ -329,7 +312,6 @@ xfs_parseargs(
                } else if (!strcmp(this_char, MNTOPT_IKEEP)) {
                        mp->m_flags |= XFS_MOUNT_IKEEP;
                } else if (!strcmp(this_char, MNTOPT_NOIKEEP)) {
-                       dmapi_implies_ikeep = 0;
                        mp->m_flags &= ~XFS_MOUNT_IKEEP;
                } else if (!strcmp(this_char, MNTOPT_LARGEIO)) {
                        mp->m_flags &= ~XFS_MOUNT_COMPAT_IOSIZE;
@@ -370,12 +352,6 @@ xfs_parseargs(
                } else if (!strcmp(this_char, MNTOPT_GQUOTANOENF)) {
                        mp->m_qflags |= (XFS_GQUOTA_ACCT | XFS_GQUOTA_ACTIVE);
                        mp->m_qflags &= ~XFS_OQUOTA_ENFD;
-               } else if (!strcmp(this_char, MNTOPT_DMAPI)) {
-                       mp->m_flags |= XFS_MOUNT_DMAPI;
-               } else if (!strcmp(this_char, MNTOPT_XDSM)) {
-                       mp->m_flags |= XFS_MOUNT_DMAPI;
-               } else if (!strcmp(this_char, MNTOPT_DMI)) {
-                       mp->m_flags |= XFS_MOUNT_DMAPI;
                } else if (!strcmp(this_char, MNTOPT_DELAYLOG)) {
                        mp->m_flags |= XFS_MOUNT_DELAYLOG;
                        cmn_err(CE_WARN,
@@ -387,9 +363,11 @@ xfs_parseargs(
                        cmn_err(CE_WARN,
        "XFS: ihashsize no longer used, option is deprecated.");
                } else if (!strcmp(this_char, "osyncisdsync")) {
-                       /* no-op, this is now the default */
                        cmn_err(CE_WARN,
-       "XFS: osyncisdsync is now the default, option is deprecated.");
+       "XFS: osyncisdsync has no effect, option is deprecated.");
+               } else if (!strcmp(this_char, "osyncisosync")) {
+                       cmn_err(CE_WARN,
+       "XFS: osyncisosync has no effect, option is deprecated.");
                } else if (!strcmp(this_char, "irixsgid")) {
                        cmn_err(CE_WARN,
        "XFS: irixsgid is now a sysctl(2) variable, option is deprecated.");
@@ -430,12 +408,6 @@ xfs_parseargs(
                return EINVAL;
        }
 
-       if ((mp->m_flags & XFS_MOUNT_DMAPI) && (!*mtpt || *mtpt[0] == '\0')) {
-               printk("XFS: %s option needs the mount point option as well\n",
-                       MNTOPT_DMAPI);
-               return EINVAL;
-       }
-
        if ((dsunit && !dswidth) || (!dsunit && dswidth)) {
                cmn_err(CE_WARN,
                        "XFS: sunit and swidth must be specified together");
@@ -449,18 +421,6 @@ xfs_parseargs(
                return EINVAL;
        }
 
-       /*
-        * Applications using DMI filesystems often expect the
-        * inode generation number to be monotonically increasing.
-        * If we delete inode chunks we break this assumption, so
-        * keep unused inode chunks on disk for DMI filesystems
-        * until we come up with a better solution.
-        * Note that if "ikeep" or "noikeep" mount options are
-        * supplied, then they are honored.
-        */
-       if ((mp->m_flags & XFS_MOUNT_DMAPI) && dmapi_implies_ikeep)
-               mp->m_flags |= XFS_MOUNT_IKEEP;
-
 done:
        if (!(mp->m_flags & XFS_MOUNT_NOALIGN)) {
                /*
@@ -539,10 +499,8 @@ xfs_showargs(
                { XFS_MOUNT_SWALLOC,            "," MNTOPT_SWALLOC },
                { XFS_MOUNT_NOUUID,             "," MNTOPT_NOUUID },
                { XFS_MOUNT_NORECOVERY,         "," MNTOPT_NORECOVERY },
-               { XFS_MOUNT_OSYNCISOSYNC,       "," MNTOPT_OSYNCISOSYNC },
                { XFS_MOUNT_ATTR2,              "," MNTOPT_ATTR2 },
                { XFS_MOUNT_FILESTREAMS,        "," MNTOPT_FILESTREAM },
-               { XFS_MOUNT_DMAPI,              "," MNTOPT_DMAPI },
                { XFS_MOUNT_GRPID,              "," MNTOPT_GRPID },
                { XFS_MOUNT_DELAYLOG,           "," MNTOPT_DELAYLOG },
                { 0, NULL }
@@ -947,7 +905,7 @@ xfs_fs_destroy_inode(
 {
        struct xfs_inode        *ip = XFS_I(inode);
 
-       xfs_itrace_entry(ip);
+       trace_xfs_destroy_inode(ip);
 
        XFS_STATS_INC(vn_reclaim);
 
@@ -1063,10 +1021,8 @@ xfs_log_inode(
         * an inode in another recent transaction.  So we play it safe and
         * fire off the transaction anyway.
         */
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
+       xfs_trans_ijoin(tp, ip);
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
-       xfs_trans_set_sync(tp);
        error = xfs_trans_commit(tp, 0);
        xfs_ilock_demote(ip, XFS_ILOCK_EXCL);
 
@@ -1082,27 +1038,18 @@ xfs_fs_write_inode(
        struct xfs_mount        *mp = ip->i_mount;
        int                     error = EAGAIN;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_write_inode(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
        if (wbc->sync_mode == WB_SYNC_ALL) {
                /*
-                * Make sure the inode has hit stable storage.  By using the
-                * log and the fsync transactions we reduce the IOs we have
-                * to do here from two (log and inode) to just the log.
-                *
-                * Note: We still need to do a delwri write of the inode after
-                * this to flush it to the backing buffer so that bulkstat
-                * works properly if this is the first time the inode has been
-                * written.  Because we hold the ilock atomically over the
-                * transaction commit and the inode flush we are guaranteed
-                * that the inode is not pinned when it returns. If the flush
-                * lock is already held, then the inode has already been
-                * flushed once and we don't need to flush it again.  Hence
-                * the code will only flush the inode if it isn't already
-                * being flushed.
+                * Make sure the inode has made it it into the log.  Instead
+                * of forcing it all the way to stable storage using a
+                * synchronous transaction we let the log force inside the
+                * ->sync_fs call do that for thus, which reduces the number
+                * of synchronous log foces dramatically.
                 */
                xfs_ioend_wait(ip);
                xfs_ilock(ip, XFS_ILOCK_SHARED);
@@ -1116,27 +1063,29 @@ xfs_fs_write_inode(
                 * We make this non-blocking if the inode is contended, return
                 * EAGAIN to indicate to the caller that they did not succeed.
                 * This prevents the flush path from blocking on inodes inside
-                * another operation right now, they get caught later by xfs_sync.
+                * another operation right now, they get caught later by
+                * xfs_sync.
                 */
                if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
                        goto out;
-       }
 
-       if (xfs_ipincount(ip) || !xfs_iflock_nowait(ip))
-               goto out_unlock;
+               if (xfs_ipincount(ip) || !xfs_iflock_nowait(ip))
+                       goto out_unlock;
 
-       /*
-        * Now we have the flush lock and the inode is not pinned, we can check
-        * if the inode is really clean as we know that there are no pending
-        * transaction completions, it is not waiting on the delayed write
-        * queue and there is no IO in progress.
-        */
-       if (xfs_inode_clean(ip)) {
-               xfs_ifunlock(ip);
-               error = 0;
-               goto out_unlock;
+               /*
+                * Now we have the flush lock and the inode is not pinned, we
+                * can check if the inode is really clean as we know that
+                * there are no pending transaction completions, it is not
+                * waiting on the delayed write queue and there is no IO in
+                * progress.
+                */
+               if (xfs_inode_clean(ip)) {
+                       xfs_ifunlock(ip);
+                       error = 0;
+                       goto out_unlock;
+               }
+               error = xfs_iflush(ip, 0);
        }
-       error = xfs_iflush(ip, 0);
 
  out_unlock:
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
@@ -1156,7 +1105,8 @@ xfs_fs_clear_inode(
 {
        xfs_inode_t             *ip = XFS_I(inode);
 
-       xfs_itrace_entry(ip);
+       trace_xfs_clear_inode(ip);
+
        XFS_STATS_INC(vn_rele);
        XFS_STATS_INC(vn_remove);
        XFS_STATS_DEC(vn_active);
@@ -1193,22 +1143,13 @@ xfs_fs_put_super(
 {
        struct xfs_mount        *mp = XFS_M(sb);
 
+       /*
+        * Unregister the memory shrinker before we tear down the mount
+        * structure so we don't have memory reclaim racing with us here.
+        */
+       xfs_inode_shrinker_unregister(mp);
        xfs_syncd_stop(mp);
 
-       if (!(sb->s_flags & MS_RDONLY)) {
-               /*
-                * XXX(hch): this should be SYNC_WAIT.
-                *
-                * Or more likely not needed at all because the VFS is already
-                * calling ->sync_fs after shutting down all filestem
-                * operations and just before calling ->put_super.
-                */
-               xfs_sync_data(mp, 0);
-               xfs_sync_attr(mp, 0);
-       }
-
-       XFS_SEND_PREUNMOUNT(mp);
-
        /*
         * Blow away any referenced inode in the filestreams cache.
         * This can and will cause log traffic as inodes go inactive
@@ -1218,14 +1159,10 @@ xfs_fs_put_super(
 
        XFS_bflush(mp->m_ddev_targp);
 
-       XFS_SEND_UNMOUNT(mp);
-
        xfs_unmountfs(mp);
        xfs_freesb(mp);
-       xfs_inode_shrinker_unregister(mp);
        xfs_icsb_destroy_counters(mp);
        xfs_close_devices(mp);
-       xfs_dmops_put(mp);
        xfs_free_fsname(mp);
        kfree(mp);
 }
@@ -1543,7 +1480,6 @@ xfs_fs_fill_super(
        struct inode            *root;
        struct xfs_mount        *mp = NULL;
        int                     flags = 0, error = ENOMEM;
-       char                    *mtpt = NULL;
 
        mp = kzalloc(sizeof(struct xfs_mount), GFP_KERNEL);
        if (!mp)
@@ -1559,7 +1495,7 @@ xfs_fs_fill_super(
        mp->m_super = sb;
        sb->s_fs_info = mp;
 
-       error = xfs_parseargs(mp, (char *)data, &mtpt);
+       error = xfs_parseargs(mp, (char *)data);
        if (error)
                goto out_free_fsname;
 
@@ -1571,16 +1507,12 @@ xfs_fs_fill_super(
 #endif
        sb->s_op = &xfs_super_operations;
 
-       error = xfs_dmops_get(mp);
-       if (error)
-               goto out_free_fsname;
-
        if (silent)
                flags |= XFS_MFSI_QUIET;
 
        error = xfs_open_devices(mp);
        if (error)
-               goto out_put_dmops;
+               goto out_free_fsname;
 
        if (xfs_icsb_init_counters(mp))
                mp->m_flags |= XFS_MOUNT_NO_PERCPU_SB;
@@ -1608,8 +1540,6 @@ xfs_fs_fill_super(
        if (error)
                goto out_filestream_unmount;
 
-       XFS_SEND_MOUNT(mp, DM_RIGHT_NULL, mtpt, mp->m_fsname);
-
        sb->s_magic = XFS_SB_MAGIC;
        sb->s_blocksize = mp->m_sb.sb_blocksize;
        sb->s_blocksize_bits = ffs(sb->s_blocksize) - 1;
@@ -1638,7 +1568,6 @@ xfs_fs_fill_super(
 
        xfs_inode_shrinker_register(mp);
 
-       kfree(mtpt);
        return 0;
 
  out_filestream_unmount:
@@ -1648,11 +1577,8 @@ xfs_fs_fill_super(
  out_destroy_counters:
        xfs_icsb_destroy_counters(mp);
        xfs_close_devices(mp);
- out_put_dmops:
-       xfs_dmops_put(mp);
  out_free_fsname:
        xfs_free_fsname(mp);
-       kfree(mtpt);
        kfree(mp);
  out:
        return -error;
@@ -1759,6 +1685,12 @@ xfs_init_zones(void)
        if (!xfs_trans_zone)
                goto out_destroy_ifork_zone;
 
+       xfs_log_item_desc_zone =
+               kmem_zone_init(sizeof(struct xfs_log_item_desc),
+                              "xfs_log_item_desc");
+       if (!xfs_log_item_desc_zone)
+               goto out_destroy_trans_zone;
+
        /*
         * The size of the zone allocated buf log item is the maximum
         * size possible under XFS.  This wastes a little bit of memory,
@@ -1768,7 +1700,7 @@ xfs_init_zones(void)
                                (((XFS_MAX_BLOCKSIZE / XFS_BLF_CHUNK) /
                                  NBWORD) * sizeof(int))), "xfs_buf_item");
        if (!xfs_buf_item_zone)
-               goto out_destroy_trans_zone;
+               goto out_destroy_log_item_desc_zone;
 
        xfs_efd_zone = kmem_zone_init((sizeof(xfs_efd_log_item_t) +
                        ((XFS_EFD_MAX_FAST_EXTENTS - 1) *
@@ -1805,6 +1737,8 @@ xfs_init_zones(void)
        kmem_zone_destroy(xfs_efd_zone);
  out_destroy_buf_item_zone:
        kmem_zone_destroy(xfs_buf_item_zone);
+ out_destroy_log_item_desc_zone:
+       kmem_zone_destroy(xfs_log_item_desc_zone);
  out_destroy_trans_zone:
        kmem_zone_destroy(xfs_trans_zone);
  out_destroy_ifork_zone:
@@ -1835,6 +1769,7 @@ xfs_destroy_zones(void)
        kmem_zone_destroy(xfs_efi_zone);
        kmem_zone_destroy(xfs_efd_zone);
        kmem_zone_destroy(xfs_buf_item_zone);
+       kmem_zone_destroy(xfs_log_item_desc_zone);
        kmem_zone_destroy(xfs_trans_zone);
        kmem_zone_destroy(xfs_ifork_zone);
        kmem_zone_destroy(xfs_dabuf_zone);
index 519618e9279eda5c4d81ca398679d835ff77df28..1ef4a4d2d99796caf7ea1be05fc1becb56846f16 100644 (file)
@@ -56,12 +56,6 @@ extern void xfs_qm_exit(void);
 # define XFS_BIGFS_STRING
 #endif
 
-#ifdef CONFIG_XFS_DMAPI
-# define XFS_DMAPI_STRING      "dmapi support, "
-#else
-# define XFS_DMAPI_STRING
-#endif
-
 #ifdef DEBUG
 # define XFS_DBG_STRING                "debug"
 #else
@@ -72,7 +66,6 @@ extern void xfs_qm_exit(void);
                                XFS_SECURITY_STRING \
                                XFS_REALTIME_STRING \
                                XFS_BIGFS_STRING \
-                               XFS_DMAPI_STRING \
                                XFS_DBG_STRING /* DBG must be last */
 
 struct xfs_inode;
index a51a07c3a70cfa8b5514add3dae137402bbc56b6..dfcbd98d15997e62e7d8a433fa71e5b8a9912609 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_inode.h"
 #include "xfs_dinode.h"
 #include "xfs_error.h"
-#include "xfs_mru_cache.h"
 #include "xfs_filestream.h"
 #include "xfs_vnodeops.h"
-#include "xfs_utils.h"
-#include "xfs_buf_item.h"
 #include "xfs_inode_item.h"
-#include "xfs_rw.h"
 #include "xfs_quota.h"
 #include "xfs_trace.h"
 
@@ -319,7 +308,7 @@ xfs_sync_inode_attr(
 /*
  * Write out pagecache data for the whole filesystem.
  */
-int
+STATIC int
 xfs_sync_data(
        struct xfs_mount        *mp,
        int                     flags)
@@ -340,7 +329,7 @@ xfs_sync_data(
 /*
  * Write out inode metadata (attributes) for the whole filesystem.
  */
-int
+STATIC int
 xfs_sync_attr(
        struct xfs_mount        *mp,
        int                     flags)
@@ -373,8 +362,7 @@ xfs_commit_dummy_trans(
 
        xfs_ilock(ip, XFS_ILOCK_EXCL);
 
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
+       xfs_trans_ijoin(tp, ip);
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        error = xfs_trans_commit(tp, 0);
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
@@ -867,7 +855,36 @@ out:
 reclaim:
        xfs_ifunlock(ip);
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
-       xfs_ireclaim(ip);
+
+       XFS_STATS_INC(xs_ig_reclaims);
+       /*
+        * Remove the inode from the per-AG radix tree.
+        *
+        * Because radix_tree_delete won't complain even if the item was never
+        * added to the tree assert that it's been there before to catch
+        * problems with the inode life time early on.
+        */
+       write_lock(&pag->pag_ici_lock);
+       if (!radix_tree_delete(&pag->pag_ici_root,
+                               XFS_INO_TO_AGINO(ip->i_mount, ip->i_ino)))
+               ASSERT(0);
+       write_unlock(&pag->pag_ici_lock);
+
+       /*
+        * Here we do an (almost) spurious inode lock in order to coordinate
+        * with inode cache radix tree lookups.  This is because the lookup
+        * can reference the inodes in the cache without taking references.
+        *
+        * We make that OK here by ensuring that we wait until the inode is
+        * unlocked after the lookup before we go ahead and free it.  We get
+        * both the ilock and the iolock because the code may need to drop the
+        * ilock one but will still hold the iolock.
+        */
+       xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
+       xfs_qm_dqdetach(ip);
+       xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
+
+       xfs_inode_free(ip);
        return error;
 
 }
index e28139aaa4aa42c6085100856345e0156a33eef3..fe78726196f8200cd777298e82560f12f180e23c 100644 (file)
@@ -35,9 +35,6 @@ typedef struct xfs_sync_work {
 int xfs_syncd_init(struct xfs_mount *mp);
 void xfs_syncd_stop(struct xfs_mount *mp);
 
-int xfs_sync_attr(struct xfs_mount *mp, int flags);
-int xfs_sync_data(struct xfs_mount *mp, int flags);
-
 int xfs_quiesce_data(struct xfs_mount *mp);
 void xfs_quiesce_attr(struct xfs_mount *mp);
 
index d12be8470cbac741dcdc42ba402cb2e228dd93a2..88d25d4aa56ec34b0a9039af8d52d567c478a429 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_ialloc.h"
 #include "xfs_itable.h"
index 302820690904d1eff4de201ca97ca97a5fad4c9d..c657cdca2cd2648ac173332556bc371ffb577847 100644 (file)
@@ -317,8 +317,6 @@ DEFINE_BUF_EVENT(xfs_buf_init);
 DEFINE_BUF_EVENT(xfs_buf_free);
 DEFINE_BUF_EVENT(xfs_buf_hold);
 DEFINE_BUF_EVENT(xfs_buf_rele);
-DEFINE_BUF_EVENT(xfs_buf_pin);
-DEFINE_BUF_EVENT(xfs_buf_unpin);
 DEFINE_BUF_EVENT(xfs_buf_iodone);
 DEFINE_BUF_EVENT(xfs_buf_iorequest);
 DEFINE_BUF_EVENT(xfs_buf_bawrite);
@@ -541,7 +539,7 @@ DEFINE_LOCK_EVENT(xfs_ilock_nowait);
 DEFINE_LOCK_EVENT(xfs_ilock_demote);
 DEFINE_LOCK_EVENT(xfs_iunlock);
 
-DECLARE_EVENT_CLASS(xfs_iget_class,
+DECLARE_EVENT_CLASS(xfs_inode_class,
        TP_PROTO(struct xfs_inode *ip),
        TP_ARGS(ip),
        TP_STRUCT__entry(
@@ -557,16 +555,38 @@ DECLARE_EVENT_CLASS(xfs_iget_class,
                  __entry->ino)
 )
 
-#define DEFINE_IGET_EVENT(name) \
-DEFINE_EVENT(xfs_iget_class, name, \
+#define DEFINE_INODE_EVENT(name) \
+DEFINE_EVENT(xfs_inode_class, name, \
        TP_PROTO(struct xfs_inode *ip), \
        TP_ARGS(ip))
-DEFINE_IGET_EVENT(xfs_iget_skip);
-DEFINE_IGET_EVENT(xfs_iget_reclaim);
-DEFINE_IGET_EVENT(xfs_iget_found);
-DEFINE_IGET_EVENT(xfs_iget_alloc);
-
-DECLARE_EVENT_CLASS(xfs_inode_class,
+DEFINE_INODE_EVENT(xfs_iget_skip);
+DEFINE_INODE_EVENT(xfs_iget_reclaim);
+DEFINE_INODE_EVENT(xfs_iget_reclaim_fail);
+DEFINE_INODE_EVENT(xfs_iget_hit);
+DEFINE_INODE_EVENT(xfs_iget_miss);
+
+DEFINE_INODE_EVENT(xfs_getattr);
+DEFINE_INODE_EVENT(xfs_setattr);
+DEFINE_INODE_EVENT(xfs_readlink);
+DEFINE_INODE_EVENT(xfs_alloc_file_space);
+DEFINE_INODE_EVENT(xfs_free_file_space);
+DEFINE_INODE_EVENT(xfs_readdir);
+#ifdef CONFIG_XFS_POSIX_ACL
+DEFINE_INODE_EVENT(xfs_check_acl);
+#endif
+DEFINE_INODE_EVENT(xfs_vm_bmap);
+DEFINE_INODE_EVENT(xfs_file_ioctl);
+DEFINE_INODE_EVENT(xfs_file_compat_ioctl);
+DEFINE_INODE_EVENT(xfs_ioctl_setattr);
+DEFINE_INODE_EVENT(xfs_file_fsync);
+DEFINE_INODE_EVENT(xfs_destroy_inode);
+DEFINE_INODE_EVENT(xfs_write_inode);
+DEFINE_INODE_EVENT(xfs_clear_inode);
+
+DEFINE_INODE_EVENT(xfs_dquot_dqalloc);
+DEFINE_INODE_EVENT(xfs_dquot_dqdetach);
+
+DECLARE_EVENT_CLASS(xfs_iref_class,
        TP_PROTO(struct xfs_inode *ip, unsigned long caller_ip),
        TP_ARGS(ip, caller_ip),
        TP_STRUCT__entry(
@@ -591,20 +611,71 @@ DECLARE_EVENT_CLASS(xfs_inode_class,
                  (char *)__entry->caller_ip)
 )
 
-#define DEFINE_INODE_EVENT(name) \
-DEFINE_EVENT(xfs_inode_class, name, \
+#define DEFINE_IREF_EVENT(name) \
+DEFINE_EVENT(xfs_iref_class, name, \
        TP_PROTO(struct xfs_inode *ip, unsigned long caller_ip), \
        TP_ARGS(ip, caller_ip))
-DEFINE_INODE_EVENT(xfs_ihold);
-DEFINE_INODE_EVENT(xfs_irele);
-DEFINE_INODE_EVENT(xfs_inode_pin);
-DEFINE_INODE_EVENT(xfs_inode_unpin);
-DEFINE_INODE_EVENT(xfs_inode_unpin_nowait);
+DEFINE_IREF_EVENT(xfs_ihold);
+DEFINE_IREF_EVENT(xfs_irele);
+DEFINE_IREF_EVENT(xfs_inode_pin);
+DEFINE_IREF_EVENT(xfs_inode_unpin);
+DEFINE_IREF_EVENT(xfs_inode_unpin_nowait);
+
+DECLARE_EVENT_CLASS(xfs_namespace_class,
+       TP_PROTO(struct xfs_inode *dp, struct xfs_name *name),
+       TP_ARGS(dp, name),
+       TP_STRUCT__entry(
+               __field(dev_t, dev)
+               __field(xfs_ino_t, dp_ino)
+               __dynamic_array(char, name, name->len)
+       ),
+       TP_fast_assign(
+               __entry->dev = VFS_I(dp)->i_sb->s_dev;
+               __entry->dp_ino = dp->i_ino;
+               memcpy(__get_str(name), name->name, name->len);
+       ),
+       TP_printk("dev %d:%d dp ino 0x%llx name %s",
+                 MAJOR(__entry->dev), MINOR(__entry->dev),
+                 __entry->dp_ino,
+                 __get_str(name))
+)
 
-/* the old xfs_itrace_entry tracer - to be replaced by s.th. in the VFS */
-DEFINE_INODE_EVENT(xfs_inode);
-#define xfs_itrace_entry(ip)    \
-       trace_xfs_inode(ip, _THIS_IP_)
+#define DEFINE_NAMESPACE_EVENT(name) \
+DEFINE_EVENT(xfs_namespace_class, name, \
+       TP_PROTO(struct xfs_inode *dp, struct xfs_name *name), \
+       TP_ARGS(dp, name))
+DEFINE_NAMESPACE_EVENT(xfs_remove);
+DEFINE_NAMESPACE_EVENT(xfs_link);
+DEFINE_NAMESPACE_EVENT(xfs_lookup);
+DEFINE_NAMESPACE_EVENT(xfs_create);
+DEFINE_NAMESPACE_EVENT(xfs_symlink);
+
+TRACE_EVENT(xfs_rename,
+       TP_PROTO(struct xfs_inode *src_dp, struct xfs_inode *target_dp,
+                struct xfs_name *src_name, struct xfs_name *target_name),
+       TP_ARGS(src_dp, target_dp, src_name, target_name),
+       TP_STRUCT__entry(
+               __field(dev_t, dev)
+               __field(xfs_ino_t, src_dp_ino)
+               __field(xfs_ino_t, target_dp_ino)
+               __dynamic_array(char, src_name, src_name->len)
+               __dynamic_array(char, target_name, target_name->len)
+       ),
+       TP_fast_assign(
+               __entry->dev = VFS_I(src_dp)->i_sb->s_dev;
+               __entry->src_dp_ino = src_dp->i_ino;
+               __entry->target_dp_ino = target_dp->i_ino;
+               memcpy(__get_str(src_name), src_name->name, src_name->len);
+               memcpy(__get_str(target_name), target_name->name, target_name->len);
+       ),
+       TP_printk("dev %d:%d src dp ino 0x%llx target dp ino 0x%llx"
+                 " src name %s target name %s",
+                 MAJOR(__entry->dev), MINOR(__entry->dev),
+                 __entry->src_dp_ino,
+                 __entry->target_dp_ino,
+                 __get_str(src_name),
+                 __get_str(target_name))
+)
 
 DECLARE_EVENT_CLASS(xfs_dquot_class,
        TP_PROTO(struct xfs_dquot *dqp),
@@ -684,9 +755,6 @@ DEFINE_DQUOT_EVENT(xfs_dqrele);
 DEFINE_DQUOT_EVENT(xfs_dqflush);
 DEFINE_DQUOT_EVENT(xfs_dqflush_force);
 DEFINE_DQUOT_EVENT(xfs_dqflush_done);
-/* not really iget events, but we re-use the format */
-DEFINE_IGET_EVENT(xfs_dquot_dqalloc);
-DEFINE_IGET_EVENT(xfs_dquot_dqdetach);
 
 DECLARE_EVENT_CLASS(xfs_loggrant_class,
        TP_PROTO(struct log *log, struct xlog_ticket *tic),
@@ -834,33 +902,29 @@ DECLARE_EVENT_CLASS(xfs_page_class,
                __field(loff_t, size)
                __field(unsigned long, offset)
                __field(int, delalloc)
-               __field(int, unmapped)
                __field(int, unwritten)
        ),
        TP_fast_assign(
-               int delalloc = -1, unmapped = -1, unwritten = -1;
+               int delalloc = -1, unwritten = -1;
 
                if (page_has_buffers(page))
-                       xfs_count_page_state(page, &delalloc,
-                                            &unmapped, &unwritten);
+                       xfs_count_page_state(page, &delalloc, &unwritten);
                __entry->dev = inode->i_sb->s_dev;
                __entry->ino = XFS_I(inode)->i_ino;
                __entry->pgoff = page_offset(page);
                __entry->size = i_size_read(inode);
                __entry->offset = off;
                __entry->delalloc = delalloc;
-               __entry->unmapped = unmapped;
                __entry->unwritten = unwritten;
        ),
        TP_printk("dev %d:%d ino 0x%llx pgoff 0x%lx size 0x%llx offset %lx "
-                 "delalloc %d unmapped %d unwritten %d",
+                 "delalloc %d unwritten %d",
                  MAJOR(__entry->dev), MINOR(__entry->dev),
                  __entry->ino,
                  __entry->pgoff,
                  __entry->size,
                  __entry->offset,
                  __entry->delalloc,
-                 __entry->unmapped,
                  __entry->unwritten)
 )
 
index 585e7633dfc75b176df3989186628385b857bf8e..e1a2f6800e01da339586080d23b6a760747a4725 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dinode.h"
 #include "xfs_inode.h"
-#include "xfs_btree.h"
-#include "xfs_ialloc.h"
 #include "xfs_bmap.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
 #include "xfs_itable.h"
-#include "xfs_rw.h"
 #include "xfs_attr.h"
 #include "xfs_buf_item.h"
 #include "xfs_trans_space.h"
@@ -64,8 +54,6 @@
    flush lock - ditto.
 */
 
-STATIC void            xfs_qm_dqflush_done(xfs_buf_t *, xfs_dq_logitem_t *);
-
 #ifdef DEBUG
 xfs_buftarg_t *xfs_dqerror_target;
 int xfs_do_dqerror;
@@ -390,21 +378,14 @@ xfs_qm_dqalloc(
                return (ESRCH);
        }
 
-       /*
-        * xfs_trans_commit normally decrements the vnode ref count
-        * when it unlocks the inode. Since we want to keep the quota
-        * inode around, we bump the vnode ref count now.
-        */
-       IHOLD(quotip);
-
-       xfs_trans_ijoin(tp, quotip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, quotip, XFS_ILOCK_EXCL);
        nmaps = 1;
        if ((error = xfs_bmapi(tp, quotip,
                              offset_fsb, XFS_DQUOT_CLUSTER_SIZE_FSB,
                              XFS_BMAPI_METADATA | XFS_BMAPI_WRITE,
                              &firstblock,
                              XFS_QM_DQALLOC_SPACE_RES(mp),
-                             &map, &nmaps, &flist, NULL))) {
+                             &map, &nmaps, &flist))) {
                goto error0;
        }
        ASSERT(map.br_blockcount == XFS_DQUOT_CLUSTER_SIZE_FSB);
@@ -520,7 +501,7 @@ xfs_qm_dqtobp(
                error = xfs_bmapi(NULL, quotip, dqp->q_fileoffset,
                                  XFS_DQUOT_CLUSTER_SIZE_FSB,
                                  XFS_BMAPI_METADATA,
-                                 NULL, 0, &map, &nmaps, NULL, NULL);
+                                 NULL, 0, &map, &nmaps, NULL);
 
                xfs_iunlock(quotip, XFS_ILOCK_SHARED);
                if (error)
@@ -1141,6 +1122,46 @@ xfs_qm_dqrele(
        xfs_qm_dqput(dqp);
 }
 
+/*
+ * This is the dquot flushing I/O completion routine.  It is called
+ * from interrupt level when the buffer containing the dquot is
+ * flushed to disk.  It is responsible for removing the dquot logitem
+ * from the AIL if it has not been re-logged, and unlocking the dquot's
+ * flush lock. This behavior is very similar to that of inodes..
+ */
+STATIC void
+xfs_qm_dqflush_done(
+       struct xfs_buf          *bp,
+       struct xfs_log_item     *lip)
+{
+       xfs_dq_logitem_t        *qip = (struct xfs_dq_logitem *)lip;
+       xfs_dquot_t             *dqp = qip->qli_dquot;
+       struct xfs_ail          *ailp = lip->li_ailp;
+
+       /*
+        * We only want to pull the item from the AIL if its
+        * location in the log has not changed since we started the flush.
+        * Thus, we only bother if the dquot's lsn has
+        * not changed. First we check the lsn outside the lock
+        * since it's cheaper, and then we recheck while
+        * holding the lock before removing the dquot from the AIL.
+        */
+       if ((lip->li_flags & XFS_LI_IN_AIL) &&
+           lip->li_lsn == qip->qli_flush_lsn) {
+
+               /* xfs_trans_ail_delete() drops the AIL lock. */
+               spin_lock(&ailp->xa_lock);
+               if (lip->li_lsn == qip->qli_flush_lsn)
+                       xfs_trans_ail_delete(ailp, lip);
+               else
+                       spin_unlock(&ailp->xa_lock);
+       }
+
+       /*
+        * Release the dq's flush lock since we're done with it.
+        */
+       xfs_dqfunlock(dqp);
+}
 
 /*
  * Write a modified dquot to disk.
@@ -1222,8 +1243,9 @@ xfs_qm_dqflush(
         * Attach an iodone routine so that we can remove this dquot from the
         * AIL and release the flush lock once the dquot is synced to disk.
         */
-       xfs_buf_attach_iodone(bp, (void(*)(xfs_buf_t *, xfs_log_item_t *))
-                             xfs_qm_dqflush_done, &(dqp->q_logitem.qli_item));
+       xfs_buf_attach_iodone(bp, xfs_qm_dqflush_done,
+                                 &dqp->q_logitem.qli_item);
+
        /*
         * If the buffer is pinned then push on the log so we won't
         * get stuck waiting in the write for too long.
@@ -1247,50 +1269,6 @@ xfs_qm_dqflush(
 
 }
 
-/*
- * This is the dquot flushing I/O completion routine.  It is called
- * from interrupt level when the buffer containing the dquot is
- * flushed to disk.  It is responsible for removing the dquot logitem
- * from the AIL if it has not been re-logged, and unlocking the dquot's
- * flush lock. This behavior is very similar to that of inodes..
- */
-/*ARGSUSED*/
-STATIC void
-xfs_qm_dqflush_done(
-       xfs_buf_t               *bp,
-       xfs_dq_logitem_t        *qip)
-{
-       xfs_dquot_t             *dqp;
-       struct xfs_ail          *ailp;
-
-       dqp = qip->qli_dquot;
-       ailp = qip->qli_item.li_ailp;
-
-       /*
-        * We only want to pull the item from the AIL if its
-        * location in the log has not changed since we started the flush.
-        * Thus, we only bother if the dquot's lsn has
-        * not changed. First we check the lsn outside the lock
-        * since it's cheaper, and then we recheck while
-        * holding the lock before removing the dquot from the AIL.
-        */
-       if ((qip->qli_item.li_flags & XFS_LI_IN_AIL) &&
-           qip->qli_item.li_lsn == qip->qli_flush_lsn) {
-
-               /* xfs_trans_ail_delete() drops the AIL lock. */
-               spin_lock(&ailp->xa_lock);
-               if (qip->qli_item.li_lsn == qip->qli_flush_lsn)
-                       xfs_trans_ail_delete(ailp, (xfs_log_item_t*)qip);
-               else
-                       spin_unlock(&ailp->xa_lock);
-       }
-
-       /*
-        * Release the dq's flush lock since we're done with it.
-        */
-       xfs_dqfunlock(dqp);
-}
-
 int
 xfs_qm_dqlock_nowait(
        xfs_dquot_t *dqp)
index 8d89a24ae3244d1cd2ce75bcf22d37429d5f2ced..2a1f3dc10a02dba4f401a326fd72f07bd40212af 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_bmap.h"
-#include "xfs_btree.h"
-#include "xfs_ialloc.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
 #include "xfs_itable.h"
-#include "xfs_rw.h"
 #include "xfs_attr.h"
 #include "xfs_buf_item.h"
 #include "xfs_trans_priv.h"
 #include "xfs_qm.h"
 
+static inline struct xfs_dq_logitem *DQUOT_ITEM(struct xfs_log_item *lip)
+{
+       return container_of(lip, struct xfs_dq_logitem, qli_item);
+}
+
 /*
  * returns the number of iovecs needed to log the given dquot item.
  */
-/* ARGSUSED */
 STATIC uint
 xfs_qm_dquot_logitem_size(
-       xfs_dq_logitem_t        *logitem)
+       struct xfs_log_item     *lip)
 {
        /*
         * we need only two iovecs, one for the format, one for the real thing
         */
-       return (2);
+       return 2;
 }
 
 /*
@@ -66,22 +60,21 @@ xfs_qm_dquot_logitem_size(
  */
 STATIC void
 xfs_qm_dquot_logitem_format(
-       xfs_dq_logitem_t        *logitem,
-       xfs_log_iovec_t         *logvec)
+       struct xfs_log_item     *lip,
+       struct xfs_log_iovec    *logvec)
 {
-       ASSERT(logitem);
-       ASSERT(logitem->qli_dquot);
+       struct xfs_dq_logitem   *qlip = DQUOT_ITEM(lip);
 
-       logvec->i_addr = (xfs_caddr_t)&logitem->qli_format;
+       logvec->i_addr = &qlip->qli_format;
        logvec->i_len  = sizeof(xfs_dq_logformat_t);
        logvec->i_type = XLOG_REG_TYPE_QFORMAT;
        logvec++;
-       logvec->i_addr = (xfs_caddr_t)&logitem->qli_dquot->q_core;
+       logvec->i_addr = &qlip->qli_dquot->q_core;
        logvec->i_len  = sizeof(xfs_disk_dquot_t);
        logvec->i_type = XLOG_REG_TYPE_DQUOT;
 
-       ASSERT(2 == logitem->qli_item.li_desc->lid_size);
-       logitem->qli_format.qlf_size = 2;
+       ASSERT(2 == lip->li_desc->lid_size);
+       qlip->qli_format.qlf_size = 2;
 
 }
 
@@ -90,9 +83,9 @@ xfs_qm_dquot_logitem_format(
  */
 STATIC void
 xfs_qm_dquot_logitem_pin(
-       xfs_dq_logitem_t *logitem)
+       struct xfs_log_item     *lip)
 {
-       xfs_dquot_t *dqp = logitem->qli_dquot;
+       struct xfs_dquot        *dqp = DQUOT_ITEM(lip)->qli_dquot;
 
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
        atomic_inc(&dqp->q_pincount);
@@ -104,27 +97,18 @@ xfs_qm_dquot_logitem_pin(
  * dquot must have been previously pinned with a call to
  * xfs_qm_dquot_logitem_pin().
  */
-/* ARGSUSED */
 STATIC void
 xfs_qm_dquot_logitem_unpin(
-       xfs_dq_logitem_t *logitem)
+       struct xfs_log_item     *lip,
+       int                     remove)
 {
-       xfs_dquot_t *dqp = logitem->qli_dquot;
+       struct xfs_dquot        *dqp = DQUOT_ITEM(lip)->qli_dquot;
 
        ASSERT(atomic_read(&dqp->q_pincount) > 0);
        if (atomic_dec_and_test(&dqp->q_pincount))
                wake_up(&dqp->q_pinwait);
 }
 
-/* ARGSUSED */
-STATIC void
-xfs_qm_dquot_logitem_unpin_remove(
-       xfs_dq_logitem_t *logitem,
-       xfs_trans_t      *tp)
-{
-       xfs_qm_dquot_logitem_unpin(logitem);
-}
-
 /*
  * Given the logitem, this writes the corresponding dquot entry to disk
  * asynchronously. This is called with the dquot entry securely locked;
@@ -133,12 +117,10 @@ xfs_qm_dquot_logitem_unpin_remove(
  */
 STATIC void
 xfs_qm_dquot_logitem_push(
-       xfs_dq_logitem_t        *logitem)
+       struct xfs_log_item     *lip)
 {
-       xfs_dquot_t     *dqp;
-       int             error;
-
-       dqp = logitem->qli_dquot;
+       struct xfs_dquot        *dqp = DQUOT_ITEM(lip)->qli_dquot;
+       int                     error;
 
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
        ASSERT(!completion_done(&dqp->q_flush));
@@ -160,27 +142,25 @@ xfs_qm_dquot_logitem_push(
        xfs_dqunlock(dqp);
 }
 
-/*ARGSUSED*/
 STATIC xfs_lsn_t
 xfs_qm_dquot_logitem_committed(
-       xfs_dq_logitem_t        *l,
+       struct xfs_log_item     *lip,
        xfs_lsn_t               lsn)
 {
        /*
         * We always re-log the entire dquot when it becomes dirty,
         * so, the latest copy _is_ the only one that matters.
         */
-       return (lsn);
+       return lsn;
 }
 
-
 /*
  * This is called to wait for the given dquot to be unpinned.
  * Most of these pin/unpin routines are plagiarized from inode code.
  */
 void
 xfs_qm_dqunpin_wait(
-       xfs_dquot_t     *dqp)
+       struct xfs_dquot        *dqp)
 {
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
        if (atomic_read(&dqp->q_pincount) == 0)
@@ -206,13 +186,12 @@ xfs_qm_dqunpin_wait(
  */
 STATIC void
 xfs_qm_dquot_logitem_pushbuf(
-       xfs_dq_logitem_t    *qip)
+       struct xfs_log_item     *lip)
 {
-       xfs_dquot_t     *dqp;
-       xfs_mount_t     *mp;
-       xfs_buf_t       *bp;
+       struct xfs_dq_logitem   *qlip = DQUOT_ITEM(lip);
+       struct xfs_dquot        *dqp = qlip->qli_dquot;
+       struct xfs_buf          *bp;
 
-       dqp = qip->qli_dquot;
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
 
        /*
@@ -220,22 +199,20 @@ xfs_qm_dquot_logitem_pushbuf(
         * inode flush completed and the inode was taken off the AIL.
         * So, just get out.
         */
-       if (completion_done(&dqp->q_flush)  ||
-           ((qip->qli_item.li_flags & XFS_LI_IN_AIL) == 0)) {
+       if (completion_done(&dqp->q_flush) ||
+           !(lip->li_flags & XFS_LI_IN_AIL)) {
                xfs_dqunlock(dqp);
                return;
        }
-       mp = dqp->q_mount;
-       bp = xfs_incore(mp->m_ddev_targp, qip->qli_format.qlf_blkno,
-                       mp->m_quotainfo->qi_dqchunklen, XBF_TRYLOCK);
+
+       bp = xfs_incore(dqp->q_mount->m_ddev_targp, qlip->qli_format.qlf_blkno,
+                       dqp->q_mount->m_quotainfo->qi_dqchunklen, XBF_TRYLOCK);
        xfs_dqunlock(dqp);
        if (!bp)
                return;
        if (XFS_BUF_ISDELAYWRITE(bp))
                xfs_buf_delwri_promote(bp);
        xfs_buf_relse(bp);
-       return;
-
 }
 
 /*
@@ -250,15 +227,14 @@ xfs_qm_dquot_logitem_pushbuf(
  */
 STATIC uint
 xfs_qm_dquot_logitem_trylock(
-       xfs_dq_logitem_t        *qip)
+       struct xfs_log_item     *lip)
 {
-       xfs_dquot_t             *dqp;
+       struct xfs_dquot        *dqp = DQUOT_ITEM(lip)->qli_dquot;
 
-       dqp = qip->qli_dquot;
        if (atomic_read(&dqp->q_pincount) > 0)
                return XFS_ITEM_PINNED;
 
-       if (! xfs_qm_dqlock_nowait(dqp))
+       if (!xfs_qm_dqlock_nowait(dqp))
                return XFS_ITEM_LOCKED;
 
        if (!xfs_dqflock_nowait(dqp)) {
@@ -269,11 +245,10 @@ xfs_qm_dquot_logitem_trylock(
                return XFS_ITEM_PUSHBUF;
        }
 
-       ASSERT(qip->qli_item.li_flags & XFS_LI_IN_AIL);
+       ASSERT(lip->li_flags & XFS_LI_IN_AIL);
        return XFS_ITEM_SUCCESS;
 }
 
-
 /*
  * Unlock the dquot associated with the log item.
  * Clear the fields of the dquot and dquot log item that
@@ -282,12 +257,10 @@ xfs_qm_dquot_logitem_trylock(
  */
 STATIC void
 xfs_qm_dquot_logitem_unlock(
-       xfs_dq_logitem_t    *ql)
+       struct xfs_log_item     *lip)
 {
-       xfs_dquot_t     *dqp;
+       struct xfs_dquot        *dqp = DQUOT_ITEM(lip)->qli_dquot;
 
-       ASSERT(ql != NULL);
-       dqp = ql->qli_dquot;
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
 
        /*
@@ -304,43 +277,32 @@ xfs_qm_dquot_logitem_unlock(
        xfs_dqunlock(dqp);
 }
 
-
 /*
  * this needs to stamp an lsn into the dquot, I think.
  * rpc's that look at user dquot's would then have to
  * push on the dependency recorded in the dquot
  */
-/* ARGSUSED */
 STATIC void
 xfs_qm_dquot_logitem_committing(
-       xfs_dq_logitem_t        *l,
+       struct xfs_log_item     *lip,
        xfs_lsn_t               lsn)
 {
-       return;
 }
 
-
 /*
  * This is the ops vector for dquots
  */
 static struct xfs_item_ops xfs_dquot_item_ops = {
-       .iop_size       = (uint(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_size,
-       .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
-                                       xfs_qm_dquot_logitem_format,
-       .iop_pin        = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_pin,
-       .iop_unpin      = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_unpin,
-       .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
-                                       xfs_qm_dquot_logitem_unpin_remove,
-       .iop_trylock    = (uint(*)(xfs_log_item_t*))
-                                       xfs_qm_dquot_logitem_trylock,
-       .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_unlock,
-       .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_qm_dquot_logitem_committed,
-       .iop_push       = (void(*)(xfs_log_item_t*))xfs_qm_dquot_logitem_push,
-       .iop_pushbuf    = (void(*)(xfs_log_item_t*))
-                                       xfs_qm_dquot_logitem_pushbuf,
-       .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_qm_dquot_logitem_committing
+       .iop_size       = xfs_qm_dquot_logitem_size,
+       .iop_format     = xfs_qm_dquot_logitem_format,
+       .iop_pin        = xfs_qm_dquot_logitem_pin,
+       .iop_unpin      = xfs_qm_dquot_logitem_unpin,
+       .iop_trylock    = xfs_qm_dquot_logitem_trylock,
+       .iop_unlock     = xfs_qm_dquot_logitem_unlock,
+       .iop_committed  = xfs_qm_dquot_logitem_committed,
+       .iop_push       = xfs_qm_dquot_logitem_push,
+       .iop_pushbuf    = xfs_qm_dquot_logitem_pushbuf,
+       .iop_committing = xfs_qm_dquot_logitem_committing
 };
 
 /*
@@ -350,10 +312,9 @@ static struct xfs_item_ops xfs_dquot_item_ops = {
  */
 void
 xfs_qm_dquot_logitem_init(
-       struct xfs_dquot *dqp)
+       struct xfs_dquot        *dqp)
 {
-       xfs_dq_logitem_t  *lp;
-       lp = &dqp->q_logitem;
+       struct xfs_dq_logitem   *lp = &dqp->q_logitem;
 
        xfs_log_item_init(dqp->q_mount, &lp->qli_item, XFS_LI_DQUOT,
                                        &xfs_dquot_item_ops);
@@ -374,16 +335,22 @@ xfs_qm_dquot_logitem_init(
 
 /*------------------  QUOTAOFF LOG ITEMS  -------------------*/
 
+static inline struct xfs_qoff_logitem *QOFF_ITEM(struct xfs_log_item *lip)
+{
+       return container_of(lip, struct xfs_qoff_logitem, qql_item);
+}
+
+
 /*
  * This returns the number of iovecs needed to log the given quotaoff item.
  * We only need 1 iovec for an quotaoff item.  It just logs the
  * quotaoff_log_format structure.
  */
-/*ARGSUSED*/
 STATIC uint
-xfs_qm_qoff_logitem_size(xfs_qoff_logitem_t *qf)
+xfs_qm_qoff_logitem_size(
+       struct xfs_log_item     *lip)
 {
-       return (1);
+       return 1;
 }
 
 /*
@@ -394,53 +361,46 @@ xfs_qm_qoff_logitem_size(xfs_qoff_logitem_t *qf)
  * slots in the quotaoff item have been filled.
  */
 STATIC void
-xfs_qm_qoff_logitem_format(xfs_qoff_logitem_t  *qf,
-                          xfs_log_iovec_t      *log_vector)
+xfs_qm_qoff_logitem_format(
+       struct xfs_log_item     *lip,
+       struct xfs_log_iovec    *log_vector)
 {
-       ASSERT(qf->qql_format.qf_type == XFS_LI_QUOTAOFF);
+       struct xfs_qoff_logitem *qflip = QOFF_ITEM(lip);
+
+       ASSERT(qflip->qql_format.qf_type == XFS_LI_QUOTAOFF);
 
-       log_vector->i_addr = (xfs_caddr_t)&(qf->qql_format);
+       log_vector->i_addr = &qflip->qql_format;
        log_vector->i_len = sizeof(xfs_qoff_logitem_t);
        log_vector->i_type = XLOG_REG_TYPE_QUOTAOFF;
-       qf->qql_format.qf_size = 1;
+       qflip->qql_format.qf_size = 1;
 }
 
-
 /*
  * Pinning has no meaning for an quotaoff item, so just return.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_qm_qoff_logitem_pin(xfs_qoff_logitem_t *qf)
+xfs_qm_qoff_logitem_pin(
+       struct xfs_log_item     *lip)
 {
-       return;
 }
 
-
 /*
  * Since pinning has no meaning for an quotaoff item, unpinning does
  * not either.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_qm_qoff_logitem_unpin(xfs_qoff_logitem_t *qf)
+xfs_qm_qoff_logitem_unpin(
+       struct xfs_log_item     *lip,
+       int                     remove)
 {
-       return;
-}
-
-/*ARGSUSED*/
-STATIC void
-xfs_qm_qoff_logitem_unpin_remove(xfs_qoff_logitem_t *qf, xfs_trans_t *tp)
-{
-       return;
 }
 
 /*
  * Quotaoff items have no locking, so just return success.
  */
-/*ARGSUSED*/
 STATIC uint
-xfs_qm_qoff_logitem_trylock(xfs_qoff_logitem_t *qf)
+xfs_qm_qoff_logitem_trylock(
+       struct xfs_log_item     *lip)
 {
        return XFS_ITEM_LOCKED;
 }
@@ -449,53 +409,51 @@ xfs_qm_qoff_logitem_trylock(xfs_qoff_logitem_t *qf)
  * Quotaoff items have no locking or pushing, so return failure
  * so that the caller doesn't bother with us.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_qm_qoff_logitem_unlock(xfs_qoff_logitem_t *qf)
+xfs_qm_qoff_logitem_unlock(
+       struct xfs_log_item     *lip)
 {
-       return;
 }
 
 /*
  * The quotaoff-start-item is logged only once and cannot be moved in the log,
  * so simply return the lsn at which it's been logged.
  */
-/*ARGSUSED*/
 STATIC xfs_lsn_t
-xfs_qm_qoff_logitem_committed(xfs_qoff_logitem_t *qf, xfs_lsn_t lsn)
+xfs_qm_qoff_logitem_committed(
+       struct xfs_log_item     *lip,
+       xfs_lsn_t               lsn)
 {
-       return (lsn);
+       return lsn;
 }
 
 /*
  * There isn't much you can do to push on an quotaoff item.  It is simply
  * stuck waiting for the log to be flushed to disk.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_qm_qoff_logitem_push(xfs_qoff_logitem_t *qf)
+xfs_qm_qoff_logitem_push(
+       struct xfs_log_item     *lip)
 {
-       return;
 }
 
 
-/*ARGSUSED*/
 STATIC xfs_lsn_t
 xfs_qm_qoffend_logitem_committed(
-       xfs_qoff_logitem_t *qfe,
-       xfs_lsn_t lsn)
+       struct xfs_log_item     *lip,
+       xfs_lsn_t               lsn)
 {
-       xfs_qoff_logitem_t      *qfs;
-       struct xfs_ail          *ailp;
+       struct xfs_qoff_logitem *qfe = QOFF_ITEM(lip);
+       struct xfs_qoff_logitem *qfs = qfe->qql_start_lip;
+       struct xfs_ail          *ailp = qfs->qql_item.li_ailp;
 
-       qfs = qfe->qql_start_lip;
-       ailp = qfs->qql_item.li_ailp;
-       spin_lock(&ailp->xa_lock);
        /*
         * Delete the qoff-start logitem from the AIL.
         * xfs_trans_ail_delete() drops the AIL lock.
         */
+       spin_lock(&ailp->xa_lock);
        xfs_trans_ail_delete(ailp, (xfs_log_item_t *)qfs);
+
        kmem_free(qfs);
        kmem_free(qfe);
        return (xfs_lsn_t)-1;
@@ -515,71 +473,52 @@ xfs_qm_qoffend_logitem_committed(
  * (truly makes the quotaoff irrevocable).  If we do something else,
  * then maybe we don't need two.
  */
-/* ARGSUSED */
-STATIC void
-xfs_qm_qoff_logitem_committing(xfs_qoff_logitem_t *qip, xfs_lsn_t commit_lsn)
-{
-       return;
-}
-
-/* ARGSUSED */
 STATIC void
-xfs_qm_qoffend_logitem_committing(xfs_qoff_logitem_t *qip, xfs_lsn_t commit_lsn)
+xfs_qm_qoff_logitem_committing(
+       struct xfs_log_item     *lip,
+       xfs_lsn_t               commit_lsn)
 {
-       return;
 }
 
 static struct xfs_item_ops xfs_qm_qoffend_logitem_ops = {
-       .iop_size       = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_size,
-       .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
-                                       xfs_qm_qoff_logitem_format,
-       .iop_pin        = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_pin,
-       .iop_unpin      = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_unpin,
-       .iop_unpin_remove = (void(*)(xfs_log_item_t*,xfs_trans_t*))
-                                       xfs_qm_qoff_logitem_unpin_remove,
-       .iop_trylock    = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_trylock,
-       .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_unlock,
-       .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_qm_qoffend_logitem_committed,
-       .iop_push       = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_push,
-       .iop_pushbuf    = NULL,
-       .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_qm_qoffend_logitem_committing
+       .iop_size       = xfs_qm_qoff_logitem_size,
+       .iop_format     = xfs_qm_qoff_logitem_format,
+       .iop_pin        = xfs_qm_qoff_logitem_pin,
+       .iop_unpin      = xfs_qm_qoff_logitem_unpin,
+       .iop_trylock    = xfs_qm_qoff_logitem_trylock,
+       .iop_unlock     = xfs_qm_qoff_logitem_unlock,
+       .iop_committed  = xfs_qm_qoffend_logitem_committed,
+       .iop_push       = xfs_qm_qoff_logitem_push,
+       .iop_committing = xfs_qm_qoff_logitem_committing
 };
 
 /*
  * This is the ops vector shared by all quotaoff-start log items.
  */
 static struct xfs_item_ops xfs_qm_qoff_logitem_ops = {
-       .iop_size       = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_size,
-       .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
-                                       xfs_qm_qoff_logitem_format,
-       .iop_pin        = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_pin,
-       .iop_unpin      = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_unpin,
-       .iop_unpin_remove = (void(*)(xfs_log_item_t*,xfs_trans_t*))
-                                       xfs_qm_qoff_logitem_unpin_remove,
-       .iop_trylock    = (uint(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_trylock,
-       .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_unlock,
-       .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_qm_qoff_logitem_committed,
-       .iop_push       = (void(*)(xfs_log_item_t*))xfs_qm_qoff_logitem_push,
-       .iop_pushbuf    = NULL,
-       .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_qm_qoff_logitem_committing
+       .iop_size       = xfs_qm_qoff_logitem_size,
+       .iop_format     = xfs_qm_qoff_logitem_format,
+       .iop_pin        = xfs_qm_qoff_logitem_pin,
+       .iop_unpin      = xfs_qm_qoff_logitem_unpin,
+       .iop_trylock    = xfs_qm_qoff_logitem_trylock,
+       .iop_unlock     = xfs_qm_qoff_logitem_unlock,
+       .iop_committed  = xfs_qm_qoff_logitem_committed,
+       .iop_push       = xfs_qm_qoff_logitem_push,
+       .iop_committing = xfs_qm_qoff_logitem_committing
 };
 
 /*
  * Allocate and initialize an quotaoff item of the correct quota type(s).
  */
-xfs_qoff_logitem_t *
+struct xfs_qoff_logitem *
 xfs_qm_qoff_logitem_init(
-       struct xfs_mount *mp,
-       xfs_qoff_logitem_t *start,
-       uint flags)
+       struct xfs_mount        *mp,
+       struct xfs_qoff_logitem *start,
+       uint                    flags)
 {
-       xfs_qoff_logitem_t      *qf;
+       struct xfs_qoff_logitem *qf;
 
-       qf = (xfs_qoff_logitem_t*) kmem_zalloc(sizeof(xfs_qoff_logitem_t), KM_SLEEP);
+       qf = kmem_zalloc(sizeof(struct xfs_qoff_logitem), KM_SLEEP);
 
        xfs_log_item_init(mp, &qf->qql_item, XFS_LI_QUOTAOFF, start ?
                        &xfs_qm_qoffend_logitem_ops : &xfs_qm_qoff_logitem_ops);
@@ -587,5 +526,5 @@ xfs_qm_qoff_logitem_init(
        qf->qql_format.qf_type = XFS_LI_QUOTAOFF;
        qf->qql_format.qf_flags = flags;
        qf->qql_start_lip = start;
-       return (qf);
+       return qf;
 }
index 67c018392d62a8ecef3c93f35c2b942b0b52137d..9a92407109a19921b2a0914711be6ce70b1b1f12 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
-#include "xfs_btree.h"
 #include "xfs_ialloc.h"
 #include "xfs_itable.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
 #include "xfs_bmap.h"
-#include "xfs_rw.h"
 #include "xfs_attr.h"
 #include "xfs_buf_item.h"
 #include "xfs_trans_space.h"
@@ -1497,7 +1490,7 @@ xfs_qm_dqiterate(
                                  maxlblkcnt - lblkno,
                                  XFS_BMAPI_METADATA,
                                  NULL,
-                                 0, map, &nmaps, NULL, NULL);
+                                 0, map, &nmaps, NULL);
                xfs_iunlock(qip, XFS_ILOCK_SHARED);
                if (error)
                        break;
@@ -1669,7 +1662,8 @@ xfs_qm_dqusage_adjust(
         * making us disable quotas for the file system.
         */
        if ((error = xfs_qm_dqget_noattach(ip, &udqp, &gdqp))) {
-               xfs_iput(ip, XFS_ILOCK_EXCL);
+               xfs_iunlock(ip, XFS_ILOCK_EXCL);
+               IRELE(ip);
                *res = BULKSTAT_RV_GIVEUP;
                return error;
        }
@@ -1682,7 +1676,8 @@ xfs_qm_dqusage_adjust(
                 * Walk thru the extent list and count the realtime blocks.
                 */
                if ((error = xfs_qm_get_rtblks(ip, &rtblks))) {
-                       xfs_iput(ip, XFS_ILOCK_EXCL);
+                       xfs_iunlock(ip, XFS_ILOCK_EXCL);
+                       IRELE(ip);
                        if (udqp)
                                xfs_qm_dqput(udqp);
                        if (gdqp)
index 97b410c12794d5ddf52579625d4a256ed384d872..bea02d786c5d30763e3ceee6022fe248a63fb454 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dinode.h"
 #include "xfs_inode.h"
-#include "xfs_ialloc.h"
 #include "xfs_itable.h"
-#include "xfs_btree.h"
 #include "xfs_bmap.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
-#include "xfs_rw.h"
 #include "xfs_attr.h"
 #include "xfs_buf_item.h"
 #include "xfs_qm.h"
index 3d1fc79532e2ab3a2c736c5e799bdd3b39da71dc..8671a0b32644010a04e98f64518c63050add8048 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dinode.h"
 #include "xfs_inode.h"
-#include "xfs_ialloc.h"
 #include "xfs_itable.h"
 #include "xfs_bmap.h"
-#include "xfs_btree.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
-#include "xfs_rw.h"
 #include "xfs_attr.h"
 #include "xfs_buf_item.h"
 #include "xfs_qm.h"
index b4487764e923b7c493aac813e9161764a0f0ccfb..d257eb8557c43a873644ea6481ec5611b9a0051f 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dinode.h"
 #include "xfs_inode.h"
-#include "xfs_ialloc.h"
 #include "xfs_itable.h"
 #include "xfs_bmap.h"
-#include "xfs_btree.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
-#include "xfs_rw.h"
 #include "xfs_attr.h"
 #include "xfs_buf_item.h"
 #include "xfs_utils.h"
@@ -248,40 +238,74 @@ out_unlock:
        return error;
 }
 
+STATIC int
+xfs_qm_scall_trunc_qfile(
+       struct xfs_mount        *mp,
+       xfs_ino_t               ino)
+{
+       struct xfs_inode        *ip;
+       struct xfs_trans        *tp;
+       int                     error;
+
+       if (ino == NULLFSINO)
+               return 0;
+
+       error = xfs_iget(mp, NULL, ino, 0, 0, &ip);
+       if (error)
+               return error;
+
+       xfs_ilock(ip, XFS_IOLOCK_EXCL);
+
+       tp = xfs_trans_alloc(mp, XFS_TRANS_TRUNCATE_FILE);
+       error = xfs_trans_reserve(tp, 0, XFS_ITRUNCATE_LOG_RES(mp), 0,
+                                 XFS_TRANS_PERM_LOG_RES,
+                                 XFS_ITRUNCATE_LOG_COUNT);
+       if (error) {
+               xfs_trans_cancel(tp, 0);
+               xfs_iunlock(ip, XFS_IOLOCK_EXCL);
+               goto out_put;
+       }
+
+       xfs_ilock(ip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin(tp, ip);
+
+       error = xfs_itruncate_finish(&tp, ip, 0, XFS_DATA_FORK, 1);
+       if (error) {
+               xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES |
+                                    XFS_TRANS_ABORT);
+               goto out_unlock;
+       }
+
+       xfs_ichgtime(ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
+       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
+
+out_unlock:
+       xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
+out_put:
+       IRELE(ip);
+       return error;
+}
+
 int
 xfs_qm_scall_trunc_qfiles(
        xfs_mount_t     *mp,
        uint            flags)
 {
        int             error = 0, error2 = 0;
-       xfs_inode_t     *qip;
 
        if (!xfs_sb_version_hasquota(&mp->m_sb) || flags == 0) {
                qdprintk("qtrunc flags=%x m_qflags=%x\n", flags, mp->m_qflags);
                return XFS_ERROR(EINVAL);
        }
 
-       if ((flags & XFS_DQ_USER) && mp->m_sb.sb_uquotino != NULLFSINO) {
-               error = xfs_iget(mp, NULL, mp->m_sb.sb_uquotino, 0, 0, &qip);
-               if (!error) {
-                       error = xfs_truncate_file(mp, qip);
-                       IRELE(qip);
-               }
-       }
-
-       if ((flags & (XFS_DQ_GROUP|XFS_DQ_PROJ)) &&
-           mp->m_sb.sb_gquotino != NULLFSINO) {
-               error2 = xfs_iget(mp, NULL, mp->m_sb.sb_gquotino, 0, 0, &qip);
-               if (!error2) {
-                       error2 = xfs_truncate_file(mp, qip);
-                       IRELE(qip);
-               }
-       }
+       if (flags & XFS_DQ_USER)
+               error = xfs_qm_scall_trunc_qfile(mp, mp->m_sb.sb_uquotino);
+       if (flags & (XFS_DQ_GROUP|XFS_DQ_PROJ))
+               error2 = xfs_qm_scall_trunc_qfile(mp, mp->m_sb.sb_gquotino);
 
        return error ? error : error2;
 }
 
-
 /*
  * Switch on (a given) quota enforcement for a filesystem.  This takes
  * effect immediately.
@@ -875,8 +899,9 @@ xfs_dqrele_inode(
                xfs_qm_dqrele(ip->i_gdquot);
                ip->i_gdquot = NULL;
        }
-       xfs_iput(ip, XFS_ILOCK_EXCL);
+       xfs_iunlock(ip, XFS_ILOCK_EXCL);
 
+       IRELE(ip);
        return 0;
 }
 
@@ -1143,7 +1168,8 @@ xfs_qm_internalqcheck_adjust(
         * of those now.
         */
        if (! ipreleased) {
-               xfs_iput(ip, lock_flags);
+               xfs_iunlock(ip, lock_flags);
+               IRELE(ip);
                ipreleased = B_TRUE;
                goto again;
        }
@@ -1160,7 +1186,8 @@ xfs_qm_internalqcheck_adjust(
                ASSERT(gd);
                xfs_qm_internalqcheck_dqadjust(ip, gd);
        }
-       xfs_iput(ip, lock_flags);
+       xfs_iunlock(ip, lock_flags);
+       IRELE(ip);
        *res = BULKSTAT_RV_DIDONE;
        return (0);
 }
index 061d827da33cd6ea9411c99665ab74d309ebfde9..7de91d1b75c06c91daea768da891ab49a4152818 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_attr_sf.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_dinode.h"
 #include "xfs_inode.h"
-#include "xfs_ialloc.h"
 #include "xfs_itable.h"
-#include "xfs_btree.h"
 #include "xfs_bmap.h"
 #include "xfs_rtalloc.h"
 #include "xfs_error.h"
-#include "xfs_rw.h"
 #include "xfs_attr.h"
 #include "xfs_buf_item.h"
 #include "xfs_trans_priv.h"
@@ -59,16 +49,14 @@ xfs_trans_dqjoin(
        xfs_trans_t     *tp,
        xfs_dquot_t     *dqp)
 {
-       xfs_dq_logitem_t    *lp = &dqp->q_logitem;
-
        ASSERT(dqp->q_transp != tp);
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
-       ASSERT(lp->qli_dquot == dqp);
+       ASSERT(dqp->q_logitem.qli_dquot == dqp);
 
        /*
         * Get a log_item_desc to point at the new item.
         */
-       (void) xfs_trans_add_item(tp, (xfs_log_item_t*)(lp));
+       xfs_trans_add_item(tp, &dqp->q_logitem.qli_item);
 
        /*
         * Initialize i_transp so we can later determine if this dquot is
@@ -93,16 +81,11 @@ xfs_trans_log_dquot(
        xfs_trans_t     *tp,
        xfs_dquot_t     *dqp)
 {
-       xfs_log_item_desc_t     *lidp;
-
        ASSERT(dqp->q_transp == tp);
        ASSERT(XFS_DQ_IS_LOCKED(dqp));
 
-       lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)(&dqp->q_logitem));
-       ASSERT(lidp != NULL);
-
        tp->t_flags |= XFS_TRANS_DIRTY;
-       lidp->lid_flags |= XFS_LID_DIRTY;
+       dqp->q_logitem.qli_item.li_desc->lid_flags |= XFS_LID_DIRTY;
 }
 
 /*
@@ -874,9 +857,8 @@ xfs_trans_get_qoff_item(
        /*
         * Get a log_item_desc to point at the new item.
         */
-       (void) xfs_trans_add_item(tp, (xfs_log_item_t*)q);
-
-       return (q);
+       xfs_trans_add_item(tp, &q->qql_item);
+       return q;
 }
 
 
@@ -890,13 +872,8 @@ xfs_trans_log_quotaoff_item(
        xfs_trans_t             *tp,
        xfs_qoff_logitem_t      *qlp)
 {
-       xfs_log_item_desc_t     *lidp;
-
-       lidp = xfs_trans_find_item(tp, (xfs_log_item_t *)qlp);
-       ASSERT(lidp != NULL);
-
        tp->t_flags |= XFS_TRANS_DIRTY;
-       lidp->lid_flags |= XFS_LID_DIRTY;
+       qlp->qql_item.li_desc->lid_flags |= XFS_LID_DIRTY;
 }
 
 STATIC void
index 3f3610a7ee059210eea3beadbffe13f87609dce9..975aa10e1a47a3536499b035947ed0c5ac5098a5 100644 (file)
@@ -22,7 +22,6 @@
 #include "xfs_sb.h"
 #include "xfs_inum.h"
 #include "xfs_ag.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_error.h"
 
index a7fbe8a99b12bf2c360ea19372a380ae5d27c855..af168faccc7a5cb8edfacf2e0e0a350028d449fe 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
-#include "xfs_ialloc.h"
 #include "xfs_alloc.h"
 #include "xfs_error.h"
 #include "xfs_trace.h"
@@ -688,8 +683,6 @@ xfs_alloc_ag_vextent_near(
        xfs_agblock_t   ltbno;          /* start bno of left side entry */
        xfs_agblock_t   ltbnoa;         /* aligned ... */
        xfs_extlen_t    ltdiff;         /* difference to left side entry */
-       /*REFERENCED*/
-       xfs_agblock_t   ltend;          /* end bno of left side entry */
        xfs_extlen_t    ltlen;          /* length of left side entry */
        xfs_extlen_t    ltlena;         /* aligned ... */
        xfs_agblock_t   ltnew;          /* useful start bno of left side */
@@ -814,8 +807,7 @@ xfs_alloc_ag_vextent_near(
                if ((error = xfs_alloc_get_rec(cnt_cur, &ltbno, &ltlen, &i)))
                        goto error0;
                XFS_WANT_CORRUPTED_GOTO(i == 1, error0);
-               ltend = ltbno + ltlen;
-               ASSERT(ltend <= be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length));
+               ASSERT(ltbno + ltlen <= be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length));
                args->len = blen;
                if (!xfs_alloc_fix_minleft(args)) {
                        xfs_btree_del_cursor(cnt_cur, XFS_BTREE_NOERROR);
@@ -828,7 +820,7 @@ xfs_alloc_ag_vextent_near(
                 */
                args->agbno = bnew;
                ASSERT(bnew >= ltbno);
-               ASSERT(bnew + blen <= ltend);
+               ASSERT(bnew + blen <= ltbno + ltlen);
                /*
                 * Set up a cursor for the by-bno tree.
                 */
@@ -1157,7 +1149,6 @@ xfs_alloc_ag_vextent_near(
        /*
         * Fix up the length and compute the useful address.
         */
-       ltend = ltbno + ltlen;
        args->len = XFS_EXTLEN_MIN(ltlena, args->maxlen);
        xfs_alloc_fix_len(args);
        if (!xfs_alloc_fix_minleft(args)) {
@@ -1170,7 +1161,7 @@ xfs_alloc_ag_vextent_near(
        (void)xfs_alloc_compute_diff(args->agbno, rlen, args->alignment, ltbno,
                ltlen, &ltnew);
        ASSERT(ltnew >= ltbno);
-       ASSERT(ltnew + rlen <= ltend);
+       ASSERT(ltnew + rlen <= ltbno + ltlen);
        ASSERT(ltnew + rlen <= be32_to_cpu(XFS_BUF_TO_AGF(args->agbp)->agf_length));
        args->agbno = ltnew;
        if ((error = xfs_alloc_fixup_trees(cnt_cur, bno_cur_lt, ltbno, ltlen,
index 6d05199b667cea3c72576750924a8ee8a63effcc..895009a97271fbbd27fcb63b97b9546f375a8778 100644 (file)
@@ -27,16 +27,16 @@ struct xfs_busy_extent;
 /*
  * Freespace allocation types.  Argument to xfs_alloc_[v]extent.
  */
-typedef enum xfs_alloctype
-{
-       XFS_ALLOCTYPE_ANY_AG,           /* allocate anywhere, use rotor */
-       XFS_ALLOCTYPE_FIRST_AG,         /* ... start at ag 0 */
-       XFS_ALLOCTYPE_START_AG,         /* anywhere, start in this a.g. */
-       XFS_ALLOCTYPE_THIS_AG,          /* anywhere in this a.g. */
-       XFS_ALLOCTYPE_START_BNO,        /* near this block else anywhere */
-       XFS_ALLOCTYPE_NEAR_BNO,         /* in this a.g. and near this block */
-       XFS_ALLOCTYPE_THIS_BNO          /* at exactly this block */
-} xfs_alloctype_t;
+#define XFS_ALLOCTYPE_ANY_AG   0x01    /* allocate anywhere, use rotor */
+#define XFS_ALLOCTYPE_FIRST_AG 0x02    /* ... start at ag 0 */
+#define XFS_ALLOCTYPE_START_AG 0x04    /* anywhere, start in this a.g. */
+#define XFS_ALLOCTYPE_THIS_AG  0x08    /* anywhere in this a.g. */
+#define XFS_ALLOCTYPE_START_BNO        0x10    /* near this block else anywhere */
+#define XFS_ALLOCTYPE_NEAR_BNO 0x20    /* in this a.g. and near this block */
+#define XFS_ALLOCTYPE_THIS_BNO 0x40    /* at exactly this block */
+
+/* this should become an enum again when the tracing code is fixed */
+typedef unsigned int xfs_alloctype_t;
 
 #define XFS_ALLOC_TYPES \
        { XFS_ALLOCTYPE_ANY_AG,         "ANY_AG" }, \
index 83f4942187594ac4b998712dc66b2385b083963e..97f7328967fdfe8148b8e1e2479feaa98499859b 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
 #include "xfs_btree_trace.h"
-#include "xfs_ialloc.h"
 #include "xfs_alloc.h"
 #include "xfs_error.h"
 #include "xfs_trace.h"
index b9c196a53c42e219a6cca9113d95be704ecc8f9e..c2568242a9015eaf0bd571104bfc2c468fc2e6bb 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
 #include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_alloc.h"
-#include "xfs_btree.h"
 #include "xfs_inode_item.h"
 #include "xfs_bmap.h"
 #include "xfs_attr.h"
@@ -325,8 +319,7 @@ xfs_attr_set_int(
                return (error);
        }
 
-       xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(args.trans, dp);
+       xfs_trans_ijoin(args.trans, dp);
 
        /*
         * If the attribute list is non-existent or a shortform list,
@@ -396,10 +389,8 @@ xfs_attr_set_int(
                 * bmap_finish() may have committed the last trans and started
                 * a new one.  We need the inode to be in all transactions.
                 */
-               if (committed) {
-                       xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
-                       xfs_trans_ihold(args.trans, dp);
-               }
+               if (committed)
+                       xfs_trans_ijoin(args.trans, dp);
 
                /*
                 * Commit the leaf transformation.  We'll need another (linked)
@@ -544,8 +535,7 @@ xfs_attr_remove_int(xfs_inode_t *dp, struct xfs_name *name, int flags)
         * No need to make quota reservations here. We expect to release some
         * blocks not allocate in the common case.
         */
-       xfs_trans_ijoin(args.trans, dp, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(args.trans, dp);
+       xfs_trans_ijoin(args.trans, dp);
 
        /*
         * Decide on what work routines to call based on the inode size.
@@ -821,8 +811,7 @@ xfs_attr_inactive(xfs_inode_t *dp)
         * No need to make quota reservations here. We expect to release some
         * blocks, not allocate, in the common case.
         */
-       xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(trans, dp);
+       xfs_trans_ijoin(trans, dp);
 
        /*
         * Decide on what work routines to call based on the inode size.
@@ -981,10 +970,8 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
                 * bmap_finish() may have committed the last trans and started
                 * a new one.  We need the inode to be in all transactions.
                 */
-               if (committed) {
-                       xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
-                       xfs_trans_ihold(args->trans, dp);
-               }
+               if (committed)
+                       xfs_trans_ijoin(args->trans, dp);
 
                /*
                 * Commit the current trans (including the inode) and start
@@ -1085,10 +1072,8 @@ xfs_attr_leaf_addname(xfs_da_args_t *args)
                         * and started a new one.  We need the inode to be
                         * in all transactions.
                         */
-                       if (committed) {
-                               xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
-                               xfs_trans_ihold(args->trans, dp);
-                       }
+                       if (committed)
+                               xfs_trans_ijoin(args->trans, dp);
                } else
                        xfs_da_buf_done(bp);
 
@@ -1161,10 +1146,8 @@ xfs_attr_leaf_removename(xfs_da_args_t *args)
                 * bmap_finish() may have committed the last trans and started
                 * a new one.  We need the inode to be in all transactions.
                 */
-               if (committed) {
-                       xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
-                       xfs_trans_ihold(args->trans, dp);
-               }
+               if (committed)
+                       xfs_trans_ijoin(args->trans, dp);
        } else
                xfs_da_buf_done(bp);
        return(0);
@@ -1317,10 +1300,8 @@ restart:
                         * and started a new one.  We need the inode to be
                         * in all transactions.
                         */
-                       if (committed) {
-                               xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
-                               xfs_trans_ihold(args->trans, dp);
-                       }
+                       if (committed)
+                               xfs_trans_ijoin(args->trans, dp);
 
                        /*
                         * Commit the node conversion and start the next
@@ -1356,10 +1337,8 @@ restart:
                 * bmap_finish() may have committed the last trans and started
                 * a new one.  We need the inode to be in all transactions.
                 */
-               if (committed) {
-                       xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
-                       xfs_trans_ihold(args->trans, dp);
-               }
+               if (committed)
+                       xfs_trans_ijoin(args->trans, dp);
        } else {
                /*
                 * Addition succeeded, update Btree hashvals.
@@ -1470,10 +1449,8 @@ restart:
                         * and started a new one.  We need the inode to be
                         * in all transactions.
                         */
-                       if (committed) {
-                               xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
-                               xfs_trans_ihold(args->trans, dp);
-                       }
+                       if (committed)
+                               xfs_trans_ijoin(args->trans, dp);
                }
 
                /*
@@ -1604,10 +1581,8 @@ xfs_attr_node_removename(xfs_da_args_t *args)
                 * bmap_finish() may have committed the last trans and started
                 * a new one.  We need the inode to be in all transactions.
                 */
-               if (committed) {
-                       xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
-                       xfs_trans_ihold(args->trans, dp);
-               }
+               if (committed)
+                       xfs_trans_ijoin(args->trans, dp);
 
                /*
                 * Commit the Btree join operation and start a new trans.
@@ -1658,10 +1633,8 @@ xfs_attr_node_removename(xfs_da_args_t *args)
                         * and started a new one.  We need the inode to be
                         * in all transactions.
                         */
-                       if (committed) {
-                               xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
-                               xfs_trans_ihold(args->trans, dp);
-                       }
+                       if (committed)
+                               xfs_trans_ijoin(args->trans, dp);
                } else
                        xfs_da_brelse(args->trans, bp);
        }
@@ -2004,7 +1977,7 @@ xfs_attr_rmtval_get(xfs_da_args_t *args)
                error = xfs_bmapi(args->trans, args->dp, (xfs_fileoff_t)lblkno,
                                  args->rmtblkcnt,
                                  XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
-                                 NULL, 0, map, &nmap, NULL, NULL);
+                                 NULL, 0, map, &nmap, NULL);
                if (error)
                        return(error);
                ASSERT(nmap >= 1);
@@ -2083,7 +2056,7 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
                                  XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA |
                                                        XFS_BMAPI_WRITE,
                                  args->firstblock, args->total, &map, &nmap,
-                                 args->flist, NULL);
+                                 args->flist);
                if (!error) {
                        error = xfs_bmap_finish(&args->trans, args->flist,
                                                &committed);
@@ -2099,10 +2072,8 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
                 * bmap_finish() may have committed the last trans and started
                 * a new one.  We need the inode to be in all transactions.
                 */
-               if (committed) {
-                       xfs_trans_ijoin(args->trans, dp, XFS_ILOCK_EXCL);
-                       xfs_trans_ihold(args->trans, dp);
-               }
+               if (committed)
+                       xfs_trans_ijoin(args->trans, dp);
 
                ASSERT(nmap == 1);
                ASSERT((map.br_startblock != DELAYSTARTBLOCK) &&
@@ -2136,7 +2107,7 @@ xfs_attr_rmtval_set(xfs_da_args_t *args)
                                  args->rmtblkcnt,
                                  XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
                                  args->firstblock, 0, &map, &nmap,
-                                 NULL, NULL);
+                                 NULL);
                if (error) {
                        return(error);
                }
@@ -2201,7 +2172,7 @@ xfs_attr_rmtval_remove(xfs_da_args_t *args)
                                        args->rmtblkcnt,
                                        XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
                                        args->firstblock, 0, &map, &nmap,
-                                       args->flist, NULL);
+                                       args->flist);
                if (error) {
                        return(error);
                }
@@ -2239,7 +2210,7 @@ xfs_attr_rmtval_remove(xfs_da_args_t *args)
                error = xfs_bunmapi(args->trans, args->dp, lblkno, blkcnt,
                                    XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
                                    1, args->firstblock, args->flist,
-                                   NULL, &done);
+                                   &done);
                if (!error) {
                        error = xfs_bmap_finish(&args->trans, args->flist,
                                                &committed);
@@ -2255,10 +2226,8 @@ xfs_attr_rmtval_remove(xfs_da_args_t *args)
                 * bmap_finish() may have committed the last trans and started
                 * a new one.  We need the inode to be in all transactions.
                 */
-               if (committed) {
-                       xfs_trans_ijoin(args->trans, args->dp, XFS_ILOCK_EXCL);
-                       xfs_trans_ihold(args->trans, args->dp);
-               }
+               if (committed)
+                       xfs_trans_ijoin(args->trans, args->dp);
 
                /*
                 * Close out trans and start the next one in the chain.
index a90ce74fc256904837381f61e49c0e569818e89f..a6cff8edcdb6a33cfa6b5554c06be24439801528 100644 (file)
@@ -24,8 +24,6 @@
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
@@ -33,7 +31,6 @@
 #include "xfs_ialloc_btree.h"
 #include "xfs_alloc.h"
 #include "xfs_btree.h"
-#include "xfs_dir2_sf.h"
 #include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
@@ -2931,7 +2928,7 @@ xfs_attr_leaf_freextent(xfs_trans_t **trans, xfs_inode_t *dp,
                nmap = 1;
                error = xfs_bmapi(*trans, dp, (xfs_fileoff_t)tblkno, tblkcnt,
                                        XFS_BMAPI_ATTRFORK | XFS_BMAPI_METADATA,
-                                       NULL, 0, &map, &nmap, NULL, NULL);
+                                       NULL, 0, &map, &nmap, NULL);
                if (error) {
                        return(error);
                }
index 99587ded043f84b580f0d3331df408a0aa0960fe..23f14e595c18cd3a8068796f5b73396fa9db98f9 100644 (file)
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
 #include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
-#include "xfs_ialloc.h"
 #include "xfs_itable.h"
 #include "xfs_dir2_data.h"
 #include "xfs_dir2_leaf.h"
@@ -104,7 +101,6 @@ xfs_bmap_add_extent(
        xfs_fsblock_t           *first, /* pointer to firstblock variable */
        xfs_bmap_free_t         *flist, /* list of extents to be freed */
        int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     whichfork, /* data or attr fork */
        int                     rsvd);  /* OK to allocate reserved blocks */
 
@@ -122,7 +118,6 @@ xfs_bmap_add_extent_delay_real(
        xfs_fsblock_t           *first, /* pointer to firstblock variable */
        xfs_bmap_free_t         *flist, /* list of extents to be freed */
        int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     rsvd);  /* OK to allocate reserved blocks */
 
 /*
@@ -135,7 +130,6 @@ xfs_bmap_add_extent_hole_delay(
        xfs_extnum_t            idx,    /* extent number to update/insert */
        xfs_bmbt_irec_t         *new,   /* new data to add to file extents */
        int                     *logflagsp,/* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     rsvd);  /* OK to allocate reserved blocks */
 
 /*
@@ -149,7 +143,6 @@ xfs_bmap_add_extent_hole_real(
        xfs_btree_cur_t         *cur,   /* if null, not a btree */
        xfs_bmbt_irec_t         *new,   /* new data to add to file extents */
        int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     whichfork); /* data or attr fork */
 
 /*
@@ -162,8 +155,7 @@ xfs_bmap_add_extent_unwritten_real(
        xfs_extnum_t            idx,    /* extent number to update/insert */
        xfs_btree_cur_t         **curp, /* if *curp is null, not a btree */
        xfs_bmbt_irec_t         *new,   /* new data to add to file extents */
-       int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta); /* Change made to incore extents */
+       int                     *logflagsp); /* inode logging flags */
 
 /*
  * xfs_bmap_alloc is called by xfs_bmapi to allocate an extent for a file.
@@ -200,7 +192,6 @@ xfs_bmap_del_extent(
        xfs_btree_cur_t         *cur,   /* if null, not a btree */
        xfs_bmbt_irec_t         *new,   /* new data to add to file extents */
        int                     *logflagsp,/* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     whichfork, /* data or attr fork */
        int                     rsvd);   /* OK to allocate reserved blocks */
 
@@ -489,7 +480,6 @@ xfs_bmap_add_extent(
        xfs_fsblock_t           *first, /* pointer to firstblock variable */
        xfs_bmap_free_t         *flist, /* list of extents to be freed */
        int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     whichfork, /* data or attr fork */
        int                     rsvd)   /* OK to use reserved data blocks */
 {
@@ -524,15 +514,6 @@ xfs_bmap_add_extent(
                        logflags = XFS_ILOG_CORE | xfs_ilog_fext(whichfork);
                } else
                        logflags = 0;
-               /* DELTA: single new extent */
-               if (delta) {
-                       if (delta->xed_startoff > new->br_startoff)
-                               delta->xed_startoff = new->br_startoff;
-                       if (delta->xed_blockcount <
-                                       new->br_startoff + new->br_blockcount)
-                               delta->xed_blockcount = new->br_startoff +
-                                               new->br_blockcount;
-               }
        }
        /*
         * Any kind of new delayed allocation goes here.
@@ -542,7 +523,7 @@ xfs_bmap_add_extent(
                        ASSERT((cur->bc_private.b.flags &
                                XFS_BTCUR_BPRV_WASDEL) == 0);
                if ((error = xfs_bmap_add_extent_hole_delay(ip, idx, new,
-                               &logflags, delta, rsvd)))
+                               &logflags, rsvd)))
                        goto done;
        }
        /*
@@ -553,7 +534,7 @@ xfs_bmap_add_extent(
                        ASSERT((cur->bc_private.b.flags &
                                XFS_BTCUR_BPRV_WASDEL) == 0);
                if ((error = xfs_bmap_add_extent_hole_real(ip, idx, cur, new,
-                               &logflags, delta, whichfork)))
+                               &logflags, whichfork)))
                        goto done;
        } else {
                xfs_bmbt_irec_t prev;   /* old extent at offset idx */
@@ -578,17 +559,17 @@ xfs_bmap_add_extent(
                                                XFS_BTCUR_BPRV_WASDEL);
                                if ((error = xfs_bmap_add_extent_delay_real(ip,
                                        idx, &cur, new, &da_new, first, flist,
-                                       &logflags, delta, rsvd)))
+                                       &logflags, rsvd)))
                                        goto done;
                        } else if (new->br_state == XFS_EXT_NORM) {
                                ASSERT(new->br_state == XFS_EXT_NORM);
                                if ((error = xfs_bmap_add_extent_unwritten_real(
-                                       ip, idx, &cur, new, &logflags, delta)))
+                                       ip, idx, &cur, new, &logflags)))
                                        goto done;
                        } else {
                                ASSERT(new->br_state == XFS_EXT_UNWRITTEN);
                                if ((error = xfs_bmap_add_extent_unwritten_real(
-                                       ip, idx, &cur, new, &logflags, delta)))
+                                       ip, idx, &cur, new, &logflags)))
                                        goto done;
                        }
                        ASSERT(*curp == cur || *curp == NULL);
@@ -601,7 +582,7 @@ xfs_bmap_add_extent(
                                ASSERT((cur->bc_private.b.flags &
                                        XFS_BTCUR_BPRV_WASDEL) == 0);
                        if ((error = xfs_bmap_add_extent_hole_real(ip, idx, cur,
-                                       new, &logflags, delta, whichfork)))
+                                       new, &logflags, whichfork)))
                                goto done;
                }
        }
@@ -666,7 +647,6 @@ xfs_bmap_add_extent_delay_real(
        xfs_fsblock_t           *first, /* pointer to firstblock variable */
        xfs_bmap_free_t         *flist, /* list of extents to be freed */
        int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     rsvd)   /* OK to use reserved data block allocation */
 {
        xfs_btree_cur_t         *cur;   /* btree cursor */
@@ -797,11 +777,6 @@ xfs_bmap_add_extent_delay_real(
                                goto done;
                }
                *dnew = 0;
-               /* DELTA: Three in-core extents are replaced by one. */
-               temp = LEFT.br_startoff;
-               temp2 = LEFT.br_blockcount +
-                       PREV.br_blockcount +
-                       RIGHT.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING | BMAP_LEFT_CONTIG:
@@ -832,10 +807,6 @@ xfs_bmap_add_extent_delay_real(
                                goto done;
                }
                *dnew = 0;
-               /* DELTA: Two in-core extents are replaced by one. */
-               temp = LEFT.br_startoff;
-               temp2 = LEFT.br_blockcount +
-                       PREV.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING | BMAP_RIGHT_CONTIG:
@@ -867,10 +838,6 @@ xfs_bmap_add_extent_delay_real(
                                goto done;
                }
                *dnew = 0;
-               /* DELTA: Two in-core extents are replaced by one. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount +
-                       RIGHT.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING:
@@ -900,9 +867,6 @@ xfs_bmap_add_extent_delay_real(
                        XFS_WANT_CORRUPTED_GOTO(i == 1, done);
                }
                *dnew = 0;
-               /* DELTA: The in-core extent described by new changed type. */
-               temp = new->br_startoff;
-               temp2 = new->br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_LEFT_CONTIG:
@@ -942,10 +906,6 @@ xfs_bmap_add_extent_delay_real(
                xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
                trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_);
                *dnew = temp;
-               /* DELTA: The boundary between two in-core extents moved. */
-               temp = LEFT.br_startoff;
-               temp2 = LEFT.br_blockcount +
-                       PREV.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING:
@@ -990,9 +950,6 @@ xfs_bmap_add_extent_delay_real(
                xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
                trace_xfs_bmap_post_update(ip, idx + 1, state, _THIS_IP_);
                *dnew = temp;
-               /* DELTA: One in-core extent is split in two. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount;
                break;
 
        case BMAP_RIGHT_FILLING | BMAP_RIGHT_CONTIG:
@@ -1031,10 +988,6 @@ xfs_bmap_add_extent_delay_real(
                xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
                trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_);
                *dnew = temp;
-               /* DELTA: The boundary between two in-core extents moved. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount +
-                       RIGHT.br_blockcount;
                break;
 
        case BMAP_RIGHT_FILLING:
@@ -1078,9 +1031,6 @@ xfs_bmap_add_extent_delay_real(
                xfs_bmbt_set_startblock(ep, nullstartblock((int)temp));
                trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_);
                *dnew = temp;
-               /* DELTA: One in-core extent is split in two. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount;
                break;
 
        case 0:
@@ -1161,9 +1111,6 @@ xfs_bmap_add_extent_delay_real(
                        nullstartblock((int)temp2));
                trace_xfs_bmap_post_update(ip, idx + 2, state, _THIS_IP_);
                *dnew = temp + temp2;
-               /* DELTA: One in-core extent is split in three. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_LEFT_CONTIG | BMAP_RIGHT_CONTIG:
@@ -1179,13 +1126,6 @@ xfs_bmap_add_extent_delay_real(
                ASSERT(0);
        }
        *curp = cur;
-       if (delta) {
-               temp2 += temp;
-               if (delta->xed_startoff > temp)
-                       delta->xed_startoff = temp;
-               if (delta->xed_blockcount < temp2)
-                       delta->xed_blockcount = temp2;
-       }
 done:
        *logflagsp = rval;
        return error;
@@ -1204,8 +1144,7 @@ xfs_bmap_add_extent_unwritten_real(
        xfs_extnum_t            idx,    /* extent number to update/insert */
        xfs_btree_cur_t         **curp, /* if *curp is null, not a btree */
        xfs_bmbt_irec_t         *new,   /* new data to add to file extents */
-       int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta) /* Change made to incore extents */
+       int                     *logflagsp) /* inode logging flags */
 {
        xfs_btree_cur_t         *cur;   /* btree cursor */
        xfs_bmbt_rec_host_t     *ep;    /* extent entry for idx */
@@ -1219,8 +1158,6 @@ xfs_bmap_add_extent_unwritten_real(
                                        /* left is 0, right is 1, prev is 2 */
        int                     rval=0; /* return value (logging flags) */
        int                     state = 0;/* state bits, accessed thru macros */
-       xfs_filblks_t           temp=0;
-       xfs_filblks_t           temp2=0;
 
 #define        LEFT            r[0]
 #define        RIGHT           r[1]
@@ -1341,11 +1278,6 @@ xfs_bmap_add_extent_unwritten_real(
                                RIGHT.br_blockcount, LEFT.br_state)))
                                goto done;
                }
-               /* DELTA: Three in-core extents are replaced by one. */
-               temp = LEFT.br_startoff;
-               temp2 = LEFT.br_blockcount +
-                       PREV.br_blockcount +
-                       RIGHT.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING | BMAP_LEFT_CONTIG:
@@ -1382,10 +1314,6 @@ xfs_bmap_add_extent_unwritten_real(
                                LEFT.br_state)))
                                goto done;
                }
-               /* DELTA: Two in-core extents are replaced by one. */
-               temp = LEFT.br_startoff;
-               temp2 = LEFT.br_blockcount +
-                       PREV.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING | BMAP_RIGHT_CONTIG:
@@ -1422,10 +1350,6 @@ xfs_bmap_add_extent_unwritten_real(
                                newext)))
                                goto done;
                }
-               /* DELTA: Two in-core extents are replaced by one. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount +
-                       RIGHT.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_RIGHT_FILLING:
@@ -1453,9 +1377,6 @@ xfs_bmap_add_extent_unwritten_real(
                                newext)))
                                goto done;
                }
-               /* DELTA: The in-core extent described by new changed type. */
-               temp = new->br_startoff;
-               temp2 = new->br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_LEFT_CONTIG:
@@ -1501,10 +1422,6 @@ xfs_bmap_add_extent_unwritten_real(
                                LEFT.br_state))
                                goto done;
                }
-               /* DELTA: The boundary between two in-core extents moved. */
-               temp = LEFT.br_startoff;
-               temp2 = LEFT.br_blockcount +
-                       PREV.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING:
@@ -1544,9 +1461,6 @@ xfs_bmap_add_extent_unwritten_real(
                                goto done;
                        XFS_WANT_CORRUPTED_GOTO(i == 1, done);
                }
-               /* DELTA: One in-core extent is split in two. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount;
                break;
 
        case BMAP_RIGHT_FILLING | BMAP_RIGHT_CONTIG:
@@ -1587,10 +1501,6 @@ xfs_bmap_add_extent_unwritten_real(
                                newext)))
                                goto done;
                }
-               /* DELTA: The boundary between two in-core extents moved. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount +
-                       RIGHT.br_blockcount;
                break;
 
        case BMAP_RIGHT_FILLING:
@@ -1630,9 +1540,6 @@ xfs_bmap_add_extent_unwritten_real(
                                goto done;
                        XFS_WANT_CORRUPTED_GOTO(i == 1, done);
                }
-               /* DELTA: One in-core extent is split in two. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount;
                break;
 
        case 0:
@@ -1692,9 +1599,6 @@ xfs_bmap_add_extent_unwritten_real(
                                goto done;
                        XFS_WANT_CORRUPTED_GOTO(i == 1, done);
                }
-               /* DELTA: One in-core extent is split in three. */
-               temp = PREV.br_startoff;
-               temp2 = PREV.br_blockcount;
                break;
 
        case BMAP_LEFT_FILLING | BMAP_LEFT_CONTIG | BMAP_RIGHT_CONTIG:
@@ -1710,13 +1614,6 @@ xfs_bmap_add_extent_unwritten_real(
                ASSERT(0);
        }
        *curp = cur;
-       if (delta) {
-               temp2 += temp;
-               if (delta->xed_startoff > temp)
-                       delta->xed_startoff = temp;
-               if (delta->xed_blockcount < temp2)
-                       delta->xed_blockcount = temp2;
-       }
 done:
        *logflagsp = rval;
        return error;
@@ -1736,7 +1633,6 @@ xfs_bmap_add_extent_hole_delay(
        xfs_extnum_t            idx,    /* extent number to update/insert */
        xfs_bmbt_irec_t         *new,   /* new data to add to file extents */
        int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     rsvd)           /* OK to allocate reserved blocks */
 {
        xfs_bmbt_rec_host_t     *ep;    /* extent record for idx */
@@ -1747,7 +1643,6 @@ xfs_bmap_add_extent_hole_delay(
        xfs_bmbt_irec_t         right;  /* right neighbor extent entry */
        int                     state;  /* state bits, accessed thru macros */
        xfs_filblks_t           temp=0; /* temp for indirect calculations */
-       xfs_filblks_t           temp2=0;
 
        ifp = XFS_IFORK_PTR(ip, XFS_DATA_FORK);
        ep = xfs_iext_get_ext(ifp, idx);
@@ -1819,9 +1714,6 @@ xfs_bmap_add_extent_hole_delay(
 
                xfs_iext_remove(ip, idx, 1, state);
                ip->i_df.if_lastex = idx - 1;
-               /* DELTA: Two in-core extents were replaced by one. */
-               temp2 = temp;
-               temp = left.br_startoff;
                break;
 
        case BMAP_LEFT_CONTIG:
@@ -1841,9 +1733,6 @@ xfs_bmap_add_extent_hole_delay(
                trace_xfs_bmap_post_update(ip, idx - 1, state, _THIS_IP_);
 
                ip->i_df.if_lastex = idx - 1;
-               /* DELTA: One in-core extent grew into a hole. */
-               temp2 = temp;
-               temp = left.br_startoff;
                break;
 
        case BMAP_RIGHT_CONTIG:
@@ -1862,9 +1751,6 @@ xfs_bmap_add_extent_hole_delay(
                trace_xfs_bmap_post_update(ip, idx, state, _THIS_IP_);
 
                ip->i_df.if_lastex = idx;
-               /* DELTA: One in-core extent grew into a hole. */
-               temp2 = temp;
-               temp = new->br_startoff;
                break;
 
        case 0:
@@ -1876,9 +1762,6 @@ xfs_bmap_add_extent_hole_delay(
                oldlen = newlen = 0;
                xfs_iext_insert(ip, idx, 1, new, state);
                ip->i_df.if_lastex = idx;
-               /* DELTA: A new in-core extent was added in a hole. */
-               temp2 = new->br_blockcount;
-               temp = new->br_startoff;
                break;
        }
        if (oldlen != newlen) {
@@ -1889,13 +1772,6 @@ xfs_bmap_add_extent_hole_delay(
                 * Nothing to do for disk quota accounting here.
                 */
        }
-       if (delta) {
-               temp2 += temp;
-               if (delta->xed_startoff > temp)
-                       delta->xed_startoff = temp;
-               if (delta->xed_blockcount < temp2)
-                       delta->xed_blockcount = temp2;
-       }
        *logflagsp = 0;
        return 0;
 }
@@ -1911,7 +1787,6 @@ xfs_bmap_add_extent_hole_real(
        xfs_btree_cur_t         *cur,   /* if null, not a btree */
        xfs_bmbt_irec_t         *new,   /* new data to add to file extents */
        int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     whichfork) /* data or attr fork */
 {
        xfs_bmbt_rec_host_t     *ep;    /* pointer to extent entry ins. point */
@@ -1922,8 +1797,6 @@ xfs_bmap_add_extent_hole_real(
        xfs_bmbt_irec_t         right;  /* right neighbor extent entry */
        int                     rval=0; /* return value (logging flags) */
        int                     state;  /* state bits, accessed thru macros */
-       xfs_filblks_t           temp=0;
-       xfs_filblks_t           temp2=0;
 
        ifp = XFS_IFORK_PTR(ip, whichfork);
        ASSERT(idx <= ifp->if_bytes / (uint)sizeof(xfs_bmbt_rec_t));
@@ -2020,11 +1893,6 @@ xfs_bmap_add_extent_hole_real(
                                        left.br_state)))
                                goto done;
                }
-               /* DELTA: Two in-core extents were replaced by one. */
-               temp = left.br_startoff;
-               temp2 = left.br_blockcount +
-                       new->br_blockcount +
-                       right.br_blockcount;
                break;
 
        case BMAP_LEFT_CONTIG:
@@ -2056,10 +1924,6 @@ xfs_bmap_add_extent_hole_real(
                                        left.br_state)))
                                goto done;
                }
-               /* DELTA: One in-core extent grew. */
-               temp = left.br_startoff;
-               temp2 = left.br_blockcount +
-                       new->br_blockcount;
                break;
 
        case BMAP_RIGHT_CONTIG:
@@ -2092,10 +1956,6 @@ xfs_bmap_add_extent_hole_real(
                                        right.br_state)))
                                goto done;
                }
-               /* DELTA: One in-core extent grew. */
-               temp = new->br_startoff;
-               temp2 = new->br_blockcount +
-                       right.br_blockcount;
                break;
 
        case 0:
@@ -2123,18 +1983,8 @@ xfs_bmap_add_extent_hole_real(
                                goto done;
                        XFS_WANT_CORRUPTED_GOTO(i == 1, done);
                }
-               /* DELTA: A new extent was added in a hole. */
-               temp = new->br_startoff;
-               temp2 = new->br_blockcount;
                break;
        }
-       if (delta) {
-               temp2 += temp;
-               if (delta->xed_startoff > temp)
-                       delta->xed_startoff = temp;
-               if (delta->xed_blockcount < temp2)
-                       delta->xed_blockcount = temp2;
-       }
 done:
        *logflagsp = rval;
        return error;
@@ -2959,7 +2809,6 @@ xfs_bmap_del_extent(
        xfs_btree_cur_t         *cur,   /* if null, not a btree */
        xfs_bmbt_irec_t         *del,   /* data to remove from extents */
        int                     *logflagsp, /* inode logging flags */
-       xfs_extdelta_t          *delta, /* Change made to incore extents */
        int                     whichfork, /* data or attr fork */
        int                     rsvd)   /* OK to allocate reserved blocks */
 {
@@ -3265,14 +3114,6 @@ xfs_bmap_del_extent(
        if (da_old > da_new)
                xfs_mod_incore_sb(mp, XFS_SBS_FDBLOCKS, (int64_t)(da_old - da_new),
                        rsvd);
-       if (delta) {
-               /* DELTA: report the original extent. */
-               if (delta->xed_startoff > got.br_startoff)
-                       delta->xed_startoff = got.br_startoff;
-               if (delta->xed_blockcount < got.br_startoff+got.br_blockcount)
-                       delta->xed_blockcount = got.br_startoff +
-                                                       got.br_blockcount;
-       }
 done:
        *logflagsp = flags;
        return error;
@@ -3754,9 +3595,10 @@ xfs_bmap_add_attrfork(
                ip->i_d.di_aformat = XFS_DINODE_FMT_EXTENTS;
        }
        ASSERT(ip->i_d.di_anextents == 0);
-       IHOLD(ip);
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+
+       xfs_trans_ijoin_ref(tp, ip, XFS_ILOCK_EXCL);
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
+
        switch (ip->i_d.di_format) {
        case XFS_DINODE_FMT_DEV:
                ip->i_d.di_forkoff = roundup(sizeof(xfs_dev_t), 8) >> 3;
@@ -4483,8 +4325,7 @@ xfs_bmapi(
        xfs_extlen_t    total,          /* total blocks needed */
        xfs_bmbt_irec_t *mval,          /* output: map values */
        int             *nmap,          /* i/o: mval size/count */
-       xfs_bmap_free_t *flist,         /* i/o: list extents to free */
-       xfs_extdelta_t  *delta)         /* o: change made to incore extents */
+       xfs_bmap_free_t *flist)         /* i/o: list extents to free */
 {
        xfs_fsblock_t   abno;           /* allocated block number */
        xfs_extlen_t    alen;           /* allocated extent length */
@@ -4596,10 +4437,7 @@ xfs_bmapi(
        end = bno + len;
        obno = bno;
        bma.ip = NULL;
-       if (delta) {
-               delta->xed_startoff = NULLFILEOFF;
-               delta->xed_blockcount = 0;
-       }
+
        while (bno < end && n < *nmap) {
                /*
                 * Reading past eof, act as though there's a hole
@@ -4620,19 +4458,13 @@ xfs_bmapi(
                         * allocate the stuff asked for in this bmap call
                         * but that wouldn't be as good.
                         */
-                       if (wasdelay && !(flags & XFS_BMAPI_EXACT)) {
+                       if (wasdelay) {
                                alen = (xfs_extlen_t)got.br_blockcount;
                                aoff = got.br_startoff;
                                if (lastx != NULLEXTNUM && lastx) {
                                        ep = xfs_iext_get_ext(ifp, lastx - 1);
                                        xfs_bmbt_get_all(ep, &prev);
                                }
-                       } else if (wasdelay) {
-                               alen = (xfs_extlen_t)
-                                       XFS_FILBLKS_MIN(len,
-                                               (got.br_startoff +
-                                                got.br_blockcount) - bno);
-                               aoff = bno;
                        } else {
                                alen = (xfs_extlen_t)
                                        XFS_FILBLKS_MIN(len, MAXEXTLEN);
@@ -4831,7 +4663,7 @@ xfs_bmapi(
                                        got.br_state = XFS_EXT_UNWRITTEN;
                        }
                        error = xfs_bmap_add_extent(ip, lastx, &cur, &got,
-                               firstblock, flist, &tmp_logflags, delta,
+                               firstblock, flist, &tmp_logflags,
                                whichfork, (flags & XFS_BMAPI_RSVBLOCKS));
                        logflags |= tmp_logflags;
                        if (error)
@@ -4927,7 +4759,7 @@ xfs_bmapi(
                        }
                        mval->br_state = XFS_EXT_NORM;
                        error = xfs_bmap_add_extent(ip, lastx, &cur, mval,
-                               firstblock, flist, &tmp_logflags, delta,
+                               firstblock, flist, &tmp_logflags,
                                whichfork, (flags & XFS_BMAPI_RSVBLOCKS));
                        logflags |= tmp_logflags;
                        if (error)
@@ -5017,14 +4849,6 @@ xfs_bmapi(
        ASSERT(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE ||
               XFS_IFORK_NEXTENTS(ip, whichfork) > ifp->if_ext_max);
        error = 0;
-       if (delta && delta->xed_startoff != NULLFILEOFF) {
-               /* A change was actually made.
-                * Note that delta->xed_blockount is an offset at this
-                * point and needs to be converted to a block count.
-                */
-               ASSERT(delta->xed_blockcount > delta->xed_startoff);
-               delta->xed_blockcount -= delta->xed_startoff;
-       }
 error0:
        /*
         * Log everything.  Do this after conversion, there's no point in
@@ -5136,8 +4960,6 @@ xfs_bunmapi(
        xfs_fsblock_t           *firstblock,    /* first allocated block
                                                   controls a.g. for allocs */
        xfs_bmap_free_t         *flist,         /* i/o: list extents to free */
-       xfs_extdelta_t          *delta,         /* o: change made to incore
-                                                  extents */
        int                     *done)          /* set if not done yet */
 {
        xfs_btree_cur_t         *cur;           /* bmap btree cursor */
@@ -5196,10 +5018,7 @@ xfs_bunmapi(
        bno = start + len - 1;
        ep = xfs_bmap_search_extents(ip, bno, whichfork, &eof, &lastx, &got,
                &prev);
-       if (delta) {
-               delta->xed_startoff = NULLFILEOFF;
-               delta->xed_blockcount = 0;
-       }
+
        /*
         * Check to see if the given block number is past the end of the
         * file, back up to the last block if so...
@@ -5297,7 +5116,7 @@ xfs_bunmapi(
                        }
                        del.br_state = XFS_EXT_UNWRITTEN;
                        error = xfs_bmap_add_extent(ip, lastx, &cur, &del,
-                               firstblock, flist, &logflags, delta,
+                               firstblock, flist, &logflags,
                                XFS_DATA_FORK, 0);
                        if (error)
                                goto error0;
@@ -5352,7 +5171,7 @@ xfs_bunmapi(
                                prev.br_state = XFS_EXT_UNWRITTEN;
                                error = xfs_bmap_add_extent(ip, lastx - 1, &cur,
                                        &prev, firstblock, flist, &logflags,
-                                       delta, XFS_DATA_FORK, 0);
+                                       XFS_DATA_FORK, 0);
                                if (error)
                                        goto error0;
                                goto nodelete;
@@ -5361,7 +5180,7 @@ xfs_bunmapi(
                                del.br_state = XFS_EXT_UNWRITTEN;
                                error = xfs_bmap_add_extent(ip, lastx, &cur,
                                        &del, firstblock, flist, &logflags,
-                                       delta, XFS_DATA_FORK, 0);
+                                       XFS_DATA_FORK, 0);
                                if (error)
                                        goto error0;
                                goto nodelete;
@@ -5414,7 +5233,7 @@ xfs_bunmapi(
                        goto error0;
                }
                error = xfs_bmap_del_extent(ip, tp, lastx, flist, cur, &del,
-                               &tmp_logflags, delta, whichfork, rsvd);
+                               &tmp_logflags, whichfork, rsvd);
                logflags |= tmp_logflags;
                if (error)
                        goto error0;
@@ -5471,14 +5290,6 @@ nodelete:
        ASSERT(ifp->if_ext_max ==
               XFS_IFORK_SIZE(ip, whichfork) / (uint)sizeof(xfs_bmbt_rec_t));
        error = 0;
-       if (delta && delta->xed_startoff != NULLFILEOFF) {
-               /* A change was actually made.
-                * Note that delta->xed_blockount is an offset at this
-                * point and needs to be converted to a block count.
-                */
-               ASSERT(delta->xed_blockcount > delta->xed_startoff);
-               delta->xed_blockcount -= delta->xed_startoff;
-       }
 error0:
        /*
         * Log everything.  Do this after conversion, there's no point in
@@ -5605,28 +5416,6 @@ xfs_getbmap(
                prealloced = 0;
                fixlen = 1LL << 32;
        } else {
-               /*
-                * If the BMV_IF_NO_DMAPI_READ interface bit specified, do
-                * not generate a DMAPI read event.  Otherwise, if the
-                * DM_EVENT_READ bit is set for the file, generate a read
-                * event in order that the DMAPI application may do its thing
-                * before we return the extents.  Usually this means restoring
-                * user file data to regions of the file that look like holes.
-                *
-                * The "old behavior" (from XFS_IOC_GETBMAP) is to not specify
-                * BMV_IF_NO_DMAPI_READ so that read events are generated.
-                * If this were not true, callers of ioctl(XFS_IOC_GETBMAP)
-                * could misinterpret holes in a DMAPI file as true holes,
-                * when in fact they may represent offline user data.
-                */
-               if (DM_EVENT_ENABLED(ip, DM_EVENT_READ) &&
-                   !(iflags & BMV_IF_NO_DMAPI_READ)) {
-                       error = XFS_SEND_DATA(mp, DM_EVENT_READ, ip,
-                                             0, 0, 0, NULL);
-                       if (error)
-                               return XFS_ERROR(error);
-               }
-
                if (ip->i_d.di_format != XFS_DINODE_FMT_EXTENTS &&
                    ip->i_d.di_format != XFS_DINODE_FMT_BTREE &&
                    ip->i_d.di_format != XFS_DINODE_FMT_LOCAL)
@@ -5713,7 +5502,7 @@ xfs_getbmap(
                error = xfs_bmapi(NULL, ip, XFS_BB_TO_FSBT(mp, bmv->bmv_offset),
                                  XFS_BB_TO_FSB(mp, bmv->bmv_length),
                                  bmapi_flags, NULL, 0, map, &nmap,
-                                 NULL, NULL);
+                                 NULL);
                if (error)
                        goto out_free_map;
                ASSERT(nmap <= subnex);
@@ -5859,66 +5648,34 @@ xfs_bmap_eof(
 }
 
 #ifdef DEBUG
-STATIC
-xfs_buf_t *
+STATIC struct xfs_buf *
 xfs_bmap_get_bp(
-       xfs_btree_cur_t         *cur,
+       struct xfs_btree_cur    *cur,
        xfs_fsblock_t           bno)
 {
-       int i;
-       xfs_buf_t *bp;
+       struct xfs_log_item_desc *lidp;
+       int                     i;
 
        if (!cur)
-               return(NULL);
-
-       bp = NULL;
-       for(i = 0; i < XFS_BTREE_MAXLEVELS; i++) {
-               bp = cur->bc_bufs[i];
-               if (!bp) break;
-               if (XFS_BUF_ADDR(bp) == bno)
-                       break;  /* Found it */
-       }
-       if (i == XFS_BTREE_MAXLEVELS)
-               bp = NULL;
-
-       if (!bp) { /* Chase down all the log items to see if the bp is there */
-               xfs_log_item_chunk_t    *licp;
-               xfs_trans_t             *tp;
-
-               tp = cur->bc_tp;
-               licp = &tp->t_items;
-               while (!bp && licp != NULL) {
-                       if (xfs_lic_are_all_free(licp)) {
-                               licp = licp->lic_next;
-                               continue;
-                       }
-                       for (i = 0; i < licp->lic_unused; i++) {
-                               xfs_log_item_desc_t     *lidp;
-                               xfs_log_item_t          *lip;
-                               xfs_buf_log_item_t      *bip;
-                               xfs_buf_t               *lbp;
-
-                               if (xfs_lic_isfree(licp, i)) {
-                                       continue;
-                               }
-
-                               lidp = xfs_lic_slot(licp, i);
-                               lip = lidp->lid_item;
-                               if (lip->li_type != XFS_LI_BUF)
-                                       continue;
+               return NULL;
 
-                               bip = (xfs_buf_log_item_t *)lip;
-                               lbp = bip->bli_buf;
+       for (i = 0; i < XFS_BTREE_MAXLEVELS; i++) {
+               if (!cur->bc_bufs[i])
+                       break;
+               if (XFS_BUF_ADDR(cur->bc_bufs[i]) == bno)
+                       return cur->bc_bufs[i];
+       }
 
-                               if (XFS_BUF_ADDR(lbp) == bno) {
-                                       bp = lbp;
-                                       break; /* Found it */
-                               }
-                       }
-                       licp = licp->lic_next;
-               }
+       /* Chase down all the log items to see if the bp is there */
+       list_for_each_entry(lidp, &cur->bc_tp->t_items, lid_trans) {
+               struct xfs_buf_log_item *bip;
+               bip = (struct xfs_buf_log_item *)lidp->lid_item;
+               if (bip->bli_item.li_type == XFS_LI_BUF &&
+                   XFS_BUF_ADDR(bip->bli_buf) == bno)
+                       return bip->bli_buf;
        }
-       return(bp);
+
+       return NULL;
 }
 
 STATIC void
index 419dafb9d87d4a2a79b440c30a54e672a571b55f..b13569a6179b7235f315fe87f624e42336310c9e 100644 (file)
@@ -27,20 +27,6 @@ struct xfs_trans;
 
 extern kmem_zone_t     *xfs_bmap_free_item_zone;
 
-/*
- * DELTA: describe a change to the in-core extent list.
- *
- * Internally the use of xed_blockount is somewhat funky.
- * xed_blockcount contains an offset much of the time because this
- * makes merging changes easier.  (xfs_fileoff_t and xfs_filblks_t are
- * the same underlying type).
- */
-typedef struct xfs_extdelta
-{
-       xfs_fileoff_t           xed_startoff;   /* offset of range */
-       xfs_filblks_t           xed_blockcount; /* blocks in range */
-} xfs_extdelta_t;
-
 /*
  * List of extents to be free "later".
  * The list is kept sorted on xbf_startblock.
@@ -82,16 +68,13 @@ typedef     struct xfs_bmap_free
 #define XFS_BMAPI_DELAY                0x002   /* delayed write operation */
 #define XFS_BMAPI_ENTIRE       0x004   /* return entire extent, not trimmed */
 #define XFS_BMAPI_METADATA     0x008   /* mapping metadata not user data */
-#define XFS_BMAPI_EXACT                0x010   /* allocate only to spec'd bounds */
-#define XFS_BMAPI_ATTRFORK     0x020   /* use attribute fork not data */
-#define XFS_BMAPI_ASYNC                0x040   /* bunmapi xactions can be async */
-#define XFS_BMAPI_RSVBLOCKS    0x080   /* OK to alloc. reserved data blocks */
-#define        XFS_BMAPI_PREALLOC      0x100   /* preallocation op: unwritten space */
-#define        XFS_BMAPI_IGSTATE       0x200   /* Ignore state - */
+#define XFS_BMAPI_ATTRFORK     0x010   /* use attribute fork not data */
+#define XFS_BMAPI_RSVBLOCKS    0x020   /* OK to alloc. reserved data blocks */
+#define        XFS_BMAPI_PREALLOC      0x040   /* preallocation op: unwritten space */
+#define        XFS_BMAPI_IGSTATE       0x080   /* Ignore state - */
                                        /* combine contig. space */
-#define        XFS_BMAPI_CONTIG        0x400   /* must allocate only one extent */
-/*     XFS_BMAPI_DIRECT_IO     0x800   */
-#define XFS_BMAPI_CONVERT      0x1000  /* unwritten extent conversion - */
+#define        XFS_BMAPI_CONTIG        0x100   /* must allocate only one extent */
+#define XFS_BMAPI_CONVERT      0x200   /* unwritten extent conversion - */
                                        /* need write cache flushing and no */
                                        /* additional allocation alignments */
 
@@ -100,9 +83,7 @@ typedef      struct xfs_bmap_free
        { XFS_BMAPI_DELAY,      "DELAY" }, \
        { XFS_BMAPI_ENTIRE,     "ENTIRE" }, \
        { XFS_BMAPI_METADATA,   "METADATA" }, \
-       { XFS_BMAPI_EXACT,      "EXACT" }, \
        { XFS_BMAPI_ATTRFORK,   "ATTRFORK" }, \
-       { XFS_BMAPI_ASYNC,      "ASYNC" }, \
        { XFS_BMAPI_RSVBLOCKS,  "RSVBLOCKS" }, \
        { XFS_BMAPI_PREALLOC,   "PREALLOC" }, \
        { XFS_BMAPI_IGSTATE,    "IGSTATE" }, \
@@ -310,9 +291,7 @@ xfs_bmapi(
        xfs_extlen_t            total,          /* total blocks needed */
        struct xfs_bmbt_irec    *mval,          /* output: map values */
        int                     *nmap,          /* i/o: mval size/count */
-       xfs_bmap_free_t         *flist,         /* i/o: list extents to free */
-       xfs_extdelta_t          *delta);        /* o: change made to incore
-                                                  extents */
+       xfs_bmap_free_t         *flist);        /* i/o: list extents to free */
 
 /*
  * Map file blocks to filesystem blocks, simple version.
@@ -346,8 +325,6 @@ xfs_bunmapi(
        xfs_fsblock_t           *firstblock,    /* first allocated block
                                                   controls a.g. for allocs */
        xfs_bmap_free_t         *flist,         /* i/o: list extents to free */
-       xfs_extdelta_t          *delta,         /* o: change made to incore
-                                                  extents */
        int                     *done);         /* set if not done yet */
 
 /*
index 416e47e54b83fc79f2472f59de81d8a34769e940..87d3c10b695437da9043d9a72985b8d8d25280c6 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
 #include "xfs_alloc.h"
 #include "xfs_btree.h"
 #include "xfs_btree_trace.h"
-#include "xfs_ialloc.h"
 #include "xfs_itable.h"
 #include "xfs_bmap.h"
 #include "xfs_error.h"
index 96be4b0f249613fef3b0cc8ab0ae443dafc3d2f4..829af92f0fbadd0f4e311b8151055cc9e135e969 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
 #include "xfs_btree.h"
 #include "xfs_btree_trace.h"
-#include "xfs_ialloc.h"
 #include "xfs_error.h"
 #include "xfs_trace.h"
 
index 02a80984aa05f13189f4c99f186f1f098fa02e3d..1b09d7a280dfa6f1e1abcf247f27989da5fd6fc4 100644 (file)
@@ -24,7 +24,6 @@
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_buf_item.h"
 #include "xfs_trans_priv.h"
 
 kmem_zone_t    *xfs_buf_item_zone;
 
+static inline struct xfs_buf_log_item *BUF_ITEM(struct xfs_log_item *lip)
+{
+       return container_of(lip, struct xfs_buf_log_item, bli_item);
+}
+
+
 #ifdef XFS_TRANS_DEBUG
 /*
  * This function uses an alternate strategy for tracking the bytes
@@ -151,12 +156,13 @@ STATIC void       xfs_buf_do_callbacks(xfs_buf_t *bp, xfs_log_item_t *lip);
  */
 STATIC uint
 xfs_buf_item_size(
-       xfs_buf_log_item_t      *bip)
+       struct xfs_log_item     *lip)
 {
-       uint            nvecs;
-       int             next_bit;
-       int             last_bit;
-       xfs_buf_t       *bp;
+       struct xfs_buf_log_item *bip = BUF_ITEM(lip);
+       struct xfs_buf          *bp = bip->bli_buf;
+       uint                    nvecs;
+       int                     next_bit;
+       int                     last_bit;
 
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
        if (bip->bli_flags & XFS_BLI_STALE) {
@@ -170,7 +176,6 @@ xfs_buf_item_size(
                return 1;
        }
 
-       bp = bip->bli_buf;
        ASSERT(bip->bli_flags & XFS_BLI_LOGGED);
        nvecs = 1;
        last_bit = xfs_next_bit(bip->bli_format.blf_data_map,
@@ -219,13 +224,13 @@ xfs_buf_item_size(
  */
 STATIC void
 xfs_buf_item_format(
-       xfs_buf_log_item_t      *bip,
-       xfs_log_iovec_t         *log_vector)
+       struct xfs_log_item     *lip,
+       struct xfs_log_iovec    *vecp)
 {
+       struct xfs_buf_log_item *bip = BUF_ITEM(lip);
+       struct xfs_buf  *bp = bip->bli_buf;
        uint            base_size;
        uint            nvecs;
-       xfs_log_iovec_t *vecp;
-       xfs_buf_t       *bp;
        int             first_bit;
        int             last_bit;
        int             next_bit;
@@ -235,8 +240,6 @@ xfs_buf_item_format(
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
        ASSERT((bip->bli_flags & XFS_BLI_LOGGED) ||
               (bip->bli_flags & XFS_BLI_STALE));
-       bp = bip->bli_buf;
-       vecp = log_vector;
 
        /*
         * The size of the base structure is the size of the
@@ -248,7 +251,7 @@ xfs_buf_item_format(
        base_size =
                (uint)(sizeof(xfs_buf_log_format_t) +
                       ((bip->bli_format.blf_map_size - 1) * sizeof(uint)));
-       vecp->i_addr = (xfs_caddr_t)&bip->bli_format;
+       vecp->i_addr = &bip->bli_format;
        vecp->i_len = base_size;
        vecp->i_type = XLOG_REG_TYPE_BFORMAT;
        vecp++;
@@ -263,7 +266,7 @@ xfs_buf_item_format(
         */
        if (bip->bli_flags & XFS_BLI_INODE_BUF) {
                if (!((bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF) &&
-                     xfs_log_item_in_current_chkpt(&bip->bli_item)))
+                     xfs_log_item_in_current_chkpt(lip)))
                        bip->bli_format.blf_flags |= XFS_BLF_INODE_BUF;
                bip->bli_flags &= ~XFS_BLI_INODE_BUF;
        }
@@ -356,66 +359,90 @@ xfs_buf_item_format(
 
 /*
  * This is called to pin the buffer associated with the buf log item in memory
- * so it cannot be written out.  Simply call bpin() on the buffer to do this.
+ * so it cannot be written out.
  *
  * We also always take a reference to the buffer log item here so that the bli
  * is held while the item is pinned in memory. This means that we can
  * unconditionally drop the reference count a transaction holds when the
  * transaction is completed.
  */
-
 STATIC void
 xfs_buf_item_pin(
-       xfs_buf_log_item_t      *bip)
+       struct xfs_log_item     *lip)
 {
-       xfs_buf_t       *bp;
+       struct xfs_buf_log_item *bip = BUF_ITEM(lip);
 
-       bp = bip->bli_buf;
-       ASSERT(XFS_BUF_ISBUSY(bp));
+       ASSERT(XFS_BUF_ISBUSY(bip->bli_buf));
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
        ASSERT((bip->bli_flags & XFS_BLI_LOGGED) ||
               (bip->bli_flags & XFS_BLI_STALE));
-       atomic_inc(&bip->bli_refcount);
+
        trace_xfs_buf_item_pin(bip);
-       xfs_bpin(bp);
-}
 
+       atomic_inc(&bip->bli_refcount);
+       atomic_inc(&bip->bli_buf->b_pin_count);
+}
 
 /*
  * This is called to unpin the buffer associated with the buf log
  * item which was previously pinned with a call to xfs_buf_item_pin().
- * Just call bunpin() on the buffer to do this.
  *
  * Also drop the reference to the buf item for the current transaction.
  * If the XFS_BLI_STALE flag is set and we are the last reference,
  * then free up the buf log item and unlock the buffer.
+ *
+ * If the remove flag is set we are called from uncommit in the
+ * forced-shutdown path.  If that is true and the reference count on
+ * the log item is going to drop to zero we need to free the item's
+ * descriptor in the transaction.
  */
 STATIC void
 xfs_buf_item_unpin(
-       xfs_buf_log_item_t      *bip)
+       struct xfs_log_item     *lip,
+       int                     remove)
 {
-       struct xfs_ail  *ailp;
-       xfs_buf_t       *bp;
-       int             freed;
+       struct xfs_buf_log_item *bip = BUF_ITEM(lip);
+       xfs_buf_t       *bp = bip->bli_buf;
+       struct xfs_ail  *ailp = lip->li_ailp;
        int             stale = bip->bli_flags & XFS_BLI_STALE;
+       int             freed;
 
-       bp = bip->bli_buf;
-       ASSERT(bp != NULL);
        ASSERT(XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *) == bip);
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
+
        trace_xfs_buf_item_unpin(bip);
 
        freed = atomic_dec_and_test(&bip->bli_refcount);
-       ailp = bip->bli_item.li_ailp;
-       xfs_bunpin(bp);
+
+       if (atomic_dec_and_test(&bp->b_pin_count))
+               wake_up_all(&bp->b_waiters);
+
        if (freed && stale) {
                ASSERT(bip->bli_flags & XFS_BLI_STALE);
                ASSERT(XFS_BUF_VALUSEMA(bp) <= 0);
                ASSERT(!(XFS_BUF_ISDELAYWRITE(bp)));
                ASSERT(XFS_BUF_ISSTALE(bp));
                ASSERT(bip->bli_format.blf_flags & XFS_BLF_CANCEL);
+
                trace_xfs_buf_item_unpin_stale(bip);
 
+               if (remove) {
+                       /*
+                        * We have to remove the log item from the transaction
+                        * as we are about to release our reference to the
+                        * buffer.  If we don't, the unlock that occurs later
+                        * in xfs_trans_uncommit() will ry to reference the
+                        * buffer which we no longer have a hold on.
+                        */
+                       xfs_trans_del_item(lip);
+
+                       /*
+                        * Since the transaction no longer refers to the buffer,
+                        * the buffer should no longer refer to the transaction.
+                        */
+                       XFS_BUF_SET_FSPRIVATE2(bp, NULL);
+               }
+
                /*
                 * If we get called here because of an IO error, we may
                 * or may not have the item on the AIL. xfs_trans_ail_delete()
@@ -436,48 +463,6 @@ xfs_buf_item_unpin(
        }
 }
 
-/*
- * this is called from uncommit in the forced-shutdown path.
- * we need to check to see if the reference count on the log item
- * is going to drop to zero.  If so, unpin will free the log item
- * so we need to free the item's descriptor (that points to the item)
- * in the transaction.
- */
-STATIC void
-xfs_buf_item_unpin_remove(
-       xfs_buf_log_item_t      *bip,
-       xfs_trans_t             *tp)
-{
-       /* will xfs_buf_item_unpin() call xfs_buf_item_relse()? */
-       if ((atomic_read(&bip->bli_refcount) == 1) &&
-           (bip->bli_flags & XFS_BLI_STALE)) {
-               /*
-                * yes -- We can safely do some work here and then call
-                * buf_item_unpin to do the rest because we are
-                * are holding the buffer locked so no one else will be
-                * able to bump up the refcount. We have to remove the
-                * log item from the transaction as we are about to release
-                * our reference to the buffer. If we don't, the unlock that
-                * occurs later in the xfs_trans_uncommit() will try to
-                * reference the buffer which we no longer have a hold on.
-                */
-               struct xfs_log_item_desc *lidp;
-
-               ASSERT(XFS_BUF_VALUSEMA(bip->bli_buf) <= 0);
-               trace_xfs_buf_item_unpin_stale(bip);
-
-               lidp = xfs_trans_find_item(tp, (xfs_log_item_t *)bip);
-               xfs_trans_free_item(tp, lidp);
-
-               /*
-                * Since the transaction no longer refers to the buffer, the
-                * buffer should no longer refer to the transaction.
-                */
-               XFS_BUF_SET_FSPRIVATE2(bip->bli_buf, NULL);
-       }
-       xfs_buf_item_unpin(bip);
-}
-
 /*
  * This is called to attempt to lock the buffer associated with this
  * buf log item.  Don't sleep on the buffer lock.  If we can't get
@@ -488,11 +473,11 @@ xfs_buf_item_unpin_remove(
  */
 STATIC uint
 xfs_buf_item_trylock(
-       xfs_buf_log_item_t      *bip)
+       struct xfs_log_item     *lip)
 {
-       xfs_buf_t       *bp;
+       struct xfs_buf_log_item *bip = BUF_ITEM(lip);
+       struct xfs_buf          *bp = bip->bli_buf;
 
-       bp = bip->bli_buf;
        if (XFS_BUF_ISPINNED(bp))
                return XFS_ITEM_PINNED;
        if (!XFS_BUF_CPSEMA(bp))
@@ -529,13 +514,12 @@ xfs_buf_item_trylock(
  */
 STATIC void
 xfs_buf_item_unlock(
-       xfs_buf_log_item_t      *bip)
+       struct xfs_log_item     *lip)
 {
-       int             aborted;
-       xfs_buf_t       *bp;
-       uint            hold;
-
-       bp = bip->bli_buf;
+       struct xfs_buf_log_item *bip = BUF_ITEM(lip);
+       struct xfs_buf          *bp = bip->bli_buf;
+       int                     aborted;
+       uint                    hold;
 
        /* Clear the buffer's association with this transaction. */
        XFS_BUF_SET_FSPRIVATE2(bp, NULL);
@@ -546,7 +530,7 @@ xfs_buf_item_unlock(
         * (cancelled) buffers at unpin time, but we'll never go through the
         * pin/unpin cycle if we abort inside commit.
         */
-       aborted = (bip->bli_item.li_flags & XFS_LI_ABORTED) != 0;
+       aborted = (lip->li_flags & XFS_LI_ABORTED) != 0;
 
        /*
         * Before possibly freeing the buf item, determine if we should
@@ -607,16 +591,16 @@ xfs_buf_item_unlock(
  */
 STATIC xfs_lsn_t
 xfs_buf_item_committed(
-       xfs_buf_log_item_t      *bip,
+       struct xfs_log_item     *lip,
        xfs_lsn_t               lsn)
 {
+       struct xfs_buf_log_item *bip = BUF_ITEM(lip);
+
        trace_xfs_buf_item_committed(bip);
 
-       if ((bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF) &&
-           (bip->bli_item.li_lsn != 0)) {
-               return bip->bli_item.li_lsn;
-       }
-       return (lsn);
+       if ((bip->bli_flags & XFS_BLI_INODE_ALLOC_BUF) && lip->li_lsn != 0)
+               return lip->li_lsn;
+       return lsn;
 }
 
 /*
@@ -626,15 +610,16 @@ xfs_buf_item_committed(
  */
 STATIC void
 xfs_buf_item_push(
-       xfs_buf_log_item_t      *bip)
+       struct xfs_log_item     *lip)
 {
-       xfs_buf_t       *bp;
+       struct xfs_buf_log_item *bip = BUF_ITEM(lip);
+       struct xfs_buf          *bp = bip->bli_buf;
 
        ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
+       ASSERT(!XFS_BUF_ISDELAYWRITE(bp));
+
        trace_xfs_buf_item_push(bip);
 
-       bp = bip->bli_buf;
-       ASSERT(!XFS_BUF_ISDELAYWRITE(bp));
        xfs_buf_relse(bp);
 }
 
@@ -646,22 +631,24 @@ xfs_buf_item_push(
  */
 STATIC void
 xfs_buf_item_pushbuf(
-       xfs_buf_log_item_t      *bip)
+       struct xfs_log_item     *lip)
 {
-       xfs_buf_t       *bp;
+       struct xfs_buf_log_item *bip = BUF_ITEM(lip);
+       struct xfs_buf          *bp = bip->bli_buf;
 
        ASSERT(!(bip->bli_flags & XFS_BLI_STALE));
+       ASSERT(XFS_BUF_ISDELAYWRITE(bp));
+
        trace_xfs_buf_item_pushbuf(bip);
 
-       bp = bip->bli_buf;
-       ASSERT(XFS_BUF_ISDELAYWRITE(bp));
        xfs_buf_delwri_promote(bp);
        xfs_buf_relse(bp);
 }
 
-/* ARGSUSED */
 STATIC void
-xfs_buf_item_committing(xfs_buf_log_item_t *bip, xfs_lsn_t commit_lsn)
+xfs_buf_item_committing(
+       struct xfs_log_item     *lip,
+       xfs_lsn_t               commit_lsn)
 {
 }
 
@@ -669,21 +656,16 @@ xfs_buf_item_committing(xfs_buf_log_item_t *bip, xfs_lsn_t commit_lsn)
  * This is the ops vector shared by all buf log items.
  */
 static struct xfs_item_ops xfs_buf_item_ops = {
-       .iop_size       = (uint(*)(xfs_log_item_t*))xfs_buf_item_size,
-       .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
-                                       xfs_buf_item_format,
-       .iop_pin        = (void(*)(xfs_log_item_t*))xfs_buf_item_pin,
-       .iop_unpin      = (void(*)(xfs_log_item_t*))xfs_buf_item_unpin,
-       .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t *))
-                                       xfs_buf_item_unpin_remove,
-       .iop_trylock    = (uint(*)(xfs_log_item_t*))xfs_buf_item_trylock,
-       .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_buf_item_unlock,
-       .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_buf_item_committed,
-       .iop_push       = (void(*)(xfs_log_item_t*))xfs_buf_item_push,
-       .iop_pushbuf    = (void(*)(xfs_log_item_t*))xfs_buf_item_pushbuf,
-       .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_buf_item_committing
+       .iop_size       = xfs_buf_item_size,
+       .iop_format     = xfs_buf_item_format,
+       .iop_pin        = xfs_buf_item_pin,
+       .iop_unpin      = xfs_buf_item_unpin,
+       .iop_trylock    = xfs_buf_item_trylock,
+       .iop_unlock     = xfs_buf_item_unlock,
+       .iop_committed  = xfs_buf_item_committed,
+       .iop_push       = xfs_buf_item_push,
+       .iop_pushbuf    = xfs_buf_item_pushbuf,
+       .iop_committing = xfs_buf_item_committing
 };
 
 
@@ -712,7 +694,6 @@ xfs_buf_item_init(
         */
        if (bp->b_mount != mp)
                bp->b_mount = mp;
-       XFS_BUF_SET_BDSTRAT_FUNC(bp, xfs_bdstrat_cb);
        if (XFS_BUF_FSPRIVATE(bp, void *) != NULL) {
                lip = XFS_BUF_FSPRIVATE(bp, xfs_log_item_t *);
                if (lip->li_type == XFS_LI_BUF) {
@@ -1098,15 +1079,14 @@ xfs_buf_error_relse(
  * It is called by xfs_buf_iodone_callbacks() above which will take
  * care of cleaning up the buffer itself.
  */
-/* ARGSUSED */
 void
 xfs_buf_iodone(
-       xfs_buf_t               *bp,
-       xfs_buf_log_item_t      *bip)
+       struct xfs_buf          *bp,
+       struct xfs_log_item     *lip)
 {
-       struct xfs_ail          *ailp = bip->bli_item.li_ailp;
+       struct xfs_ail          *ailp = lip->li_ailp;
 
-       ASSERT(bip->bli_buf == bp);
+       ASSERT(BUF_ITEM(lip)->bli_buf == bp);
 
        xfs_buf_rele(bp);
 
@@ -1120,6 +1100,6 @@ xfs_buf_iodone(
         * Either way, AIL is useless if we're forcing a shutdown.
         */
        spin_lock(&ailp->xa_lock);
-       xfs_trans_ail_delete(ailp, (xfs_log_item_t *)bip);
-       xfs_buf_item_free(bip);
+       xfs_trans_ail_delete(ailp, lip);
+       xfs_buf_item_free(BUF_ITEM(lip));
 }
index f20bb472d582f1e5b711c1593958b3593ad2167c..0e2ed43f16c71ace4bde6152ef2eca33b2fa966d 100644 (file)
@@ -124,7 +124,7 @@ void        xfs_buf_attach_iodone(struct xfs_buf *,
                              void(*)(struct xfs_buf *, xfs_log_item_t *),
                              xfs_log_item_t *);
 void   xfs_buf_iodone_callbacks(struct xfs_buf *);
-void   xfs_buf_iodone(struct xfs_buf *, xfs_buf_log_item_t *);
+void   xfs_buf_iodone(struct xfs_buf *, struct xfs_log_item *);
 
 #ifdef XFS_TRANS_DEBUG
 void
index 0ca556b4bf313bf8526769ff051f188df5a3066e..30fa0e206fba84a5279ed9f92f6c9b7035484f47 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
 #include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
 #include "xfs_alloc.h"
-#include "xfs_btree.h"
 #include "xfs_bmap.h"
 #include "xfs_attr.h"
 #include "xfs_attr_leaf.h"
@@ -581,16 +576,14 @@ xfs_da_node_add(xfs_da_state_t *state, xfs_da_state_blk_t *oldblk,
        xfs_da_intnode_t *node;
        xfs_da_node_entry_t *btree;
        int tmp;
-       xfs_mount_t *mp;
 
        node = oldblk->bp->data;
-       mp = state->mp;
        ASSERT(be16_to_cpu(node->hdr.info.magic) == XFS_DA_NODE_MAGIC);
        ASSERT((oldblk->index >= 0) && (oldblk->index <= be16_to_cpu(node->hdr.count)));
        ASSERT(newblk->blkno != 0);
        if (state->args->whichfork == XFS_DATA_FORK)
-               ASSERT(newblk->blkno >= mp->m_dirleafblk &&
-                      newblk->blkno < mp->m_dirfreeblk);
+               ASSERT(newblk->blkno >= state->mp->m_dirleafblk &&
+                      newblk->blkno < state->mp->m_dirfreeblk);
 
        /*
         * We may need to make some room before we insert the new node.
@@ -1601,7 +1594,7 @@ xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno)
                        xfs_bmapi_aflag(w)|XFS_BMAPI_WRITE|XFS_BMAPI_METADATA|
                        XFS_BMAPI_CONTIG,
                        args->firstblock, args->total, &map, &nmap,
-                       args->flist, NULL))) {
+                       args->flist))) {
                return error;
        }
        ASSERT(nmap <= 1);
@@ -1622,8 +1615,7 @@ xfs_da_grow_inode(xfs_da_args_t *args, xfs_dablk_t *new_blkno)
                                        xfs_bmapi_aflag(w)|XFS_BMAPI_WRITE|
                                        XFS_BMAPI_METADATA,
                                        args->firstblock, args->total,
-                                       &mapp[mapi], &nmap, args->flist,
-                                       NULL))) {
+                                       &mapp[mapi], &nmap, args->flist))) {
                                kmem_free(mapp);
                                return error;
                        }
@@ -1884,7 +1876,7 @@ xfs_da_shrink_inode(xfs_da_args_t *args, xfs_dablk_t dead_blkno,
                 */
                if ((error = xfs_bunmapi(tp, dp, dead_blkno, count,
                                xfs_bmapi_aflag(w)|XFS_BMAPI_METADATA,
-                               0, args->firstblock, args->flist, NULL,
+                               0, args->firstblock, args->flist,
                                &done)) == ENOSPC) {
                        if (w != XFS_DATA_FORK)
                                break;
@@ -1989,7 +1981,7 @@ xfs_da_do_buf(
                                        nfsb,
                                        XFS_BMAPI_METADATA |
                                                xfs_bmapi_aflag(whichfork),
-                                       NULL, 0, mapp, &nmap, NULL, NULL)))
+                                       NULL, 0, mapp, &nmap, NULL)))
                                goto exit0;
                }
        } else {
index 7f159d2a429a97e8a71e0fd57298ec499519c064..3b9582c60a225117f7b6d4180e4287b0118375ed 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
 #include "xfs_bmap.h"
-#include "xfs_btree.h"
-#include "xfs_ialloc.h"
 #include "xfs_itable.h"
 #include "xfs_dfrag.h"
 #include "xfs_error.h"
-#include "xfs_rw.h"
 #include "xfs_vnodeops.h"
 #include "xfs_trace.h"
 
@@ -425,11 +416,8 @@ xfs_swap_extents(
        }
 
 
-       IHOLD(ip);
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-
-       IHOLD(tip);
-       xfs_trans_ijoin(tp, tip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, tip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
 
        xfs_trans_log_inode(tp, ip,  ilf_fields);
        xfs_trans_log_inode(tp, tip, tilf_fields);
index 42520f041265fea2d7df1d02bc8a4e3e82215337..a1321bc7f19210a3b4bd1d87ec7c9d5eae410b28 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
@@ -382,7 +380,7 @@ xfs_readdir(
        int             rval;           /* return value */
        int             v;              /* type-checking value */
 
-       xfs_itrace_entry(dp);
+       trace_xfs_readdir(dp);
 
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return XFS_ERROR(EIO);
@@ -549,7 +547,7 @@ xfs_dir2_grow_inode(
        if ((error = xfs_bmapi(tp, dp, bno, count,
                        XFS_BMAPI_WRITE|XFS_BMAPI_METADATA|XFS_BMAPI_CONTIG,
                        args->firstblock, args->total, &map, &nmap,
-                       args->flist, NULL)))
+                       args->flist)))
                return error;
        ASSERT(nmap <= 1);
        if (nmap == 1) {
@@ -581,8 +579,7 @@ xfs_dir2_grow_inode(
                        if ((error = xfs_bmapi(tp, dp, b, c,
                                        XFS_BMAPI_WRITE|XFS_BMAPI_METADATA,
                                        args->firstblock, args->total,
-                                       &mapp[mapi], &nmap, args->flist,
-                                       NULL))) {
+                                       &mapp[mapi], &nmap, args->flist))) {
                                kmem_free(mapp);
                                return error;
                        }
@@ -715,7 +712,7 @@ xfs_dir2_shrink_inode(
         */
        if ((error = xfs_bunmapi(tp, dp, da, mp->m_dirblkfsbs,
                        XFS_BMAPI_METADATA, 0, args->firstblock, args->flist,
-                       NULL, &done))) {
+                       &done))) {
                /*
                 * ENOSPC actually can happen if we're in a removename with
                 * no space reservation, and the resulting block removal
index 779a267b0a84c55a83764d25d469493b24ca0a7f..580d99cef9e7bb25a4344343cf080df23b3e51a3 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
@@ -1073,10 +1071,10 @@ xfs_dir2_sf_to_block(
         */
 
        buf_len = dp->i_df.if_bytes;
-       buf = kmem_alloc(dp->i_df.if_bytes, KM_SLEEP);
+       buf = kmem_alloc(buf_len, KM_SLEEP);
 
-       memcpy(buf, sfp, dp->i_df.if_bytes);
-       xfs_idata_realloc(dp, -dp->i_df.if_bytes, XFS_DATA_FORK);
+       memcpy(buf, sfp, buf_len);
+       xfs_idata_realloc(dp, -buf_len, XFS_DATA_FORK);
        dp->i_d.di_size = 0;
        xfs_trans_log_inode(tp, dp, XFS_ILOG_CORE);
        /*
index 498f8d694330dba475aad5c1c1d1147f73bfab9c..921595b84f5bc613835c1e05601875b46b16c871 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_dir2_data.h"
index e2d89854ec9ec4649f2016d3c2592832bb5ee403..504be8640e918250d5ea58a6df3d64c223655187 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dir2_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
@@ -875,7 +873,7 @@ xfs_dir2_leaf_getdents(
                                        xfs_dir2_byte_to_da(mp,
                                                XFS_DIR2_LEAF_OFFSET) - map_off,
                                        XFS_BMAPI_METADATA, NULL, 0,
-                                       &map[map_valid], &nmap, NULL, NULL);
+                                       &map[map_valid], &nmap, NULL);
                                /*
                                 * Don't know if we should ignore this or
                                 * try to return an error.
index 78fc4d9ae7562d02ea2068132ac44a81e9dfa776..f9a0864b696afea29fec8567a906ac793c882455 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_bmap.h"
index c1a5945d463a3d4ff3abd6aca0beb42f535f6988..b1bae6b1eed9b730ba8dba261e1755fcf207c10c 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
diff --git a/fs/xfs/xfs_dmapi.h b/fs/xfs/xfs_dmapi.h
deleted file mode 100644 (file)
index 2813cdd..0000000
+++ /dev/null
@@ -1,170 +0,0 @@
-/*
- * Copyright (c) 2000-2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * 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.
- *
- * This program is distributed in the hope that it would 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 the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-#ifndef __XFS_DMAPI_H__
-#define __XFS_DMAPI_H__
-
-/*     Values used to define the on-disk version of dm_attrname_t. All
- *     on-disk attribute names start with the 8-byte string "SGI_DMI_".
- *
- *      In the on-disk inode, DMAPI attribute names consist of the user-provided
- *      name with the DMATTR_PREFIXSTRING pre-pended.  This string must NEVER be
- *      changed.
- */
-
-#define DMATTR_PREFIXLEN       8
-#define DMATTR_PREFIXSTRING    "SGI_DMI_"
-
-typedef enum {
-       DM_EVENT_INVALID        = -1,
-       DM_EVENT_CANCEL         = 0,            /* not supported */
-       DM_EVENT_MOUNT          = 1,
-       DM_EVENT_PREUNMOUNT     = 2,
-       DM_EVENT_UNMOUNT        = 3,
-       DM_EVENT_DEBUT          = 4,            /* not supported */
-       DM_EVENT_CREATE         = 5,
-       DM_EVENT_CLOSE          = 6,            /* not supported */
-       DM_EVENT_POSTCREATE     = 7,
-       DM_EVENT_REMOVE         = 8,
-       DM_EVENT_POSTREMOVE     = 9,
-       DM_EVENT_RENAME         = 10,
-       DM_EVENT_POSTRENAME     = 11,
-       DM_EVENT_LINK           = 12,
-       DM_EVENT_POSTLINK       = 13,
-       DM_EVENT_SYMLINK        = 14,
-       DM_EVENT_POSTSYMLINK    = 15,
-       DM_EVENT_READ           = 16,
-       DM_EVENT_WRITE          = 17,
-       DM_EVENT_TRUNCATE       = 18,
-       DM_EVENT_ATTRIBUTE      = 19,
-       DM_EVENT_DESTROY        = 20,
-       DM_EVENT_NOSPACE        = 21,
-       DM_EVENT_USER           = 22,
-       DM_EVENT_MAX            = 23
-} dm_eventtype_t;
-#define HAVE_DM_EVENTTYPE_T
-
-typedef enum {
-       DM_RIGHT_NULL,
-       DM_RIGHT_SHARED,
-       DM_RIGHT_EXCL
-} dm_right_t;
-#define HAVE_DM_RIGHT_T
-
-/* Defines for determining if an event message should be sent. */
-#ifdef HAVE_DMAPI
-#define        DM_EVENT_ENABLED(ip, event) ( \
-       unlikely ((ip)->i_mount->m_flags & XFS_MOUNT_DMAPI) && \
-               ( ((ip)->i_d.di_dmevmask & (1 << event)) || \
-                 ((ip)->i_mount->m_dmevmask & (1 << event)) ) \
-       )
-#else
-#define DM_EVENT_ENABLED(ip, event)    (0)
-#endif
-
-#define DM_XFS_VALID_FS_EVENTS         ( \
-       (1 << DM_EVENT_PREUNMOUNT)      | \
-       (1 << DM_EVENT_UNMOUNT)         | \
-       (1 << DM_EVENT_NOSPACE)         | \
-       (1 << DM_EVENT_DEBUT)           | \
-       (1 << DM_EVENT_CREATE)          | \
-       (1 << DM_EVENT_POSTCREATE)      | \
-       (1 << DM_EVENT_REMOVE)          | \
-       (1 << DM_EVENT_POSTREMOVE)      | \
-       (1 << DM_EVENT_RENAME)          | \
-       (1 << DM_EVENT_POSTRENAME)      | \
-       (1 << DM_EVENT_LINK)            | \
-       (1 << DM_EVENT_POSTLINK)        | \
-       (1 << DM_EVENT_SYMLINK)         | \
-       (1 << DM_EVENT_POSTSYMLINK)     | \
-       (1 << DM_EVENT_ATTRIBUTE)       | \
-       (1 << DM_EVENT_DESTROY)         )
-
-/* Events valid in dm_set_eventlist() when called with a file handle for
-   a regular file or a symlink.  These events are persistent.
-*/
-
-#define        DM_XFS_VALID_FILE_EVENTS        ( \
-       (1 << DM_EVENT_ATTRIBUTE)       | \
-       (1 << DM_EVENT_DESTROY)         )
-
-/* Events valid in dm_set_eventlist() when called with a file handle for
-   a directory.  These events are persistent.
-*/
-
-#define        DM_XFS_VALID_DIRECTORY_EVENTS   ( \
-       (1 << DM_EVENT_CREATE)          | \
-       (1 << DM_EVENT_POSTCREATE)      | \
-       (1 << DM_EVENT_REMOVE)          | \
-       (1 << DM_EVENT_POSTREMOVE)      | \
-       (1 << DM_EVENT_RENAME)          | \
-       (1 << DM_EVENT_POSTRENAME)      | \
-       (1 << DM_EVENT_LINK)            | \
-       (1 << DM_EVENT_POSTLINK)        | \
-       (1 << DM_EVENT_SYMLINK)         | \
-       (1 << DM_EVENT_POSTSYMLINK)     | \
-       (1 << DM_EVENT_ATTRIBUTE)       | \
-       (1 << DM_EVENT_DESTROY)         )
-
-/* Events supported by the XFS filesystem. */
-#define        DM_XFS_SUPPORTED_EVENTS         ( \
-       (1 << DM_EVENT_MOUNT)           | \
-       (1 << DM_EVENT_PREUNMOUNT)      | \
-       (1 << DM_EVENT_UNMOUNT)         | \
-       (1 << DM_EVENT_NOSPACE)         | \
-       (1 << DM_EVENT_CREATE)          | \
-       (1 << DM_EVENT_POSTCREATE)      | \
-       (1 << DM_EVENT_REMOVE)          | \
-       (1 << DM_EVENT_POSTREMOVE)      | \
-       (1 << DM_EVENT_RENAME)          | \
-       (1 << DM_EVENT_POSTRENAME)      | \
-       (1 << DM_EVENT_LINK)            | \
-       (1 << DM_EVENT_POSTLINK)        | \
-       (1 << DM_EVENT_SYMLINK)         | \
-       (1 << DM_EVENT_POSTSYMLINK)     | \
-       (1 << DM_EVENT_READ)            | \
-       (1 << DM_EVENT_WRITE)           | \
-       (1 << DM_EVENT_TRUNCATE)        | \
-       (1 << DM_EVENT_ATTRIBUTE)       | \
-       (1 << DM_EVENT_DESTROY)         )
-
-
-/*
- *     Definitions used for the flags field on dm_send_*_event().
- */
-
-#define DM_FLAGS_NDELAY                0x001   /* return EAGAIN after dm_pending() */
-#define DM_FLAGS_UNWANTED      0x002   /* event not in fsys dm_eventset_t */
-#define DM_FLAGS_IMUX          0x004   /* thread holds i_mutex */
-#define DM_FLAGS_IALLOCSEM_RD  0x010   /* thread holds i_alloc_sem rd */
-#define DM_FLAGS_IALLOCSEM_WR  0x020   /* thread holds i_alloc_sem wr */
-
-/*
- *     Pull in platform specific event flags defines
- */
-#include "xfs_dmapi_priv.h"
-
-/*
- *     Macros to turn caller specified delay/block flags into
- *     dm_send_xxxx_event flag DM_FLAGS_NDELAY.
- */
-
-#define FILP_DELAY_FLAG(filp) ((filp->f_flags&(O_NDELAY|O_NONBLOCK)) ? \
-                       DM_FLAGS_NDELAY : 0)
-#define AT_DELAY_FLAG(f) ((f & XFS_ATTR_NONBLOCK) ? DM_FLAGS_NDELAY : 0)
-
-#endif  /* __XFS_DMAPI_H__ */
diff --git a/fs/xfs/xfs_dmops.c b/fs/xfs/xfs_dmops.c
deleted file mode 100644 (file)
index e71e258..0000000
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * 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.
- *
- * This program is distributed in the hope that it would 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 the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-#include "xfs.h"
-#include "xfs_fs.h"
-#include "xfs_types.h"
-#include "xfs_log.h"
-#include "xfs_trans.h"
-#include "xfs_sb.h"
-#include "xfs_dmapi.h"
-#include "xfs_inum.h"
-#include "xfs_ag.h"
-#include "xfs_mount.h"
-
-
-static struct xfs_dmops xfs_dmcore_stub = {
-       .xfs_send_data          = (xfs_send_data_t)fs_nosys,
-       .xfs_send_mmap          = (xfs_send_mmap_t)fs_noerr,
-       .xfs_send_destroy       = (xfs_send_destroy_t)fs_nosys,
-       .xfs_send_namesp        = (xfs_send_namesp_t)fs_nosys,
-       .xfs_send_mount         = (xfs_send_mount_t)fs_nosys,
-       .xfs_send_unmount       = (xfs_send_unmount_t)fs_noerr,
-};
-
-int
-xfs_dmops_get(struct xfs_mount *mp)
-{
-       if (mp->m_flags & XFS_MOUNT_DMAPI) {
-               cmn_err(CE_WARN,
-                       "XFS: dmapi support not available in this kernel.");
-               return EINVAL;
-       }
-
-       mp->m_dm_ops = &xfs_dmcore_stub;
-       return 0;
-}
-
-void
-xfs_dmops_put(struct xfs_mount *mp)
-{
-}
index 047b8a8e5c294856f861251a4cbfa7a7ec0d00fc..ed99902676615e166a8e08371bf79c3a33d98021 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_utils.h"
index 409fe81585fdbb38ea66546c01c4dc74922464b3..a55e687bf562f1174e37e0764e9dab1405333a7a 100644 (file)
@@ -24,7 +24,6 @@
 #include "xfs_buf_item.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_trans_priv.h"
 #include "xfs_extfree_item.h"
 kmem_zone_t    *xfs_efi_zone;
 kmem_zone_t    *xfs_efd_zone;
 
-STATIC void    xfs_efi_item_unlock(xfs_efi_log_item_t *);
+static inline struct xfs_efi_log_item *EFI_ITEM(struct xfs_log_item *lip)
+{
+       return container_of(lip, struct xfs_efi_log_item, efi_item);
+}
 
 void
-xfs_efi_item_free(xfs_efi_log_item_t *efip)
+xfs_efi_item_free(
+       struct xfs_efi_log_item *efip)
 {
-       int nexts = efip->efi_format.efi_nextents;
-
-       if (nexts > XFS_EFI_MAX_FAST_EXTENTS) {
+       if (efip->efi_format.efi_nextents > XFS_EFI_MAX_FAST_EXTENTS)
                kmem_free(efip);
-       } else {
+       else
                kmem_zone_free(xfs_efi_zone, efip);
-       }
 }
 
 /*
@@ -52,9 +52,9 @@ xfs_efi_item_free(xfs_efi_log_item_t *efip)
  * We only need 1 iovec for an efi item.  It just logs the efi_log_format
  * structure.
  */
-/*ARGSUSED*/
 STATIC uint
-xfs_efi_item_size(xfs_efi_log_item_t *efip)
+xfs_efi_item_size(
+       struct xfs_log_item     *lip)
 {
        return 1;
 }
@@ -67,10 +67,12 @@ xfs_efi_item_size(xfs_efi_log_item_t *efip)
  * slots in the efi item have been filled.
  */
 STATIC void
-xfs_efi_item_format(xfs_efi_log_item_t *efip,
-                   xfs_log_iovec_t     *log_vector)
+xfs_efi_item_format(
+       struct xfs_log_item     *lip,
+       struct xfs_log_iovec    *log_vector)
 {
-       uint    size;
+       struct xfs_efi_log_item *efip = EFI_ITEM(lip);
+       uint                    size;
 
        ASSERT(efip->efi_next_extent == efip->efi_format.efi_nextents);
 
@@ -80,7 +82,7 @@ xfs_efi_item_format(xfs_efi_log_item_t        *efip,
        size += (efip->efi_format.efi_nextents - 1) * sizeof(xfs_extent_t);
        efip->efi_format.efi_size = 1;
 
-       log_vector->i_addr = (xfs_caddr_t)&(efip->efi_format);
+       log_vector->i_addr = &efip->efi_format;
        log_vector->i_len = size;
        log_vector->i_type = XLOG_REG_TYPE_EFI_FORMAT;
        ASSERT(size >= sizeof(xfs_efi_log_format_t));
@@ -90,60 +92,33 @@ xfs_efi_item_format(xfs_efi_log_item_t      *efip,
 /*
  * Pinning has no meaning for an efi item, so just return.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_efi_item_pin(xfs_efi_log_item_t *efip)
+xfs_efi_item_pin(
+       struct xfs_log_item     *lip)
 {
-       return;
 }
 
-
 /*
  * While EFIs cannot really be pinned, the unpin operation is the
  * last place at which the EFI is manipulated during a transaction.
  * Here we coordinate with xfs_efi_cancel() to determine who gets to
  * free the EFI.
  */
-/*ARGSUSED*/
-STATIC void
-xfs_efi_item_unpin(xfs_efi_log_item_t *efip)
-{
-       struct xfs_ail          *ailp = efip->efi_item.li_ailp;
-
-       spin_lock(&ailp->xa_lock);
-       if (efip->efi_flags & XFS_EFI_CANCELED) {
-               /* xfs_trans_ail_delete() drops the AIL lock. */
-               xfs_trans_ail_delete(ailp, (xfs_log_item_t *)efip);
-               xfs_efi_item_free(efip);
-       } else {
-               efip->efi_flags |= XFS_EFI_COMMITTED;
-               spin_unlock(&ailp->xa_lock);
-       }
-}
-
-/*
- * like unpin only we have to also clear the xaction descriptor
- * pointing the log item if we free the item.  This routine duplicates
- * unpin because efi_flags is protected by the AIL lock.  Freeing
- * the descriptor and then calling unpin would force us to drop the AIL
- * lock which would open up a race condition.
- */
 STATIC void
-xfs_efi_item_unpin_remove(xfs_efi_log_item_t *efip, xfs_trans_t *tp)
+xfs_efi_item_unpin(
+       struct xfs_log_item     *lip,
+       int                     remove)
 {
-       struct xfs_ail          *ailp = efip->efi_item.li_ailp;
-       xfs_log_item_desc_t     *lidp;
+       struct xfs_efi_log_item *efip = EFI_ITEM(lip);
+       struct xfs_ail          *ailp = lip->li_ailp;
 
        spin_lock(&ailp->xa_lock);
        if (efip->efi_flags & XFS_EFI_CANCELED) {
-               /*
-                * free the xaction descriptor pointing to this item
-                */
-               lidp = xfs_trans_find_item(tp, (xfs_log_item_t *) efip);
-               xfs_trans_free_item(tp, lidp);
+               if (remove)
+                       xfs_trans_del_item(lip);
 
                /* xfs_trans_ail_delete() drops the AIL lock. */
-               xfs_trans_ail_delete(ailp, (xfs_log_item_t *)efip);
+               xfs_trans_ail_delete(ailp, lip);
                xfs_efi_item_free(efip);
        } else {
                efip->efi_flags |= XFS_EFI_COMMITTED;
@@ -158,9 +133,9 @@ xfs_efi_item_unpin_remove(xfs_efi_log_item_t *efip, xfs_trans_t *tp)
  * XFS_ITEM_PINNED so that the caller will eventually flush the log.
  * This should help in getting the EFI out of the AIL.
  */
-/*ARGSUSED*/
 STATIC uint
-xfs_efi_item_trylock(xfs_efi_log_item_t *efip)
+xfs_efi_item_trylock(
+       struct xfs_log_item     *lip)
 {
        return XFS_ITEM_PINNED;
 }
@@ -168,13 +143,12 @@ xfs_efi_item_trylock(xfs_efi_log_item_t *efip)
 /*
  * Efi items have no locking, so just return.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_efi_item_unlock(xfs_efi_log_item_t *efip)
+xfs_efi_item_unlock(
+       struct xfs_log_item     *lip)
 {
-       if (efip->efi_item.li_flags & XFS_LI_ABORTED)
-               xfs_efi_item_free(efip);
-       return;
+       if (lip->li_flags & XFS_LI_ABORTED)
+               xfs_efi_item_free(EFI_ITEM(lip));
 }
 
 /*
@@ -183,9 +157,10 @@ xfs_efi_item_unlock(xfs_efi_log_item_t *efip)
  * flag is not paid any attention here.  Checking for that is delayed
  * until the EFI is unpinned.
  */
-/*ARGSUSED*/
 STATIC xfs_lsn_t
-xfs_efi_item_committed(xfs_efi_log_item_t *efip, xfs_lsn_t lsn)
+xfs_efi_item_committed(
+       struct xfs_log_item     *lip,
+       xfs_lsn_t               lsn)
 {
        return lsn;
 }
@@ -195,11 +170,10 @@ xfs_efi_item_committed(xfs_efi_log_item_t *efip, xfs_lsn_t lsn)
  * stuck waiting for all of its corresponding efd items to be
  * committed to disk.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_efi_item_push(xfs_efi_log_item_t *efip)
+xfs_efi_item_push(
+       struct xfs_log_item     *lip)
 {
-       return;
 }
 
 /*
@@ -209,61 +183,55 @@ xfs_efi_item_push(xfs_efi_log_item_t *efip)
  * example, for inodes, the inode is locked throughout the extent freeing
  * so the dependency should be recorded there.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_efi_item_committing(xfs_efi_log_item_t *efip, xfs_lsn_t lsn)
+xfs_efi_item_committing(
+       struct xfs_log_item     *lip,
+       xfs_lsn_t               lsn)
 {
-       return;
 }
 
 /*
  * This is the ops vector shared by all efi log items.
  */
 static struct xfs_item_ops xfs_efi_item_ops = {
-       .iop_size       = (uint(*)(xfs_log_item_t*))xfs_efi_item_size,
-       .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
-                                       xfs_efi_item_format,
-       .iop_pin        = (void(*)(xfs_log_item_t*))xfs_efi_item_pin,
-       .iop_unpin      = (void(*)(xfs_log_item_t*))xfs_efi_item_unpin,
-       .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t *))
-                                       xfs_efi_item_unpin_remove,
-       .iop_trylock    = (uint(*)(xfs_log_item_t*))xfs_efi_item_trylock,
-       .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_efi_item_unlock,
-       .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_efi_item_committed,
-       .iop_push       = (void(*)(xfs_log_item_t*))xfs_efi_item_push,
-       .iop_pushbuf    = NULL,
-       .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_efi_item_committing
+       .iop_size       = xfs_efi_item_size,
+       .iop_format     = xfs_efi_item_format,
+       .iop_pin        = xfs_efi_item_pin,
+       .iop_unpin      = xfs_efi_item_unpin,
+       .iop_trylock    = xfs_efi_item_trylock,
+       .iop_unlock     = xfs_efi_item_unlock,
+       .iop_committed  = xfs_efi_item_committed,
+       .iop_push       = xfs_efi_item_push,
+       .iop_committing = xfs_efi_item_committing
 };
 
 
 /*
  * Allocate and initialize an efi item with the given number of extents.
  */
-xfs_efi_log_item_t *
-xfs_efi_init(xfs_mount_t       *mp,
-            uint               nextents)
+struct xfs_efi_log_item *
+xfs_efi_init(
+       struct xfs_mount        *mp,
+       uint                    nextents)
 
 {
-       xfs_efi_log_item_t      *efip;
+       struct xfs_efi_log_item *efip;
        uint                    size;
 
        ASSERT(nextents > 0);
        if (nextents > XFS_EFI_MAX_FAST_EXTENTS) {
                size = (uint)(sizeof(xfs_efi_log_item_t) +
                        ((nextents - 1) * sizeof(xfs_extent_t)));
-               efip = (xfs_efi_log_item_t*)kmem_zalloc(size, KM_SLEEP);
+               efip = kmem_zalloc(size, KM_SLEEP);
        } else {
-               efip = (xfs_efi_log_item_t*)kmem_zone_zalloc(xfs_efi_zone,
-                                                            KM_SLEEP);
+               efip = kmem_zone_zalloc(xfs_efi_zone, KM_SLEEP);
        }
 
        xfs_log_item_init(mp, &efip->efi_item, XFS_LI_EFI, &xfs_efi_item_ops);
        efip->efi_format.efi_nextents = nextents;
        efip->efi_format.efi_id = (__psint_t)(void*)efip;
 
-       return (efip);
+       return efip;
 }
 
 /*
@@ -276,7 +244,7 @@ xfs_efi_init(xfs_mount_t    *mp,
 int
 xfs_efi_copy_format(xfs_log_iovec_t *buf, xfs_efi_log_format_t *dst_efi_fmt)
 {
-       xfs_efi_log_format_t *src_efi_fmt = (xfs_efi_log_format_t *)buf->i_addr;
+       xfs_efi_log_format_t *src_efi_fmt = buf->i_addr;
        uint i;
        uint len = sizeof(xfs_efi_log_format_t) + 
                (src_efi_fmt->efi_nextents - 1) * sizeof(xfs_extent_t);  
@@ -289,8 +257,7 @@ xfs_efi_copy_format(xfs_log_iovec_t *buf, xfs_efi_log_format_t *dst_efi_fmt)
                memcpy((char *)dst_efi_fmt, (char*)src_efi_fmt, len);
                return 0;
        } else if (buf->i_len == len32) {
-               xfs_efi_log_format_32_t *src_efi_fmt_32 =
-                       (xfs_efi_log_format_32_t *)buf->i_addr;
+               xfs_efi_log_format_32_t *src_efi_fmt_32 = buf->i_addr;
 
                dst_efi_fmt->efi_type     = src_efi_fmt_32->efi_type;
                dst_efi_fmt->efi_size     = src_efi_fmt_32->efi_size;
@@ -304,8 +271,7 @@ xfs_efi_copy_format(xfs_log_iovec_t *buf, xfs_efi_log_format_t *dst_efi_fmt)
                }
                return 0;
        } else if (buf->i_len == len64) {
-               xfs_efi_log_format_64_t *src_efi_fmt_64 =
-                       (xfs_efi_log_format_64_t *)buf->i_addr;
+               xfs_efi_log_format_64_t *src_efi_fmt_64 = buf->i_addr;
 
                dst_efi_fmt->efi_type     = src_efi_fmt_64->efi_type;
                dst_efi_fmt->efi_size     = src_efi_fmt_64->efi_size;
@@ -356,16 +322,18 @@ xfs_efi_release(xfs_efi_log_item_t        *efip,
        }
 }
 
-STATIC void
-xfs_efd_item_free(xfs_efd_log_item_t *efdp)
+static inline struct xfs_efd_log_item *EFD_ITEM(struct xfs_log_item *lip)
 {
-       int nexts = efdp->efd_format.efd_nextents;
+       return container_of(lip, struct xfs_efd_log_item, efd_item);
+}
 
-       if (nexts > XFS_EFD_MAX_FAST_EXTENTS) {
+STATIC void
+xfs_efd_item_free(struct xfs_efd_log_item *efdp)
+{
+       if (efdp->efd_format.efd_nextents > XFS_EFD_MAX_FAST_EXTENTS)
                kmem_free(efdp);
-       } else {
+       else
                kmem_zone_free(xfs_efd_zone, efdp);
-       }
 }
 
 /*
@@ -373,9 +341,9 @@ xfs_efd_item_free(xfs_efd_log_item_t *efdp)
  * We only need 1 iovec for an efd item.  It just logs the efd_log_format
  * structure.
  */
-/*ARGSUSED*/
 STATIC uint
-xfs_efd_item_size(xfs_efd_log_item_t *efdp)
+xfs_efd_item_size(
+       struct xfs_log_item     *lip)
 {
        return 1;
 }
@@ -388,10 +356,12 @@ xfs_efd_item_size(xfs_efd_log_item_t *efdp)
  * slots in the efd item have been filled.
  */
 STATIC void
-xfs_efd_item_format(xfs_efd_log_item_t *efdp,
-                   xfs_log_iovec_t     *log_vector)
+xfs_efd_item_format(
+       struct xfs_log_item     *lip,
+       struct xfs_log_iovec    *log_vector)
 {
-       uint    size;
+       struct xfs_efd_log_item *efdp = EFD_ITEM(lip);
+       uint                    size;
 
        ASSERT(efdp->efd_next_extent == efdp->efd_format.efd_nextents);
 
@@ -401,48 +371,38 @@ xfs_efd_item_format(xfs_efd_log_item_t    *efdp,
        size += (efdp->efd_format.efd_nextents - 1) * sizeof(xfs_extent_t);
        efdp->efd_format.efd_size = 1;
 
-       log_vector->i_addr = (xfs_caddr_t)&(efdp->efd_format);
+       log_vector->i_addr = &efdp->efd_format;
        log_vector->i_len = size;
        log_vector->i_type = XLOG_REG_TYPE_EFD_FORMAT;
        ASSERT(size >= sizeof(xfs_efd_log_format_t));
 }
 
-
 /*
  * Pinning has no meaning for an efd item, so just return.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_efd_item_pin(xfs_efd_log_item_t *efdp)
+xfs_efd_item_pin(
+       struct xfs_log_item     *lip)
 {
-       return;
 }
 
-
 /*
  * Since pinning has no meaning for an efd item, unpinning does
  * not either.
  */
-/*ARGSUSED*/
-STATIC void
-xfs_efd_item_unpin(xfs_efd_log_item_t *efdp)
-{
-       return;
-}
-
-/*ARGSUSED*/
 STATIC void
-xfs_efd_item_unpin_remove(xfs_efd_log_item_t *efdp, xfs_trans_t *tp)
+xfs_efd_item_unpin(
+       struct xfs_log_item     *lip,
+       int                     remove)
 {
-       return;
 }
 
 /*
  * Efd items have no locking, so just return success.
  */
-/*ARGSUSED*/
 STATIC uint
-xfs_efd_item_trylock(xfs_efd_log_item_t *efdp)
+xfs_efd_item_trylock(
+       struct xfs_log_item     *lip)
 {
        return XFS_ITEM_LOCKED;
 }
@@ -451,13 +411,12 @@ xfs_efd_item_trylock(xfs_efd_log_item_t *efdp)
  * Efd items have no locking or pushing, so return failure
  * so that the caller doesn't bother with us.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_efd_item_unlock(xfs_efd_log_item_t *efdp)
+xfs_efd_item_unlock(
+       struct xfs_log_item     *lip)
 {
-       if (efdp->efd_item.li_flags & XFS_LI_ABORTED)
-               xfs_efd_item_free(efdp);
-       return;
+       if (lip->li_flags & XFS_LI_ABORTED)
+               xfs_efd_item_free(EFD_ITEM(lip));
 }
 
 /*
@@ -467,15 +426,18 @@ xfs_efd_item_unlock(xfs_efd_log_item_t *efdp)
  * return -1 to keep the transaction code from further referencing
  * this item.
  */
-/*ARGSUSED*/
 STATIC xfs_lsn_t
-xfs_efd_item_committed(xfs_efd_log_item_t *efdp, xfs_lsn_t lsn)
+xfs_efd_item_committed(
+       struct xfs_log_item     *lip,
+       xfs_lsn_t               lsn)
 {
+       struct xfs_efd_log_item *efdp = EFD_ITEM(lip);
+
        /*
         * If we got a log I/O error, it's always the case that the LR with the
         * EFI got unpinned and freed before the EFD got aborted.
         */
-       if ((efdp->efd_item.li_flags & XFS_LI_ABORTED) == 0)
+       if (!(lip->li_flags & XFS_LI_ABORTED))
                xfs_efi_release(efdp->efd_efip, efdp->efd_format.efd_nextents);
 
        xfs_efd_item_free(efdp);
@@ -486,11 +448,10 @@ xfs_efd_item_committed(xfs_efd_log_item_t *efdp, xfs_lsn_t lsn)
  * There isn't much you can do to push on an efd item.  It is simply
  * stuck waiting for the log to be flushed to disk.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_efd_item_push(xfs_efd_log_item_t *efdp)
+xfs_efd_item_push(
+       struct xfs_log_item     *lip)
 {
-       return;
 }
 
 /*
@@ -500,55 +461,48 @@ xfs_efd_item_push(xfs_efd_log_item_t *efdp)
  * example, for inodes, the inode is locked throughout the extent freeing
  * so the dependency should be recorded there.
  */
-/*ARGSUSED*/
 STATIC void
-xfs_efd_item_committing(xfs_efd_log_item_t *efip, xfs_lsn_t lsn)
+xfs_efd_item_committing(
+       struct xfs_log_item     *lip,
+       xfs_lsn_t               lsn)
 {
-       return;
 }
 
 /*
  * This is the ops vector shared by all efd log items.
  */
 static struct xfs_item_ops xfs_efd_item_ops = {
-       .iop_size       = (uint(*)(xfs_log_item_t*))xfs_efd_item_size,
-       .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
-                                       xfs_efd_item_format,
-       .iop_pin        = (void(*)(xfs_log_item_t*))xfs_efd_item_pin,
-       .iop_unpin      = (void(*)(xfs_log_item_t*))xfs_efd_item_unpin,
-       .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
-                                       xfs_efd_item_unpin_remove,
-       .iop_trylock    = (uint(*)(xfs_log_item_t*))xfs_efd_item_trylock,
-       .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_efd_item_unlock,
-       .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_efd_item_committed,
-       .iop_push       = (void(*)(xfs_log_item_t*))xfs_efd_item_push,
-       .iop_pushbuf    = NULL,
-       .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_efd_item_committing
+       .iop_size       = xfs_efd_item_size,
+       .iop_format     = xfs_efd_item_format,
+       .iop_pin        = xfs_efd_item_pin,
+       .iop_unpin      = xfs_efd_item_unpin,
+       .iop_trylock    = xfs_efd_item_trylock,
+       .iop_unlock     = xfs_efd_item_unlock,
+       .iop_committed  = xfs_efd_item_committed,
+       .iop_push       = xfs_efd_item_push,
+       .iop_committing = xfs_efd_item_committing
 };
 
-
 /*
  * Allocate and initialize an efd item with the given number of extents.
  */
-xfs_efd_log_item_t *
-xfs_efd_init(xfs_mount_t       *mp,
-            xfs_efi_log_item_t *efip,
-            uint               nextents)
+struct xfs_efd_log_item *
+xfs_efd_init(
+       struct xfs_mount        *mp,
+       struct xfs_efi_log_item *efip,
+       uint                    nextents)
 
 {
-       xfs_efd_log_item_t      *efdp;
+       struct xfs_efd_log_item *efdp;
        uint                    size;
 
        ASSERT(nextents > 0);
        if (nextents > XFS_EFD_MAX_FAST_EXTENTS) {
                size = (uint)(sizeof(xfs_efd_log_item_t) +
                        ((nextents - 1) * sizeof(xfs_extent_t)));
-               efdp = (xfs_efd_log_item_t*)kmem_zalloc(size, KM_SLEEP);
+               efdp = kmem_zalloc(size, KM_SLEEP);
        } else {
-               efdp = (xfs_efd_log_item_t*)kmem_zone_zalloc(xfs_efd_zone,
-                                                            KM_SLEEP);
+               efdp = kmem_zone_zalloc(xfs_efd_zone, KM_SLEEP);
        }
 
        xfs_log_item_init(mp, &efdp->efd_item, XFS_LI_EFD, &xfs_efd_item_ops);
@@ -556,5 +510,5 @@ xfs_efd_init(xfs_mount_t    *mp,
        efdp->efd_format.efd_nextents = nextents;
        efdp->efd_format.efd_efi_id = efip->efi_format.efi_id;
 
-       return (efdp);
+       return efdp;
 }
index 390850ee6603922651e9ceebfc0f160ce7ff9495..9b715dce5699df0833ea92058683a5b9f30f8868 100644 (file)
 #include "xfs.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_inum.h"
-#include "xfs_dir2.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_ag.h"
-#include "xfs_dmapi.h"
 #include "xfs_log.h"
 #include "xfs_trans.h"
 #include "xfs_sb.h"
@@ -127,6 +123,82 @@ typedef struct fstrm_item
        xfs_inode_t     *pip;   /* Parent directory inode pointer. */
 } fstrm_item_t;
 
+/*
+ * Allocation group filestream associations are tracked with per-ag atomic
+ * counters.  These counters allow _xfs_filestream_pick_ag() to tell whether a
+ * particular AG already has active filestreams associated with it. The mount
+ * point's m_peraglock is used to protect these counters from per-ag array
+ * re-allocation during a growfs operation.  When xfs_growfs_data_private() is
+ * about to reallocate the array, it calls xfs_filestream_flush() with the
+ * m_peraglock held in write mode.
+ *
+ * Since xfs_mru_cache_flush() guarantees that all the free functions for all
+ * the cache elements have finished executing before it returns, it's safe for
+ * the free functions to use the atomic counters without m_peraglock protection.
+ * This allows the implementation of xfs_fstrm_free_func() to be agnostic about
+ * whether it was called with the m_peraglock held in read mode, write mode or
+ * not held at all.  The race condition this addresses is the following:
+ *
+ *  - The work queue scheduler fires and pulls a filestream directory cache
+ *    element off the LRU end of the cache for deletion, then gets pre-empted.
+ *  - A growfs operation grabs the m_peraglock in write mode, flushes all the
+ *    remaining items from the cache and reallocates the mount point's per-ag
+ *    array, resetting all the counters to zero.
+ *  - The work queue thread resumes and calls the free function for the element
+ *    it started cleaning up earlier.  In the process it decrements the
+ *    filestreams counter for an AG that now has no references.
+ *
+ * With a shrinkfs feature, the above scenario could panic the system.
+ *
+ * All other uses of the following macros should be protected by either the
+ * m_peraglock held in read mode, or the cache's internal locking exposed by the
+ * interval between a call to xfs_mru_cache_lookup() and a call to
+ * xfs_mru_cache_done().  In addition, the m_peraglock must be held in read mode
+ * when new elements are added to the cache.
+ *
+ * Combined, these locking rules ensure that no associations will ever exist in
+ * the cache that reference per-ag array elements that have since been
+ * reallocated.
+ */
+static int
+xfs_filestream_peek_ag(
+       xfs_mount_t     *mp,
+       xfs_agnumber_t  agno)
+{
+       struct xfs_perag *pag;
+       int             ret;
+
+       pag = xfs_perag_get(mp, agno);
+       ret = atomic_read(&pag->pagf_fstrms);
+       xfs_perag_put(pag);
+       return ret;
+}
+
+static int
+xfs_filestream_get_ag(
+       xfs_mount_t     *mp,
+       xfs_agnumber_t  agno)
+{
+       struct xfs_perag *pag;
+       int             ret;
+
+       pag = xfs_perag_get(mp, agno);
+       ret = atomic_inc_return(&pag->pagf_fstrms);
+       xfs_perag_put(pag);
+       return ret;
+}
+
+static void
+xfs_filestream_put_ag(
+       xfs_mount_t     *mp,
+       xfs_agnumber_t  agno)
+{
+       struct xfs_perag *pag;
+
+       pag = xfs_perag_get(mp, agno);
+       atomic_dec(&pag->pagf_fstrms);
+       xfs_perag_put(pag);
+}
 
 /*
  * Scan the AGs starting at startag looking for an AG that isn't in use and has
@@ -355,16 +427,14 @@ xfs_fstrm_free_func(
 {
        fstrm_item_t    *item  = (fstrm_item_t *)data;
        xfs_inode_t     *ip = item->ip;
-       int ref;
 
        ASSERT(ip->i_ino == ino);
 
        xfs_iflags_clear(ip, XFS_IFILESTREAM);
 
        /* Drop the reference taken on the AG when the item was added. */
-       ref = xfs_filestream_put_ag(ip->i_mount, item->ag);
+       xfs_filestream_put_ag(ip->i_mount, item->ag);
 
-       ASSERT(ref >= 0);
        TRACE_FREE(ip->i_mount, ip, item->pip, item->ag,
                xfs_filestream_peek_ag(ip->i_mount, item->ag));
 
index 260f757bbc5dd0dcea68e6fc6f0200cf2548e930..09dd9af454349b57fe2a8a7bec0f3c5c3c7e4e3e 100644 (file)
@@ -42,88 +42,6 @@ extern ktrace_t *xfs_filestreams_trace_buf;
 
 #endif
 
-/*
- * Allocation group filestream associations are tracked with per-ag atomic
- * counters.  These counters allow _xfs_filestream_pick_ag() to tell whether a
- * particular AG already has active filestreams associated with it. The mount
- * point's m_peraglock is used to protect these counters from per-ag array
- * re-allocation during a growfs operation.  When xfs_growfs_data_private() is
- * about to reallocate the array, it calls xfs_filestream_flush() with the
- * m_peraglock held in write mode.
- *
- * Since xfs_mru_cache_flush() guarantees that all the free functions for all
- * the cache elements have finished executing before it returns, it's safe for
- * the free functions to use the atomic counters without m_peraglock protection.
- * This allows the implementation of xfs_fstrm_free_func() to be agnostic about
- * whether it was called with the m_peraglock held in read mode, write mode or
- * not held at all.  The race condition this addresses is the following:
- *
- *  - The work queue scheduler fires and pulls a filestream directory cache
- *    element off the LRU end of the cache for deletion, then gets pre-empted.
- *  - A growfs operation grabs the m_peraglock in write mode, flushes all the
- *    remaining items from the cache and reallocates the mount point's per-ag
- *    array, resetting all the counters to zero.
- *  - The work queue thread resumes and calls the free function for the element
- *    it started cleaning up earlier.  In the process it decrements the
- *    filestreams counter for an AG that now has no references.
- *
- * With a shrinkfs feature, the above scenario could panic the system.
- *
- * All other uses of the following macros should be protected by either the
- * m_peraglock held in read mode, or the cache's internal locking exposed by the
- * interval between a call to xfs_mru_cache_lookup() and a call to
- * xfs_mru_cache_done().  In addition, the m_peraglock must be held in read mode
- * when new elements are added to the cache.
- *
- * Combined, these locking rules ensure that no associations will ever exist in
- * the cache that reference per-ag array elements that have since been
- * reallocated.
- */
-/*
- * xfs_filestream_peek_ag is only used in tracing code
- */
-static inline int
-xfs_filestream_peek_ag(
-       xfs_mount_t     *mp,
-       xfs_agnumber_t  agno)
-{
-       struct xfs_perag *pag;
-       int             ret;
-
-       pag = xfs_perag_get(mp, agno);
-       ret = atomic_read(&pag->pagf_fstrms);
-       xfs_perag_put(pag);
-       return ret;
-}
-
-static inline int
-xfs_filestream_get_ag(
-       xfs_mount_t     *mp,
-       xfs_agnumber_t  agno)
-{
-       struct xfs_perag *pag;
-       int             ret;
-
-       pag = xfs_perag_get(mp, agno);
-       ret = atomic_inc_return(&pag->pagf_fstrms);
-       xfs_perag_put(pag);
-       return ret;
-}
-
-static inline int
-xfs_filestream_put_ag(
-       xfs_mount_t     *mp,
-       xfs_agnumber_t  agno)
-{
-       struct xfs_perag *pag;
-       int             ret;
-
-       pag = xfs_perag_get(mp, agno);
-       ret = atomic_dec_return(&pag->pagf_fstrms);
-       xfs_perag_put(pag);
-       return ret;
-}
-
 /* allocation selection flags */
 typedef enum xfs_fstrm_alloc {
        XFS_PICK_USERDATA = 1,
index 37a6f62c57b6f89cd93ca38ed6099c5952367401..dbca5f5c37bad18fc220ce21f551d17b58f0c13a 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
@@ -626,8 +622,7 @@ xfs_fs_log_dummy(
        ip = mp->m_rootip;
        xfs_ilock(ip, XFS_ILOCK_EXCL);
 
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
+       xfs_trans_ijoin(tp, ip);
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        xfs_trans_set_sync(tp);
        error = xfs_trans_commit(tp, 0);
index c7142a064c48d7b052d9ac0225f33562d0552386..abf80ae1e95bed43db56f17dd8a7ffc06039a60a 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
index c282a9af5393da36022e471332dc45d37705bcbb..d352862cefa01d7e3c743ed1904b1d1da59bc1b2 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
index 8f8b91be2c996dce5b75901038c507bb4b9ef1da..b1ecc6f97adea06467967178b9a8c6903a41262e 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
@@ -95,7 +91,7 @@ xfs_inode_alloc(
        return ip;
 }
 
-STATIC void
+void
 xfs_inode_free(
        struct xfs_inode        *ip)
 {
@@ -212,7 +208,7 @@ xfs_iget_cache_hit(
                        ip->i_flags &= ~XFS_INEW;
                        ip->i_flags |= XFS_IRECLAIMABLE;
                        __xfs_inode_set_reclaim_tag(pag, ip);
-                       trace_xfs_iget_reclaim(ip);
+                       trace_xfs_iget_reclaim_fail(ip);
                        goto out_error;
                }
 
@@ -227,6 +223,7 @@ xfs_iget_cache_hit(
        } else {
                /* If the VFS inode is being torn down, pause and try again. */
                if (!igrab(inode)) {
+                       trace_xfs_iget_skip(ip);
                        error = EAGAIN;
                        goto out_error;
                }
@@ -234,6 +231,7 @@ xfs_iget_cache_hit(
                /* We've got a live one. */
                spin_unlock(&ip->i_flags_lock);
                read_unlock(&pag->pag_ici_lock);
+               trace_xfs_iget_hit(ip);
        }
 
        if (lock_flags != 0)
@@ -242,7 +240,6 @@ xfs_iget_cache_hit(
        xfs_iflags_clear(ip, XFS_ISTALE);
        XFS_STATS_INC(xs_ig_found);
 
-       trace_xfs_iget_found(ip);
        return 0;
 
 out_error:
@@ -264,7 +261,6 @@ xfs_iget_cache_miss(
 {
        struct xfs_inode        *ip;
        int                     error;
-       unsigned long           first_index, mask;
        xfs_agino_t             agino = XFS_INO_TO_AGINO(mp, ino);
 
        ip = xfs_inode_alloc(mp, ino);
@@ -275,7 +271,7 @@ xfs_iget_cache_miss(
        if (error)
                goto out_destroy;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_iget_miss(ip);
 
        if ((ip->i_d.di_mode == 0) && !(flags & XFS_IGET_CREATE)) {
                error = ENOENT;
@@ -301,8 +297,6 @@ xfs_iget_cache_miss(
                        BUG();
        }
 
-       mask = ~(((XFS_INODE_CLUSTER_SIZE(mp) >> mp->m_sb.sb_inodelog)) - 1);
-       first_index = agino & mask;
        write_lock(&pag->pag_ici_lock);
 
        /* insert the new inode */
@@ -321,7 +315,6 @@ xfs_iget_cache_miss(
        write_unlock(&pag->pag_ici_lock);
        radix_tree_preload_end();
 
-       trace_xfs_iget_alloc(ip);
        *ipp = ip;
        return 0;
 
@@ -421,97 +414,6 @@ out_error_or_again:
        return error;
 }
 
-/*
- * Decrement reference count of an inode structure and unlock it.
- *
- * ip -- the inode being released
- * lock_flags -- this parameter indicates the inode's locks to be
- *       to be released.  See the comment on xfs_iunlock() for a list
- *      of valid values.
- */
-void
-xfs_iput(xfs_inode_t   *ip,
-        uint           lock_flags)
-{
-       xfs_itrace_entry(ip);
-       xfs_iunlock(ip, lock_flags);
-       IRELE(ip);
-}
-
-/*
- * Special iput for brand-new inodes that are still locked
- */
-void
-xfs_iput_new(
-       xfs_inode_t     *ip,
-       uint            lock_flags)
-{
-       struct inode    *inode = VFS_I(ip);
-
-       xfs_itrace_entry(ip);
-
-       if ((ip->i_d.di_mode == 0)) {
-               ASSERT(!xfs_iflags_test(ip, XFS_IRECLAIMABLE));
-               make_bad_inode(inode);
-       }
-       if (inode->i_state & I_NEW)
-               unlock_new_inode(inode);
-       if (lock_flags)
-               xfs_iunlock(ip, lock_flags);
-       IRELE(ip);
-}
-
-/*
- * This is called free all the memory associated with an inode.
- * It must free the inode itself and any buffers allocated for
- * if_extents/if_data and if_broot.  It must also free the lock
- * associated with the inode.
- *
- * Note: because we don't initialise everything on reallocation out
- * of the zone, we must ensure we nullify everything correctly before
- * freeing the structure.
- */
-void
-xfs_ireclaim(
-       struct xfs_inode        *ip)
-{
-       struct xfs_mount        *mp = ip->i_mount;
-       struct xfs_perag        *pag;
-       xfs_agino_t             agino = XFS_INO_TO_AGINO(mp, ip->i_ino);
-
-       XFS_STATS_INC(xs_ig_reclaims);
-
-       /*
-        * Remove the inode from the per-AG radix tree.
-        *
-        * Because radix_tree_delete won't complain even if the item was never
-        * added to the tree assert that it's been there before to catch
-        * problems with the inode life time early on.
-        */
-       pag = xfs_perag_get(mp, XFS_INO_TO_AGNO(mp, ip->i_ino));
-       write_lock(&pag->pag_ici_lock);
-       if (!radix_tree_delete(&pag->pag_ici_root, agino))
-               ASSERT(0);
-       write_unlock(&pag->pag_ici_lock);
-       xfs_perag_put(pag);
-
-       /*
-        * Here we do an (almost) spurious inode lock in order to coordinate
-        * with inode cache radix tree lookups.  This is because the lookup
-        * can reference the inodes in the cache without taking references.
-        *
-        * We make that OK here by ensuring that we wait until the inode is
-        * unlocked after the lookup before we go ahead and free it.  We get
-        * both the ilock and the iolock because the code may need to drop the
-        * ilock one but will still hold the iolock.
-        */
-       xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-       xfs_qm_dqdetach(ip);
-       xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-
-       xfs_inode_free(ip);
-}
-
 /*
  * This is a wrapper routine around the xfs_ilock() routine
  * used to centralize some grungy code.  It is used in places
index b76a829d7e200d4ead1b9e4406faf93f1e4093e0..68415cb4f23cab39861119c68838b1b099029df2 100644 (file)
 #include "xfs_trans_priv.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
 #include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
@@ -44,7 +41,6 @@
 #include "xfs_alloc.h"
 #include "xfs_ialloc.h"
 #include "xfs_bmap.h"
-#include "xfs_rw.h"
 #include "xfs_error.h"
 #include "xfs_utils.h"
 #include "xfs_quota.h"
@@ -426,7 +422,7 @@ xfs_iformat(
        if (!XFS_DFORK_Q(dip))
                return 0;
        ASSERT(ip->i_afp == NULL);
-       ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_SLEEP);
+       ip->i_afp = kmem_zone_zalloc(xfs_ifork_zone, KM_SLEEP | KM_NOFS);
        ip->i_afp->if_ext_max =
                XFS_IFORK_ASIZE(ip) / (uint)sizeof(xfs_bmbt_rec_t);
        switch (dip->di_aformat) {
@@ -509,7 +505,7 @@ xfs_iformat_local(
                ifp->if_u1.if_data = ifp->if_u2.if_inline_data;
        else {
                real_size = roundup(size, 4);
-               ifp->if_u1.if_data = kmem_alloc(real_size, KM_SLEEP);
+               ifp->if_u1.if_data = kmem_alloc(real_size, KM_SLEEP | KM_NOFS);
        }
        ifp->if_bytes = size;
        ifp->if_real_bytes = real_size;
@@ -636,7 +632,7 @@ xfs_iformat_btree(
        }
 
        ifp->if_broot_bytes = size;
-       ifp->if_broot = kmem_alloc(size, KM_SLEEP);
+       ifp->if_broot = kmem_alloc(size, KM_SLEEP | KM_NOFS);
        ASSERT(ifp->if_broot != NULL);
        /*
         * Copy and convert from the on-disk structure
@@ -922,7 +918,6 @@ xfs_iread_extents(
        int             error;
        xfs_ifork_t     *ifp;
        xfs_extnum_t    nextents;
-       size_t          size;
 
        if (unlikely(XFS_IFORK_FORMAT(ip, whichfork) != XFS_DINODE_FMT_BTREE)) {
                XFS_ERROR_REPORT("xfs_iread_extents", XFS_ERRLEVEL_LOW,
@@ -930,7 +925,6 @@ xfs_iread_extents(
                return XFS_ERROR(EFSCORRUPTED);
        }
        nextents = XFS_IFORK_NEXTENTS(ip, whichfork);
-       size = nextents * sizeof(xfs_bmbt_rec_t);
        ifp = XFS_IFORK_PTR(ip, whichfork);
 
        /*
@@ -1226,7 +1220,7 @@ xfs_isize_check(
                                       (xfs_ufsize_t)XFS_MAXIOFFSET(mp)) -
                          map_first),
                         XFS_BMAPI_ENTIRE, NULL, 0, imaps, &nimaps,
-                        NULL, NULL))
+                        NULL))
            return;
        ASSERT(nimaps == 1);
        ASSERT(imaps[0].br_startblock == HOLESTARTBLOCK);
@@ -1460,7 +1454,7 @@ xfs_itruncate_finish(
        ASSERT((*tp)->t_flags & XFS_TRANS_PERM_LOG_RES);
        ASSERT(ip->i_transp == *tp);
        ASSERT(ip->i_itemp != NULL);
-       ASSERT(ip->i_itemp->ili_flags & XFS_ILI_HOLD);
+       ASSERT(ip->i_itemp->ili_lock_flags == 0);
 
 
        ntp = *tp;
@@ -1589,11 +1583,10 @@ xfs_itruncate_finish(
                xfs_bmap_init(&free_list, &first_block);
                error = xfs_bunmapi(ntp, ip,
                                    first_unmap_block, unmap_len,
-                                   xfs_bmapi_aflag(fork) |
-                                     (sync ? 0 : XFS_BMAPI_ASYNC),
+                                   xfs_bmapi_aflag(fork),
                                    XFS_ITRUNC_MAX_EXTENTS,
                                    &first_block, &free_list,
-                                   NULL, &done);
+                                   &done);
                if (error) {
                        /*
                         * If the bunmapi call encounters an error,
@@ -1612,12 +1605,8 @@ xfs_itruncate_finish(
                 */
                error = xfs_bmap_finish(tp, &free_list, &committed);
                ntp = *tp;
-               if (committed) {
-                       /* link the inode into the next xact in the chain */
-                       xfs_trans_ijoin(ntp, ip,
-                                       XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-                       xfs_trans_ihold(ntp, ip);
-               }
+               if (committed)
+                       xfs_trans_ijoin(ntp, ip);
 
                if (error) {
                        /*
@@ -1646,9 +1635,7 @@ xfs_itruncate_finish(
                error = xfs_trans_commit(*tp, 0);
                *tp = ntp;
 
-               /* link the inode into the next transaction in the chain */
-               xfs_trans_ijoin(ntp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-               xfs_trans_ihold(ntp, ip);
+               xfs_trans_ijoin(ntp, ip);
 
                if (error)
                        return error;
@@ -1985,7 +1972,7 @@ xfs_ifree_cluster(
                        if (lip->li_type == XFS_LI_INODE) {
                                iip = (xfs_inode_log_item_t *)lip;
                                ASSERT(iip->ili_logged == 1);
-                               lip->li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*)) xfs_istale_done;
+                               lip->li_cb = xfs_istale_done;
                                xfs_trans_ail_copy_lsn(mp->m_ail,
                                                        &iip->ili_flush_lsn,
                                                        &iip->ili_item.li_lsn);
@@ -2055,9 +2042,8 @@ xfs_ifree_cluster(
                        xfs_trans_ail_copy_lsn(mp->m_ail, &iip->ili_flush_lsn,
                                                &iip->ili_item.li_lsn);
 
-                       xfs_buf_attach_iodone(bp,
-                               (void(*)(xfs_buf_t*,xfs_log_item_t*))
-                               xfs_istale_done, (xfs_log_item_t *)iip);
+                       xfs_buf_attach_iodone(bp, xfs_istale_done,
+                                                 &iip->ili_item);
 
                        if (ip != free_ip)
                                xfs_iunlock(ip, XFS_ILOCK_EXCL);
@@ -2203,7 +2189,7 @@ xfs_iroot_realloc(
                 */
                if (ifp->if_broot_bytes == 0) {
                        new_size = (size_t)XFS_BMAP_BROOT_SPACE_CALC(rec_diff);
-                       ifp->if_broot = kmem_alloc(new_size, KM_SLEEP);
+                       ifp->if_broot = kmem_alloc(new_size, KM_SLEEP | KM_NOFS);
                        ifp->if_broot_bytes = (int)new_size;
                        return;
                }
@@ -2219,7 +2205,7 @@ xfs_iroot_realloc(
                new_size = (size_t)XFS_BMAP_BROOT_SPACE_CALC(new_max);
                ifp->if_broot = kmem_realloc(ifp->if_broot, new_size,
                                (size_t)XFS_BMAP_BROOT_SPACE_CALC(cur_max), /* old size */
-                               KM_SLEEP);
+                               KM_SLEEP | KM_NOFS);
                op = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1,
                                                     ifp->if_broot_bytes);
                np = (char *)XFS_BMAP_BROOT_PTR_ADDR(mp, ifp->if_broot, 1,
@@ -2245,7 +2231,7 @@ xfs_iroot_realloc(
        else
                new_size = 0;
        if (new_size > 0) {
-               new_broot = kmem_alloc(new_size, KM_SLEEP);
+               new_broot = kmem_alloc(new_size, KM_SLEEP | KM_NOFS);
                /*
                 * First copy over the btree block header.
                 */
@@ -2349,7 +2335,8 @@ xfs_idata_realloc(
                real_size = roundup(new_size, 4);
                if (ifp->if_u1.if_data == NULL) {
                        ASSERT(ifp->if_real_bytes == 0);
-                       ifp->if_u1.if_data = kmem_alloc(real_size, KM_SLEEP);
+                       ifp->if_u1.if_data = kmem_alloc(real_size,
+                                                       KM_SLEEP | KM_NOFS);
                } else if (ifp->if_u1.if_data != ifp->if_u2.if_inline_data) {
                        /*
                         * Only do the realloc if the underlying size
@@ -2360,11 +2347,12 @@ xfs_idata_realloc(
                                        kmem_realloc(ifp->if_u1.if_data,
                                                        real_size,
                                                        ifp->if_real_bytes,
-                                                       KM_SLEEP);
+                                                       KM_SLEEP | KM_NOFS);
                        }
                } else {
                        ASSERT(ifp->if_real_bytes == 0);
-                       ifp->if_u1.if_data = kmem_alloc(real_size, KM_SLEEP);
+                       ifp->if_u1.if_data = kmem_alloc(real_size,
+                                                       KM_SLEEP | KM_NOFS);
                        memcpy(ifp->if_u1.if_data, ifp->if_u2.if_inline_data,
                                ifp->if_bytes);
                }
@@ -2731,7 +2719,6 @@ cluster_corrupt_out:
                 * mark it as stale and brelse.
                 */
                if (XFS_BUF_IODONE_FUNC(bp)) {
-                       XFS_BUF_CLR_BDSTRAT_FUNC(bp);
                        XFS_BUF_UNDONE(bp);
                        XFS_BUF_STALE(bp);
                        XFS_BUF_ERROR(bp,EIO);
@@ -3069,8 +3056,7 @@ xfs_iflush_int(
                 * and unlock the inode's flush lock when the inode is
                 * completely written to disk.
                 */
-               xfs_buf_attach_iodone(bp, (void(*)(xfs_buf_t*,xfs_log_item_t*))
-                                     xfs_iflush_done, (xfs_log_item_t *)iip);
+               xfs_buf_attach_iodone(bp, xfs_iflush_done, &iip->ili_item);
 
                ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
                ASSERT(XFS_BUF_IODONE_FUNC(bp) != NULL);
@@ -3514,13 +3500,11 @@ xfs_iext_remove_indirect(
        xfs_extnum_t    ext_diff;       /* extents to remove in current list */
        xfs_extnum_t    nex1;           /* number of extents before idx */
        xfs_extnum_t    nex2;           /* extents after idx + count */
-       int             nlists;         /* entries in indirection array */
        int             page_idx = idx; /* index in target extent list */
 
        ASSERT(ifp->if_flags & XFS_IFEXTIREC);
        erp = xfs_iext_idx_to_irec(ifp,  &page_idx, &erp_idx, 0);
        ASSERT(erp != NULL);
-       nlists = ifp->if_real_bytes / XFS_IEXT_BUFSZ;
        nex1 = page_idx;
        ext_cnt = count;
        while (ext_cnt) {
index 78550df13cd664ee4811447f836e9d0f8dc31405..0898c5417d12b53476594d5cfdfaee665de56533 100644 (file)
@@ -443,8 +443,6 @@ static inline void xfs_ifunlock(xfs_inode_t *ip)
  */
 int            xfs_iget(struct xfs_mount *, struct xfs_trans *, xfs_ino_t,
                         uint, uint, xfs_inode_t **);
-void           xfs_iput(xfs_inode_t *, uint);
-void           xfs_iput_new(xfs_inode_t *, uint);
 void           xfs_ilock(xfs_inode_t *, uint);
 int            xfs_ilock_nowait(xfs_inode_t *, uint);
 void           xfs_iunlock(xfs_inode_t *, uint);
@@ -452,7 +450,7 @@ void                xfs_ilock_demote(xfs_inode_t *, uint);
 int            xfs_isilocked(xfs_inode_t *, uint);
 uint           xfs_ilock_map_shared(xfs_inode_t *);
 void           xfs_iunlock_map_shared(xfs_inode_t *, uint);
-void           xfs_ireclaim(xfs_inode_t *);
+void           xfs_inode_free(struct xfs_inode *ip);
 
 /*
  * xfs_inode.c prototypes.
index cf8249a600047b6d7dac03c7c11a4986020ce227..fe00777e2796317146ce1e20142cc7f4e3679635 100644 (file)
 #include "xfs_log.h"
 #include "xfs_inum.h"
 #include "xfs_trans.h"
-#include "xfs_buf_item.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_trans_priv.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
-#include "xfs_btree.h"
-#include "xfs_ialloc.h"
-#include "xfs_rw.h"
 #include "xfs_error.h"
 #include "xfs_trace.h"
 
 
 kmem_zone_t    *xfs_ili_zone;          /* inode log item zone */
 
+static inline struct xfs_inode_log_item *INODE_ITEM(struct xfs_log_item *lip)
+{
+       return container_of(lip, struct xfs_inode_log_item, ili_item);
+}
+
+
 /*
  * This returns the number of iovecs needed to log the given inode item.
  *
@@ -55,13 +51,11 @@ kmem_zone_t *xfs_ili_zone;          /* inode log item zone */
  */
 STATIC uint
 xfs_inode_item_size(
-       xfs_inode_log_item_t    *iip)
+       struct xfs_log_item     *lip)
 {
-       uint            nvecs;
-       xfs_inode_t     *ip;
-
-       ip = iip->ili_inode;
-       nvecs = 2;
+       struct xfs_inode_log_item *iip = INODE_ITEM(lip);
+       struct xfs_inode        *ip = iip->ili_inode;
+       uint                    nvecs = 2;
 
        /*
         * Only log the data/extents/b-tree root if there is something
@@ -212,21 +206,17 @@ xfs_inode_item_size(
  */
 STATIC void
 xfs_inode_item_format(
-       xfs_inode_log_item_t    *iip,
-       xfs_log_iovec_t         *log_vector)
+       struct xfs_log_item     *lip,
+       struct xfs_log_iovec    *vecp)
 {
+       struct xfs_inode_log_item *iip = INODE_ITEM(lip);
+       struct xfs_inode        *ip = iip->ili_inode;
        uint                    nvecs;
-       xfs_log_iovec_t         *vecp;
-       xfs_inode_t             *ip;
        size_t                  data_bytes;
        xfs_bmbt_rec_t          *ext_buffer;
-       int                     nrecs;
        xfs_mount_t             *mp;
 
-       ip = iip->ili_inode;
-       vecp = log_vector;
-
-       vecp->i_addr = (xfs_caddr_t)&iip->ili_format;
+       vecp->i_addr = &iip->ili_format;
        vecp->i_len  = sizeof(xfs_inode_log_format_t);
        vecp->i_type = XLOG_REG_TYPE_IFORMAT;
        vecp++;
@@ -277,7 +267,7 @@ xfs_inode_item_format(
         */
        xfs_synchronize_times(ip);
 
-       vecp->i_addr = (xfs_caddr_t)&ip->i_d;
+       vecp->i_addr = &ip->i_d;
        vecp->i_len  = sizeof(struct xfs_icdinode);
        vecp->i_type = XLOG_REG_TYPE_ICORE;
        vecp++;
@@ -323,18 +313,17 @@ xfs_inode_item_format(
                        ASSERT(ip->i_df.if_u1.if_extents != NULL);
                        ASSERT(ip->i_d.di_nextents > 0);
                        ASSERT(iip->ili_extents_buf == NULL);
-                       nrecs = ip->i_df.if_bytes /
-                               (uint)sizeof(xfs_bmbt_rec_t);
-                       ASSERT(nrecs > 0);
+                       ASSERT((ip->i_df.if_bytes /
+                               (uint)sizeof(xfs_bmbt_rec_t)) > 0);
 #ifdef XFS_NATIVE_HOST
-                       if (nrecs == ip->i_d.di_nextents) {
+                       if (ip->i_d.di_nextents == ip->i_df.if_bytes /
+                                               (uint)sizeof(xfs_bmbt_rec_t)) {
                                /*
                                 * There are no delayed allocation
                                 * extents, so just point to the
                                 * real extents array.
                                 */
-                               vecp->i_addr =
-                                       (char *)(ip->i_df.if_u1.if_extents);
+                               vecp->i_addr = ip->i_df.if_u1.if_extents;
                                vecp->i_len = ip->i_df.if_bytes;
                                vecp->i_type = XLOG_REG_TYPE_IEXT;
                        } else
@@ -352,7 +341,7 @@ xfs_inode_item_format(
                                ext_buffer = kmem_alloc(ip->i_df.if_bytes,
                                        KM_SLEEP);
                                iip->ili_extents_buf = ext_buffer;
-                               vecp->i_addr = (xfs_caddr_t)ext_buffer;
+                               vecp->i_addr = ext_buffer;
                                vecp->i_len = xfs_iextents_copy(ip, ext_buffer,
                                                XFS_DATA_FORK);
                                vecp->i_type = XLOG_REG_TYPE_IEXT;
@@ -371,7 +360,7 @@ xfs_inode_item_format(
                if (iip->ili_format.ilf_fields & XFS_ILOG_DBROOT) {
                        ASSERT(ip->i_df.if_broot_bytes > 0);
                        ASSERT(ip->i_df.if_broot != NULL);
-                       vecp->i_addr = (xfs_caddr_t)ip->i_df.if_broot;
+                       vecp->i_addr = ip->i_df.if_broot;
                        vecp->i_len = ip->i_df.if_broot_bytes;
                        vecp->i_type = XLOG_REG_TYPE_IBROOT;
                        vecp++;
@@ -389,7 +378,7 @@ xfs_inode_item_format(
                        ASSERT(ip->i_df.if_u1.if_data != NULL);
                        ASSERT(ip->i_d.di_size > 0);
 
-                       vecp->i_addr = (xfs_caddr_t)ip->i_df.if_u1.if_data;
+                       vecp->i_addr = ip->i_df.if_u1.if_data;
                        /*
                         * Round i_bytes up to a word boundary.
                         * The underlying memory is guaranteed to
@@ -437,7 +426,7 @@ xfs_inode_item_format(
         * Assert that no attribute-related log flags are set.
         */
        if (!XFS_IFORK_Q(ip)) {
-               ASSERT(nvecs == iip->ili_item.li_desc->lid_size);
+               ASSERT(nvecs == lip->li_desc->lid_size);
                iip->ili_format.ilf_size = nvecs;
                ASSERT(!(iip->ili_format.ilf_fields &
                         (XFS_ILOG_ADATA | XFS_ILOG_ABROOT | XFS_ILOG_AEXT)));
@@ -449,21 +438,21 @@ xfs_inode_item_format(
                ASSERT(!(iip->ili_format.ilf_fields &
                         (XFS_ILOG_ADATA | XFS_ILOG_ABROOT)));
                if (iip->ili_format.ilf_fields & XFS_ILOG_AEXT) {
-                       ASSERT(ip->i_afp->if_bytes > 0);
-                       ASSERT(ip->i_afp->if_u1.if_extents != NULL);
-                       ASSERT(ip->i_d.di_anextents > 0);
 #ifdef DEBUG
-                       nrecs = ip->i_afp->if_bytes /
+                       int nrecs = ip->i_afp->if_bytes /
                                (uint)sizeof(xfs_bmbt_rec_t);
-#endif
                        ASSERT(nrecs > 0);
                        ASSERT(nrecs == ip->i_d.di_anextents);
+                       ASSERT(ip->i_afp->if_bytes > 0);
+                       ASSERT(ip->i_afp->if_u1.if_extents != NULL);
+                       ASSERT(ip->i_d.di_anextents > 0);
+#endif
 #ifdef XFS_NATIVE_HOST
                        /*
                         * There are not delayed allocation extents
                         * for attributes, so just point at the array.
                         */
-                       vecp->i_addr = (char *)(ip->i_afp->if_u1.if_extents);
+                       vecp->i_addr = ip->i_afp->if_u1.if_extents;
                        vecp->i_len = ip->i_afp->if_bytes;
 #else
                        ASSERT(iip->ili_aextents_buf == NULL);
@@ -473,7 +462,7 @@ xfs_inode_item_format(
                        ext_buffer = kmem_alloc(ip->i_afp->if_bytes,
                                KM_SLEEP);
                        iip->ili_aextents_buf = ext_buffer;
-                       vecp->i_addr = (xfs_caddr_t)ext_buffer;
+                       vecp->i_addr = ext_buffer;
                        vecp->i_len = xfs_iextents_copy(ip, ext_buffer,
                                        XFS_ATTR_FORK);
 #endif
@@ -490,7 +479,7 @@ xfs_inode_item_format(
                if (iip->ili_format.ilf_fields & XFS_ILOG_ABROOT) {
                        ASSERT(ip->i_afp->if_broot_bytes > 0);
                        ASSERT(ip->i_afp->if_broot != NULL);
-                       vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_broot;
+                       vecp->i_addr = ip->i_afp->if_broot;
                        vecp->i_len = ip->i_afp->if_broot_bytes;
                        vecp->i_type = XLOG_REG_TYPE_IATTR_BROOT;
                        vecp++;
@@ -506,7 +495,7 @@ xfs_inode_item_format(
                        ASSERT(ip->i_afp->if_bytes > 0);
                        ASSERT(ip->i_afp->if_u1.if_data != NULL);
 
-                       vecp->i_addr = (xfs_caddr_t)ip->i_afp->if_u1.if_data;
+                       vecp->i_addr = ip->i_afp->if_u1.if_data;
                        /*
                         * Round i_bytes up to a word boundary.
                         * The underlying memory is guaranteed to
@@ -528,7 +517,7 @@ xfs_inode_item_format(
                break;
        }
 
-       ASSERT(nvecs == iip->ili_item.li_desc->lid_size);
+       ASSERT(nvecs == lip->li_desc->lid_size);
        iip->ili_format.ilf_size = nvecs;
 }
 
@@ -539,12 +528,14 @@ xfs_inode_item_format(
  */
 STATIC void
 xfs_inode_item_pin(
-       xfs_inode_log_item_t    *iip)
+       struct xfs_log_item     *lip)
 {
-       ASSERT(xfs_isilocked(iip->ili_inode, XFS_ILOCK_EXCL));
+       struct xfs_inode        *ip = INODE_ITEM(lip)->ili_inode;
+
+       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
 
-       trace_xfs_inode_pin(iip->ili_inode, _RET_IP_);
-       atomic_inc(&iip->ili_inode->i_pincount);
+       trace_xfs_inode_pin(ip, _RET_IP_);
+       atomic_inc(&ip->i_pincount);
 }
 
 
@@ -554,12 +545,12 @@ xfs_inode_item_pin(
  *
  * Also wake up anyone in xfs_iunpin_wait() if the count goes to 0.
  */
-/* ARGSUSED */
 STATIC void
 xfs_inode_item_unpin(
-       xfs_inode_log_item_t    *iip)
+       struct xfs_log_item     *lip,
+       int                     remove)
 {
-       struct xfs_inode        *ip = iip->ili_inode;
+       struct xfs_inode        *ip = INODE_ITEM(lip)->ili_inode;
 
        trace_xfs_inode_unpin(ip, _RET_IP_);
        ASSERT(atomic_read(&ip->i_pincount) > 0);
@@ -567,15 +558,6 @@ xfs_inode_item_unpin(
                wake_up(&ip->i_ipin_wait);
 }
 
-/* ARGSUSED */
-STATIC void
-xfs_inode_item_unpin_remove(
-       xfs_inode_log_item_t    *iip,
-       xfs_trans_t             *tp)
-{
-       xfs_inode_item_unpin(iip);
-}
-
 /*
  * This is called to attempt to lock the inode associated with this
  * inode log item, in preparation for the push routine which does the actual
@@ -591,19 +573,16 @@ xfs_inode_item_unpin_remove(
  */
 STATIC uint
 xfs_inode_item_trylock(
-       xfs_inode_log_item_t    *iip)
+       struct xfs_log_item     *lip)
 {
-       register xfs_inode_t    *ip;
-
-       ip = iip->ili_inode;
+       struct xfs_inode_log_item *iip = INODE_ITEM(lip);
+       struct xfs_inode        *ip = iip->ili_inode;
 
-       if (xfs_ipincount(ip) > 0) {
+       if (xfs_ipincount(ip) > 0)
                return XFS_ITEM_PINNED;
-       }
 
-       if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED)) {
+       if (!xfs_ilock_nowait(ip, XFS_ILOCK_SHARED))
                return XFS_ITEM_LOCKED;
-       }
 
        if (!xfs_iflock_nowait(ip)) {
                /*
@@ -629,7 +608,7 @@ xfs_inode_item_trylock(
        if (!XFS_FORCED_SHUTDOWN(ip->i_mount)) {
                ASSERT(iip->ili_format.ilf_fields != 0);
                ASSERT(iip->ili_logged == 0);
-               ASSERT(iip->ili_item.li_flags & XFS_LI_IN_AIL);
+               ASSERT(lip->li_flags & XFS_LI_IN_AIL);
        }
 #endif
        return XFS_ITEM_SUCCESS;
@@ -643,26 +622,18 @@ xfs_inode_item_trylock(
  */
 STATIC void
 xfs_inode_item_unlock(
-       xfs_inode_log_item_t    *iip)
+       struct xfs_log_item     *lip)
 {
-       uint            hold;
-       uint            iolocked;
-       uint            lock_flags;
-       xfs_inode_t     *ip;
+       struct xfs_inode_log_item *iip = INODE_ITEM(lip);
+       struct xfs_inode        *ip = iip->ili_inode;
+       unsigned short          lock_flags;
 
-       ASSERT(iip != NULL);
        ASSERT(iip->ili_inode->i_itemp != NULL);
        ASSERT(xfs_isilocked(iip->ili_inode, XFS_ILOCK_EXCL));
-       ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
-                 XFS_ILI_IOLOCKED_EXCL)) ||
-              xfs_isilocked(iip->ili_inode, XFS_IOLOCK_EXCL));
-       ASSERT((!(iip->ili_inode->i_itemp->ili_flags &
-                 XFS_ILI_IOLOCKED_SHARED)) ||
-              xfs_isilocked(iip->ili_inode, XFS_IOLOCK_SHARED));
+
        /*
         * Clear the transaction pointer in the inode.
         */
-       ip = iip->ili_inode;
        ip->i_transp = NULL;
 
        /*
@@ -686,34 +657,11 @@ xfs_inode_item_unlock(
                iip->ili_aextents_buf = NULL;
        }
 
-       /*
-        * Figure out if we should unlock the inode or not.
-        */
-       hold = iip->ili_flags & XFS_ILI_HOLD;
-
-       /*
-        * Before clearing out the flags, remember whether we
-        * are holding the inode's IO lock.
-        */
-       iolocked = iip->ili_flags & XFS_ILI_IOLOCKED_ANY;
-
-       /*
-        * Clear out the fields of the inode log item particular
-        * to the current transaction.
-        */
-       iip->ili_flags = 0;
-
-       /*
-        * Unlock the inode if XFS_ILI_HOLD was not set.
-        */
-       if (!hold) {
-               lock_flags = XFS_ILOCK_EXCL;
-               if (iolocked & XFS_ILI_IOLOCKED_EXCL) {
-                       lock_flags |= XFS_IOLOCK_EXCL;
-               } else if (iolocked & XFS_ILI_IOLOCKED_SHARED) {
-                       lock_flags |= XFS_IOLOCK_SHARED;
-               }
-               xfs_iput(iip->ili_inode, lock_flags);
+       lock_flags = iip->ili_lock_flags;
+       iip->ili_lock_flags = 0;
+       if (lock_flags) {
+               xfs_iunlock(iip->ili_inode, lock_flags);
+               IRELE(iip->ili_inode);
        }
 }
 
@@ -725,13 +673,12 @@ xfs_inode_item_unlock(
  * is the only one that matters.  Therefore, simply return the
  * given lsn.
  */
-/*ARGSUSED*/
 STATIC xfs_lsn_t
 xfs_inode_item_committed(
-       xfs_inode_log_item_t    *iip,
+       struct xfs_log_item     *lip,
        xfs_lsn_t               lsn)
 {
-       return (lsn);
+       return lsn;
 }
 
 /*
@@ -743,13 +690,12 @@ xfs_inode_item_committed(
  */
 STATIC void
 xfs_inode_item_pushbuf(
-       xfs_inode_log_item_t    *iip)
+       struct xfs_log_item     *lip)
 {
-       xfs_inode_t     *ip;
-       xfs_mount_t     *mp;
-       xfs_buf_t       *bp;
+       struct xfs_inode_log_item *iip = INODE_ITEM(lip);
+       struct xfs_inode        *ip = iip->ili_inode;
+       struct xfs_buf          *bp;
 
-       ip = iip->ili_inode;
        ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED));
 
        /*
@@ -757,14 +703,13 @@ xfs_inode_item_pushbuf(
         * inode was taken off the AIL. So, just get out.
         */
        if (completion_done(&ip->i_flush) ||
-           ((iip->ili_item.li_flags & XFS_LI_IN_AIL) == 0)) {
+           !(lip->li_flags & XFS_LI_IN_AIL)) {
                xfs_iunlock(ip, XFS_ILOCK_SHARED);
                return;
        }
 
-       mp = ip->i_mount;
-       bp = xfs_incore(mp->m_ddev_targp, iip->ili_format.ilf_blkno,
-                   iip->ili_format.ilf_len, XBF_TRYLOCK);
+       bp = xfs_incore(ip->i_mount->m_ddev_targp, iip->ili_format.ilf_blkno,
+                       iip->ili_format.ilf_len, XBF_TRYLOCK);
 
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
        if (!bp)
@@ -772,10 +717,8 @@ xfs_inode_item_pushbuf(
        if (XFS_BUF_ISDELAYWRITE(bp))
                xfs_buf_delwri_promote(bp);
        xfs_buf_relse(bp);
-       return;
 }
 
-
 /*
  * This is called to asynchronously write the inode associated with this
  * inode log item out to disk. The inode will already have been locked by
@@ -783,14 +726,14 @@ xfs_inode_item_pushbuf(
  */
 STATIC void
 xfs_inode_item_push(
-       xfs_inode_log_item_t    *iip)
+       struct xfs_log_item     *lip)
 {
-       xfs_inode_t     *ip;
-
-       ip = iip->ili_inode;
+       struct xfs_inode_log_item *iip = INODE_ITEM(lip);
+       struct xfs_inode        *ip = iip->ili_inode;
 
        ASSERT(xfs_isilocked(ip, XFS_ILOCK_SHARED));
        ASSERT(!completion_done(&ip->i_flush));
+
        /*
         * Since we were able to lock the inode's flush lock and
         * we found it on the AIL, the inode must be dirty.  This
@@ -813,43 +756,34 @@ xfs_inode_item_push(
         */
        (void) xfs_iflush(ip, 0);
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
-
-       return;
 }
 
 /*
  * XXX rcc - this one really has to do something.  Probably needs
  * to stamp in a new field in the incore inode.
  */
-/* ARGSUSED */
 STATIC void
 xfs_inode_item_committing(
-       xfs_inode_log_item_t    *iip,
+       struct xfs_log_item     *lip,
        xfs_lsn_t               lsn)
 {
-       iip->ili_last_lsn = lsn;
-       return;
+       INODE_ITEM(lip)->ili_last_lsn = lsn;
 }
 
 /*
  * This is the ops vector shared by all buf log items.
  */
 static struct xfs_item_ops xfs_inode_item_ops = {
-       .iop_size       = (uint(*)(xfs_log_item_t*))xfs_inode_item_size,
-       .iop_format     = (void(*)(xfs_log_item_t*, xfs_log_iovec_t*))
-                                       xfs_inode_item_format,
-       .iop_pin        = (void(*)(xfs_log_item_t*))xfs_inode_item_pin,
-       .iop_unpin      = (void(*)(xfs_log_item_t*))xfs_inode_item_unpin,
-       .iop_unpin_remove = (void(*)(xfs_log_item_t*, xfs_trans_t*))
-                                       xfs_inode_item_unpin_remove,
-       .iop_trylock    = (uint(*)(xfs_log_item_t*))xfs_inode_item_trylock,
-       .iop_unlock     = (void(*)(xfs_log_item_t*))xfs_inode_item_unlock,
-       .iop_committed  = (xfs_lsn_t(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_inode_item_committed,
-       .iop_push       = (void(*)(xfs_log_item_t*))xfs_inode_item_push,
-       .iop_pushbuf    = (void(*)(xfs_log_item_t*))xfs_inode_item_pushbuf,
-       .iop_committing = (void(*)(xfs_log_item_t*, xfs_lsn_t))
-                                       xfs_inode_item_committing
+       .iop_size       = xfs_inode_item_size,
+       .iop_format     = xfs_inode_item_format,
+       .iop_pin        = xfs_inode_item_pin,
+       .iop_unpin      = xfs_inode_item_unpin,
+       .iop_trylock    = xfs_inode_item_trylock,
+       .iop_unlock     = xfs_inode_item_unlock,
+       .iop_committed  = xfs_inode_item_committed,
+       .iop_push       = xfs_inode_item_push,
+       .iop_pushbuf    = xfs_inode_item_pushbuf,
+       .iop_committing = xfs_inode_item_committing
 };
 
 
@@ -858,10 +792,10 @@ static struct xfs_item_ops xfs_inode_item_ops = {
  */
 void
 xfs_inode_item_init(
-       xfs_inode_t     *ip,
-       xfs_mount_t     *mp)
+       struct xfs_inode        *ip,
+       struct xfs_mount        *mp)
 {
-       xfs_inode_log_item_t    *iip;
+       struct xfs_inode_log_item *iip;
 
        ASSERT(ip->i_itemp == NULL);
        iip = ip->i_itemp = kmem_zone_zalloc(xfs_ili_zone, KM_SLEEP);
@@ -899,14 +833,14 @@ xfs_inode_item_destroy(
  * from the AIL if it has not been re-logged, and unlocking the inode's
  * flush lock.
  */
-/*ARGSUSED*/
 void
 xfs_iflush_done(
-       xfs_buf_t               *bp,
-       xfs_inode_log_item_t    *iip)
+       struct xfs_buf          *bp,
+       struct xfs_log_item     *lip)
 {
+       struct xfs_inode_log_item *iip = INODE_ITEM(lip);
        xfs_inode_t             *ip = iip->ili_inode;
-       struct xfs_ail          *ailp = iip->ili_item.li_ailp;
+       struct xfs_ail          *ailp = lip->li_ailp;
 
        /*
         * We only want to pull the item from the AIL if it is
@@ -917,12 +851,11 @@ xfs_iflush_done(
         * the lock since it's cheaper, and then we recheck while
         * holding the lock before removing the inode from the AIL.
         */
-       if (iip->ili_logged &&
-           (iip->ili_item.li_lsn == iip->ili_flush_lsn)) {
+       if (iip->ili_logged && lip->li_lsn == iip->ili_flush_lsn) {
                spin_lock(&ailp->xa_lock);
-               if (iip->ili_item.li_lsn == iip->ili_flush_lsn) {
+               if (lip->li_lsn == iip->ili_flush_lsn) {
                        /* xfs_trans_ail_delete() drops the AIL lock. */
-                       xfs_trans_ail_delete(ailp, (xfs_log_item_t*)iip);
+                       xfs_trans_ail_delete(ailp, lip);
                } else {
                        spin_unlock(&ailp->xa_lock);
                }
@@ -940,8 +873,6 @@ xfs_iflush_done(
         * Release the inode's flush lock since we're done with it.
         */
        xfs_ifunlock(ip);
-
-       return;
 }
 
 /*
@@ -957,10 +888,8 @@ xfs_iflush_abort(
        xfs_inode_t             *ip)
 {
        xfs_inode_log_item_t    *iip = ip->i_itemp;
-       xfs_mount_t             *mp;
 
        iip = ip->i_itemp;
-       mp = ip->i_mount;
        if (iip) {
                struct xfs_ail  *ailp = iip->ili_item.li_ailp;
                if (iip->ili_item.li_flags & XFS_LI_IN_AIL) {
@@ -991,10 +920,10 @@ xfs_iflush_abort(
 
 void
 xfs_istale_done(
-       xfs_buf_t               *bp,
-       xfs_inode_log_item_t    *iip)
+       struct xfs_buf          *bp,
+       struct xfs_log_item     *lip)
 {
-       xfs_iflush_abort(iip->ili_inode);
+       xfs_iflush_abort(INODE_ITEM(lip)->ili_inode);
 }
 
 /*
@@ -1007,9 +936,8 @@ xfs_inode_item_format_convert(
        xfs_inode_log_format_t  *in_f)
 {
        if (buf->i_len == sizeof(xfs_inode_log_format_32_t)) {
-               xfs_inode_log_format_32_t *in_f32;
+               xfs_inode_log_format_32_t *in_f32 = buf->i_addr;
 
-               in_f32 = (xfs_inode_log_format_32_t *)buf->i_addr;
                in_f->ilf_type = in_f32->ilf_type;
                in_f->ilf_size = in_f32->ilf_size;
                in_f->ilf_fields = in_f32->ilf_fields;
@@ -1025,9 +953,8 @@ xfs_inode_item_format_convert(
                in_f->ilf_boffset = in_f32->ilf_boffset;
                return 0;
        } else if (buf->i_len == sizeof(xfs_inode_log_format_64_t)){
-               xfs_inode_log_format_64_t *in_f64;
+               xfs_inode_log_format_64_t *in_f64 = buf->i_addr;
 
-               in_f64 = (xfs_inode_log_format_64_t *)buf->i_addr;
                in_f->ilf_type = in_f64->ilf_type;
                in_f->ilf_size = in_f64->ilf_size;
                in_f->ilf_fields = in_f64->ilf_fields;
index 9a467958ecdd4706e22c5f16faf212b7fda7f3ad..d3dee61e6d91fde1671157b3ee2deeee8df49fcd 100644 (file)
@@ -103,12 +103,6 @@ typedef struct xfs_inode_log_format_64 {
                                 XFS_ILOG_ADATA | XFS_ILOG_AEXT | \
                                 XFS_ILOG_ABROOT)
 
-#define        XFS_ILI_HOLD            0x1
-#define        XFS_ILI_IOLOCKED_EXCL   0x2
-#define        XFS_ILI_IOLOCKED_SHARED 0x4
-
-#define        XFS_ILI_IOLOCKED_ANY   (XFS_ILI_IOLOCKED_EXCL | XFS_ILI_IOLOCKED_SHARED)
-
 static inline int xfs_ilog_fbroot(int w)
 {
        return (w == XFS_DATA_FORK ? XFS_ILOG_DBROOT : XFS_ILOG_ABROOT);
@@ -137,7 +131,7 @@ typedef struct xfs_inode_log_item {
        struct xfs_inode        *ili_inode;        /* inode ptr */
        xfs_lsn_t               ili_flush_lsn;     /* lsn at last flush */
        xfs_lsn_t               ili_last_lsn;      /* lsn at last transaction */
-       unsigned short          ili_flags;         /* misc flags */
+       unsigned short          ili_lock_flags;    /* lock flags */
        unsigned short          ili_logged;        /* flushed logged data */
        unsigned int            ili_last_fields;   /* fields when flushed */
        struct xfs_bmbt_rec     *ili_extents_buf;  /* array of logged
@@ -161,8 +155,8 @@ static inline int xfs_inode_clean(xfs_inode_t *ip)
 
 extern void xfs_inode_item_init(struct xfs_inode *, struct xfs_mount *);
 extern void xfs_inode_item_destroy(struct xfs_inode *);
-extern void xfs_iflush_done(struct xfs_buf *, xfs_inode_log_item_t *);
-extern void xfs_istale_done(struct xfs_buf *, xfs_inode_log_item_t *);
+extern void xfs_iflush_done(struct xfs_buf *, struct xfs_log_item *);
+extern void xfs_istale_done(struct xfs_buf *, struct xfs_log_item *);
 extern void xfs_iflush_abort(struct xfs_inode *);
 extern int xfs_inode_item_format_convert(xfs_log_iovec_t *,
                                         xfs_inode_log_format_t *);
index ef14943829dabc38aa0f4f7d667ce0de6f9f2d05..20576146369f86fffa9f7f40dfe4d33f2b363fb5 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
 #include "xfs_alloc.h"
-#include "xfs_dmapi.h"
 #include "xfs_quota.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
-#include "xfs_ialloc.h"
 #include "xfs_btree.h"
 #include "xfs_bmap.h"
 #include "xfs_rtalloc.h"
@@ -123,7 +118,7 @@ xfs_iomap(
        error = xfs_bmapi(NULL, ip, offset_fsb,
                        (xfs_filblks_t)(end_fsb - offset_fsb),
                        bmapi_flags,  NULL, 0, imap,
-                       nimaps, NULL, NULL);
+                       nimaps, NULL);
 
        if (error)
                goto out;
@@ -138,7 +133,7 @@ xfs_iomap(
                        break;
                }
 
-               if (flags & (BMAPI_DIRECT|BMAPI_MMAP)) {
+               if (flags & BMAPI_DIRECT) {
                        error = xfs_iomap_write_direct(ip, offset, count, flags,
                                                       imap, nimaps);
                } else {
@@ -247,7 +242,7 @@ xfs_iomap_write_direct(
        xfs_off_t       offset,
        size_t          count,
        int             flags,
-       xfs_bmbt_irec_t *ret_imap,
+       xfs_bmbt_irec_t *imap,
        int             *nmaps)
 {
        xfs_mount_t     *mp = ip->i_mount;
@@ -261,7 +256,6 @@ xfs_iomap_write_direct(
        int             quota_flag;
        int             rt;
        xfs_trans_t     *tp;
-       xfs_bmbt_irec_t imap;
        xfs_bmap_free_t free_list;
        uint            qblocks, resblks, resrtextents;
        int             committed;
@@ -285,10 +279,10 @@ xfs_iomap_write_direct(
                if (error)
                        goto error_out;
        } else {
-               if (*nmaps && (ret_imap->br_startblock == HOLESTARTBLOCK))
+               if (*nmaps && (imap->br_startblock == HOLESTARTBLOCK))
                        last_fsb = MIN(last_fsb, (xfs_fileoff_t)
-                                       ret_imap->br_blockcount +
-                                       ret_imap->br_startoff);
+                                       imap->br_blockcount +
+                                       imap->br_startoff);
        }
        count_fsb = last_fsb - offset_fsb;
        ASSERT(count_fsb > 0);
@@ -334,20 +328,22 @@ xfs_iomap_write_direct(
        if (error)
                goto error1;
 
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
+       xfs_trans_ijoin(tp, ip);
 
        bmapi_flag = XFS_BMAPI_WRITE;
        if ((flags & BMAPI_DIRECT) && (offset < ip->i_size || extsz))
                bmapi_flag |= XFS_BMAPI_PREALLOC;
 
        /*
-        * Issue the xfs_bmapi() call to allocate the blocks
+        * Issue the xfs_bmapi() call to allocate the blocks.
+        *
+        * From this point onwards we overwrite the imap pointer that the
+        * caller gave to us.
         */
        xfs_bmap_init(&free_list, &firstfsb);
        nimaps = 1;
        error = xfs_bmapi(tp, ip, offset_fsb, count_fsb, bmapi_flag,
-               &firstfsb, 0, &imap, &nimaps, &free_list, NULL);
+               &firstfsb, 0, imap, &nimaps, &free_list);
        if (error)
                goto error0;
 
@@ -369,12 +365,11 @@ xfs_iomap_write_direct(
                goto error_out;
        }
 
-       if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip))) {
-               error = xfs_cmn_err_fsblock_zero(ip, &imap);
+       if (!(imap->br_startblock || XFS_IS_REALTIME_INODE(ip))) {
+               error = xfs_cmn_err_fsblock_zero(ip, imap);
                goto error_out;
        }
 
-       *ret_imap = imap;
        *nmaps = 1;
        return 0;
 
@@ -425,7 +420,7 @@ xfs_iomap_eof_want_preallocate(
                imaps = nimaps;
                firstblock = NULLFSBLOCK;
                error = xfs_bmapi(NULL, ip, start_fsb, count_fsb, 0,
-                                 &firstblock, 0, imap, &imaps, NULL, NULL);
+                                 &firstblock, 0, imap, &imaps, NULL);
                if (error)
                        return error;
                for (n = 0; n < imaps; n++) {
@@ -500,7 +495,7 @@ retry:
                          (xfs_filblks_t)(last_fsb - offset_fsb),
                          XFS_BMAPI_DELAY | XFS_BMAPI_WRITE |
                          XFS_BMAPI_ENTIRE, &firstblock, 1, imap,
-                         &nimaps, NULL, NULL);
+                         &nimaps, NULL);
        if (error && (error != ENOSPC))
                return XFS_ERROR(error);
 
@@ -548,7 +543,7 @@ xfs_iomap_write_allocate(
        xfs_inode_t     *ip,
        xfs_off_t       offset,
        size_t          count,
-       xfs_bmbt_irec_t *map,
+       xfs_bmbt_irec_t *imap,
        int             *retmap)
 {
        xfs_mount_t     *mp = ip->i_mount;
@@ -557,7 +552,6 @@ xfs_iomap_write_allocate(
        xfs_fsblock_t   first_block;
        xfs_bmap_free_t free_list;
        xfs_filblks_t   count_fsb;
-       xfs_bmbt_irec_t imap;
        xfs_trans_t     *tp;
        int             nimaps, committed;
        int             error = 0;
@@ -573,8 +567,8 @@ xfs_iomap_write_allocate(
                return XFS_ERROR(error);
 
        offset_fsb = XFS_B_TO_FSBT(mp, offset);
-       count_fsb = map->br_blockcount;
-       map_start_fsb = map->br_startoff;
+       count_fsb = imap->br_blockcount;
+       map_start_fsb = imap->br_startoff;
 
        XFS_STATS_ADD(xs_xstrat_bytes, XFS_FSB_TO_B(mp, count_fsb));
 
@@ -602,8 +596,7 @@ xfs_iomap_write_allocate(
                                return XFS_ERROR(error);
                        }
                        xfs_ilock(ip, XFS_ILOCK_EXCL);
-                       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-                       xfs_trans_ihold(tp, ip);
+                       xfs_trans_ijoin(tp, ip);
 
                        xfs_bmap_init(&free_list, &first_block);
 
@@ -654,10 +647,15 @@ xfs_iomap_write_allocate(
                                }
                        }
 
-                       /* Go get the actual blocks */
+                       /*
+                        * Go get the actual blocks.
+                        *
+                        * From this point onwards we overwrite the imap
+                        * pointer that the caller gave to us.
+                        */
                        error = xfs_bmapi(tp, ip, map_start_fsb, count_fsb,
                                        XFS_BMAPI_WRITE, &first_block, 1,
-                                       &imap, &nimaps, &free_list, NULL);
+                                       imap, &nimaps, &free_list);
                        if (error)
                                goto trans_cancel;
 
@@ -676,13 +674,12 @@ xfs_iomap_write_allocate(
                 * See if we were able to allocate an extent that
                 * covers at least part of the callers request
                 */
-               if (!(imap.br_startblock || XFS_IS_REALTIME_INODE(ip)))
-                       return xfs_cmn_err_fsblock_zero(ip, &imap);
+               if (!(imap->br_startblock || XFS_IS_REALTIME_INODE(ip)))
+                       return xfs_cmn_err_fsblock_zero(ip, imap);
 
-               if ((offset_fsb >= imap.br_startoff) &&
-                   (offset_fsb < (imap.br_startoff +
-                                  imap.br_blockcount))) {
-                       *map = imap;
+               if ((offset_fsb >= imap->br_startoff) &&
+                   (offset_fsb < (imap->br_startoff +
+                                  imap->br_blockcount))) {
                        *retmap = 1;
                        XFS_STATS_INC(xs_xstrat_quick);
                        return 0;
@@ -692,8 +689,8 @@ xfs_iomap_write_allocate(
                 * So far we have not mapped the requested part of the
                 * file, just surrounding data, try again.
                 */
-               count_fsb -= imap.br_blockcount;
-               map_start_fsb = imap.br_startoff + imap.br_blockcount;
+               count_fsb -= imap->br_blockcount;
+               map_start_fsb = imap->br_startoff + imap->br_blockcount;
        }
 
 trans_cancel:
@@ -766,8 +763,7 @@ xfs_iomap_write_unwritten(
                }
 
                xfs_ilock(ip, XFS_ILOCK_EXCL);
-               xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
 
                /*
                 * Modify the unwritten extent state of the buffer.
@@ -776,7 +772,7 @@ xfs_iomap_write_unwritten(
                nimaps = 1;
                error = xfs_bmapi(tp, ip, offset_fsb, count_fsb,
                                  XFS_BMAPI_WRITE|XFS_BMAPI_CONVERT, &firstfsb,
-                                 1, &imap, &nimaps, &free_list, NULL);
+                                 1, &imap, &nimaps, &free_list);
                if (error)
                        goto error_on_bmapi_transaction;
 
index 81ac4afd45b3300c80261fb11e1d61dfceea007e..7748a430f50d229d82d66771ee759927dc41d983 100644 (file)
 #ifndef __XFS_IOMAP_H__
 #define __XFS_IOMAP_H__
 
-typedef enum {
-       /* base extent manipulation calls */
-       BMAPI_READ = (1 << 0),          /* read extents */
-       BMAPI_WRITE = (1 << 1),         /* create extents */
-       BMAPI_ALLOCATE = (1 << 2),      /* delayed allocate to real extents */
-       /* modifiers */
-       BMAPI_IGNSTATE = (1 << 4),      /* ignore unwritten state on read */
-       BMAPI_DIRECT = (1 << 5),        /* direct instead of buffered write */
-       BMAPI_MMAP = (1 << 6),          /* allocate for mmap write */
-       BMAPI_TRYLOCK = (1 << 7),       /* non-blocking request */
-} bmapi_flags_t;
+/* base extent manipulation calls */
+#define BMAPI_READ     (1 << 0)        /* read extents */
+#define BMAPI_WRITE    (1 << 1)        /* create extents */
+#define BMAPI_ALLOCATE (1 << 2)        /* delayed allocate to real extents */
+
+/* modifiers */
+#define BMAPI_IGNSTATE (1 << 4)        /* ignore unwritten state on read */
+#define BMAPI_DIRECT   (1 << 5)        /* direct instead of buffered write */
+#define BMAPI_MMA      (1 << 6)        /* allocate for mmap write */
+#define BMAPI_TRYLOCK  (1 << 7)        /* non-blocking request */
 
 #define BMAPI_FLAGS \
        { BMAPI_READ,           "READ" }, \
@@ -36,7 +35,6 @@ typedef enum {
        { BMAPI_ALLOCATE,       "ALLOCATE" }, \
        { BMAPI_IGNSTATE,       "IGNSTATE" }, \
        { BMAPI_DIRECT,         "DIRECT" }, \
-       { BMAPI_MMAP,           "MMAP" }, \
        { BMAPI_TRYLOCK,        "TRYLOCK" }
 
 struct xfs_inode;
index 2b86f86105125c3869a641b68bc73b984ce69e79..7e3626e5925c4ada9ed16e4fa103bbefd0ef1734 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_ialloc.h"
 #include "xfs_itable.h"
 #include "xfs_error.h"
 #include "xfs_btree.h"
+#include "xfs_trace.h"
 
 STATIC int
 xfs_internal_inum(
@@ -143,7 +140,8 @@ xfs_bulkstat_one_int(
                buf->bs_blocks = dic->di_nblocks + ip->i_delayed_blks;
                break;
        }
-       xfs_iput(ip, XFS_ILOCK_SHARED);
+       xfs_iunlock(ip, XFS_ILOCK_SHARED);
+       IRELE(ip);
 
        error = formatter(buffer, ubsize, ubused, buf);
 
index 5215abc8023aadf15014c8f475ed529508695e30..925d572bf0f405e9a94be11b74549c5f760b3ec4 100644 (file)
@@ -24,8 +24,6 @@
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_error.h"
 #include "xfs_log_priv.h"
@@ -35,8 +33,6 @@
 #include "xfs_ialloc_btree.h"
 #include "xfs_log_recover.h"
 #include "xfs_trans_priv.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_rw.h"
@@ -337,7 +333,6 @@ xfs_log_reserve(
        int                     retval = 0;
 
        ASSERT(client == XFS_TRANSACTION || client == XFS_LOG);
-       ASSERT((flags & XFS_LOG_NOSLEEP) == 0);
 
        if (XLOG_FORCED_SHUTDOWN(log))
                return XFS_ERROR(EIO);
@@ -552,7 +547,7 @@ xfs_log_unmount_write(xfs_mount_t *mp)
                                .magic = XLOG_UNMOUNT_TYPE,
                        };
                        struct xfs_log_iovec reg = {
-                               .i_addr = (void *)&magic,
+                               .i_addr = &magic,
                                .i_len = sizeof(magic),
                                .i_type = XLOG_REG_TYPE_UNMOUNT,
                        };
@@ -1047,7 +1042,6 @@ xlog_alloc_log(xfs_mount_t        *mp,
        xlog_in_core_t          *iclog, *prev_iclog=NULL;
        xfs_buf_t               *bp;
        int                     i;
-       int                     iclogsize;
        int                     error = ENOMEM;
        uint                    log2_size = 0;
 
@@ -1127,7 +1121,6 @@ xlog_alloc_log(xfs_mount_t        *mp,
         * with different amounts of memory.  See the definition of
         * xlog_in_core_t in xfs_log_priv.h for details.
         */
-       iclogsize = log->l_iclog_size;
        ASSERT(log->l_iclog_size >= 4096);
        for (i=0; i < log->l_iclog_bufs; i++) {
                *iclogp = kmem_zalloc(sizeof(xlog_in_core_t), KM_MAYFAIL);
@@ -1428,11 +1421,8 @@ xlog_sync(xlog_t         *log,
        XFS_BUF_BUSY(bp);
        XFS_BUF_ASYNC(bp);
        bp->b_flags |= XBF_LOG_BUFFER;
-       /*
-        * Do an ordered write for the log block.
-        * Its unnecessary to flush the first split block in the log wrap case.
-        */
-       if (!split && (log->l_mp->m_flags & XFS_MOUNT_BARRIER))
+
+       if (log->l_mp->m_flags & XFS_MOUNT_BARRIER)
                XFS_BUF_ORDERED(bp);
 
        ASSERT(XFS_BUF_ADDR(bp) <= log->l_logBBsize-1);
index 04c78e642cc83b237ed0c5d6258f82e0ccdcad26..916eb7db14d9a09ff541882bf12905d9fd5068ea 100644 (file)
@@ -55,14 +55,10 @@ static inline xfs_lsn_t     _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
 /*
  * Flags to xfs_log_reserve()
  *
- *     XFS_LOG_SLEEP:   If space is not available, sleep (default)
- *     XFS_LOG_NOSLEEP: If space is not available, return error
  *     XFS_LOG_PERM_RESERV: Permanent reservation.  When writes are
  *             performed against this type of reservation, the reservation
  *             is not decreased.  Long running transactions should use this.
  */
-#define XFS_LOG_SLEEP          0x0
-#define XFS_LOG_NOSLEEP                0x1
 #define XFS_LOG_PERM_RESERV    0x2
 
 /*
@@ -104,7 +100,7 @@ static inline xfs_lsn_t     _lsn_cmp(xfs_lsn_t lsn1, xfs_lsn_t lsn2)
 #define XLOG_REG_TYPE_MAX              19
 
 typedef struct xfs_log_iovec {
-       xfs_caddr_t     i_addr;         /* beginning address of region */
+       void            *i_addr;        /* beginning address of region */
        int             i_len;          /* length in bytes of region */
        uint            i_type;         /* type of region */
 } xfs_log_iovec_t;
@@ -201,9 +197,4 @@ int xfs_log_commit_cil(struct xfs_mount *mp, struct xfs_trans *tp,
 bool   xfs_log_item_in_current_chkpt(struct xfs_log_item *lip);
 
 #endif
-
-
-extern int xlog_debug;         /* set to 1 to enable real log */
-
-
 #endif /* __XFS_LOG_H__ */
index bb17cc044bf37c994dbf877292ecaf36aa3842fb..31e4ea2d19acfc08f069813dffa367e6b2420973 100644 (file)
@@ -26,8 +26,6 @@
 #include "xfs_log_priv.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_error.h"
 #include "xfs_alloc.h"
@@ -554,7 +552,7 @@ xlog_cil_push(
        thdr.th_type = XFS_TRANS_CHECKPOINT;
        thdr.th_tid = tic->t_tid;
        thdr.th_num_items = num_iovecs;
-       lhdr.i_addr = (xfs_caddr_t)&thdr;
+       lhdr.i_addr = &thdr;
        lhdr.i_len = sizeof(xfs_trans_header_t);
        lhdr.i_type = XLOG_REG_TYPE_TRANSHDR;
        tic->t_curr_res -= lhdr.i_len + sizeof(xlog_op_header_t);
index 9ac5cfab27b96da77ac033559229090a3c52490a..6f3f5fa37acf16cec91cf55eb36d0d7c1b20d0b2 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_error.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
@@ -1565,9 +1561,7 @@ xlog_recover_reorder_trans(
 
        list_splice_init(&trans->r_itemq, &sort_list);
        list_for_each_entry_safe(item, n, &sort_list, ri_list) {
-               xfs_buf_log_format_t    *buf_f;
-
-               buf_f = (xfs_buf_log_format_t *)item->ri_buf[0].i_addr;
+               xfs_buf_log_format_t    *buf_f = item->ri_buf[0].i_addr;
 
                switch (ITEM_TYPE(item)) {
                case XFS_LI_BUF:
@@ -1892,9 +1886,8 @@ xlog_recover_do_inode_buffer(
                 * current di_next_unlinked field.  Extract its value
                 * and copy it to the buffer copy.
                 */
-               logged_nextp = (xfs_agino_t *)
-                              ((char *)(item->ri_buf[item_index].i_addr) +
-                               (next_unlinked_offset - reg_buf_offset));
+               logged_nextp = item->ri_buf[item_index].i_addr +
+                               next_unlinked_offset - reg_buf_offset;
                if (unlikely(*logged_nextp == 0)) {
                        xfs_fs_cmn_err(CE_ALERT, mp,
                                "bad inode buffer log record (ptr = 0x%p, bp = 0x%p).  XFS trying to replay bad (0) inode di_next_unlinked field",
@@ -1973,8 +1966,7 @@ xlog_recover_do_reg_buffer(
                                        item->ri_buf[i].i_len, __func__);
                                goto next;
                        }
-                       error = xfs_qm_dqcheck((xfs_disk_dquot_t *)
-                                              item->ri_buf[i].i_addr,
+                       error = xfs_qm_dqcheck(item->ri_buf[i].i_addr,
                                               -1, 0, XFS_QMOPT_DOWARN,
                                               "dquot_buf_recover");
                        if (error)
@@ -2187,7 +2179,7 @@ xlog_recover_do_buffer_trans(
        xlog_recover_item_t     *item,
        int                     pass)
 {
-       xfs_buf_log_format_t    *buf_f;
+       xfs_buf_log_format_t    *buf_f = item->ri_buf[0].i_addr;
        xfs_mount_t             *mp;
        xfs_buf_t               *bp;
        int                     error;
@@ -2197,8 +2189,6 @@ xlog_recover_do_buffer_trans(
        ushort                  flags;
        uint                    buf_flags;
 
-       buf_f = (xfs_buf_log_format_t *)item->ri_buf[0].i_addr;
-
        if (pass == XLOG_RECOVER_PASS1) {
                /*
                 * In this pass we're only looking for buf items
@@ -2319,10 +2309,9 @@ xlog_recover_do_inode_trans(
        }
 
        if (item->ri_buf[0].i_len == sizeof(xfs_inode_log_format_t)) {
-               in_f = (xfs_inode_log_format_t *)item->ri_buf[0].i_addr;
+               in_f = item->ri_buf[0].i_addr;
        } else {
-               in_f = (xfs_inode_log_format_t *)kmem_alloc(
-                       sizeof(xfs_inode_log_format_t), KM_SLEEP);
+               in_f = kmem_alloc(sizeof(xfs_inode_log_format_t), KM_SLEEP);
                need_free = 1;
                error = xfs_inode_item_format_convert(&item->ri_buf[0], in_f);
                if (error)
@@ -2370,7 +2359,7 @@ xlog_recover_do_inode_trans(
                error = EFSCORRUPTED;
                goto error;
        }
-       dicp = (xfs_icdinode_t *)(item->ri_buf[1].i_addr);
+       dicp = item->ri_buf[1].i_addr;
        if (unlikely(dicp->di_magic != XFS_DINODE_MAGIC)) {
                xfs_buf_relse(bp);
                xfs_fs_cmn_err(CE_ALERT, mp,
@@ -2461,7 +2450,7 @@ xlog_recover_do_inode_trans(
        }
 
        /* The core is in in-core format */
-       xfs_dinode_to_disk(dip, (xfs_icdinode_t *)item->ri_buf[1].i_addr);
+       xfs_dinode_to_disk(dip, item->ri_buf[1].i_addr);
 
        /* the rest is in on-disk format */
        if (item->ri_buf[1].i_len > sizeof(struct xfs_icdinode)) {
@@ -2578,7 +2567,7 @@ xlog_recover_do_quotaoff_trans(
                return (0);
        }
 
-       qoff_f = (xfs_qoff_logformat_t *)item->ri_buf[0].i_addr;
+       qoff_f = item->ri_buf[0].i_addr;
        ASSERT(qoff_f);
 
        /*
@@ -2622,9 +2611,8 @@ xlog_recover_do_dquot_trans(
        if (mp->m_qflags == 0)
                return (0);
 
-       recddq = (xfs_disk_dquot_t *)item->ri_buf[1].i_addr;
-
-       if (item->ri_buf[1].i_addr == NULL) {
+       recddq = item->ri_buf[1].i_addr;
+       if (recddq == NULL) {
                cmn_err(CE_ALERT,
                        "XFS: NULL dquot in %s.", __func__);
                return XFS_ERROR(EIO);
@@ -2654,7 +2642,7 @@ xlog_recover_do_dquot_trans(
         * The other possibility, of course, is that the quota subsystem was
         * removed since the last mount - ENOSYS.
         */
-       dq_f = (xfs_dq_logformat_t *)item->ri_buf[0].i_addr;
+       dq_f = item->ri_buf[0].i_addr;
        ASSERT(dq_f);
        if ((error = xfs_qm_dqcheck(recddq,
                           dq_f->qlf_id,
@@ -2721,7 +2709,7 @@ xlog_recover_do_efi_trans(
                return 0;
        }
 
-       efi_formatp = (xfs_efi_log_format_t *)item->ri_buf[0].i_addr;
+       efi_formatp = item->ri_buf[0].i_addr;
 
        mp = log->l_mp;
        efip = xfs_efi_init(mp, efi_formatp->efi_nextents);
@@ -2767,7 +2755,7 @@ xlog_recover_do_efd_trans(
                return;
        }
 
-       efd_formatp = (xfs_efd_log_format_t *)item->ri_buf[0].i_addr;
+       efd_formatp = item->ri_buf[0].i_addr;
        ASSERT((item->ri_buf[0].i_len == (sizeof(xfs_efd_log_format_32_t) +
                ((efd_formatp->efd_nextents - 1) * sizeof(xfs_extent_32_t)))) ||
               (item->ri_buf[0].i_len == (sizeof(xfs_efd_log_format_64_t) +
index 69f62d8b2816c52389f4947c9d86b3958ccf57a6..aeb9d72ebf6e55102bb4b7a98dbaa60264511165 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
index 5761087ee8ea31be3e4c571630ceca807485e5e3..622da2179a57bd1546d84d2a1cba26202c627135 100644 (file)
@@ -66,65 +66,6 @@ struct xfs_nameops;
 struct xfs_ail;
 struct xfs_quotainfo;
 
-
-/*
- * Prototypes and functions for the Data Migration subsystem.
- */
-
-typedef int    (*xfs_send_data_t)(int, struct xfs_inode *,
-                       xfs_off_t, size_t, int, int *);
-typedef int    (*xfs_send_mmap_t)(struct vm_area_struct *, uint);
-typedef int    (*xfs_send_destroy_t)(struct xfs_inode *, dm_right_t);
-typedef int    (*xfs_send_namesp_t)(dm_eventtype_t, struct xfs_mount *,
-                       struct xfs_inode *, dm_right_t,
-                       struct xfs_inode *, dm_right_t,
-                       const unsigned char *, const unsigned char *,
-                       mode_t, int, int);
-typedef int    (*xfs_send_mount_t)(struct xfs_mount *, dm_right_t,
-                       char *, char *);
-typedef void   (*xfs_send_unmount_t)(struct xfs_mount *, struct xfs_inode *,
-                       dm_right_t, mode_t, int, int);
-
-typedef struct xfs_dmops {
-       xfs_send_data_t         xfs_send_data;
-       xfs_send_mmap_t         xfs_send_mmap;
-       xfs_send_destroy_t      xfs_send_destroy;
-       xfs_send_namesp_t       xfs_send_namesp;
-       xfs_send_mount_t        xfs_send_mount;
-       xfs_send_unmount_t      xfs_send_unmount;
-} xfs_dmops_t;
-
-#define XFS_DMAPI_UNMOUNT_FLAGS(mp) \
-       (((mp)->m_dmevmask & (1 << DM_EVENT_UNMOUNT)) ? 0 : DM_FLAGS_UNWANTED)
-
-#define XFS_SEND_DATA(mp, ev,ip,off,len,fl,lock) \
-       (*(mp)->m_dm_ops->xfs_send_data)(ev,ip,off,len,fl,lock)
-#define XFS_SEND_MMAP(mp, vma,fl) \
-       (*(mp)->m_dm_ops->xfs_send_mmap)(vma,fl)
-#define XFS_SEND_DESTROY(mp, ip,right) \
-       (*(mp)->m_dm_ops->xfs_send_destroy)(ip,right)
-#define XFS_SEND_NAMESP(mp, ev,b1,r1,b2,r2,n1,n2,mode,rval,fl) \
-       (*(mp)->m_dm_ops->xfs_send_namesp)(ev,NULL,b1,r1,b2,r2,n1,n2,mode,rval,fl)
-#define XFS_SEND_MOUNT(mp,right,path,name) \
-       (*(mp)->m_dm_ops->xfs_send_mount)(mp,right,path,name)
-#define XFS_SEND_PREUNMOUNT(mp) \
-do { \
-       if (mp->m_flags & XFS_MOUNT_DMAPI) { \
-               (*(mp)->m_dm_ops->xfs_send_namesp)(DM_EVENT_PREUNMOUNT, mp, \
-                       (mp)->m_rootip, DM_RIGHT_NULL, \
-                       (mp)->m_rootip, DM_RIGHT_NULL, \
-                       NULL, NULL, 0, 0, XFS_DMAPI_UNMOUNT_FLAGS(mp)); \
-       } \
-} while (0)
-#define XFS_SEND_UNMOUNT(mp) \
-do { \
-       if (mp->m_flags & XFS_MOUNT_DMAPI) { \
-               (*(mp)->m_dm_ops->xfs_send_unmount)(mp, (mp)->m_rootip, \
-                       DM_RIGHT_NULL, 0, 0, XFS_DMAPI_UNMOUNT_FLAGS(mp)); \
-       } \
-} while (0)
-
-
 #ifdef HAVE_PERCPU_SB
 
 /*
@@ -241,8 +182,6 @@ typedef struct xfs_mount {
        uint                    m_chsize;       /* size of next field */
        struct xfs_chash        *m_chash;       /* fs private inode per-cluster
                                                 * hash table */
-       struct xfs_dmops        *m_dm_ops;      /* vector of DMI ops */
-       struct xfs_qmops        *m_qm_ops;      /* vector of XQM ops */
        atomic_t                m_active_trans; /* number trans frozen */
 #ifdef HAVE_PERCPU_SB
        xfs_icsb_cnts_t __percpu *m_sb_cnts;    /* per-cpu superblock counters */
@@ -269,7 +208,6 @@ typedef struct xfs_mount {
                                                   must be synchronous except
                                                   for space allocations */
 #define XFS_MOUNT_DELAYLOG     (1ULL << 1)     /* delayed logging is enabled */
-#define XFS_MOUNT_DMAPI                (1ULL << 2)     /* dmapi is enabled */
 #define XFS_MOUNT_WAS_CLEAN    (1ULL << 3)
 #define XFS_MOUNT_FS_SHUTDOWN  (1ULL << 4)     /* atomic stop of all filesystem
                                                   operations, typically for
@@ -282,8 +220,6 @@ typedef struct xfs_mount {
 #define XFS_MOUNT_GRPID                (1ULL << 9)     /* group-ID assigned from directory */
 #define XFS_MOUNT_NORECOVERY   (1ULL << 10)    /* no recovery - dirty fs */
 #define XFS_MOUNT_DFLT_IOSIZE  (1ULL << 12)    /* set default i/o size */
-#define XFS_MOUNT_OSYNCISOSYNC (1ULL << 13)    /* o_sync is REALLY o_sync */
-                                               /* osyncisdsync is now default*/
 #define XFS_MOUNT_32BITINODES  (1ULL << 14)    /* do not create inodes above
                                                 * 32 bits in size */
 #define XFS_MOUNT_SMALL_INUMS  (1ULL << 15)    /* users wants 32bit inodes */
@@ -440,11 +376,6 @@ extern int xfs_sb_validate_fsb_count(struct xfs_sb *, __uint64_t);
 
 extern int     xfs_dev_is_read_only(struct xfs_mount *, char *);
 
-extern int     xfs_dmops_get(struct xfs_mount *);
-extern void    xfs_dmops_put(struct xfs_mount *);
-
-extern struct xfs_dmops xfs_dmcore_xfs;
-
 #endif /* __KERNEL__ */
 
 extern void    xfs_mod_sb(struct xfs_trans *, __int64_t);
index fc1cda23b8171552ff6fd99d34adebf6be782bb3..8fca957200dfcba000f1f0eb4da51eb1d4f8516e 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
@@ -116,20 +113,7 @@ xfs_rename(
        int             spaceres;
        int             num_inodes;
 
-       xfs_itrace_entry(src_dp);
-       xfs_itrace_entry(target_dp);
-
-       if (DM_EVENT_ENABLED(src_dp, DM_EVENT_RENAME) ||
-           DM_EVENT_ENABLED(target_dp, DM_EVENT_RENAME)) {
-               error = XFS_SEND_NAMESP(mp, DM_EVENT_RENAME,
-                                       src_dp, DM_RIGHT_NULL,
-                                       target_dp, DM_RIGHT_NULL,
-                                       src_name->name, target_name->name,
-                                       0, 0, 0);
-               if (error)
-                       return error;
-       }
-       /* Return through std_return after this point. */
+       trace_xfs_rename(src_dp, target_dp, src_name, target_name);
 
        new_parent = (src_dp != target_dp);
        src_is_directory = ((src_ip->i_d.di_mode & S_IFMT) == S_IFDIR);
@@ -184,26 +168,14 @@ xfs_rename(
        /*
         * Join all the inodes to the transaction. From this point on,
         * we can rely on either trans_commit or trans_cancel to unlock
-        * them.  Note that we need to add a vnode reference to the
-        * directories since trans_commit & trans_cancel will decrement
-        * them when they unlock the inodes.  Also, we need to be careful
-        * not to add an inode to the transaction more than once.
+        * them.
         */
-       IHOLD(src_dp);
-       xfs_trans_ijoin(tp, src_dp, XFS_ILOCK_EXCL);
-
-       if (new_parent) {
-               IHOLD(target_dp);
-               xfs_trans_ijoin(tp, target_dp, XFS_ILOCK_EXCL);
-       }
-
-       IHOLD(src_ip);
-       xfs_trans_ijoin(tp, src_ip, XFS_ILOCK_EXCL);
-
-       if (target_ip) {
-               IHOLD(target_ip);
-               xfs_trans_ijoin(tp, target_ip, XFS_ILOCK_EXCL);
-       }
+       xfs_trans_ijoin_ref(tp, src_dp, XFS_ILOCK_EXCL);
+       if (new_parent)
+               xfs_trans_ijoin_ref(tp, target_dp, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, src_ip, XFS_ILOCK_EXCL);
+       if (target_ip)
+               xfs_trans_ijoin_ref(tp, target_ip, XFS_ILOCK_EXCL);
 
        /*
         * If we are using project inheritance, we only allow renames
@@ -369,26 +341,13 @@ xfs_rename(
         * trans_commit will unlock src_ip, target_ip & decrement
         * the vnode references.
         */
-       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
-
-       /* Fall through to std_return with error = 0 or errno from
-        * xfs_trans_commit      */
-std_return:
-       if (DM_EVENT_ENABLED(src_dp, DM_EVENT_POSTRENAME) ||
-           DM_EVENT_ENABLED(target_dp, DM_EVENT_POSTRENAME)) {
-               (void) XFS_SEND_NAMESP (mp, DM_EVENT_POSTRENAME,
-                                       src_dp, DM_RIGHT_NULL,
-                                       target_dp, DM_RIGHT_NULL,
-                                       src_name->name, target_name->name,
-                                       0, error, 0);
-       }
-       return error;
+       return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
 
  abort_return:
        cancel_flags |= XFS_TRANS_ABORT;
-       /* FALLTHROUGH */
  error_return:
        xfs_bmap_cancel(&free_list);
        xfs_trans_cancel(tp, cancel_flags);
-       goto std_return;
+ std_return:
+       return error;
 }
index a2d32ce335aa681c3beab111f4c844873353f6af..891260fea11e3bc442f2de17349f16d532fad6a9 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
-#include "xfs_btree.h"
-#include "xfs_ialloc.h"
 #include "xfs_alloc.h"
 #include "xfs_bmap.h"
 #include "xfs_rtalloc.h"
@@ -129,7 +122,7 @@ xfs_growfs_rt_alloc(
                cancelflags |= XFS_TRANS_ABORT;
                error = xfs_bmapi(tp, ip, oblocks, nblocks - oblocks,
                        XFS_BMAPI_WRITE | XFS_BMAPI_METADATA, &firstblock,
-                       resblks, &map, &nmap, &flist, NULL);
+                       resblks, &map, &nmap, &flist);
                if (!error && nmap < 1)
                        error = XFS_ERROR(ENOSPC);
                if (error)
index e336742a58a47a467a24abb0688b8c1fe7853207..56861d5daaef54432a94a640a7b1e65812030ef7 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
-#include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
-#include "xfs_inode_item.h"
-#include "xfs_itable.h"
-#include "xfs_btree.h"
-#include "xfs_alloc.h"
-#include "xfs_ialloc.h"
-#include "xfs_attr.h"
-#include "xfs_bmap.h"
 #include "xfs_error.h"
-#include "xfs_buf_item.h"
 #include "xfs_rw.h"
-#include "xfs_trace.h"
 
 /*
  * Force a shutdown of the filesystem instantly while keeping
index 28547dfce037643fb19744ed36906d5e7f3c1c76..fdca7416c754636a26dae9a312003932f7306d9f 100644 (file)
@@ -1,5 +1,6 @@
 /*
  * Copyright (c) 2000-2003,2005 Silicon Graphics, Inc.
+ * Copyright (C) 2010 Red Hat, Inc.
  * All Rights Reserved.
  *
  * This program is free software; you can redistribute it and/or
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_error.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
@@ -47,6 +44,7 @@
 #include "xfs_trace.h"
 
 kmem_zone_t    *xfs_trans_zone;
+kmem_zone_t    *xfs_log_item_desc_zone;
 
 
 /*
@@ -597,8 +595,7 @@ _xfs_trans_alloc(
        tp->t_magic = XFS_TRANS_MAGIC;
        tp->t_type = type;
        tp->t_mountp = mp;
-       tp->t_items_free = XFS_LIC_NUM_SLOTS;
-       xfs_lic_init(&(tp->t_items));
+       INIT_LIST_HEAD(&tp->t_items);
        INIT_LIST_HEAD(&tp->t_busy);
        return tp;
 }
@@ -643,8 +640,7 @@ xfs_trans_dup(
        ntp->t_magic = XFS_TRANS_MAGIC;
        ntp->t_type = tp->t_type;
        ntp->t_mountp = tp->t_mountp;
-       ntp->t_items_free = XFS_LIC_NUM_SLOTS;
-       xfs_lic_init(&(ntp->t_items));
+       INIT_LIST_HEAD(&ntp->t_items);
        INIT_LIST_HEAD(&ntp->t_busy);
 
        ASSERT(tp->t_flags & XFS_TRANS_PERM_LOG_RES);
@@ -1123,6 +1119,108 @@ xfs_trans_unreserve_and_mod_sb(
        }
 }
 
+/*
+ * Add the given log item to the transaction's list of log items.
+ *
+ * The log item will now point to its new descriptor with its li_desc field.
+ */
+void
+xfs_trans_add_item(
+       struct xfs_trans        *tp,
+       struct xfs_log_item     *lip)
+{
+       struct xfs_log_item_desc *lidp;
+
+       ASSERT(lip->li_mountp = tp->t_mountp);
+       ASSERT(lip->li_ailp = tp->t_mountp->m_ail);
+
+       lidp = kmem_zone_zalloc(xfs_log_item_desc_zone, KM_SLEEP | KM_NOFS);
+
+       lidp->lid_item = lip;
+       lidp->lid_flags = 0;
+       lidp->lid_size = 0;
+       list_add_tail(&lidp->lid_trans, &tp->t_items);
+
+       lip->li_desc = lidp;
+}
+
+STATIC void
+xfs_trans_free_item_desc(
+       struct xfs_log_item_desc *lidp)
+{
+       list_del_init(&lidp->lid_trans);
+       kmem_zone_free(xfs_log_item_desc_zone, lidp);
+}
+
+/*
+ * Unlink and free the given descriptor.
+ */
+void
+xfs_trans_del_item(
+       struct xfs_log_item     *lip)
+{
+       xfs_trans_free_item_desc(lip->li_desc);
+       lip->li_desc = NULL;
+}
+
+/*
+ * Unlock all of the items of a transaction and free all the descriptors
+ * of that transaction.
+ */
+STATIC void
+xfs_trans_free_items(
+       struct xfs_trans        *tp,
+       xfs_lsn_t               commit_lsn,
+       int                     flags)
+{
+       struct xfs_log_item_desc *lidp, *next;
+
+       list_for_each_entry_safe(lidp, next, &tp->t_items, lid_trans) {
+               struct xfs_log_item     *lip = lidp->lid_item;
+
+               lip->li_desc = NULL;
+
+               if (commit_lsn != NULLCOMMITLSN)
+                       IOP_COMMITTING(lip, commit_lsn);
+               if (flags & XFS_TRANS_ABORT)
+                       lip->li_flags |= XFS_LI_ABORTED;
+               IOP_UNLOCK(lip);
+
+               xfs_trans_free_item_desc(lidp);
+       }
+}
+
+/*
+ * Unlock the items associated with a transaction.
+ *
+ * Items which were not logged should be freed.  Those which were logged must
+ * still be tracked so they can be unpinned when the transaction commits.
+ */
+STATIC void
+xfs_trans_unlock_items(
+       struct xfs_trans        *tp,
+       xfs_lsn_t               commit_lsn)
+{
+       struct xfs_log_item_desc *lidp, *next;
+
+       list_for_each_entry_safe(lidp, next, &tp->t_items, lid_trans) {
+               struct xfs_log_item     *lip = lidp->lid_item;
+
+               lip->li_desc = NULL;
+
+               if (commit_lsn != NULLCOMMITLSN)
+                       IOP_COMMITTING(lip, commit_lsn);
+               IOP_UNLOCK(lip);
+
+               /*
+                * Free the descriptor if the item is not dirty
+                * within this transaction.
+                */
+               if (!(lidp->lid_flags & XFS_LID_DIRTY))
+                       xfs_trans_free_item_desc(lidp);
+       }
+}
+
 /*
  * Total up the number of log iovecs needed to commit this
  * transaction.  The transaction itself needs one for the
@@ -1134,30 +1232,27 @@ xfs_trans_count_vecs(
        struct xfs_trans        *tp)
 {
        int                     nvecs;
-       xfs_log_item_desc_t     *lidp;
+       struct xfs_log_item_desc *lidp;
 
        nvecs = 1;
-       lidp = xfs_trans_first_item(tp);
-       ASSERT(lidp != NULL);
 
        /* In the non-debug case we need to start bailing out if we
         * didn't find a log_item here, return zero and let trans_commit
         * deal with it.
         */
-       if (lidp == NULL)
+       if (list_empty(&tp->t_items)) {
+               ASSERT(0);
                return 0;
+       }
 
-       while (lidp != NULL) {
+       list_for_each_entry(lidp, &tp->t_items, lid_trans) {
                /*
                 * Skip items which aren't dirty in this transaction.
                 */
-               if (!(lidp->lid_flags & XFS_LID_DIRTY)) {
-                       lidp = xfs_trans_next_item(tp, lidp);
+               if (!(lidp->lid_flags & XFS_LID_DIRTY))
                        continue;
-               }
                lidp->lid_size = IOP_SIZE(lidp->lid_item);
                nvecs += lidp->lid_size;
-               lidp = xfs_trans_next_item(tp, lidp);
        }
 
        return nvecs;
@@ -1177,7 +1272,7 @@ xfs_trans_fill_vecs(
        struct xfs_trans        *tp,
        struct xfs_log_iovec    *log_vector)
 {
-       xfs_log_item_desc_t     *lidp;
+       struct xfs_log_item_desc *lidp;
        struct xfs_log_iovec    *vecp;
        uint                    nitems;
 
@@ -1188,14 +1283,11 @@ xfs_trans_fill_vecs(
        vecp = log_vector + 1;
 
        nitems = 0;
-       lidp = xfs_trans_first_item(tp);
-       ASSERT(lidp);
-       while (lidp) {
+       ASSERT(!list_empty(&tp->t_items));
+       list_for_each_entry(lidp, &tp->t_items, lid_trans) {
                /* Skip items which aren't dirty in this transaction. */
-               if (!(lidp->lid_flags & XFS_LID_DIRTY)) {
-                       lidp = xfs_trans_next_item(tp, lidp);
+               if (!(lidp->lid_flags & XFS_LID_DIRTY))
                        continue;
-               }
 
                /*
                 * The item may be marked dirty but not log anything.  This can
@@ -1206,7 +1298,6 @@ xfs_trans_fill_vecs(
                IOP_FORMAT(lidp->lid_item, vecp);
                vecp += lidp->lid_size;
                IOP_PIN(lidp->lid_item);
-               lidp = xfs_trans_next_item(tp, lidp);
        }
 
        /*
@@ -1284,7 +1375,7 @@ xfs_trans_item_committed(
         * log item flags, if anyone else stales the buffer we do not want to
         * pay any attention to it.
         */
-       IOP_UNPIN(lip);
+       IOP_UNPIN(lip, 0);
 }
 
 /*
@@ -1301,24 +1392,15 @@ xfs_trans_committed(
        struct xfs_trans        *tp,
        int                     abortflag)
 {
-       xfs_log_item_desc_t     *lidp;
-       xfs_log_item_chunk_t    *licp;
-       xfs_log_item_chunk_t    *next_licp;
+       struct xfs_log_item_desc *lidp, *next;
 
        /* Call the transaction's completion callback if there is one. */
        if (tp->t_callback != NULL)
                tp->t_callback(tp, tp->t_callarg);
 
-       for (lidp = xfs_trans_first_item(tp);
-            lidp != NULL;
-            lidp = xfs_trans_next_item(tp, lidp)) {
+       list_for_each_entry_safe(lidp, next, &tp->t_items, lid_trans) {
                xfs_trans_item_committed(lidp->lid_item, tp->t_lsn, abortflag);
-       }
-
-       /* free the item chunks, ignoring the embedded chunk */
-       for (licp = tp->t_items.lic_next; licp != NULL; licp = next_licp) {
-               next_licp = licp->lic_next;
-               kmem_free(licp);
+               xfs_trans_free_item_desc(lidp);
        }
 
        xfs_trans_free(tp);
@@ -1333,16 +1415,14 @@ xfs_trans_uncommit(
        struct xfs_trans        *tp,
        uint                    flags)
 {
-       xfs_log_item_desc_t     *lidp;
+       struct xfs_log_item_desc *lidp;
 
-       for (lidp = xfs_trans_first_item(tp);
-            lidp != NULL;
-            lidp = xfs_trans_next_item(tp, lidp)) {
+       list_for_each_entry(lidp, &tp->t_items, lid_trans) {
                /*
                 * Unpin all but those that aren't dirty.
                 */
                if (lidp->lid_flags & XFS_LID_DIRTY)
-                       IOP_UNPIN_REMOVE(lidp->lid_item, tp);
+                       IOP_UNPIN(lidp->lid_item, 1);
        }
 
        xfs_trans_unreserve_and_mod_sb(tp);
@@ -1508,33 +1588,28 @@ STATIC struct xfs_log_vec *
 xfs_trans_alloc_log_vecs(
        xfs_trans_t     *tp)
 {
-       xfs_log_item_desc_t     *lidp;
+       struct xfs_log_item_desc *lidp;
        struct xfs_log_vec      *lv = NULL;
        struct xfs_log_vec      *ret_lv = NULL;
 
-       lidp = xfs_trans_first_item(tp);
 
        /* Bail out if we didn't find a log item.  */
-       if (!lidp) {
+       if (list_empty(&tp->t_items)) {
                ASSERT(0);
                return NULL;
        }
 
-       while (lidp != NULL) {
+       list_for_each_entry(lidp, &tp->t_items, lid_trans) {
                struct xfs_log_vec *new_lv;
 
                /* Skip items which aren't dirty in this transaction. */
-               if (!(lidp->lid_flags & XFS_LID_DIRTY)) {
-                       lidp = xfs_trans_next_item(tp, lidp);
+               if (!(lidp->lid_flags & XFS_LID_DIRTY))
                        continue;
-               }
 
                /* Skip items that do not have any vectors for writing */
                lidp->lid_size = IOP_SIZE(lidp->lid_item);
-               if (!lidp->lid_size) {
-                       lidp = xfs_trans_next_item(tp, lidp);
+               if (!lidp->lid_size)
                        continue;
-               }
 
                new_lv = kmem_zalloc(sizeof(*new_lv) +
                                lidp->lid_size * sizeof(struct xfs_log_iovec),
@@ -1549,7 +1624,6 @@ xfs_trans_alloc_log_vecs(
                else
                        lv->lv_next = new_lv;
                lv = new_lv;
-               lidp = xfs_trans_next_item(tp, lidp);
        }
 
        return ret_lv;
@@ -1708,12 +1782,6 @@ xfs_trans_cancel(
        int                     flags)
 {
        int                     log_flags;
-#ifdef DEBUG
-       xfs_log_item_chunk_t    *licp;
-       xfs_log_item_desc_t     *lidp;
-       xfs_log_item_t          *lip;
-       int                     i;
-#endif
        xfs_mount_t             *mp = tp->t_mountp;
 
        /*
@@ -1732,21 +1800,11 @@ xfs_trans_cancel(
                xfs_force_shutdown(mp, SHUTDOWN_CORRUPT_INCORE);
        }
 #ifdef DEBUG
-       if (!(flags & XFS_TRANS_ABORT)) {
-               licp = &(tp->t_items);
-               while (licp != NULL) {
-                       lidp = licp->lic_descs;
-                       for (i = 0; i < licp->lic_unused; i++, lidp++) {
-                               if (xfs_lic_isfree(licp, i)) {
-                                       continue;
-                               }
-
-                               lip = lidp->lid_item;
-                               if (!XFS_FORCED_SHUTDOWN(mp))
-                                       ASSERT(!(lip->li_type == XFS_LI_EFD));
-                       }
-                       licp = licp->lic_next;
-               }
+       if (!(flags & XFS_TRANS_ABORT) && !XFS_FORCED_SHUTDOWN(mp)) {
+               struct xfs_log_item_desc *lidp;
+
+               list_for_each_entry(lidp, &tp->t_items, lid_trans)
+                       ASSERT(!(lidp->lid_item->li_type == XFS_LI_EFD));
        }
 #endif
        xfs_trans_unreserve_and_mod_sb(tp);
@@ -1834,7 +1892,6 @@ xfs_trans_roll(
        if (error)
                return error;
 
-       xfs_trans_ijoin(trans, dp, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(trans, dp);
+       xfs_trans_ijoin(trans, dp);
        return 0;
 }
index e639e8e9a2a978ed6404725ce52b6f4cdbe840ba..c13c0f97b4945d7ff80990aeb7d4c0a8e12d0139 100644 (file)
@@ -161,105 +161,14 @@ typedef struct xfs_trans_header {
  * the amount of space needed to log the item it describes
  * once we get to commit processing (see xfs_trans_commit()).
  */
-typedef struct xfs_log_item_desc {
+struct xfs_log_item_desc {
        struct xfs_log_item     *lid_item;
-       ushort          lid_size;
-       unsigned char   lid_flags;
-       unsigned char   lid_index;
-} xfs_log_item_desc_t;
+       ushort                  lid_size;
+       unsigned char           lid_flags;
+       struct list_head        lid_trans;
+};
 
 #define XFS_LID_DIRTY          0x1
-#define XFS_LID_PINNED         0x2
-
-/*
- * This structure is used to maintain a chunk list of log_item_desc
- * structures. The free field is a bitmask indicating which descriptors
- * in this chunk's array are free.  The unused field is the first value
- * not used since this chunk was allocated.
- */
-#define        XFS_LIC_NUM_SLOTS       15
-typedef struct xfs_log_item_chunk {
-       struct xfs_log_item_chunk       *lic_next;
-       ushort                          lic_free;
-       ushort                          lic_unused;
-       xfs_log_item_desc_t             lic_descs[XFS_LIC_NUM_SLOTS];
-} xfs_log_item_chunk_t;
-
-#define        XFS_LIC_MAX_SLOT        (XFS_LIC_NUM_SLOTS - 1)
-#define        XFS_LIC_FREEMASK        ((1 << XFS_LIC_NUM_SLOTS) - 1)
-
-
-/*
- * Initialize the given chunk.  Set the chunk's free descriptor mask
- * to indicate that all descriptors are free.  The caller gets to set
- * lic_unused to the right value (0 matches all free).  The
- * lic_descs.lid_index values are set up as each desc is allocated.
- */
-static inline void xfs_lic_init(xfs_log_item_chunk_t *cp)
-{
-       cp->lic_free = XFS_LIC_FREEMASK;
-}
-
-static inline void xfs_lic_init_slot(xfs_log_item_chunk_t *cp, int slot)
-{
-       cp->lic_descs[slot].lid_index = (unsigned char)(slot);
-}
-
-static inline int xfs_lic_vacancy(xfs_log_item_chunk_t *cp)
-{
-       return cp->lic_free & XFS_LIC_FREEMASK;
-}
-
-static inline void xfs_lic_all_free(xfs_log_item_chunk_t *cp)
-{
-       cp->lic_free = XFS_LIC_FREEMASK;
-}
-
-static inline int xfs_lic_are_all_free(xfs_log_item_chunk_t *cp)
-{
-       return ((cp->lic_free & XFS_LIC_FREEMASK) == XFS_LIC_FREEMASK);
-}
-
-static inline int xfs_lic_isfree(xfs_log_item_chunk_t *cp, int slot)
-{
-       return (cp->lic_free & (1 << slot));
-}
-
-static inline void xfs_lic_claim(xfs_log_item_chunk_t *cp, int slot)
-{
-       cp->lic_free &= ~(1 << slot);
-}
-
-static inline void xfs_lic_relse(xfs_log_item_chunk_t *cp, int slot)
-{
-       cp->lic_free |= 1 << slot;
-}
-
-static inline xfs_log_item_desc_t *
-xfs_lic_slot(xfs_log_item_chunk_t *cp, int slot)
-{
-       return &(cp->lic_descs[slot]);
-}
-
-static inline int xfs_lic_desc_to_slot(xfs_log_item_desc_t *dp)
-{
-       return (uint)dp->lid_index;
-}
-
-/*
- * Calculate the address of a chunk given a descriptor pointer:
- * dp - dp->lid_index give the address of the start of the lic_descs array.
- * From this we subtract the offset of the lic_descs field in a chunk.
- * All of this yields the address of the chunk, which is
- * cast to a chunk pointer.
- */
-static inline xfs_log_item_chunk_t *
-xfs_lic_desc_to_chunk(xfs_log_item_desc_t *dp)
-{
-       return (xfs_log_item_chunk_t*) \
-               (((xfs_caddr_t)((dp) - (dp)->lid_index)) - \
-               (xfs_caddr_t)(((xfs_log_item_chunk_t*)0)->lic_descs));
-}
 
 #define        XFS_TRANS_MAGIC         0x5452414E      /* 'TRAN' */
 /*
@@ -275,8 +184,6 @@ xfs_lic_desc_to_chunk(xfs_log_item_desc_t *dp)
 /*
  * Values for call flags parameter.
  */
-#define        XFS_TRANS_NOSLEEP               0x1
-#define        XFS_TRANS_WAIT                  0x2
 #define        XFS_TRANS_RELEASE_LOG_RES       0x4
 #define        XFS_TRANS_ABORT                 0x8
 
@@ -438,8 +345,7 @@ typedef struct xfs_item_ops {
        uint (*iop_size)(xfs_log_item_t *);
        void (*iop_format)(xfs_log_item_t *, struct xfs_log_iovec *);
        void (*iop_pin)(xfs_log_item_t *);
-       void (*iop_unpin)(xfs_log_item_t *);
-       void (*iop_unpin_remove)(xfs_log_item_t *, struct xfs_trans *);
+       void (*iop_unpin)(xfs_log_item_t *, int remove);
        uint (*iop_trylock)(xfs_log_item_t *);
        void (*iop_unlock)(xfs_log_item_t *);
        xfs_lsn_t (*iop_committed)(xfs_log_item_t *, xfs_lsn_t);
@@ -451,8 +357,7 @@ typedef struct xfs_item_ops {
 #define IOP_SIZE(ip)           (*(ip)->li_ops->iop_size)(ip)
 #define IOP_FORMAT(ip,vp)      (*(ip)->li_ops->iop_format)(ip, vp)
 #define IOP_PIN(ip)            (*(ip)->li_ops->iop_pin)(ip)
-#define IOP_UNPIN(ip)          (*(ip)->li_ops->iop_unpin)(ip)
-#define IOP_UNPIN_REMOVE(ip,tp) (*(ip)->li_ops->iop_unpin_remove)(ip, tp)
+#define IOP_UNPIN(ip, remove)  (*(ip)->li_ops->iop_unpin)(ip, remove)
 #define IOP_TRYLOCK(ip)                (*(ip)->li_ops->iop_trylock)(ip)
 #define IOP_UNLOCK(ip)         (*(ip)->li_ops->iop_unlock)(ip)
 #define IOP_COMMITTED(ip, lsn) (*(ip)->li_ops->iop_committed)(ip, lsn)
@@ -516,8 +421,7 @@ typedef struct xfs_trans {
        int64_t                 t_rblocks_delta;/* superblock rblocks change */
        int64_t                 t_rextents_delta;/* superblocks rextents chg */
        int64_t                 t_rextslog_delta;/* superblocks rextslog chg */
-       unsigned int            t_items_free;   /* log item descs free */
-       xfs_log_item_chunk_t    t_items;        /* first log item desc chunk */
+       struct list_head        t_items;        /* log item descriptors */
        xfs_trans_header_t      t_header;       /* header for in-log trans */
        struct list_head        t_busy;         /* list of busy extents */
        unsigned long           t_pflags;       /* saved process flags state */
@@ -569,8 +473,8 @@ void                xfs_trans_dquot_buf(xfs_trans_t *, struct xfs_buf *, uint);
 void           xfs_trans_inode_alloc_buf(xfs_trans_t *, struct xfs_buf *);
 int            xfs_trans_iget(struct xfs_mount *, xfs_trans_t *,
                               xfs_ino_t , uint, uint, struct xfs_inode **);
-void           xfs_trans_ijoin(xfs_trans_t *, struct xfs_inode *, uint);
-void           xfs_trans_ihold(xfs_trans_t *, struct xfs_inode *);
+void           xfs_trans_ijoin_ref(struct xfs_trans *, struct xfs_inode *, uint);
+void           xfs_trans_ijoin(struct xfs_trans *, struct xfs_inode *);
 void           xfs_trans_log_buf(xfs_trans_t *, struct xfs_buf *, uint, uint);
 void           xfs_trans_log_inode(xfs_trans_t *, struct xfs_inode *, uint);
 struct xfs_efi_log_item        *xfs_trans_get_efi(xfs_trans_t *, uint);
@@ -595,6 +499,7 @@ int         xfs_trans_ail_init(struct xfs_mount *);
 void           xfs_trans_ail_destroy(struct xfs_mount *);
 
 extern kmem_zone_t     *xfs_trans_zone;
+extern kmem_zone_t     *xfs_log_item_desc_zone;
 
 #endif /* __KERNEL__ */
 
index e799824f72451ff017175144994c3322040945a6..dc9069568ff7182db00b0cf6bf9008ea41aeff69 100644 (file)
@@ -24,7 +24,6 @@
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_trans_priv.h"
 #include "xfs_error.h"
index 63d81a22f4fd60c6d6abc93538c37e6480c8fd3b..90af025e6839e69a8fb32e49e76d810b2ceb9cf9 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_buf_item.h"
@@ -51,36 +47,17 @@ xfs_trans_buf_item_match(
        xfs_daddr_t             blkno,
        int                     len)
 {
-       xfs_log_item_chunk_t    *licp;
-       xfs_log_item_desc_t     *lidp;
-       xfs_buf_log_item_t      *blip;
-       int                     i;
+       struct xfs_log_item_desc *lidp;
+       struct xfs_buf_log_item *blip;
 
        len = BBTOB(len);
-       for (licp = &tp->t_items; licp != NULL; licp = licp->lic_next) {
-               if (xfs_lic_are_all_free(licp)) {
-                       ASSERT(licp == &tp->t_items);
-                       ASSERT(licp->lic_next == NULL);
-                       return NULL;
-               }
-
-               for (i = 0; i < licp->lic_unused; i++) {
-                       /*
-                        * Skip unoccupied slots.
-                        */
-                       if (xfs_lic_isfree(licp, i))
-                               continue;
-
-                       lidp = xfs_lic_slot(licp, i);
-                       blip = (xfs_buf_log_item_t *)lidp->lid_item;
-                       if (blip->bli_item.li_type != XFS_LI_BUF)
-                               continue;
-
-                       if (XFS_BUF_TARGET(blip->bli_buf) == target &&
-                           XFS_BUF_ADDR(blip->bli_buf) == blkno &&
-                           XFS_BUF_COUNT(blip->bli_buf) == len)
-                               return blip->bli_buf;
-               }
+       list_for_each_entry(lidp, &tp->t_items, lid_trans) {
+               blip = (struct xfs_buf_log_item *)lidp->lid_item;
+               if (blip->bli_item.li_type == XFS_LI_BUF &&
+                   XFS_BUF_TARGET(blip->bli_buf) == target &&
+                   XFS_BUF_ADDR(blip->bli_buf) == blkno &&
+                   XFS_BUF_COUNT(blip->bli_buf) == len)
+                       return blip->bli_buf;
        }
 
        return NULL;
@@ -127,7 +104,7 @@ _xfs_trans_bjoin(
        /*
         * Get a log_item_desc to point at the new item.
         */
-       (void) xfs_trans_add_item(tp, (xfs_log_item_t *)bip);
+       xfs_trans_add_item(tp, &bip->bli_item);
 
        /*
         * Initialize b_fsprivate2 so we can find it with incore_match()
@@ -483,7 +460,6 @@ xfs_trans_brelse(xfs_trans_t        *tp,
 {
        xfs_buf_log_item_t      *bip;
        xfs_log_item_t          *lip;
-       xfs_log_item_desc_t     *lidp;
 
        /*
         * Default to a normal brelse() call if the tp is NULL.
@@ -514,13 +490,6 @@ xfs_trans_brelse(xfs_trans_t       *tp,
        ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_CANCEL));
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
 
-       /*
-        * Find the item descriptor pointing to this buffer's
-        * log item.  It must be there.
-        */
-       lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
-       ASSERT(lidp != NULL);
-
        trace_xfs_trans_brelse(bip);
 
        /*
@@ -536,7 +505,7 @@ xfs_trans_brelse(xfs_trans_t        *tp,
         * If the buffer is dirty within this transaction, we can't
         * release it until we commit.
         */
-       if (lidp->lid_flags & XFS_LID_DIRTY)
+       if (bip->bli_item.li_desc->lid_flags & XFS_LID_DIRTY)
                return;
 
        /*
@@ -553,7 +522,7 @@ xfs_trans_brelse(xfs_trans_t        *tp,
        /*
         * Free up the log item descriptor tracking the released item.
         */
-       xfs_trans_free_item(tp, lidp);
+       xfs_trans_del_item(&bip->bli_item);
 
        /*
         * Clear the hold flag in the buf log item if it is set.
@@ -665,7 +634,6 @@ xfs_trans_log_buf(xfs_trans_t       *tp,
                  uint          last)
 {
        xfs_buf_log_item_t      *bip;
-       xfs_log_item_desc_t     *lidp;
 
        ASSERT(XFS_BUF_ISBUSY(bp));
        ASSERT(XFS_BUF_FSPRIVATE2(bp, xfs_trans_t *) == tp);
@@ -690,7 +658,7 @@ xfs_trans_log_buf(xfs_trans_t       *tp,
        bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
        XFS_BUF_SET_IODONE_FUNC(bp, xfs_buf_iodone_callbacks);
-       bip->bli_item.li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*))xfs_buf_iodone;
+       bip->bli_item.li_cb = xfs_buf_iodone;
 
        trace_xfs_trans_log_buf(bip);
 
@@ -707,11 +675,8 @@ xfs_trans_log_buf(xfs_trans_t      *tp,
                bip->bli_format.blf_flags &= ~XFS_BLF_CANCEL;
        }
 
-       lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
-       ASSERT(lidp != NULL);
-
        tp->t_flags |= XFS_TRANS_DIRTY;
-       lidp->lid_flags |= XFS_LID_DIRTY;
+       bip->bli_item.li_desc->lid_flags |= XFS_LID_DIRTY;
        bip->bli_flags |= XFS_BLI_LOGGED;
        xfs_buf_item_log(bip, first, last);
 }
@@ -740,7 +705,6 @@ xfs_trans_binval(
        xfs_trans_t     *tp,
        xfs_buf_t       *bp)
 {
-       xfs_log_item_desc_t     *lidp;
        xfs_buf_log_item_t      *bip;
 
        ASSERT(XFS_BUF_ISBUSY(bp));
@@ -748,8 +712,6 @@ xfs_trans_binval(
        ASSERT(XFS_BUF_FSPRIVATE(bp, void *) != NULL);
 
        bip = XFS_BUF_FSPRIVATE(bp, xfs_buf_log_item_t *);
-       lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)bip);
-       ASSERT(lidp != NULL);
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
 
        trace_xfs_trans_binval(bip);
@@ -764,7 +726,7 @@ xfs_trans_binval(
                ASSERT(!(bip->bli_flags & (XFS_BLI_LOGGED | XFS_BLI_DIRTY)));
                ASSERT(!(bip->bli_format.blf_flags & XFS_BLF_INODE_BUF));
                ASSERT(bip->bli_format.blf_flags & XFS_BLF_CANCEL);
-               ASSERT(lidp->lid_flags & XFS_LID_DIRTY);
+               ASSERT(bip->bli_item.li_desc->lid_flags & XFS_LID_DIRTY);
                ASSERT(tp->t_flags & XFS_TRANS_DIRTY);
                return;
        }
@@ -797,7 +759,7 @@ xfs_trans_binval(
        bip->bli_format.blf_flags |= XFS_BLF_CANCEL;
        memset((char *)(bip->bli_format.blf_data_map), 0,
              (bip->bli_format.blf_map_size * sizeof(uint)));
-       lidp->lid_flags |= XFS_LID_DIRTY;
+       bip->bli_item.li_desc->lid_flags |= XFS_LID_DIRTY;
        tp->t_flags |= XFS_TRANS_DIRTY;
 }
 
@@ -853,12 +815,9 @@ xfs_trans_stale_inode_buf(
        ASSERT(atomic_read(&bip->bli_refcount) > 0);
 
        bip->bli_flags |= XFS_BLI_STALE_INODE;
-       bip->bli_item.li_cb = (void(*)(xfs_buf_t*,xfs_log_item_t*))
-               xfs_buf_iodone;
+       bip->bli_item.li_cb = xfs_buf_iodone;
 }
 
-
-
 /*
  * Mark the buffer as being one which contains newly allocated
  * inodes.  We need to make sure that even if this buffer is
index 27cce2a9c7e9108debaab50b96a92a2c0109cb39..f783d5e9fa70f30b87650a5dfe0fd09bbd80ba02 100644 (file)
@@ -23,7 +23,6 @@
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_trans_priv.h"
 #include "xfs_extfree_item.h"
@@ -49,9 +48,8 @@ xfs_trans_get_efi(xfs_trans_t *tp,
        /*
         * Get a log_item_desc to point at the new item.
         */
-       (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efip);
-
-       return (efip);
+       xfs_trans_add_item(tp, &efip->efi_item);
+       return efip;
 }
 
 /*
@@ -65,15 +63,11 @@ xfs_trans_log_efi_extent(xfs_trans_t                *tp,
                         xfs_fsblock_t          start_block,
                         xfs_extlen_t           ext_len)
 {
-       xfs_log_item_desc_t     *lidp;
        uint                    next_extent;
        xfs_extent_t            *extp;
 
-       lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efip);
-       ASSERT(lidp != NULL);
-
        tp->t_flags |= XFS_TRANS_DIRTY;
-       lidp->lid_flags |= XFS_LID_DIRTY;
+       efip->efi_item.li_desc->lid_flags |= XFS_LID_DIRTY;
 
        next_extent = efip->efi_next_extent;
        ASSERT(next_extent < efip->efi_format.efi_nextents);
@@ -106,9 +100,8 @@ xfs_trans_get_efd(xfs_trans_t               *tp,
        /*
         * Get a log_item_desc to point at the new item.
         */
-       (void) xfs_trans_add_item(tp, (xfs_log_item_t*)efdp);
-
-       return (efdp);
+       xfs_trans_add_item(tp, &efdp->efd_item);
+       return efdp;
 }
 
 /*
@@ -122,15 +115,11 @@ xfs_trans_log_efd_extent(xfs_trans_t              *tp,
                         xfs_fsblock_t          start_block,
                         xfs_extlen_t           ext_len)
 {
-       xfs_log_item_desc_t     *lidp;
        uint                    next_extent;
        xfs_extent_t            *extp;
 
-       lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)efdp);
-       ASSERT(lidp != NULL);
-
        tp->t_flags |= XFS_TRANS_DIRTY;
-       lidp->lid_flags |= XFS_LID_DIRTY;
+       efdp->efd_item.li_desc->lid_flags |= XFS_LID_DIRTY;
 
        next_extent = efdp->efd_next_extent;
        ASSERT(next_extent < efdp->efd_format.efd_nextents);
index 2559dfec946bb990afe7e44af28ae43204d6474a..cdc53a1050c56ac365a2d61114f65d1cc03fbc26 100644 (file)
 #include "xfs_trans.h"
 #include "xfs_sb.h"
 #include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
 #include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_btree.h"
-#include "xfs_ialloc.h"
 #include "xfs_trans_priv.h"
 #include "xfs_inode_item.h"
+#include "xfs_trace.h"
 
 #ifdef XFS_TRANS_DEBUG
 STATIC void
@@ -47,7 +43,6 @@ xfs_trans_inode_broot_debug(
 #define        xfs_trans_inode_broot_debug(ip)
 #endif
 
-
 /*
  * Get an inode and join it to the transaction.
  */
@@ -63,49 +58,39 @@ xfs_trans_iget(
        int                     error;
 
        error = xfs_iget(mp, tp, ino, flags, lock_flags, ipp);
-       if (!error && tp)
-               xfs_trans_ijoin(tp, *ipp, lock_flags);
+       if (!error && tp) {
+               xfs_trans_ijoin(tp, *ipp);
+               (*ipp)->i_itemp->ili_lock_flags = lock_flags;
+       }
        return error;
 }
 
 /*
- * Add the locked inode to the transaction.
- * The inode must be locked, and it cannot be associated with any
- * transaction.  The caller must specify the locks already held
- * on the inode.
+ * Add a locked inode to the transaction.
+ *
+ * The inode must be locked, and it cannot be associated with any transaction.
  */
 void
 xfs_trans_ijoin(
-       xfs_trans_t     *tp,
-       xfs_inode_t     *ip,
-       uint            lock_flags)
+       struct xfs_trans        *tp,
+       struct xfs_inode        *ip)
 {
        xfs_inode_log_item_t    *iip;
 
        ASSERT(ip->i_transp == NULL);
        ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
-       ASSERT(lock_flags & XFS_ILOCK_EXCL);
        if (ip->i_itemp == NULL)
                xfs_inode_item_init(ip, ip->i_mount);
        iip = ip->i_itemp;
-       ASSERT(iip->ili_flags == 0);
+       ASSERT(iip->ili_lock_flags == 0);
 
        /*
         * Get a log_item_desc to point at the new item.
         */
-       (void) xfs_trans_add_item(tp, (xfs_log_item_t*)(iip));
+       xfs_trans_add_item(tp, &iip->ili_item);
 
        xfs_trans_inode_broot_debug(ip);
 
-       /*
-        * If the IO lock is already held, mark that in the inode log item.
-        */
-       if (lock_flags & XFS_IOLOCK_EXCL) {
-               iip->ili_flags |= XFS_ILI_IOLOCKED_EXCL;
-       } else if (lock_flags & XFS_IOLOCK_SHARED) {
-               iip->ili_flags |= XFS_ILI_IOLOCKED_SHARED;
-       }
-
        /*
         * Initialize i_transp so we can find it with xfs_inode_incore()
         * in xfs_trans_iget() above.
@@ -113,27 +98,25 @@ xfs_trans_ijoin(
        ip->i_transp = tp;
 }
 
-
-
 /*
- * Mark the inode as not needing to be unlocked when the inode item's
- * IOP_UNLOCK() routine is called.  The inode must already be locked
- * and associated with the given transaction.
+ * Add a locked inode to the transaction.
+ *
+ *
+ * Grabs a reference to the inode which will be dropped when the transaction
+ * is commited.  The inode will also be unlocked at that point.  The inode
+ * must be locked, and it cannot be associated with any transaction.
  */
-/*ARGSUSED*/
 void
-xfs_trans_ihold(
-       xfs_trans_t     *tp,
-       xfs_inode_t     *ip)
+xfs_trans_ijoin_ref(
+       struct xfs_trans        *tp,
+       struct xfs_inode        *ip,
+       uint                    lock_flags)
 {
-       ASSERT(ip->i_transp == tp);
-       ASSERT(ip->i_itemp != NULL);
-       ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
-
-       ip->i_itemp->ili_flags |= XFS_ILI_HOLD;
+       xfs_trans_ijoin(tp, ip);
+       IHOLD(ip);
+       ip->i_itemp->ili_lock_flags = lock_flags;
 }
 
-
 /*
  * This is called to mark the fields indicated in fieldmask as needing
  * to be logged when the transaction is committed.  The inode must
@@ -149,17 +132,12 @@ xfs_trans_log_inode(
        xfs_inode_t     *ip,
        uint            flags)
 {
-       xfs_log_item_desc_t     *lidp;
-
        ASSERT(ip->i_transp == tp);
        ASSERT(ip->i_itemp != NULL);
        ASSERT(xfs_isilocked(ip, XFS_ILOCK_EXCL));
 
-       lidp = xfs_trans_find_item(tp, (xfs_log_item_t*)(ip->i_itemp));
-       ASSERT(lidp != NULL);
-
        tp->t_flags |= XFS_TRANS_DIRTY;
-       lidp->lid_flags |= XFS_LID_DIRTY;
+       ip->i_itemp->ili_item.li_desc->lid_flags |= XFS_LID_DIRTY;
 
        /*
         * Always OR in the bits from the ili_last_fields field.
diff --git a/fs/xfs/xfs_trans_item.c b/fs/xfs/xfs_trans_item.c
deleted file mode 100644 (file)
index f11d37d..0000000
+++ /dev/null
@@ -1,441 +0,0 @@
-/*
- * Copyright (c) 2000-2002,2005 Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * 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.
- *
- * This program is distributed in the hope that it would 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 the Free Software Foundation,
- * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- */
-#include "xfs.h"
-#include "xfs_fs.h"
-#include "xfs_types.h"
-#include "xfs_log.h"
-#include "xfs_inum.h"
-#include "xfs_trans.h"
-#include "xfs_trans_priv.h"
-/* XXX: from here down needed until struct xfs_trans has its own ailp */
-#include "xfs_bit.h"
-#include "xfs_buf_item.h"
-#include "xfs_sb.h"
-#include "xfs_ag.h"
-#include "xfs_dir2.h"
-#include "xfs_dmapi.h"
-#include "xfs_mount.h"
-
-STATIC int     xfs_trans_unlock_chunk(xfs_log_item_chunk_t *,
-                                       int, int, xfs_lsn_t);
-
-/*
- * This is called to add the given log item to the transaction's
- * list of log items.  It must find a free log item descriptor
- * or allocate a new one and add the item to that descriptor.
- * The function returns a pointer to item descriptor used to point
- * to the new item.  The log item will now point to its new descriptor
- * with its li_desc field.
- */
-xfs_log_item_desc_t *
-xfs_trans_add_item(xfs_trans_t *tp, xfs_log_item_t *lip)
-{
-       xfs_log_item_desc_t     *lidp;
-       xfs_log_item_chunk_t    *licp;
-       int                     i=0;
-
-       /*
-        * If there are no free descriptors, allocate a new chunk
-        * of them and put it at the front of the chunk list.
-        */
-       if (tp->t_items_free == 0) {
-               licp = (xfs_log_item_chunk_t*)
-                      kmem_alloc(sizeof(xfs_log_item_chunk_t), KM_SLEEP);
-               ASSERT(licp != NULL);
-               /*
-                * Initialize the chunk, and then
-                * claim the first slot in the newly allocated chunk.
-                */
-               xfs_lic_init(licp);
-               xfs_lic_claim(licp, 0);
-               licp->lic_unused = 1;
-               xfs_lic_init_slot(licp, 0);
-               lidp = xfs_lic_slot(licp, 0);
-
-               /*
-                * Link in the new chunk and update the free count.
-                */
-               licp->lic_next = tp->t_items.lic_next;
-               tp->t_items.lic_next = licp;
-               tp->t_items_free = XFS_LIC_NUM_SLOTS - 1;
-
-               /*
-                * Initialize the descriptor and the generic portion
-                * of the log item.
-                *
-                * Point the new slot at this item and return it.
-                * Also point the log item at its currently active
-                * descriptor and set the item's mount pointer.
-                */
-               lidp->lid_item = lip;
-               lidp->lid_flags = 0;
-               lidp->lid_size = 0;
-               lip->li_desc = lidp;
-               lip->li_mountp = tp->t_mountp;
-               lip->li_ailp = tp->t_mountp->m_ail;
-               return lidp;
-       }
-
-       /*
-        * Find the free descriptor. It is somewhere in the chunklist
-        * of descriptors.
-        */
-       licp = &tp->t_items;
-       while (licp != NULL) {
-               if (xfs_lic_vacancy(licp)) {
-                       if (licp->lic_unused <= XFS_LIC_MAX_SLOT) {
-                               i = licp->lic_unused;
-                               ASSERT(xfs_lic_isfree(licp, i));
-                               break;
-                       }
-                       for (i = 0; i <= XFS_LIC_MAX_SLOT; i++) {
-                               if (xfs_lic_isfree(licp, i))
-                                       break;
-                       }
-                       ASSERT(i <= XFS_LIC_MAX_SLOT);
-                       break;
-               }
-               licp = licp->lic_next;
-       }
-       ASSERT(licp != NULL);
-       /*
-        * If we find a free descriptor, claim it,
-        * initialize it, and return it.
-        */
-       xfs_lic_claim(licp, i);
-       if (licp->lic_unused <= i) {
-               licp->lic_unused = i + 1;
-               xfs_lic_init_slot(licp, i);
-       }
-       lidp = xfs_lic_slot(licp, i);
-       tp->t_items_free--;
-       lidp->lid_item = lip;
-       lidp->lid_flags = 0;
-       lidp->lid_size = 0;
-       lip->li_desc = lidp;
-       lip->li_mountp = tp->t_mountp;
-       lip->li_ailp = tp->t_mountp->m_ail;
-       return lidp;
-}
-
-/*
- * Free the given descriptor.
- *
- * This requires setting the bit in the chunk's free mask corresponding
- * to the given slot.
- */
-void
-xfs_trans_free_item(xfs_trans_t        *tp, xfs_log_item_desc_t *lidp)
-{
-       uint                    slot;
-       xfs_log_item_chunk_t    *licp;
-       xfs_log_item_chunk_t    **licpp;
-
-       slot = xfs_lic_desc_to_slot(lidp);
-       licp = xfs_lic_desc_to_chunk(lidp);
-       xfs_lic_relse(licp, slot);
-       lidp->lid_item->li_desc = NULL;
-       tp->t_items_free++;
-
-       /*
-        * If there are no more used items in the chunk and this is not
-        * the chunk embedded in the transaction structure, then free
-        * the chunk. First pull it from the chunk list and then
-        * free it back to the heap.  We didn't bother with a doubly
-        * linked list here because the lists should be very short
-        * and this is not a performance path.  It's better to save
-        * the memory of the extra pointer.
-        *
-        * Also decrement the transaction structure's count of free items
-        * by the number in a chunk since we are freeing an empty chunk.
-        */
-       if (xfs_lic_are_all_free(licp) && (licp != &(tp->t_items))) {
-               licpp = &(tp->t_items.lic_next);
-               while (*licpp != licp) {
-                       ASSERT(*licpp != NULL);
-                       licpp = &((*licpp)->lic_next);
-               }
-               *licpp = licp->lic_next;
-               kmem_free(licp);
-               tp->t_items_free -= XFS_LIC_NUM_SLOTS;
-       }
-}
-
-/*
- * This is called to find the descriptor corresponding to the given
- * log item.  It returns a pointer to the descriptor.
- * The log item MUST have a corresponding descriptor in the given
- * transaction.  This routine does not return NULL, it panics.
- *
- * The descriptor pointer is kept in the log item's li_desc field.
- * Just return it.
- */
-/*ARGSUSED*/
-xfs_log_item_desc_t *
-xfs_trans_find_item(xfs_trans_t        *tp, xfs_log_item_t *lip)
-{
-       ASSERT(lip->li_desc != NULL);
-
-       return lip->li_desc;
-}
-
-
-/*
- * Return a pointer to the first descriptor in the chunk list.
- * This does not return NULL if there are none, it panics.
- *
- * The first descriptor must be in either the first or second chunk.
- * This is because the only chunk allowed to be empty is the first.
- * All others are freed when they become empty.
- *
- * At some point this and xfs_trans_next_item() should be optimized
- * to quickly look at the mask to determine if there is anything to
- * look at.
- */
-xfs_log_item_desc_t *
-xfs_trans_first_item(xfs_trans_t *tp)
-{
-       xfs_log_item_chunk_t    *licp;
-       int                     i;
-
-       licp = &tp->t_items;
-       /*
-        * If it's not in the first chunk, skip to the second.
-        */
-       if (xfs_lic_are_all_free(licp)) {
-               licp = licp->lic_next;
-       }
-
-       /*
-        * Return the first non-free descriptor in the chunk.
-        */
-       ASSERT(!xfs_lic_are_all_free(licp));
-       for (i = 0; i < licp->lic_unused; i++) {
-               if (xfs_lic_isfree(licp, i)) {
-                       continue;
-               }
-
-               return xfs_lic_slot(licp, i);
-       }
-       cmn_err(CE_WARN, "xfs_trans_first_item() -- no first item");
-       return NULL;
-}
-
-
-/*
- * Given a descriptor, return the next descriptor in the chunk list.
- * This returns NULL if there are no more used descriptors in the list.
- *
- * We do this by first locating the chunk in which the descriptor resides,
- * and then scanning forward in the chunk and the list for the next
- * used descriptor.
- */
-/*ARGSUSED*/
-xfs_log_item_desc_t *
-xfs_trans_next_item(xfs_trans_t *tp, xfs_log_item_desc_t *lidp)
-{
-       xfs_log_item_chunk_t    *licp;
-       int                     i;
-
-       licp = xfs_lic_desc_to_chunk(lidp);
-
-       /*
-        * First search the rest of the chunk. The for loop keeps us
-        * from referencing things beyond the end of the chunk.
-        */
-       for (i = (int)xfs_lic_desc_to_slot(lidp) + 1; i < licp->lic_unused; i++) {
-               if (xfs_lic_isfree(licp, i)) {
-                       continue;
-               }
-
-               return xfs_lic_slot(licp, i);
-       }
-
-       /*
-        * Now search the next chunk.  It must be there, because the
-        * next chunk would have been freed if it were empty.
-        * If there is no next chunk, return NULL.
-        */
-       if (licp->lic_next == NULL) {
-               return NULL;
-       }
-
-       licp = licp->lic_next;
-       ASSERT(!xfs_lic_are_all_free(licp));
-       for (i = 0; i < licp->lic_unused; i++) {
-               if (xfs_lic_isfree(licp, i)) {
-                       continue;
-               }
-
-               return xfs_lic_slot(licp, i);
-       }
-       ASSERT(0);
-       /* NOTREACHED */
-       return NULL; /* keep gcc quite */
-}
-
-/*
- * This is called to unlock all of the items of a transaction and to free
- * all the descriptors of that transaction.
- *
- * It walks the list of descriptors and unlocks each item.  It frees
- * each chunk except that embedded in the transaction as it goes along.
- */
-void
-xfs_trans_free_items(
-       xfs_trans_t     *tp,
-       xfs_lsn_t       commit_lsn,
-       int             flags)
-{
-       xfs_log_item_chunk_t    *licp;
-       xfs_log_item_chunk_t    *next_licp;
-       int                     abort;
-
-       abort = flags & XFS_TRANS_ABORT;
-       licp = &tp->t_items;
-       /*
-        * Special case the embedded chunk so we don't free it below.
-        */
-       if (!xfs_lic_are_all_free(licp)) {
-               (void) xfs_trans_unlock_chunk(licp, 1, abort, commit_lsn);
-               xfs_lic_all_free(licp);
-               licp->lic_unused = 0;
-       }
-       licp = licp->lic_next;
-
-       /*
-        * Unlock each item in each chunk and free the chunks.
-        */
-       while (licp != NULL) {
-               ASSERT(!xfs_lic_are_all_free(licp));
-               (void) xfs_trans_unlock_chunk(licp, 1, abort, commit_lsn);
-               next_licp = licp->lic_next;
-               kmem_free(licp);
-               licp = next_licp;
-       }
-
-       /*
-        * Reset the transaction structure's free item count.
-        */
-       tp->t_items_free = XFS_LIC_NUM_SLOTS;
-       tp->t_items.lic_next = NULL;
-}
-
-
-
-/*
- * This is called to unlock the items associated with a transaction.
- * Items which were not logged should be freed.
- * Those which were logged must still be tracked so they can be unpinned
- * when the transaction commits.
- */
-void
-xfs_trans_unlock_items(xfs_trans_t *tp, xfs_lsn_t commit_lsn)
-{
-       xfs_log_item_chunk_t    *licp;
-       xfs_log_item_chunk_t    *next_licp;
-       xfs_log_item_chunk_t    **licpp;
-       int                     freed;
-
-       freed = 0;
-       licp = &tp->t_items;
-
-       /*
-        * Special case the embedded chunk so we don't free.
-        */
-       if (!xfs_lic_are_all_free(licp)) {
-               freed = xfs_trans_unlock_chunk(licp, 0, 0, commit_lsn);
-       }
-       licpp = &(tp->t_items.lic_next);
-       licp = licp->lic_next;
-
-       /*
-        * Unlock each item in each chunk, free non-dirty descriptors,
-        * and free empty chunks.
-        */
-       while (licp != NULL) {
-               ASSERT(!xfs_lic_are_all_free(licp));
-               freed += xfs_trans_unlock_chunk(licp, 0, 0, commit_lsn);
-               next_licp = licp->lic_next;
-               if (xfs_lic_are_all_free(licp)) {
-                       *licpp = next_licp;
-                       kmem_free(licp);
-                       freed -= XFS_LIC_NUM_SLOTS;
-               } else {
-                       licpp = &(licp->lic_next);
-               }
-               ASSERT(*licpp == next_licp);
-               licp = next_licp;
-       }
-
-       /*
-        * Fix the free descriptor count in the transaction.
-        */
-       tp->t_items_free += freed;
-}
-
-/*
- * Unlock each item pointed to by a descriptor in the given chunk.
- * Stamp the commit lsn into each item if necessary.
- * Free descriptors pointing to items which are not dirty if freeing_chunk
- * is zero. If freeing_chunk is non-zero, then we need to unlock all
- * items in the chunk.
- * 
- * Return the number of descriptors freed.
- */
-STATIC int
-xfs_trans_unlock_chunk(
-       xfs_log_item_chunk_t    *licp,
-       int                     freeing_chunk,
-       int                     abort,
-       xfs_lsn_t               commit_lsn)
-{
-       xfs_log_item_desc_t     *lidp;
-       xfs_log_item_t          *lip;
-       int                     i;
-       int                     freed;
-
-       freed = 0;
-       lidp = licp->lic_descs;
-       for (i = 0; i < licp->lic_unused; i++, lidp++) {
-               if (xfs_lic_isfree(licp, i)) {
-                       continue;
-               }
-               lip = lidp->lid_item;
-               lip->li_desc = NULL;
-
-               if (commit_lsn != NULLCOMMITLSN)
-                       IOP_COMMITTING(lip, commit_lsn);
-               if (abort)
-                       lip->li_flags |= XFS_LI_ABORTED;
-               IOP_UNLOCK(lip);
-
-               /*
-                * Free the descriptor if the item is not dirty
-                * within this transaction and the caller is not
-                * going to just free the entire thing regardless.
-                */
-               if (!(freeing_chunk) &&
-                   (!(lidp->lid_flags & XFS_LID_DIRTY) || abort)) {
-                       xfs_lic_relse(licp, i);
-                       freed++;
-               }
-       }
-
-       return freed;
-}
index c6e4f2c8de6e8049a760b1510eb42beb54a295ae..e2d93d8ead7b68b9b6ab74b1869a3f8e10721981 100644 (file)
@@ -23,22 +23,8 @@ struct xfs_log_item_desc;
 struct xfs_mount;
 struct xfs_trans;
 
-/*
- * From xfs_trans_item.c
- */
-struct xfs_log_item_desc       *xfs_trans_add_item(struct xfs_trans *,
-                                           struct xfs_log_item *);
-void                           xfs_trans_free_item(struct xfs_trans *,
-                                           struct xfs_log_item_desc *);
-struct xfs_log_item_desc       *xfs_trans_find_item(struct xfs_trans *,
-                                            struct xfs_log_item *);
-struct xfs_log_item_desc       *xfs_trans_first_item(struct xfs_trans *);
-struct xfs_log_item_desc       *xfs_trans_next_item(struct xfs_trans *,
-                                            struct xfs_log_item_desc *);
-
-void   xfs_trans_unlock_items(struct xfs_trans *tp, xfs_lsn_t commit_lsn);
-void   xfs_trans_free_items(struct xfs_trans *tp, xfs_lsn_t commit_lsn,
-                               int flags);
+void   xfs_trans_add_item(struct xfs_trans *, struct xfs_log_item *);
+void   xfs_trans_del_item(struct xfs_log_item *);
 
 void   xfs_trans_item_committed(struct xfs_log_item *lip,
                                xfs_lsn_t commit_lsn, int aborted);
index 4d88616bde914ea4fe07696a30fdbd81fca878fa..b7d5769d2df04a6d5599fec813ce59693275c701 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
 #include "xfs_bmap.h"
 #include "xfs_error.h"
 #include "xfs_quota.h"
-#include "xfs_rw.h"
 #include "xfs_itable.h"
 #include "xfs_utils.h"
 
@@ -324,86 +320,3 @@ xfs_bumplink(
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        return 0;
 }
-
-/*
- * Try to truncate the given file to 0 length.  Currently called
- * only out of xfs_remove when it has to truncate a file to free
- * up space for the remove to proceed.
- */
-int
-xfs_truncate_file(
-       xfs_mount_t     *mp,
-       xfs_inode_t     *ip)
-{
-       xfs_trans_t     *tp;
-       int             error;
-
-#ifdef QUOTADEBUG
-       /*
-        * This is called to truncate the quotainodes too.
-        */
-       if (XFS_IS_UQUOTA_ON(mp)) {
-               if (ip->i_ino != mp->m_sb.sb_uquotino)
-                       ASSERT(ip->i_udquot);
-       }
-       if (XFS_IS_OQUOTA_ON(mp)) {
-               if (ip->i_ino != mp->m_sb.sb_gquotino)
-                       ASSERT(ip->i_gdquot);
-       }
-#endif
-       /*
-        * Make the call to xfs_itruncate_start before starting the
-        * transaction, because we cannot make the call while we're
-        * in a transaction.
-        */
-       xfs_ilock(ip, XFS_IOLOCK_EXCL);
-       error = xfs_itruncate_start(ip, XFS_ITRUNC_DEFINITE, (xfs_fsize_t)0);
-       if (error) {
-               xfs_iunlock(ip, XFS_IOLOCK_EXCL);
-               return error;
-       }
-
-       tp = xfs_trans_alloc(mp, XFS_TRANS_TRUNCATE_FILE);
-       if ((error = xfs_trans_reserve(tp, 0, XFS_ITRUNCATE_LOG_RES(mp), 0,
-                                     XFS_TRANS_PERM_LOG_RES,
-                                     XFS_ITRUNCATE_LOG_COUNT))) {
-               xfs_trans_cancel(tp, 0);
-               xfs_iunlock(ip, XFS_IOLOCK_EXCL);
-               return error;
-       }
-
-       /*
-        * Follow the normal truncate locking protocol.  Since we
-        * hold the inode in the transaction, we know that its number
-        * of references will stay constant.
-        */
-       xfs_ilock(ip, XFS_ILOCK_EXCL);
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
-       /*
-        * Signal a sync xaction.  The only case where that isn't
-        * the case is if we're truncating an already unlinked file
-        * on a wsync fs.  In that case, we know the blocks can't
-        * reappear in the file because the links to file are
-        * permanently toast.  Currently, we're always going to
-        * want a sync transaction because this code is being
-        * called from places where nlink is guaranteed to be 1
-        * but I'm leaving the tests in to protect against future
-        * changes -- rcc.
-        */
-       error = xfs_itruncate_finish(&tp, ip, (xfs_fsize_t)0,
-                                    XFS_DATA_FORK,
-                                    ((ip->i_d.di_nlink != 0 ||
-                                      !(mp->m_flags & XFS_MOUNT_WSYNC))
-                                     ? 1 : 0));
-       if (error) {
-               xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES |
-                                XFS_TRANS_ABORT);
-       } else {
-               xfs_ichgtime(ip, XFS_ICHGTIME_MOD | XFS_ICHGTIME_CHG);
-               error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
-       }
-       xfs_iunlock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-
-       return error;
-}
index ef321225d2698cfa2f5982d24099388d0cdae0eb..f55b9678264f0edc8edb23b9aff16bab44b8f355 100644 (file)
@@ -18,7 +18,6 @@
 #ifndef __XFS_UTILS_H__
 #define __XFS_UTILS_H__
 
-extern int xfs_truncate_file(xfs_mount_t *, xfs_inode_t *);
 extern int xfs_dir_ialloc(xfs_trans_t **, xfs_inode_t *, mode_t, xfs_nlink_t,
                                xfs_dev_t, cred_t *, prid_t, int,
                                xfs_inode_t **, int *);
index c1646838898f45120767046f0b62d43cca92dd54..3ac137dd531bb5481b5ec04ef085de3a6506878d 100644 (file)
 #include "xfs_sb.h"
 #include "xfs_ag.h"
 #include "xfs_dir2.h"
-#include "xfs_dmapi.h"
 #include "xfs_mount.h"
 #include "xfs_da_btree.h"
 #include "xfs_bmap_btree.h"
-#include "xfs_alloc_btree.h"
 #include "xfs_ialloc_btree.h"
-#include "xfs_dir2_sf.h"
-#include "xfs_attr_sf.h"
 #include "xfs_dinode.h"
 #include "xfs_inode.h"
 #include "xfs_inode_item.h"
 #include "xfs_itable.h"
-#include "xfs_btree.h"
 #include "xfs_ialloc.h"
 #include "xfs_alloc.h"
 #include "xfs_bmap.h"
@@ -73,7 +68,7 @@ xfs_setattr(
        struct xfs_dquot        *udqp, *gdqp, *olddquot1, *olddquot2;
        int                     need_iolock = 1;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_setattr(ip);
 
        if (mp->m_flags & XFS_MOUNT_RDONLY)
                return XFS_ERROR(EROFS);
@@ -143,16 +138,6 @@ xfs_setattr(
                        goto error_return;
                }
        } else {
-               if (DM_EVENT_ENABLED(ip, DM_EVENT_TRUNCATE) &&
-                   !(flags & XFS_ATTR_DMI)) {
-                       int dmflags = AT_DELAY_FLAG(flags) | DM_SEM_FLAG_WR;
-                       code = XFS_SEND_DATA(mp, DM_EVENT_TRUNCATE, ip,
-                               iattr->ia_size, 0, dmflags, NULL);
-                       if (code) {
-                               lock_flags = 0;
-                               goto error_return;
-                       }
-               }
                if (need_iolock)
                        lock_flags |= XFS_IOLOCK_EXCL;
        }
@@ -283,8 +268,7 @@ xfs_setattr(
                commit_flags = XFS_TRANS_RELEASE_LOG_RES;
                xfs_ilock(ip, XFS_ILOCK_EXCL);
 
-               xfs_trans_ijoin(tp, ip, lock_flags);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
 
                /*
                 * Only change the c/mtime if we are changing the size
@@ -334,8 +318,7 @@ xfs_setattr(
                        xfs_iflags_set(ip, XFS_ITRUNCATED);
                }
        } else if (tp) {
-               xfs_trans_ijoin(tp, ip, lock_flags);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
        }
 
        /*
@@ -470,17 +453,10 @@ xfs_setattr(
                        return XFS_ERROR(code);
        }
 
-       if (DM_EVENT_ENABLED(ip, DM_EVENT_ATTRIBUTE) &&
-           !(flags & XFS_ATTR_DMI)) {
-               (void) XFS_SEND_NAMESP(mp, DM_EVENT_ATTRIBUTE, ip, DM_RIGHT_NULL,
-                                       NULL, DM_RIGHT_NULL, NULL, NULL,
-                                       0, 0, AT_DELAY_FLAG(flags));
-       }
        return 0;
 
  abort_return:
        commit_flags |= XFS_TRANS_ABORT;
-       /* FALLTHROUGH */
  error_return:
        xfs_qm_dqrele(udqp);
        xfs_qm_dqrele(gdqp);
@@ -516,7 +492,7 @@ xfs_readlink_bmap(
        int             error = 0;
 
        error = xfs_bmapi(NULL, ip, 0, XFS_B_TO_FSB(mp, pathlen), 0, NULL, 0,
-                       mval, &nmaps, NULL, NULL);
+                       mval, &nmaps, NULL);
        if (error)
                goto out;
 
@@ -557,7 +533,7 @@ xfs_readlink(
        int             pathlen;
        int             error = 0;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_readlink(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -613,14 +589,14 @@ xfs_free_eofblocks(
         */
        end_fsb = XFS_B_TO_FSB(mp, ((xfs_ufsize_t)ip->i_size));
        last_fsb = XFS_B_TO_FSB(mp, (xfs_ufsize_t)XFS_MAXIOFFSET(mp));
-       map_len = last_fsb - end_fsb;
-       if (map_len <= 0)
+       if (last_fsb <= end_fsb)
                return 0;
+       map_len = last_fsb - end_fsb;
 
        nimaps = 1;
        xfs_ilock(ip, XFS_ILOCK_SHARED);
        error = xfs_bmapi(NULL, ip, end_fsb, map_len, 0,
-                         NULL, 0, &imap, &nimaps, NULL, NULL);
+                         NULL, 0, &imap, &nimaps, NULL);
        xfs_iunlock(ip, XFS_ILOCK_SHARED);
 
        if (!error && (nimaps != 0) &&
@@ -675,10 +651,7 @@ xfs_free_eofblocks(
                }
 
                xfs_ilock(ip, XFS_ILOCK_EXCL);
-               xfs_trans_ijoin(tp, ip,
-                               XFS_IOLOCK_EXCL |
-                               XFS_ILOCK_EXCL);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
 
                error = xfs_itruncate_finish(&tp, ip,
                                             ip->i_size,
@@ -750,8 +723,7 @@ xfs_inactive_symlink_rmt(
        xfs_ilock(ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
        size = (int)ip->i_d.di_size;
        ip->i_d.di_size = 0;
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
+       xfs_trans_ijoin(tp, ip);
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        /*
         * Find the block(s) so we can inval and unmap them.
@@ -761,7 +733,7 @@ xfs_inactive_symlink_rmt(
        nmaps = ARRAY_SIZE(mval);
        if ((error = xfs_bmapi(tp, ip, 0, XFS_B_TO_FSB(mp, size),
                        XFS_BMAPI_METADATA, &first_block, 0, mval, &nmaps,
-                       &free_list, NULL)))
+                       &free_list)))
                goto error0;
        /*
         * Invalidate the block(s).
@@ -776,7 +748,7 @@ xfs_inactive_symlink_rmt(
         * Unmap the dead block(s) to the free_list.
         */
        if ((error = xfs_bunmapi(tp, ip, 0, size, XFS_BMAPI_METADATA, nmaps,
-                       &first_block, &free_list, NULL, &done)))
+                       &first_block, &free_list, &done)))
                goto error1;
        ASSERT(done);
        /*
@@ -795,8 +767,7 @@ xfs_inactive_symlink_rmt(
         * Mark it dirty so it will be logged and moved forward in the log as
         * part of every commit.
         */
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
+       xfs_trans_ijoin(tp, ip);
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
        /*
         * Get a new, empty transaction to return to our caller.
@@ -929,8 +900,7 @@ xfs_inactive_attrs(
                goto error_cancel;
 
        xfs_ilock(ip, XFS_ILOCK_EXCL);
-       xfs_trans_ijoin(tp, ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
+       xfs_trans_ijoin(tp, ip);
        xfs_idestroy_fork(ip, XFS_ATTR_FORK);
 
        ASSERT(ip->i_d.di_anextents == 0);
@@ -1035,8 +1005,6 @@ xfs_inactive(
        int             error;
        int             truncate;
 
-       xfs_itrace_entry(ip);
-
        /*
         * If the inode is already free, then there can be nothing
         * to clean up here.
@@ -1060,9 +1028,6 @@ xfs_inactive(
 
        mp = ip->i_mount;
 
-       if (ip->i_d.di_nlink == 0 && DM_EVENT_ENABLED(ip, DM_EVENT_DESTROY))
-               XFS_SEND_DESTROY(mp, ip, DM_RIGHT_NULL);
-
        error = 0;
 
        /* If this is a read-only mount, don't do this (would generate I/O) */
@@ -1120,8 +1085,7 @@ xfs_inactive(
                }
 
                xfs_ilock(ip, XFS_ILOCK_EXCL);
-               xfs_trans_ijoin(tp, ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
 
                /*
                 * normally, we have to run xfs_itruncate_finish sync.
@@ -1154,8 +1118,7 @@ xfs_inactive(
                        return VN_INACTIVE_CACHE;
                }
 
-               xfs_trans_ijoin(tp, ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
        } else {
                error = xfs_trans_reserve(tp, 0,
                                          XFS_IFREE_LOG_RES(mp),
@@ -1168,8 +1131,7 @@ xfs_inactive(
                }
 
                xfs_ilock(ip, XFS_ILOCK_EXCL | XFS_IOLOCK_EXCL);
-               xfs_trans_ijoin(tp, ip, XFS_IOLOCK_EXCL | XFS_ILOCK_EXCL);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
        }
 
        /*
@@ -1257,7 +1219,7 @@ xfs_lookup(
        int                     error;
        uint                    lock_mode;
 
-       xfs_itrace_entry(dp);
+       trace_xfs_lookup(dp, name);
 
        if (XFS_FORCED_SHUTDOWN(dp->i_mount))
                return XFS_ERROR(EIO);
@@ -1309,21 +1271,11 @@ xfs_create(
        uint                    log_res;
        uint                    log_count;
 
-       xfs_itrace_entry(dp);
+       trace_xfs_create(dp, name);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
-       if (DM_EVENT_ENABLED(dp, DM_EVENT_CREATE)) {
-               error = XFS_SEND_NAMESP(mp, DM_EVENT_CREATE,
-                               dp, DM_RIGHT_NULL, NULL,
-                               DM_RIGHT_NULL, name->name, NULL,
-                               mode, 0, 0);
-
-               if (error)
-                       return error;
-       }
-
        if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
                prid = dp->i_d.di_projid;
        else
@@ -1427,8 +1379,7 @@ xfs_create(
         * the transaction cancel unlocking dp so don't do it explicitly in the
         * error path.
         */
-       IHOLD(dp);
-       xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, dp, XFS_ILOCK_EXCL);
        unlock_dp_on_error = B_FALSE;
 
        error = xfs_dir_createname(tp, dp, name, ip->i_ino,
@@ -1487,16 +1438,7 @@ xfs_create(
        xfs_qm_dqrele(gdqp);
 
        *ipp = ip;
-
-       /* Fallthrough to std_return with error = 0  */
- std_return:
-       if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTCREATE)) {
-               XFS_SEND_NAMESP(mp, DM_EVENT_POSTCREATE, dp, DM_RIGHT_NULL,
-                               ip, DM_RIGHT_NULL, name->name, NULL, mode,
-                               error, 0);
-       }
-
-       return error;
+       return 0;
 
  out_bmap_cancel:
        xfs_bmap_cancel(&free_list);
@@ -1510,8 +1452,8 @@ xfs_create(
 
        if (unlock_dp_on_error)
                xfs_iunlock(dp, XFS_ILOCK_EXCL);
-
-       goto std_return;
+ std_return:
+       return error;
 
  out_abort_rele:
        /*
@@ -1726,20 +1668,11 @@ xfs_remove(
        uint                    resblks;
        uint                    log_count;
 
-       xfs_itrace_entry(dp);
-       xfs_itrace_entry(ip);
+       trace_xfs_remove(dp, name);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
-       if (DM_EVENT_ENABLED(dp, DM_EVENT_REMOVE)) {
-               error = XFS_SEND_NAMESP(mp, DM_EVENT_REMOVE, dp, DM_RIGHT_NULL,
-                                       NULL, DM_RIGHT_NULL, name->name, NULL,
-                                       ip->i_d.di_mode, 0, 0);
-               if (error)
-                       return error;
-       }
-
        error = xfs_qm_dqattach(dp, 0);
        if (error)
                goto std_return;
@@ -1782,15 +1715,8 @@ xfs_remove(
 
        xfs_lock_two_inodes(dp, ip, XFS_ILOCK_EXCL);
 
-       /*
-        * At this point, we've gotten both the directory and the entry
-        * inodes locked.
-        */
-       IHOLD(ip);
-       xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
-
-       IHOLD(dp);
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, dp, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, ip, XFS_ILOCK_EXCL);
 
        /*
         * If we're removing a directory perform some additional validation.
@@ -1877,21 +1803,15 @@ xfs_remove(
        if (!is_dir && link_zero && xfs_inode_is_filestream(ip))
                xfs_filestream_deassociate(ip);
 
- std_return:
-       if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTREMOVE)) {
-               XFS_SEND_NAMESP(mp, DM_EVENT_POSTREMOVE, dp, DM_RIGHT_NULL,
-                               NULL, DM_RIGHT_NULL, name->name, NULL,
-                               ip->i_d.di_mode, error, 0);
-       }
-
-       return error;
+       return 0;
 
  out_bmap_cancel:
        xfs_bmap_cancel(&free_list);
        cancel_flags |= XFS_TRANS_ABORT;
  out_trans_cancel:
        xfs_trans_cancel(tp, cancel_flags);
-       goto std_return;
+ std_return:
+       return error;
 }
 
 int
@@ -1909,25 +1829,13 @@ xfs_link(
        int                     committed;
        int                     resblks;
 
-       xfs_itrace_entry(tdp);
-       xfs_itrace_entry(sip);
+       trace_xfs_link(tdp, target_name);
 
        ASSERT(!S_ISDIR(sip->i_d.di_mode));
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
 
-       if (DM_EVENT_ENABLED(tdp, DM_EVENT_LINK)) {
-               error = XFS_SEND_NAMESP(mp, DM_EVENT_LINK,
-                                       tdp, DM_RIGHT_NULL,
-                                       sip, DM_RIGHT_NULL,
-                                       target_name->name, NULL, 0, 0, 0);
-               if (error)
-                       return error;
-       }
-
-       /* Return through std_return after this point. */
-
        error = xfs_qm_dqattach(sip, 0);
        if (error)
                goto std_return;
@@ -1953,15 +1861,8 @@ xfs_link(
 
        xfs_lock_two_inodes(sip, tdp, XFS_ILOCK_EXCL);
 
-       /*
-        * Increment vnode ref counts since xfs_trans_commit &
-        * xfs_trans_cancel will both unlock the inodes and
-        * decrement the associated ref counts.
-        */
-       IHOLD(sip);
-       IHOLD(tdp);
-       xfs_trans_ijoin(tp, sip, XFS_ILOCK_EXCL);
-       xfs_trans_ijoin(tp, tdp, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, sip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, tdp, XFS_ILOCK_EXCL);
 
        /*
         * If the source has too many links, we can't make any more to it.
@@ -2014,27 +1915,14 @@ xfs_link(
                goto abort_return;
        }
 
-       error = xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
-       if (error)
-               goto std_return;
-
-       /* Fall through to std_return with error = 0. */
-std_return:
-       if (DM_EVENT_ENABLED(sip, DM_EVENT_POSTLINK)) {
-               (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTLINK,
-                               tdp, DM_RIGHT_NULL,
-                               sip, DM_RIGHT_NULL,
-                               target_name->name, NULL, 0, error, 0);
-       }
-       return error;
+       return xfs_trans_commit(tp, XFS_TRANS_RELEASE_LOG_RES);
 
  abort_return:
        cancel_flags |= XFS_TRANS_ABORT;
-       /* FALLTHROUGH */
-
  error_return:
        xfs_trans_cancel(tp, cancel_flags);
-       goto std_return;
+ std_return:
+       return error;
 }
 
 int
@@ -2074,7 +1962,7 @@ xfs_symlink(
        ip = NULL;
        tp = NULL;
 
-       xfs_itrace_entry(dp);
+       trace_xfs_symlink(dp, link_name);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -2086,17 +1974,6 @@ xfs_symlink(
        if (pathlen >= MAXPATHLEN)      /* total string too long */
                return XFS_ERROR(ENAMETOOLONG);
 
-       if (DM_EVENT_ENABLED(dp, DM_EVENT_SYMLINK)) {
-               error = XFS_SEND_NAMESP(mp, DM_EVENT_SYMLINK, dp,
-                                       DM_RIGHT_NULL, NULL, DM_RIGHT_NULL,
-                                       link_name->name,
-                                       (unsigned char *)target_path, 0, 0, 0);
-               if (error)
-                       return error;
-       }
-
-       /* Return through std_return after this point. */
-
        udqp = gdqp = NULL;
        if (dp->i_d.di_flags & XFS_DIFLAG_PROJINHERIT)
                prid = dp->i_d.di_projid;
@@ -2180,8 +2057,7 @@ xfs_symlink(
         * transaction cancel unlocking dp so don't do it explicitly in the
         * error path.
         */
-       IHOLD(dp);
-       xfs_trans_ijoin(tp, dp, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, dp, XFS_ILOCK_EXCL);
        unlock_dp_on_error = B_FALSE;
 
        /*
@@ -2215,7 +2091,7 @@ xfs_symlink(
                error = xfs_bmapi(tp, ip, first_fsb, fs_blocks,
                                  XFS_BMAPI_WRITE | XFS_BMAPI_METADATA,
                                  &first_block, resblks, mval, &nmaps,
-                                 &free_list, NULL);
+                                 &free_list);
                if (error) {
                        goto error1;
                }
@@ -2278,21 +2154,8 @@ xfs_symlink(
        xfs_qm_dqrele(udqp);
        xfs_qm_dqrele(gdqp);
 
-       /* Fall through to std_return with error = 0 or errno from
-        * xfs_trans_commit     */
-std_return:
-       if (DM_EVENT_ENABLED(dp, DM_EVENT_POSTSYMLINK)) {
-               (void) XFS_SEND_NAMESP(mp, DM_EVENT_POSTSYMLINK,
-                                       dp, DM_RIGHT_NULL,
-                                       error ? NULL : ip,
-                                       DM_RIGHT_NULL, link_name->name,
-                                       (unsigned char *)target_path,
-                                       0, error, 0);
-       }
-
-       if (!error)
-               *ipp = ip;
-       return error;
+       *ipp = ip;
+       return 0;
 
  error2:
        IRELE(ip);
@@ -2306,8 +2169,8 @@ std_return:
 
        if (unlock_dp_on_error)
                xfs_iunlock(dp, XFS_ILOCK_EXCL);
-
-       goto std_return;
+ std_return:
+       return error;
 }
 
 int
@@ -2333,13 +2196,12 @@ xfs_set_dmattrs(
                return error;
        }
        xfs_ilock(ip, XFS_ILOCK_EXCL);
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
+       xfs_trans_ijoin_ref(tp, ip, XFS_ILOCK_EXCL);
 
        ip->i_d.di_dmevmask = evmask;
        ip->i_d.di_dmstate  = state;
 
        xfs_trans_log_inode(tp, ip, XFS_ILOG_CORE);
-       IHOLD(ip);
        error = xfs_trans_commit(tp, 0);
 
        return error;
@@ -2390,7 +2252,7 @@ xfs_alloc_file_space(
        int                     committed;
        int                     error;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_alloc_file_space(ip);
 
        if (XFS_FORCED_SHUTDOWN(mp))
                return XFS_ERROR(EIO);
@@ -2412,25 +2274,9 @@ xfs_alloc_file_space(
        startoffset_fsb = XFS_B_TO_FSBT(mp, offset);
        allocatesize_fsb = XFS_B_TO_FSB(mp, count);
 
-       /*      Generate a DMAPI event if needed.       */
-       if (alloc_type != 0 && offset < ip->i_size &&
-                       (attr_flags & XFS_ATTR_DMI) == 0  &&
-                       DM_EVENT_ENABLED(ip, DM_EVENT_WRITE)) {
-               xfs_off_t           end_dmi_offset;
-
-               end_dmi_offset = offset+len;
-               if (end_dmi_offset > ip->i_size)
-                       end_dmi_offset = ip->i_size;
-               error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip, offset,
-                                     end_dmi_offset - offset, 0, NULL);
-               if (error)
-                       return error;
-       }
-
        /*
         * Allocate file space until done or until there is an error
         */
-retry:
        while (allocatesize_fsb && !error) {
                xfs_fileoff_t   s, e;
 
@@ -2488,8 +2334,7 @@ retry:
                if (error)
                        goto error1;
 
-               xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
 
                /*
                 * Issue the xfs_bmapi() call to allocate the blocks
@@ -2498,7 +2343,7 @@ retry:
                error = xfs_bmapi(tp, ip, startoffset_fsb,
                                  allocatesize_fsb, bmapi_flag,
                                  &firstfsb, 0, imapp, &nimaps,
-                                 &free_list, NULL);
+                                 &free_list);
                if (error) {
                        goto error0;
                }
@@ -2527,17 +2372,6 @@ retry:
                startoffset_fsb += allocated_fsb;
                allocatesize_fsb -= allocated_fsb;
        }
-dmapi_enospc_check:
-       if (error == ENOSPC && (attr_flags & XFS_ATTR_DMI) == 0 &&
-           DM_EVENT_ENABLED(ip, DM_EVENT_NOSPACE)) {
-               error = XFS_SEND_NAMESP(mp, DM_EVENT_NOSPACE,
-                               ip, DM_RIGHT_NULL,
-                               ip, DM_RIGHT_NULL,
-                               NULL, NULL, 0, 0, 0); /* Delay flag intentionally unused */
-               if (error == 0)
-                       goto retry;     /* Maybe DMAPI app. has made space */
-               /* else fall through with error from XFS_SEND_DATA */
-       }
 
        return error;
 
@@ -2548,7 +2382,7 @@ error0:   /* Cancel bmap, unlock inode, unreserve quota blocks, cancel trans */
 error1:        /* Just cancel transaction */
        xfs_trans_cancel(tp, XFS_TRANS_RELEASE_LOG_RES | XFS_TRANS_ABORT);
        xfs_iunlock(ip, XFS_ILOCK_EXCL);
-       goto dmapi_enospc_check;
+       return error;
 }
 
 /*
@@ -2598,7 +2432,7 @@ xfs_zero_remaining_bytes(
                offset_fsb = XFS_B_TO_FSBT(mp, offset);
                nimap = 1;
                error = xfs_bmapi(NULL, ip, offset_fsb, 1, 0,
-                       NULL, 0, &imap, &nimap, NULL, NULL);
+                       NULL, 0, &imap, &nimap, NULL);
                if (error || nimap < 1)
                        break;
                ASSERT(imap.br_blockcount >= 1);
@@ -2661,7 +2495,6 @@ xfs_free_file_space(
 {
        int                     committed;
        int                     done;
-       xfs_off_t               end_dmi_offset;
        xfs_fileoff_t           endoffset_fsb;
        int                     error;
        xfs_fsblock_t           firstfsb;
@@ -2680,7 +2513,7 @@ xfs_free_file_space(
 
        mp = ip->i_mount;
 
-       xfs_itrace_entry(ip);
+       trace_xfs_free_file_space(ip);
 
        error = xfs_qm_dqattach(ip, 0);
        if (error)
@@ -2691,19 +2524,7 @@ xfs_free_file_space(
                return error;
        rt = XFS_IS_REALTIME_INODE(ip);
        startoffset_fsb = XFS_B_TO_FSB(mp, offset);
-       end_dmi_offset = offset + len;
-       endoffset_fsb = XFS_B_TO_FSBT(mp, end_dmi_offset);
-
-       if (offset < ip->i_size && (attr_flags & XFS_ATTR_DMI) == 0 &&
-           DM_EVENT_ENABLED(ip, DM_EVENT_WRITE)) {
-               if (end_dmi_offset > ip->i_size)
-                       end_dmi_offset = ip->i_size;
-               error = XFS_SEND_DATA(mp, DM_EVENT_WRITE, ip,
-                               offset, end_dmi_offset - offset,
-                               AT_DELAY_FLAG(attr_flags), NULL);
-               if (error)
-                       return error;
-       }
+       endoffset_fsb = XFS_B_TO_FSBT(mp, offset + len);
 
        if (attr_flags & XFS_ATTR_NOLOCK)
                need_iolock = 0;
@@ -2731,7 +2552,7 @@ xfs_free_file_space(
        if (rt && !xfs_sb_version_hasextflgbit(&mp->m_sb)) {
                nimap = 1;
                error = xfs_bmapi(NULL, ip, startoffset_fsb,
-                       1, 0, NULL, 0, &imap, &nimap, NULL, NULL);
+                       1, 0, NULL, 0, &imap, &nimap, NULL);
                if (error)
                        goto out_unlock_iolock;
                ASSERT(nimap == 0 || nimap == 1);
@@ -2746,7 +2567,7 @@ xfs_free_file_space(
                }
                nimap = 1;
                error = xfs_bmapi(NULL, ip, endoffset_fsb - 1,
-                       1, 0, NULL, 0, &imap, &nimap, NULL, NULL);
+                       1, 0, NULL, 0, &imap, &nimap, NULL);
                if (error)
                        goto out_unlock_iolock;
                ASSERT(nimap == 0 || nimap == 1);
@@ -2814,8 +2635,7 @@ xfs_free_file_space(
                if (error)
                        goto error1;
 
-               xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-               xfs_trans_ihold(tp, ip);
+               xfs_trans_ijoin(tp, ip);
 
                /*
                 * issue the bunmapi() call to free the blocks
@@ -2823,7 +2643,7 @@ xfs_free_file_space(
                xfs_bmap_init(&free_list, &firstfsb);
                error = xfs_bunmapi(tp, ip, startoffset_fsb,
                                  endoffset_fsb - startoffset_fsb,
-                                 0, 2, &firstfsb, &free_list, NULL, &done);
+                                 0, 2, &firstfsb, &free_list, &done);
                if (error) {
                        goto error0;
                }
@@ -2883,8 +2703,6 @@ xfs_change_file_space(
        xfs_trans_t     *tp;
        struct iattr    iattr;
 
-       xfs_itrace_entry(ip);
-
        if (!S_ISREG(ip->i_d.di_mode))
                return XFS_ERROR(EINVAL);
 
@@ -2985,8 +2803,7 @@ xfs_change_file_space(
 
        xfs_ilock(ip, XFS_ILOCK_EXCL);
 
-       xfs_trans_ijoin(tp, ip, XFS_ILOCK_EXCL);
-       xfs_trans_ihold(tp, ip);
+       xfs_trans_ijoin(tp, ip);
 
        if ((attr_flags & XFS_ATTR_DMI) == 0) {
                ip->i_d.di_mode &= ~S_ISUID;
index 8b1038607831360ed621ddb5542c9f686338758e..b0c1740124365979f9e6e50a0671bf217206bdda 100644 (file)
 #ifndef ASMARM_AMBA_H
 #define ASMARM_AMBA_H
 
+#include <linux/clk.h>
 #include <linux/device.h>
+#include <linux/err.h>
 #include <linux/resource.h>
 
 #define AMBA_NR_IRQS   2
 
+struct clk;
+
 struct amba_device {
        struct device           dev;
        struct resource         res;
+       struct clk              *pclk;
        u64                     dma_mask;
        unsigned int            periphid;
        unsigned int            irq[AMBA_NR_IRQS];
@@ -59,6 +64,12 @@ struct amba_device *amba_find_device(const char *, struct device *, unsigned int
 int amba_request_regions(struct amba_device *, const char *);
 void amba_release_regions(struct amba_device *);
 
+#define amba_pclk_enable(d)    \
+       (IS_ERR((d)->pclk) ? 0 : clk_enable((d)->pclk))
+
+#define amba_pclk_disable(d)   \
+       do { if (!IS_ERR((d)->pclk)) clk_disable((d)->pclk); } while (0)
+
 #define amba_config(d) (((d)->periphid >> 24) & 0xff)
 #define amba_rev(d)    (((d)->periphid >> 20) & 0x0f)
 #define amba_manf(d)   (((d)->periphid >> 12) & 0xff)
index 7e466fe72025e26fb9fde46fe91202f5768d9a3d..ca84ce70d5d5fca84b7de66533ba06cab54e5298 100644 (file)
  * @ocr_mask: available voltages on the 4 pins from the block, this
  * is ignored if a regulator is used, see the MMC_VDD_* masks in
  * mmc/host.h
- * @translate_vdd: a callback function to translate a MMC_VDD_*
- * mask into a value to be binary or:ed and written into the
- * MMCIPWR register of the block
+ * @vdd_handler: a callback function to translate a MMC_VDD_*
+ * mask into a value to be binary (or set some other custom bits
+ * in MMCIPWR) or:ed and written into the MMCIPWR register of the
+ * block.  May also control external power based on the power_mode.
  * @status: if no GPIO read function was given to the block in
  * gpio_wp (below) this function will be called to determine
  * whether a card is present in the MMC slot or not
@@ -29,7 +30,8 @@
 struct mmci_platform_data {
        unsigned int f_max;
        unsigned int ocr_mask;
-       u32 (*translate_vdd)(struct device *, unsigned int);
+       u32 (*vdd_handler)(struct device *, unsigned int vdd,
+                          unsigned char power_mode);
        unsigned int (*status)(struct device *);
        int     gpio_wp;
        int     gpio_cd;
index 5a5a7fd62490ca34fe27baa952f48de8831d8197..e1b634b635f2a3df5e8a0787c76ea371ae9d8f1a 100644 (file)
 #define UART01x_FR             0x18    /* Flag register (Read only). */
 #define UART010_IIR            0x1C    /* Interrupt indentification register (Read). */
 #define UART010_ICR            0x1C    /* Interrupt clear register (Write). */
+#define ST_UART011_LCRH_RX     0x1C    /* Rx line control register. */
 #define UART01x_ILPR           0x20    /* IrDA low power counter register. */
 #define UART011_IBRD           0x24    /* Integer baud rate divisor register. */
 #define UART011_FBRD           0x28    /* Fractional baud rate divisor register. */
 #define UART011_LCRH           0x2c    /* Line control register. */
+#define ST_UART011_LCRH_TX     0x2c    /* Tx Line control register. */
 #define UART011_CR             0x30    /* Control register. */
 #define UART011_IFLS           0x34    /* Interrupt fifo level select. */
 #define UART011_IMSC           0x38    /* Interrupt mask. */
@@ -84,6 +86,7 @@
 #define UART010_CR_TIE                 0x0020
 #define UART010_CR_RIE                 0x0010
 #define UART010_CR_MSIE                0x0008
+#define ST_UART011_CR_OVSFACT  0x0008  /* Oversampling factor */
 #define UART01x_CR_IIRLP       0x0004  /* SIR low power mode */
 #define UART01x_CR_SIREN       0x0002  /* SIR enable */
 #define UART01x_CR_UARTEN      0x0001  /* UART enable */
index 39e5ff512fbeab16280345eb3e54beb78e8ed0e7..90012b9ddbf3e5f999983bf7d2f6e388a99d25a1 100644 (file)
@@ -49,9 +49,6 @@ typedef struct __user_cap_data_struct {
 } __user *cap_user_data_t;
 
 
-#define XATTR_CAPS_SUFFIX "capability"
-#define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
-
 #define VFS_CAP_REVISION_MASK  0xFF000000
 #define VFS_CAP_REVISION_SHIFT 24
 #define VFS_CAP_FLAGS_MASK     ~VFS_CAP_REVISION_MASK
index 68ca1b0491af42051bb6e93f424b3741c1ed7278..e5106e49bd2ccce31cad95a2fe5f30efb5233dae 100644 (file)
@@ -53,6 +53,7 @@ struct inodes_stat_t {
 #define MAY_APPEND 8
 #define MAY_ACCESS 16
 #define MAY_OPEN 32
+#define MAY_CHDIR 64
 
 /*
  * flags in file.f_mode.  Note that FMODE_READ and FMODE_WRITE must correspond
@@ -415,7 +416,8 @@ struct buffer_head;
 typedef int (get_block_t)(struct inode *inode, sector_t iblock,
                        struct buffer_head *bh_result, int create);
 typedef void (dio_iodone_t)(struct kiocb *iocb, loff_t offset,
-                       ssize_t bytes, void *private);
+                       ssize_t bytes, void *private, int ret,
+                       bool is_async);
 
 /*
  * Attribute flags.  These should be or-ed together to figure out what
index 6907251d52003c64434d33d1c4f9f691e6fb1419..112a55033352bbaaf79e045f9367edd3f45f5b1e 100644 (file)
@@ -90,9 +90,41 @@ struct common_audit_data {
                        u32 requested;
                        u32 audited;
                        u32 denied;
+                       /*
+                        * auditdeny is a bit tricky and unintuitive.  See the
+                        * comments in avc.c for it's meaning and usage.
+                        */
+                       u32 auditdeny;
                        struct av_decision *avd;
                        int result;
                } selinux_audit_data;
+#endif
+#ifdef CONFIG_SECURITY_APPARMOR
+               struct {
+                       int error;
+                       int op;
+                       int type;
+                       void *profile;
+                       const char *name;
+                       const char *info;
+                       union {
+                               void *target;
+                               struct {
+                                       long pos;
+                                       void *target;
+                               } iface;
+                               struct {
+                                       int rlim;
+                                       unsigned long max;
+                               } rlim;
+                               struct {
+                                       const char *target;
+                                       u32 request;
+                                       u32 denied;
+                                       uid_t ouid;
+                               } fs;
+                       };
+               } apparmor_audit_data;
 #endif
        };
        /* these callback will be implemented by a specific LSM */
diff --git a/include/linux/marvell_phy.h b/include/linux/marvell_phy.h
new file mode 100644 (file)
index 0000000..2ed4fb8
--- /dev/null
@@ -0,0 +1,20 @@
+#ifndef _MARVELL_PHY_H
+#define _MARVELL_PHY_H
+
+/* Mask used for ID comparisons */
+#define MARVELL_PHY_ID_MASK            0xfffffff0
+
+/* Known PHY IDs */
+#define MARVELL_PHY_ID_88E1101         0x01410c60
+#define MARVELL_PHY_ID_88E1112         0x01410c90
+#define MARVELL_PHY_ID_88E1111         0x01410cc0
+#define MARVELL_PHY_ID_88E1118         0x01410e10
+#define MARVELL_PHY_ID_88E1121R                0x01410cb0
+#define MARVELL_PHY_ID_88E1145         0x01410cd0
+#define MARVELL_PHY_ID_88E1240         0x01410e30
+
+/* struct phy_device dev_flags definitions */
+#define MARVELL_PHY_M1145_FLAGS_RESISTANCE     0x00000001
+#define MARVELL_PHY_M1118_DNS323_LEDS          0x00000002
+
+#endif /* _MARVELL_PHY_H */
index 9bdd91486b49d94c42e9ac00efd29e1b282a53b5..7e4cd616bcb57c0e51358073873502c9c417c3ef 100644 (file)
@@ -253,7 +253,7 @@ struct omapfb_platform_data {
 /* in arch/arm/plat-omap/fb.c */
 extern void omapfb_set_platform_data(struct omapfb_platform_data *data);
 extern void omapfb_set_ctrl_platform_data(void *pdata);
-extern void omapfb_reserve_sdram(void);
+extern void omapfb_reserve_sdram_memblock(void);
 
 #endif
 
index 0c8819170463624c57f7c968771727eed1038691..723a93df756a1151d3344981bdf88756668e8456 100644 (file)
@@ -470,8 +470,6 @@ static inline void security_free_mnt_opts(struct security_mnt_opts *opts)
  * @path_truncate:
  *     Check permission before truncating a file.
  *     @path contains the path structure for the file.
- *     @length is the new length of the file.
- *     @time_attrs is the flags passed to do_truncate().
  *     Return 0 if permission is granted.
  * @inode_getattr:
  *     Check permission before obtaining file attributes.
@@ -1412,8 +1410,7 @@ struct security_operations {
        int (*path_rmdir) (struct path *dir, struct dentry *dentry);
        int (*path_mknod) (struct path *dir, struct dentry *dentry, int mode,
                           unsigned int dev);
-       int (*path_truncate) (struct path *path, loff_t length,
-                             unsigned int time_attrs);
+       int (*path_truncate) (struct path *path);
        int (*path_symlink) (struct path *dir, struct dentry *dentry,
                             const char *old_name);
        int (*path_link) (struct dentry *old_dentry, struct path *new_dir,
@@ -2806,8 +2803,7 @@ int security_path_mkdir(struct path *dir, struct dentry *dentry, int mode);
 int security_path_rmdir(struct path *dir, struct dentry *dentry);
 int security_path_mknod(struct path *dir, struct dentry *dentry, int mode,
                        unsigned int dev);
-int security_path_truncate(struct path *path, loff_t length,
-                          unsigned int time_attrs);
+int security_path_truncate(struct path *path);
 int security_path_symlink(struct path *dir, struct dentry *dentry,
                          const char *old_name);
 int security_path_link(struct dentry *old_dentry, struct path *new_dir,
@@ -2841,8 +2837,7 @@ static inline int security_path_mknod(struct path *dir, struct dentry *dentry,
        return 0;
 }
 
-static inline int security_path_truncate(struct path *path, loff_t length,
-                                        unsigned int time_attrs)
+static inline int security_path_truncate(struct path *path)
 {
        return 0;
 }
index 81a4e213c6cf9bd934792d0135836cc9ef8d4d36..8c0e349f4a6cb83f616f1d0046c1db7ab504d531 100644 (file)
@@ -23,6 +23,29 @@ extern int swiotlb_force;
 #define IO_TLB_SHIFT 11
 
 extern void swiotlb_init(int verbose);
+extern void swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose);
+
+/*
+ * Enumeration for sync targets
+ */
+enum dma_sync_target {
+       SYNC_FOR_CPU = 0,
+       SYNC_FOR_DEVICE = 1,
+};
+extern void *swiotlb_tbl_map_single(struct device *hwdev, dma_addr_t tbl_dma_addr,
+                                   phys_addr_t phys, size_t size,
+                                   enum dma_data_direction dir);
+
+extern void swiotlb_tbl_unmap_single(struct device *hwdev, char *dma_addr,
+                                    size_t size, enum dma_data_direction dir);
+
+extern void swiotlb_tbl_sync_single(struct device *hwdev, char *dma_addr,
+                                   size_t size, enum dma_data_direction dir,
+                                   enum dma_sync_target target);
+
+/* Accessory functions. */
+extern void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
+                          enum dma_data_direction dir);
 
 extern void
 *swiotlb_alloc_coherent(struct device *hwdev, size_t size,
@@ -42,11 +65,11 @@ extern void swiotlb_unmap_page(struct device *hwdev, dma_addr_t dev_addr,
 
 extern int
 swiotlb_map_sg(struct device *hwdev, struct scatterlist *sg, int nents,
-              int direction);
+              enum dma_data_direction dir);
 
 extern void
 swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sg, int nents,
-                int direction);
+                enum dma_data_direction dir);
 
 extern int
 swiotlb_map_sg_attrs(struct device *hwdev, struct scatterlist *sgl, int nelems,
index 5cf11765146b11ce43017e702832b4746c7ed87b..395c38a47adbbe4317cc57a44bf99b9daf08d5d9 100644 (file)
@@ -4,6 +4,7 @@
  * compatible drivers/servers. */
 #include <linux/virtio_ids.h>
 #include <linux/virtio_config.h>
+#include <linux/types.h>
 
 /* The feature bitmap for virtio 9P */
 
index 0cfa1e9c4cc152239895304d67c6d1500cff7044..f1e5bde4b35acbab2a0a5a525d59dde6e017cc61 100644 (file)
 #define XATTR_USER_PREFIX "user."
 #define XATTR_USER_PREFIX_LEN (sizeof (XATTR_USER_PREFIX) - 1)
 
+/* Security namespace */
+#define XATTR_SELINUX_SUFFIX "selinux"
+#define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX
+
+#define XATTR_SMACK_SUFFIX "SMACK64"
+#define XATTR_SMACK_IPIN "SMACK64IPIN"
+#define XATTR_SMACK_IPOUT "SMACK64IPOUT"
+#define XATTR_NAME_SMACK XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
+#define XATTR_NAME_SMACKIPIN   XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
+#define XATTR_NAME_SMACKIPOUT  XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
+
+#define XATTR_CAPS_SUFFIX "capability"
+#define XATTR_NAME_CAPS XATTR_SECURITY_PREFIX XATTR_CAPS_SUFFIX
+
 struct inode;
 struct dentry;
 
index 156c26bb8bd7d0f71057b0ec5d6f3802e4792054..a8de812ccbc8c68f15c0c434fdf5b70edcab707d 100644 (file)
@@ -88,8 +88,16 @@ do { \
  * enum p9_msg_t - 9P message types
  * @P9_TSTATFS: file system status request
  * @P9_RSTATFS: file system status response
+ * @P9_TSYMLINK: make symlink request
+ * @P9_RSYMLINK: make symlink response
+ * @P9_TMKNOD: create a special file object request
+ * @P9_RMKNOD: create a special file object response
+ * @P9_TLCREATE: prepare a handle for I/O on an new file for 9P2000.L
+ * @P9_RLCREATE: response with file access information for 9P2000.L
  * @P9_TRENAME: rename request
  * @P9_RRENAME: rename response
+ * @P9_TMKDIR: create a directory request
+ * @P9_RMKDIR: create a directory response
  * @P9_TVERSION: version handshake request
  * @P9_RVERSION: version handshake response
  * @P9_TAUTH: request to establish authentication channel
@@ -131,8 +139,30 @@ do { \
 enum p9_msg_t {
        P9_TSTATFS = 8,
        P9_RSTATFS,
+       P9_TLOPEN = 12,
+       P9_RLOPEN,
+       P9_TLCREATE = 14,
+       P9_RLCREATE,
+       P9_TSYMLINK = 16,
+       P9_RSYMLINK,
+       P9_TMKNOD = 18,
+       P9_RMKNOD,
        P9_TRENAME = 20,
        P9_RRENAME,
+       P9_TGETATTR = 24,
+       P9_RGETATTR,
+       P9_TSETATTR = 26,
+       P9_RSETATTR,
+       P9_TXATTRWALK = 30,
+       P9_RXATTRWALK,
+       P9_TXATTRCREATE = 32,
+       P9_RXATTRCREATE,
+       P9_TREADDIR = 40,
+       P9_RREADDIR,
+       P9_TLINK = 70,
+       P9_RLINK,
+       P9_TMKDIR = 72,
+       P9_RMKDIR,
        P9_TVERSION = 100,
        P9_RVERSION,
        P9_TAUTH = 102,
@@ -275,6 +305,9 @@ enum p9_qid_t {
 /* ample room for Twrite/Rread header */
 #define P9_IOHDRSZ     24
 
+/* Room for readdir header */
+#define P9_READDIRHDRSZ        24
+
 /**
  * struct p9_str - length prefixed string type
  * @len: length of the string
@@ -357,6 +390,74 @@ struct p9_wstat {
        u32 n_muid;             /* 9p2000.u extensions */
 };
 
+struct p9_stat_dotl {
+       u64 st_result_mask;
+       struct p9_qid qid;
+       u32 st_mode;
+       u32 st_uid;
+       u32 st_gid;
+       u64 st_nlink;
+       u64 st_rdev;
+       u64 st_size;
+       u64 st_blksize;
+       u64 st_blocks;
+       u64 st_atime_sec;
+       u64 st_atime_nsec;
+       u64 st_mtime_sec;
+       u64 st_mtime_nsec;
+       u64 st_ctime_sec;
+       u64 st_ctime_nsec;
+       u64 st_btime_sec;
+       u64 st_btime_nsec;
+       u64 st_gen;
+       u64 st_data_version;
+};
+
+#define P9_STATS_MODE          0x00000001ULL
+#define P9_STATS_NLINK         0x00000002ULL
+#define P9_STATS_UID           0x00000004ULL
+#define P9_STATS_GID           0x00000008ULL
+#define P9_STATS_RDEV          0x00000010ULL
+#define P9_STATS_ATIME         0x00000020ULL
+#define P9_STATS_MTIME         0x00000040ULL
+#define P9_STATS_CTIME         0x00000080ULL
+#define P9_STATS_INO           0x00000100ULL
+#define P9_STATS_SIZE          0x00000200ULL
+#define P9_STATS_BLOCKS                0x00000400ULL
+
+#define P9_STATS_BTIME         0x00000800ULL
+#define P9_STATS_GEN           0x00001000ULL
+#define P9_STATS_DATA_VERSION  0x00002000ULL
+
+#define P9_STATS_BASIC         0x000007ffULL /* Mask for fields up to BLOCKS */
+#define P9_STATS_ALL           0x00003fffULL /* Mask for All fields above */
+
+/**
+ * struct p9_iattr_dotl - P9 inode attribute for setattr
+ * @valid: bitfield specifying which fields are valid
+ *         same as in struct iattr
+ * @mode: File permission bits
+ * @uid: user id of owner
+ * @gid: group id
+ * @size: File size
+ * @atime_sec: Last access time, seconds
+ * @atime_nsec: Last access time, nanoseconds
+ * @mtime_sec: Last modification time, seconds
+ * @mtime_nsec: Last modification time, nanoseconds
+ */
+
+struct p9_iattr_dotl {
+       u32 valid;
+       u32 mode;
+       u32 uid;
+       u32 gid;
+       u64 size;
+       u64 atime_sec;
+       u64 atime_nsec;
+       u64 mtime_sec;
+       u64 mtime_nsec;
+};
+
 /* Structures for Protocol Operations */
 struct p9_tstatfs {
        u32 fid;
@@ -485,6 +586,18 @@ struct p9_rwrite {
        u32 count;
 };
 
+struct p9_treaddir {
+       u32 fid;
+       u64 offset;
+       u32 count;
+};
+
+struct p9_rreaddir {
+       u32 count;
+       u8 *data;
+};
+
+
 struct p9_tclunk {
        u32 fid;
 };
index 7dd3ed85c782a928c42cecf878bb3e7bea8f4462..d1aa2cfb30f0f46b915e55118a29e7a8e91fe7e7 100644 (file)
@@ -195,6 +195,21 @@ struct p9_fid {
        struct list_head dlist; /* list of all fids attached to a dentry */
 };
 
+/**
+ * struct p9_dirent - directory entry structure
+ * @qid: The p9 server qid for this dirent
+ * @d_off: offset to the next dirent
+ * @d_type: type of file
+ * @d_name: file name
+ */
+
+struct p9_dirent {
+       struct p9_qid qid;
+       u64 d_off;
+       unsigned char d_type;
+       char d_name[256];
+};
+
 int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb);
 int p9_client_rename(struct p9_fid *fid, struct p9_fid *newdirfid, char *name);
 int p9_client_version(struct p9_client *);
@@ -211,15 +226,31 @@ struct p9_fid *p9_client_walk(struct p9_fid *oldfid, int nwname, char **wnames,
 int p9_client_open(struct p9_fid *fid, int mode);
 int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
                                                        char *extension);
+int p9_client_link(struct p9_fid *fid, struct p9_fid *oldfid, char *newname);
+int p9_client_symlink(struct p9_fid *fid, char *name, char *symname, gid_t gid,
+                                                       struct p9_qid *qid);
+int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode,
+               gid_t gid, struct p9_qid *qid);
 int p9_client_clunk(struct p9_fid *fid);
 int p9_client_remove(struct p9_fid *fid);
 int p9_client_read(struct p9_fid *fid, char *data, char __user *udata,
                                                        u64 offset, u32 count);
 int p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
                                                        u64 offset, u32 count);
+int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset);
+int p9dirent_read(char *buf, int len, struct p9_dirent *dirent,
+                                                       int proto_version);
 struct p9_wstat *p9_client_stat(struct p9_fid *fid);
 int p9_client_wstat(struct p9_fid *fid, struct p9_wstat *wst);
+int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *attr);
+
+struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid,
+                                                       u64 request_mask);
 
+int p9_client_mknod_dotl(struct p9_fid *oldfid, char *name, int mode,
+                       dev_t rdev, gid_t gid, struct p9_qid *);
+int p9_client_mkdir_dotl(struct p9_fid *fid, char *name, int mode,
+                               gid_t gid, struct p9_qid *);
 struct p9_req_t *p9_tag_lookup(struct p9_client *, u16);
 void p9_client_cb(struct p9_client *c, struct p9_req_t *req);
 
@@ -229,5 +260,7 @@ void p9stat_free(struct p9_wstat *);
 
 int p9_is_proto_dotu(struct p9_client *clnt);
 int p9_is_proto_dotl(struct p9_client *clnt);
+struct p9_fid *p9_client_xattrwalk(struct p9_fid *, const char *, u64 *);
+int p9_client_xattrcreate(struct p9_fid *, const char *, u64, int);
 
 #endif /* NET_9P_CLIENT_H */
index 250ed11d3ed2b83b8e2a87845fe97a7db096b33c..44524cc8c32a6ca179d67b8df91394c516ee6046 100644 (file)
@@ -114,7 +114,7 @@ static __init int test_atomic64(void)
        BUG_ON(v.counter != r);
 
 #if defined(CONFIG_X86) || defined(CONFIG_MIPS) || defined(CONFIG_PPC) || \
-    defined(CONFIG_S390) || defined(_ASM_GENERIC_ATOMIC64_H)
+    defined(CONFIG_S390) || defined(_ASM_GENERIC_ATOMIC64_H) || defined(CONFIG_ARM)
        INIT(onestwos);
        BUG_ON(atomic64_dec_if_positive(&v) != (onestwos - 1));
        r -= one;
index a009055140ecf7a798625d3fee7cd856c0bb8d4c..34e3082632d8311575e27c6d2a4b87c9985dd574 100644 (file)
  */
 #define IO_TLB_MIN_SLABS ((1<<20) >> IO_TLB_SHIFT)
 
-/*
- * Enumeration for sync targets
- */
-enum dma_sync_target {
-       SYNC_FOR_CPU = 0,
-       SYNC_FOR_DEVICE = 1,
-};
-
 int swiotlb_force;
 
 /*
- * Used to do a quick range check in unmap_single and
- * sync_single_*, to see if the memory was in fact allocated by this
+ * Used to do a quick range check in swiotlb_tbl_unmap_single and
+ * swiotlb_tbl_sync_single_*, to see if the memory was in fact allocated by this
  * API.
  */
 static char *io_tlb_start, *io_tlb_end;
@@ -140,28 +132,14 @@ void swiotlb_print_info(void)
               (unsigned long long)pend);
 }
 
-/*
- * Statically reserve bounce buffer space and initialize bounce buffer data
- * structures for the software IO TLB used to implement the DMA API.
- */
-void __init
-swiotlb_init_with_default_size(size_t default_size, int verbose)
+void __init swiotlb_init_with_tbl(char *tlb, unsigned long nslabs, int verbose)
 {
        unsigned long i, bytes;
 
-       if (!io_tlb_nslabs) {
-               io_tlb_nslabs = (default_size >> IO_TLB_SHIFT);
-               io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
-       }
-
-       bytes = io_tlb_nslabs << IO_TLB_SHIFT;
+       bytes = nslabs << IO_TLB_SHIFT;
 
-       /*
-        * Get IO TLB memory from the low pages
-        */
-       io_tlb_start = alloc_bootmem_low_pages(bytes);
-       if (!io_tlb_start)
-               panic("Cannot allocate SWIOTLB buffer");
+       io_tlb_nslabs = nslabs;
+       io_tlb_start = tlb;
        io_tlb_end = io_tlb_start + bytes;
 
        /*
@@ -185,6 +163,32 @@ swiotlb_init_with_default_size(size_t default_size, int verbose)
                swiotlb_print_info();
 }
 
+/*
+ * Statically reserve bounce buffer space and initialize bounce buffer data
+ * structures for the software IO TLB used to implement the DMA API.
+ */
+void __init
+swiotlb_init_with_default_size(size_t default_size, int verbose)
+{
+       unsigned long bytes;
+
+       if (!io_tlb_nslabs) {
+               io_tlb_nslabs = (default_size >> IO_TLB_SHIFT);
+               io_tlb_nslabs = ALIGN(io_tlb_nslabs, IO_TLB_SEGSIZE);
+       }
+
+       bytes = io_tlb_nslabs << IO_TLB_SHIFT;
+
+       /*
+        * Get IO TLB memory from the low pages
+        */
+       io_tlb_start = alloc_bootmem_low_pages(bytes);
+       if (!io_tlb_start)
+               panic("Cannot allocate SWIOTLB buffer");
+
+       swiotlb_init_with_tbl(io_tlb_start, io_tlb_nslabs, verbose);
+}
+
 void __init
 swiotlb_init(int verbose)
 {
@@ -323,8 +327,8 @@ static int is_swiotlb_buffer(phys_addr_t paddr)
 /*
  * Bounce: copy the swiotlb buffer back to the original dma location
  */
-static void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
-                          enum dma_data_direction dir)
+void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
+                   enum dma_data_direction dir)
 {
        unsigned long pfn = PFN_DOWN(phys);
 
@@ -360,26 +364,25 @@ static void swiotlb_bounce(phys_addr_t phys, char *dma_addr, size_t size,
                        memcpy(phys_to_virt(phys), dma_addr, size);
        }
 }
+EXPORT_SYMBOL_GPL(swiotlb_bounce);
 
-/*
- * Allocates bounce buffer and returns its kernel virtual address.
- */
-static void *
-map_single(struct device *hwdev, phys_addr_t phys, size_t size, int dir)
+void *swiotlb_tbl_map_single(struct device *hwdev, dma_addr_t tbl_dma_addr,
+                            phys_addr_t phys, size_t size,
+                            enum dma_data_direction dir)
 {
        unsigned long flags;
        char *dma_addr;
        unsigned int nslots, stride, index, wrap;
        int i;
-       unsigned long start_dma_addr;
        unsigned long mask;
        unsigned long offset_slots;
        unsigned long max_slots;
 
        mask = dma_get_seg_boundary(hwdev);
-       start_dma_addr = swiotlb_virt_to_bus(hwdev, io_tlb_start) & mask;
 
-       offset_slots = ALIGN(start_dma_addr, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
+       tbl_dma_addr &= mask;
+
+       offset_slots = ALIGN(tbl_dma_addr, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
 
        /*
         * Carefully handle integer overflow which can occur when mask == ~0UL.
@@ -466,12 +469,27 @@ found:
 
        return dma_addr;
 }
+EXPORT_SYMBOL_GPL(swiotlb_tbl_map_single);
+
+/*
+ * Allocates bounce buffer and returns its kernel virtual address.
+ */
+
+static void *
+map_single(struct device *hwdev, phys_addr_t phys, size_t size,
+          enum dma_data_direction dir)
+{
+       dma_addr_t start_dma_addr = swiotlb_virt_to_bus(hwdev, io_tlb_start);
+
+       return swiotlb_tbl_map_single(hwdev, start_dma_addr, phys, size, dir);
+}
 
 /*
  * dma_addr is the kernel virtual address of the bounce buffer to unmap.
  */
-static void
-do_unmap_single(struct device *hwdev, char *dma_addr, size_t size, int dir)
+void
+swiotlb_tbl_unmap_single(struct device *hwdev, char *dma_addr, size_t size,
+                       enum dma_data_direction dir)
 {
        unsigned long flags;
        int i, count, nslots = ALIGN(size, 1 << IO_TLB_SHIFT) >> IO_TLB_SHIFT;
@@ -509,10 +527,12 @@ do_unmap_single(struct device *hwdev, char *dma_addr, size_t size, int dir)
        }
        spin_unlock_irqrestore(&io_tlb_lock, flags);
 }
+EXPORT_SYMBOL_GPL(swiotlb_tbl_unmap_single);
 
-static void
-sync_single(struct device *hwdev, char *dma_addr, size_t size,
-           int dir, int target)
+void
+swiotlb_tbl_sync_single(struct device *hwdev, char *dma_addr, size_t size,
+                       enum dma_data_direction dir,
+                       enum dma_sync_target target)
 {
        int index = (dma_addr - io_tlb_start) >> IO_TLB_SHIFT;
        phys_addr_t phys = io_tlb_orig_addr[index];
@@ -536,6 +556,7 @@ sync_single(struct device *hwdev, char *dma_addr, size_t size,
                BUG();
        }
 }
+EXPORT_SYMBOL_GPL(swiotlb_tbl_sync_single);
 
 void *
 swiotlb_alloc_coherent(struct device *hwdev, size_t size,
@@ -559,8 +580,8 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size,
        }
        if (!ret) {
                /*
-                * We are either out of memory or the device can't DMA
-                * to GFP_DMA memory; fall back on map_single(), which
+                * We are either out of memory or the device can't DMA to
+                * GFP_DMA memory; fall back on map_single(), which
                 * will grab memory from the lowest available address range.
                 */
                ret = map_single(hwdev, 0, size, DMA_FROM_DEVICE);
@@ -578,7 +599,7 @@ swiotlb_alloc_coherent(struct device *hwdev, size_t size,
                       (unsigned long long)dev_addr);
 
                /* DMA_TO_DEVICE to avoid memcpy in unmap_single */
-               do_unmap_single(hwdev, ret, size, DMA_TO_DEVICE);
+               swiotlb_tbl_unmap_single(hwdev, ret, size, DMA_TO_DEVICE);
                return NULL;
        }
        *dma_handle = dev_addr;
@@ -596,13 +617,14 @@ swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
        if (!is_swiotlb_buffer(paddr))
                free_pages((unsigned long)vaddr, get_order(size));
        else
-               /* DMA_TO_DEVICE to avoid memcpy in unmap_single */
-               do_unmap_single(hwdev, vaddr, size, DMA_TO_DEVICE);
+               /* DMA_TO_DEVICE to avoid memcpy in swiotlb_tbl_unmap_single */
+               swiotlb_tbl_unmap_single(hwdev, vaddr, size, DMA_TO_DEVICE);
 }
 EXPORT_SYMBOL(swiotlb_free_coherent);
 
 static void
-swiotlb_full(struct device *dev, size_t size, int dir, int do_panic)
+swiotlb_full(struct device *dev, size_t size, enum dma_data_direction dir,
+            int do_panic)
 {
        /*
         * Ran out of IOMMU space for this operation. This is very bad.
@@ -680,14 +702,14 @@ EXPORT_SYMBOL_GPL(swiotlb_map_page);
  * whatever the device wrote there.
  */
 static void unmap_single(struct device *hwdev, dma_addr_t dev_addr,
-                        size_t size, int dir)
+                        size_t size, enum dma_data_direction dir)
 {
        phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
 
        BUG_ON(dir == DMA_NONE);
 
        if (is_swiotlb_buffer(paddr)) {
-               do_unmap_single(hwdev, phys_to_virt(paddr), size, dir);
+               swiotlb_tbl_unmap_single(hwdev, phys_to_virt(paddr), size, dir);
                return;
        }
 
@@ -723,14 +745,16 @@ EXPORT_SYMBOL_GPL(swiotlb_unmap_page);
  */
 static void
 swiotlb_sync_single(struct device *hwdev, dma_addr_t dev_addr,
-                   size_t size, int dir, int target)
+                   size_t size, enum dma_data_direction dir,
+                   enum dma_sync_target target)
 {
        phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
 
        BUG_ON(dir == DMA_NONE);
 
        if (is_swiotlb_buffer(paddr)) {
-               sync_single(hwdev, phys_to_virt(paddr), size, dir, target);
+               swiotlb_tbl_sync_single(hwdev, phys_to_virt(paddr), size, dir,
+                                      target);
                return;
        }
 
@@ -809,7 +833,7 @@ EXPORT_SYMBOL(swiotlb_map_sg_attrs);
 
 int
 swiotlb_map_sg(struct device *hwdev, struct scatterlist *sgl, int nelems,
-              int dir)
+              enum dma_data_direction dir)
 {
        return swiotlb_map_sg_attrs(hwdev, sgl, nelems, dir, NULL);
 }
@@ -836,7 +860,7 @@ EXPORT_SYMBOL(swiotlb_unmap_sg_attrs);
 
 void
 swiotlb_unmap_sg(struct device *hwdev, struct scatterlist *sgl, int nelems,
-                int dir)
+                enum dma_data_direction dir)
 {
        return swiotlb_unmap_sg_attrs(hwdev, sgl, nelems, dir, NULL);
 }
@@ -851,7 +875,8 @@ EXPORT_SYMBOL(swiotlb_unmap_sg);
  */
 static void
 swiotlb_sync_sg(struct device *hwdev, struct scatterlist *sgl,
-               int nelems, int dir, int target)
+               int nelems, enum dma_data_direction dir,
+               enum dma_sync_target target)
 {
        struct scatterlist *sg;
        int i;
index 37c8da07a80b080c6d93f9a2bdd1226873354af8..dc6f2f26d0230b1462ea1ea583c6fda5dc5b49c5 100644 (file)
@@ -460,7 +460,8 @@ static int p9_check_errors(struct p9_client *c, struct p9_req_t *req)
                        return err;
                }
 
-               if (p9_is_proto_dotu(c))
+               if (p9_is_proto_dotu(c) ||
+                       p9_is_proto_dotl(c))
                        err = -ecode;
 
                if (!err || !IS_ERR_VALUE(err))
@@ -1015,14 +1016,18 @@ int p9_client_open(struct p9_fid *fid, int mode)
        struct p9_qid qid;
        int iounit;
 
-       P9_DPRINTK(P9_DEBUG_9P, ">>> TOPEN fid %d mode %d\n", fid->fid, mode);
-       err = 0;
        clnt = fid->clnt;
+       P9_DPRINTK(P9_DEBUG_9P, ">>> %s fid %d mode %d\n",
+               p9_is_proto_dotl(clnt) ? "TLOPEN" : "TOPEN", fid->fid, mode);
+       err = 0;
 
        if (fid->mode != -1)
                return -EINVAL;
 
-       req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode);
+       if (p9_is_proto_dotl(clnt))
+               req = p9_client_rpc(clnt, P9_TLOPEN, "dd", fid->fid, mode);
+       else
+               req = p9_client_rpc(clnt, P9_TOPEN, "db", fid->fid, mode);
        if (IS_ERR(req)) {
                err = PTR_ERR(req);
                goto error;
@@ -1034,10 +1039,9 @@ int p9_client_open(struct p9_fid *fid, int mode)
                goto free_and_error;
        }
 
-       P9_DPRINTK(P9_DEBUG_9P, "<<< ROPEN qid %x.%llx.%x iounit %x\n",
-                               qid.type,
-                               (unsigned long long)qid.path,
-                               qid.version, iounit);
+       P9_DPRINTK(P9_DEBUG_9P, "<<< %s qid %x.%llx.%x iounit %x\n",
+               p9_is_proto_dotl(clnt) ? "RLOPEN" : "ROPEN",  qid.type,
+               (unsigned long long)qid.path, qid.version, iounit);
 
        fid->mode = mode;
        fid->iounit = iounit;
@@ -1049,6 +1053,50 @@ error:
 }
 EXPORT_SYMBOL(p9_client_open);
 
+int p9_client_create_dotl(struct p9_fid *ofid, char *name, u32 flags, u32 mode,
+               gid_t gid, struct p9_qid *qid)
+{
+       int err = 0;
+       struct p9_client *clnt;
+       struct p9_req_t *req;
+       int iounit;
+
+       P9_DPRINTK(P9_DEBUG_9P,
+                       ">>> TLCREATE fid %d name %s flags %d mode %d gid %d\n",
+                       ofid->fid, name, flags, mode, gid);
+       clnt = ofid->clnt;
+
+       if (ofid->mode != -1)
+               return -EINVAL;
+
+       req = p9_client_rpc(clnt, P9_TLCREATE, "dsddd", ofid->fid, name, flags,
+                       mode, gid);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+
+       err = p9pdu_readf(req->rc, clnt->proto_version, "Qd", qid, &iounit);
+       if (err) {
+               p9pdu_dump(1, req->rc);
+               goto free_and_error;
+       }
+
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RLCREATE qid %x.%llx.%x iounit %x\n",
+                       qid->type,
+                       (unsigned long long)qid->path,
+                       qid->version, iounit);
+
+       ofid->mode = mode;
+       ofid->iounit = iounit;
+
+free_and_error:
+       p9_free_req(clnt, req);
+error:
+       return err;
+}
+EXPORT_SYMBOL(p9_client_create_dotl);
+
 int p9_client_fcreate(struct p9_fid *fid, char *name, u32 perm, int mode,
                     char *extension)
 {
@@ -1094,6 +1142,59 @@ error:
 }
 EXPORT_SYMBOL(p9_client_fcreate);
 
+int p9_client_symlink(struct p9_fid *dfid, char *name, char *symtgt, gid_t gid,
+               struct p9_qid *qid)
+{
+       int err = 0;
+       struct p9_client *clnt;
+       struct p9_req_t *req;
+
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TSYMLINK dfid %d name %s  symtgt %s\n",
+                       dfid->fid, name, symtgt);
+       clnt = dfid->clnt;
+
+       req = p9_client_rpc(clnt, P9_TSYMLINK, "dssd", dfid->fid, name, symtgt,
+                       gid);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+
+       err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid);
+       if (err) {
+               p9pdu_dump(1, req->rc);
+               goto free_and_error;
+       }
+
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RSYMLINK qid %x.%llx.%x\n",
+                       qid->type, (unsigned long long)qid->path, qid->version);
+
+free_and_error:
+       p9_free_req(clnt, req);
+error:
+       return err;
+}
+EXPORT_SYMBOL(p9_client_symlink);
+
+int p9_client_link(struct p9_fid *dfid, struct p9_fid *oldfid, char *newname)
+{
+       struct p9_client *clnt;
+       struct p9_req_t *req;
+
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TLINK dfid %d oldfid %d newname %s\n",
+                       dfid->fid, oldfid->fid, newname);
+       clnt = dfid->clnt;
+       req = p9_client_rpc(clnt, P9_TLINK, "dds", dfid->fid, oldfid->fid,
+                       newname);
+       if (IS_ERR(req))
+               return PTR_ERR(req);
+
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RLINK\n");
+       p9_free_req(clnt, req);
+       return 0;
+}
+EXPORT_SYMBOL(p9_client_link);
+
 int p9_client_clunk(struct p9_fid *fid)
 {
        int err;
@@ -1139,9 +1240,8 @@ int p9_client_remove(struct p9_fid *fid)
        P9_DPRINTK(P9_DEBUG_9P, "<<< RREMOVE fid %d\n", fid->fid);
 
        p9_free_req(clnt, req);
-       p9_fid_destroy(fid);
-
 error:
+       p9_fid_destroy(fid);
        return err;
 }
 EXPORT_SYMBOL(p9_client_remove);
@@ -1302,6 +1402,65 @@ error:
 }
 EXPORT_SYMBOL(p9_client_stat);
 
+struct p9_stat_dotl *p9_client_getattr_dotl(struct p9_fid *fid,
+                                                       u64 request_mask)
+{
+       int err;
+       struct p9_client *clnt;
+       struct p9_stat_dotl *ret = kmalloc(sizeof(struct p9_stat_dotl),
+                                                               GFP_KERNEL);
+       struct p9_req_t *req;
+
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TGETATTR fid %d, request_mask %lld\n",
+                                                       fid->fid, request_mask);
+
+       if (!ret)
+               return ERR_PTR(-ENOMEM);
+
+       err = 0;
+       clnt = fid->clnt;
+
+       req = p9_client_rpc(clnt, P9_TGETATTR, "dq", fid->fid, request_mask);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+
+       err = p9pdu_readf(req->rc, clnt->proto_version, "A", ret);
+       if (err) {
+               p9pdu_dump(1, req->rc);
+               p9_free_req(clnt, req);
+               goto error;
+       }
+
+       P9_DPRINTK(P9_DEBUG_9P,
+               "<<< RGETATTR st_result_mask=%lld\n"
+               "<<< qid=%x.%llx.%x\n"
+               "<<< st_mode=%8.8x st_nlink=%llu\n"
+               "<<< st_uid=%d st_gid=%d\n"
+               "<<< st_rdev=%llx st_size=%llx st_blksize=%llu st_blocks=%llu\n"
+               "<<< st_atime_sec=%lld st_atime_nsec=%lld\n"
+               "<<< st_mtime_sec=%lld st_mtime_nsec=%lld\n"
+               "<<< st_ctime_sec=%lld st_ctime_nsec=%lld\n"
+               "<<< st_btime_sec=%lld st_btime_nsec=%lld\n"
+               "<<< st_gen=%lld st_data_version=%lld",
+               ret->st_result_mask, ret->qid.type, ret->qid.path,
+               ret->qid.version, ret->st_mode, ret->st_nlink, ret->st_uid,
+               ret->st_gid, ret->st_rdev, ret->st_size, ret->st_blksize,
+               ret->st_blocks, ret->st_atime_sec, ret->st_atime_nsec,
+               ret->st_mtime_sec, ret->st_mtime_nsec, ret->st_ctime_sec,
+               ret->st_ctime_nsec, ret->st_btime_sec, ret->st_btime_nsec,
+               ret->st_gen, ret->st_data_version);
+
+       p9_free_req(clnt, req);
+       return ret;
+
+error:
+       kfree(ret);
+       return ERR_PTR(err);
+}
+EXPORT_SYMBOL(p9_client_getattr_dotl);
+
 static int p9_client_statsize(struct p9_wstat *wst, int proto_version)
 {
        int ret;
@@ -1366,6 +1525,36 @@ error:
 }
 EXPORT_SYMBOL(p9_client_wstat);
 
+int p9_client_setattr(struct p9_fid *fid, struct p9_iattr_dotl *p9attr)
+{
+       int err;
+       struct p9_req_t *req;
+       struct p9_client *clnt;
+
+       err = 0;
+       clnt = fid->clnt;
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TSETATTR fid %d\n", fid->fid);
+       P9_DPRINTK(P9_DEBUG_9P,
+               "    valid=%x mode=%x uid=%d gid=%d size=%lld\n"
+               "    atime_sec=%lld atime_nsec=%lld\n"
+               "    mtime_sec=%lld mtime_nsec=%lld\n",
+               p9attr->valid, p9attr->mode, p9attr->uid, p9attr->gid,
+               p9attr->size, p9attr->atime_sec, p9attr->atime_nsec,
+               p9attr->mtime_sec, p9attr->mtime_nsec);
+
+       req = p9_client_rpc(clnt, P9_TSETATTR, "dI", fid->fid, p9attr);
+
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RSETATTR fid %d\n", fid->fid);
+       p9_free_req(clnt, req);
+error:
+       return err;
+}
+EXPORT_SYMBOL(p9_client_setattr);
+
 int p9_client_statfs(struct p9_fid *fid, struct p9_rstatfs *sb)
 {
        int err;
@@ -1432,3 +1621,187 @@ error:
 }
 EXPORT_SYMBOL(p9_client_rename);
 
+/*
+ * An xattrwalk without @attr_name gives the fid for the lisxattr namespace
+ */
+struct p9_fid *p9_client_xattrwalk(struct p9_fid *file_fid,
+                               const char *attr_name, u64 *attr_size)
+{
+       int err;
+       struct p9_req_t *req;
+       struct p9_client *clnt;
+       struct p9_fid *attr_fid;
+
+       err = 0;
+       clnt = file_fid->clnt;
+       attr_fid = p9_fid_create(clnt);
+       if (IS_ERR(attr_fid)) {
+               err = PTR_ERR(attr_fid);
+               attr_fid = NULL;
+               goto error;
+       }
+       P9_DPRINTK(P9_DEBUG_9P,
+               ">>> TXATTRWALK file_fid %d, attr_fid %d name %s\n",
+               file_fid->fid, attr_fid->fid, attr_name);
+
+       req = p9_client_rpc(clnt, P9_TXATTRWALK, "dds",
+                       file_fid->fid, attr_fid->fid, attr_name);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+       err = p9pdu_readf(req->rc, clnt->proto_version, "q", attr_size);
+       if (err) {
+               p9pdu_dump(1, req->rc);
+               p9_free_req(clnt, req);
+               goto clunk_fid;
+       }
+       p9_free_req(clnt, req);
+       P9_DPRINTK(P9_DEBUG_9P, "<<<  RXATTRWALK fid %d size %llu\n",
+               attr_fid->fid, *attr_size);
+       return attr_fid;
+clunk_fid:
+       p9_client_clunk(attr_fid);
+       attr_fid = NULL;
+error:
+       if (attr_fid && (attr_fid != file_fid))
+               p9_fid_destroy(attr_fid);
+
+       return ERR_PTR(err);
+}
+EXPORT_SYMBOL_GPL(p9_client_xattrwalk);
+
+int p9_client_xattrcreate(struct p9_fid *fid, const char *name,
+                       u64 attr_size, int flags)
+{
+       int err;
+       struct p9_req_t *req;
+       struct p9_client *clnt;
+
+       P9_DPRINTK(P9_DEBUG_9P,
+               ">>> TXATTRCREATE fid %d name  %s size %lld flag %d\n",
+               fid->fid, name, (long long)attr_size, flags);
+       err = 0;
+       clnt = fid->clnt;
+       req = p9_client_rpc(clnt, P9_TXATTRCREATE, "dsqd",
+                       fid->fid, name, attr_size, flags);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RXATTRCREATE fid %d\n", fid->fid);
+       p9_free_req(clnt, req);
+error:
+       return err;
+}
+EXPORT_SYMBOL_GPL(p9_client_xattrcreate);
+
+int p9_client_readdir(struct p9_fid *fid, char *data, u32 count, u64 offset)
+{
+       int err, rsize, total;
+       struct p9_client *clnt;
+       struct p9_req_t *req;
+       char *dataptr;
+
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TREADDIR fid %d offset %llu count %d\n",
+                               fid->fid, (long long unsigned) offset, count);
+
+       err = 0;
+       clnt = fid->clnt;
+       total = 0;
+
+       rsize = fid->iounit;
+       if (!rsize || rsize > clnt->msize-P9_READDIRHDRSZ)
+               rsize = clnt->msize - P9_READDIRHDRSZ;
+
+       if (count < rsize)
+               rsize = count;
+
+       req = p9_client_rpc(clnt, P9_TREADDIR, "dqd", fid->fid, offset, rsize);
+       if (IS_ERR(req)) {
+               err = PTR_ERR(req);
+               goto error;
+       }
+
+       err = p9pdu_readf(req->rc, clnt->proto_version, "D", &count, &dataptr);
+       if (err) {
+               p9pdu_dump(1, req->rc);
+               goto free_and_error;
+       }
+
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RREADDIR count %d\n", count);
+
+       if (data)
+               memmove(data, dataptr, count);
+
+       p9_free_req(clnt, req);
+       return count;
+
+free_and_error:
+       p9_free_req(clnt, req);
+error:
+       return err;
+}
+EXPORT_SYMBOL(p9_client_readdir);
+
+int p9_client_mknod_dotl(struct p9_fid *fid, char *name, int mode,
+                       dev_t rdev, gid_t gid, struct p9_qid *qid)
+{
+       int err;
+       struct p9_client *clnt;
+       struct p9_req_t *req;
+
+       err = 0;
+       clnt = fid->clnt;
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TMKNOD fid %d name %s mode %d major %d "
+               "minor %d\n", fid->fid, name, mode, MAJOR(rdev), MINOR(rdev));
+       req = p9_client_rpc(clnt, P9_TMKNOD, "dsdddd", fid->fid, name, mode,
+               MAJOR(rdev), MINOR(rdev), gid);
+       if (IS_ERR(req))
+               return PTR_ERR(req);
+
+       err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid);
+       if (err) {
+               p9pdu_dump(1, req->rc);
+               goto error;
+       }
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RMKNOD qid %x.%llx.%x\n", qid->type,
+                               (unsigned long long)qid->path, qid->version);
+
+error:
+       p9_free_req(clnt, req);
+       return err;
+
+}
+EXPORT_SYMBOL(p9_client_mknod_dotl);
+
+int p9_client_mkdir_dotl(struct p9_fid *fid, char *name, int mode,
+                               gid_t gid, struct p9_qid *qid)
+{
+       int err;
+       struct p9_client *clnt;
+       struct p9_req_t *req;
+
+       err = 0;
+       clnt = fid->clnt;
+       P9_DPRINTK(P9_DEBUG_9P, ">>> TMKDIR fid %d name %s mode %d gid %d\n",
+                fid->fid, name, mode, gid);
+       req = p9_client_rpc(clnt, P9_TMKDIR, "dsdd", fid->fid, name, mode,
+               gid);
+       if (IS_ERR(req))
+               return PTR_ERR(req);
+
+       err = p9pdu_readf(req->rc, clnt->proto_version, "Q", qid);
+       if (err) {
+               p9pdu_dump(1, req->rc);
+               goto error;
+       }
+       P9_DPRINTK(P9_DEBUG_9P, "<<< RMKDIR qid %x.%llx.%x\n", qid->type,
+                               (unsigned long long)qid->path, qid->version);
+
+error:
+       p9_free_req(clnt, req);
+       return err;
+
+}
+EXPORT_SYMBOL(p9_client_mkdir_dotl);
index 149f82160130684701118255d2ec73f31667c72d..3acd3afb20c857f6f3d2451a6ce1d7ba5c14af76 100644 (file)
@@ -141,6 +141,7 @@ pdu_write_u(struct p9_fcall *pdu, const char __user *udata, size_t size)
        D - data blob (int32_t size followed by void *, results are not freed)
        T - array of strings (int16_t count, followed by strings)
        R - array of qids (int16_t count, followed by qids)
+       A - stat for 9p2000.L (p9_stat_dotl)
        ? - if optional = 1, continue parsing
 */
 
@@ -340,6 +341,33 @@ p9pdu_vreadf(struct p9_fcall *pdu, int proto_version, const char *fmt,
                                }
                        }
                        break;
+               case 'A': {
+                               struct p9_stat_dotl *stbuf =
+                                   va_arg(ap, struct p9_stat_dotl *);
+
+                               memset(stbuf, 0, sizeof(struct p9_stat_dotl));
+                               errcode =
+                                   p9pdu_readf(pdu, proto_version,
+                                       "qQdddqqqqqqqqqqqqqqq",
+                                       &stbuf->st_result_mask,
+                                       &stbuf->qid,
+                                       &stbuf->st_mode,
+                                       &stbuf->st_uid, &stbuf->st_gid,
+                                       &stbuf->st_nlink,
+                                       &stbuf->st_rdev, &stbuf->st_size,
+                                       &stbuf->st_blksize, &stbuf->st_blocks,
+                                       &stbuf->st_atime_sec,
+                                       &stbuf->st_atime_nsec,
+                                       &stbuf->st_mtime_sec,
+                                       &stbuf->st_mtime_nsec,
+                                       &stbuf->st_ctime_sec,
+                                       &stbuf->st_ctime_nsec,
+                                       &stbuf->st_btime_sec,
+                                       &stbuf->st_btime_nsec,
+                                       &stbuf->st_gen,
+                                       &stbuf->st_data_version);
+                       }
+                       break;
                case '?':
                        if ((proto_version != p9_proto_2000u) &&
                                (proto_version != p9_proto_2000L))
@@ -488,6 +516,23 @@ p9pdu_vwritef(struct p9_fcall *pdu, int proto_version, const char *fmt,
                                }
                        }
                        break;
+               case 'I':{
+                               struct p9_iattr_dotl *p9attr = va_arg(ap,
+                                                       struct p9_iattr_dotl *);
+
+                               errcode = p9pdu_writef(pdu, proto_version,
+                                                       "ddddqqqqq",
+                                                       p9attr->valid,
+                                                       p9attr->mode,
+                                                       p9attr->uid,
+                                                       p9attr->gid,
+                                                       p9attr->size,
+                                                       p9attr->atime_sec,
+                                                       p9attr->atime_nsec,
+                                                       p9attr->mtime_sec,
+                                                       p9attr->mtime_nsec);
+                       }
+                       break;
                case '?':
                        if ((proto_version != p9_proto_2000u) &&
                                (proto_version != p9_proto_2000L))
@@ -580,3 +625,30 @@ void p9pdu_reset(struct p9_fcall *pdu)
        pdu->offset = 0;
        pdu->size = 0;
 }
+
+int p9dirent_read(char *buf, int len, struct p9_dirent *dirent,
+                                               int proto_version)
+{
+       struct p9_fcall fake_pdu;
+       int ret;
+       char *nameptr;
+
+       fake_pdu.size = len;
+       fake_pdu.capacity = len;
+       fake_pdu.sdata = buf;
+       fake_pdu.offset = 0;
+
+       ret = p9pdu_readf(&fake_pdu, proto_version, "Qqbs", &dirent->qid,
+                       &dirent->d_off, &dirent->d_type, &nameptr);
+       if (ret) {
+               P9_DPRINTK(P9_DEBUG_9P, "<<< p9dirent_read failed: %d\n", ret);
+               p9pdu_dump(1, &fake_pdu);
+               goto out;
+       }
+
+       strcpy(dirent->d_name, nameptr);
+
+out:
+       return fake_pdu.offset;
+}
+EXPORT_SYMBOL(p9dirent_read);
index 98ce9bcb0e15da4443ce08cd654576c2b235b69f..c85109d809caa4767ef2576c1947fcd877e432b7 100644 (file)
@@ -948,7 +948,7 @@ p9_fd_create_unix(struct p9_client *client, const char *addr, char *args)
 
        csocket = NULL;
 
-       if (strlen(addr) > UNIX_PATH_MAX) {
+       if (strlen(addr) >= UNIX_PATH_MAX) {
                P9_EPRINTK(KERN_ERR, "p9_trans_unix: address too long: %s\n",
                        addr);
                return -ENAMETOOLONG;
index 226b9556b25f829384c107196d0110bdf75ef876..bd72ae6234947e424885f3808dbec54bddad244c 100644 (file)
@@ -140,6 +140,7 @@ config LSM_MMAP_MIN_ADDR
 source security/selinux/Kconfig
 source security/smack/Kconfig
 source security/tomoyo/Kconfig
+source security/apparmor/Kconfig
 
 source security/integrity/ima/Kconfig
 
@@ -148,6 +149,7 @@ choice
        default DEFAULT_SECURITY_SELINUX if SECURITY_SELINUX
        default DEFAULT_SECURITY_SMACK if SECURITY_SMACK
        default DEFAULT_SECURITY_TOMOYO if SECURITY_TOMOYO
+       default DEFAULT_SECURITY_APPARMOR if SECURITY_APPARMOR
        default DEFAULT_SECURITY_DAC
 
        help
@@ -163,6 +165,9 @@ choice
        config DEFAULT_SECURITY_TOMOYO
                bool "TOMOYO" if SECURITY_TOMOYO=y
 
+       config DEFAULT_SECURITY_APPARMOR
+               bool "AppArmor" if SECURITY_APPARMOR=y
+
        config DEFAULT_SECURITY_DAC
                bool "Unix Discretionary Access Controls"
 
@@ -173,6 +178,7 @@ config DEFAULT_SECURITY
        default "selinux" if DEFAULT_SECURITY_SELINUX
        default "smack" if DEFAULT_SECURITY_SMACK
        default "tomoyo" if DEFAULT_SECURITY_TOMOYO
+       default "apparmor" if DEFAULT_SECURITY_APPARMOR
        default "" if DEFAULT_SECURITY_DAC
 
 endmenu
index da20a193c8dd6623d834ef9bb1396fcaacfd9bd0..8bb0fe9e1ca94e68cac077196fad183975955d95 100644 (file)
@@ -6,6 +6,7 @@ obj-$(CONFIG_KEYS)                      += keys/
 subdir-$(CONFIG_SECURITY_SELINUX)      += selinux
 subdir-$(CONFIG_SECURITY_SMACK)                += smack
 subdir-$(CONFIG_SECURITY_TOMOYO)        += tomoyo
+subdir-$(CONFIG_SECURITY_APPARMOR)     += apparmor
 
 # always enable default capabilities
 obj-y                                  += commoncap.o
@@ -19,6 +20,7 @@ obj-$(CONFIG_SECURITY_SELINUX)                += selinux/built-in.o
 obj-$(CONFIG_SECURITY_SMACK)           += smack/built-in.o
 obj-$(CONFIG_AUDIT)                    += lsm_audit.o
 obj-$(CONFIG_SECURITY_TOMOYO)          += tomoyo/built-in.o
+obj-$(CONFIG_SECURITY_APPARMOR)                += apparmor/built-in.o
 obj-$(CONFIG_CGROUP_DEVICE)            += device_cgroup.o
 
 # Object integrity file lists
diff --git a/security/apparmor/.gitignore b/security/apparmor/.gitignore
new file mode 100644 (file)
index 0000000..0a0a99f
--- /dev/null
@@ -0,0 +1,5 @@
+#
+# Generated include files
+#
+af_names.h
+capability_names.h
diff --git a/security/apparmor/Kconfig b/security/apparmor/Kconfig
new file mode 100644 (file)
index 0000000..72555b9
--- /dev/null
@@ -0,0 +1,31 @@
+config SECURITY_APPARMOR
+       bool "AppArmor support"
+       depends on SECURITY
+       select AUDIT
+       select SECURITY_PATH
+       select SECURITYFS
+       select SECURITY_NETWORK
+       default n
+       help
+         This enables the AppArmor security module.
+         Required userspace tools (if they are not included in your
+         distribution) and further information may be found at
+         http://apparmor.wiki.kernel.org
+
+         If you are unsure how to answer this question, answer N.
+
+config SECURITY_APPARMOR_BOOTPARAM_VALUE
+       int "AppArmor boot parameter default value"
+       depends on SECURITY_APPARMOR
+       range 0 1
+       default 1
+       help
+         This option sets the default value for the kernel parameter
+         'apparmor', which allows AppArmor to be enabled or disabled
+          at boot.  If this option is set to 0 (zero), the AppArmor
+         kernel parameter will default to 0, disabling AppArmor at
+         boot.  If this option is set to 1 (one), the AppArmor
+         kernel parameter will default to 1, enabling AppArmor at
+         boot.
+
+         If you are unsure how to answer this question, answer 1.
diff --git a/security/apparmor/Makefile b/security/apparmor/Makefile
new file mode 100644 (file)
index 0000000..f204869
--- /dev/null
@@ -0,0 +1,24 @@
+# Makefile for AppArmor Linux Security Module
+#
+obj-$(CONFIG_SECURITY_APPARMOR) += apparmor.o
+
+apparmor-y := apparmorfs.o audit.o capability.o context.o ipc.o lib.o match.o \
+              path.o domain.o policy.o policy_unpack.o procattr.o lsm.o \
+              resource.o sid.o file.o
+
+clean-files: capability_names.h af_names.h
+
+quiet_cmd_make-caps = GEN     $@
+cmd_make-caps = echo "static const char *capability_names[] = {" > $@ ; sed -n -e "/CAP_FS_MASK/d" -e "s/^\#define[ \\t]\\+CAP_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\$$/[\\2]  = \"\\1\",/p" $< | tr A-Z a-z >> $@ ; echo "};" >> $@
+
+quiet_cmd_make-rlim = GEN     $@
+cmd_make-rlim = echo "static const char *rlim_names[] = {" > $@ ; sed -n --e "/AF_MAX/d" -e "s/^\# \\?define[ \\t]\\+RLIMIT_\\([A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\\(.*\\)\$$/[\\2]  = \"\\1\",/p" $< | tr A-Z a-z >> $@ ; echo "};" >> $@ ; echo "static const int rlim_map[] = {" >> $@ ; sed -n -e "/AF_MAX/d" -e "s/^\# \\?define[ \\t]\\+\\(RLIMIT_[A-Z0-9_]\\+\\)[ \\t]\\+\\([0-9]\\+\\)\\(.*\\)\$$/\\1,/p" $< >> $@ ; echo "};" >> $@
+
+$(obj)/capability.o : $(obj)/capability_names.h
+$(obj)/resource.o : $(obj)/rlim_names.h
+$(obj)/capability_names.h : $(srctree)/include/linux/capability.h
+       $(call cmd,make-caps)
+$(obj)/af_names.h : $(srctree)/include/linux/socket.h
+       $(call cmd,make-af)
+$(obj)/rlim_names.h : $(srctree)/include/asm-generic/resource.h
+       $(call cmd,make-rlim)
diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
new file mode 100644 (file)
index 0000000..7320331
--- /dev/null
@@ -0,0 +1,239 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor /sys/kernel/security/apparmor interface functions
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/security.h>
+#include <linux/vmalloc.h>
+#include <linux/module.h>
+#include <linux/seq_file.h>
+#include <linux/uaccess.h>
+#include <linux/namei.h>
+
+#include "include/apparmor.h"
+#include "include/apparmorfs.h"
+#include "include/audit.h"
+#include "include/context.h"
+#include "include/policy.h"
+
+/**
+ * aa_simple_write_to_buffer - common routine for getting policy from user
+ * @op: operation doing the user buffer copy
+ * @userbuf: user buffer to copy data from  (NOT NULL)
+ * @alloc_size: size of user buffer
+ * @copy_size: size of data to copy from user buffer
+ * @pos: position write is at in the file (NOT NULL)
+ *
+ * Returns: kernel buffer containing copy of user buffer data or an
+ *          ERR_PTR on failure.
+ */
+static char *aa_simple_write_to_buffer(int op, const char __user *userbuf,
+                                      size_t alloc_size, size_t copy_size,
+                                      loff_t *pos)
+{
+       char *data;
+
+       if (*pos != 0)
+               /* only writes from pos 0, that is complete writes */
+               return ERR_PTR(-ESPIPE);
+
+       /*
+        * Don't allow profile load/replace/remove from profiles that don't
+        * have CAP_MAC_ADMIN
+        */
+       if (!aa_may_manage_policy(op))
+               return ERR_PTR(-EACCES);
+
+       /* freed by caller to simple_write_to_buffer */
+       data = kvmalloc(alloc_size);
+       if (data == NULL)
+               return ERR_PTR(-ENOMEM);
+
+       if (copy_from_user(data, userbuf, copy_size)) {
+               kvfree(data);
+               return ERR_PTR(-EFAULT);
+       }
+
+       return data;
+}
+
+
+/* .load file hook fn to load policy */
+static ssize_t profile_load(struct file *f, const char __user *buf, size_t size,
+                           loff_t *pos)
+{
+       char *data;
+       ssize_t error;
+
+       data = aa_simple_write_to_buffer(OP_PROF_LOAD, buf, size, size, pos);
+
+       error = PTR_ERR(data);
+       if (!IS_ERR(data)) {
+               error = aa_replace_profiles(data, size, PROF_ADD);
+               kvfree(data);
+       }
+
+       return error;
+}
+
+static const struct file_operations aa_fs_profile_load = {
+       .write = profile_load
+};
+
+/* .replace file hook fn to load and/or replace policy */
+static ssize_t profile_replace(struct file *f, const char __user *buf,
+                              size_t size, loff_t *pos)
+{
+       char *data;
+       ssize_t error;
+
+       data = aa_simple_write_to_buffer(OP_PROF_REPL, buf, size, size, pos);
+       error = PTR_ERR(data);
+       if (!IS_ERR(data)) {
+               error = aa_replace_profiles(data, size, PROF_REPLACE);
+               kvfree(data);
+       }
+
+       return error;
+}
+
+static const struct file_operations aa_fs_profile_replace = {
+       .write = profile_replace
+};
+
+/* .remove file hook fn to remove loaded policy */
+static ssize_t profile_remove(struct file *f, const char __user *buf,
+                             size_t size, loff_t *pos)
+{
+       char *data;
+       ssize_t error;
+
+       /*
+        * aa_remove_profile needs a null terminated string so 1 extra
+        * byte is allocated and the copied data is null terminated.
+        */
+       data = aa_simple_write_to_buffer(OP_PROF_RM, buf, size + 1, size, pos);
+
+       error = PTR_ERR(data);
+       if (!IS_ERR(data)) {
+               data[size] = 0;
+               error = aa_remove_profiles(data, size);
+               kvfree(data);
+       }
+
+       return error;
+}
+
+static const struct file_operations aa_fs_profile_remove = {
+       .write = profile_remove
+};
+
+/** Base file system setup **/
+
+static struct dentry *aa_fs_dentry __initdata;
+
+static void __init aafs_remove(const char *name)
+{
+       struct dentry *dentry;
+
+       dentry = lookup_one_len(name, aa_fs_dentry, strlen(name));
+       if (!IS_ERR(dentry)) {
+               securityfs_remove(dentry);
+               dput(dentry);
+       }
+}
+
+/**
+ * aafs_create - create an entry in the apparmor filesystem
+ * @name: name of the entry (NOT NULL)
+ * @mask: file permission mask of the file
+ * @fops: file operations for the file (NOT NULL)
+ *
+ * Used aafs_remove to remove entries created with this fn.
+ */
+static int __init aafs_create(const char *name, int mask,
+                             const struct file_operations *fops)
+{
+       struct dentry *dentry;
+
+       dentry = securityfs_create_file(name, S_IFREG | mask, aa_fs_dentry,
+                                       NULL, fops);
+
+       return IS_ERR(dentry) ? PTR_ERR(dentry) : 0;
+}
+
+/**
+ * aa_destroy_aafs - cleanup and free aafs
+ *
+ * releases dentries allocated by aa_create_aafs
+ */
+void __init aa_destroy_aafs(void)
+{
+       if (aa_fs_dentry) {
+               aafs_remove(".remove");
+               aafs_remove(".replace");
+               aafs_remove(".load");
+
+               securityfs_remove(aa_fs_dentry);
+               aa_fs_dentry = NULL;
+       }
+}
+
+/**
+ * aa_create_aafs - create the apparmor security filesystem
+ *
+ * dentries created here are released by aa_destroy_aafs
+ *
+ * Returns: error on failure
+ */
+int __init aa_create_aafs(void)
+{
+       int error;
+
+       if (!apparmor_initialized)
+               return 0;
+
+       if (aa_fs_dentry) {
+               AA_ERROR("%s: AppArmor securityfs already exists\n", __func__);
+               return -EEXIST;
+       }
+
+       aa_fs_dentry = securityfs_create_dir("apparmor", NULL);
+       if (IS_ERR(aa_fs_dentry)) {
+               error = PTR_ERR(aa_fs_dentry);
+               aa_fs_dentry = NULL;
+               goto error;
+       }
+
+       error = aafs_create(".load", 0640, &aa_fs_profile_load);
+       if (error)
+               goto error;
+       error = aafs_create(".replace", 0640, &aa_fs_profile_replace);
+       if (error)
+               goto error;
+       error = aafs_create(".remove", 0640, &aa_fs_profile_remove);
+       if (error)
+               goto error;
+
+       /* TODO: add support for apparmorfs_null and apparmorfs_mnt */
+
+       /* Report that AppArmor fs is enabled */
+       aa_info_message("AppArmor Filesystem Enabled");
+       return 0;
+
+error:
+       aa_destroy_aafs();
+       AA_ERROR("Error creating AppArmor securityfs\n");
+       return error;
+}
+
+fs_initcall(aa_create_aafs);
diff --git a/security/apparmor/audit.c b/security/apparmor/audit.c
new file mode 100644 (file)
index 0000000..96502b2
--- /dev/null
@@ -0,0 +1,215 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor auditing functions
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/audit.h>
+#include <linux/socket.h>
+
+#include "include/apparmor.h"
+#include "include/audit.h"
+#include "include/policy.h"
+
+const char *op_table[] = {
+       "null",
+
+       "sysctl",
+       "capable",
+
+       "unlink",
+       "mkdir",
+       "rmdir",
+       "mknod",
+       "truncate",
+       "link",
+       "symlink",
+       "rename_src",
+       "rename_dest",
+       "chmod",
+       "chown",
+       "getattr",
+       "open",
+
+       "file_perm",
+       "file_lock",
+       "file_mmap",
+       "file_mprotect",
+
+       "create",
+       "post_create",
+       "bind",
+       "connect",
+       "listen",
+       "accept",
+       "sendmsg",
+       "recvmsg",
+       "getsockname",
+       "getpeername",
+       "getsockopt",
+       "setsockopt",
+       "socket_shutdown",
+
+       "ptrace",
+
+       "exec",
+       "change_hat",
+       "change_profile",
+       "change_onexec",
+
+       "setprocattr",
+       "setrlimit",
+
+       "profile_replace",
+       "profile_load",
+       "profile_remove"
+};
+
+const char *audit_mode_names[] = {
+       "normal",
+       "quiet_denied",
+       "quiet",
+       "noquiet",
+       "all"
+};
+
+static char *aa_audit_type[] = {
+       "AUDIT",
+       "ALLOWED",
+       "DENIED",
+       "HINT",
+       "STATUS",
+       "ERROR",
+       "KILLED"
+};
+
+/*
+ * Currently AppArmor auditing is fed straight into the audit framework.
+ *
+ * TODO:
+ * netlink interface for complain mode
+ * user auditing, - send user auditing to netlink interface
+ * system control of whether user audit messages go to system log
+ */
+
+/**
+ * audit_base - core AppArmor function.
+ * @ab: audit buffer to fill (NOT NULL)
+ * @ca: audit structure containing data to audit (NOT NULL)
+ *
+ * Record common AppArmor audit data from @sa
+ */
+static void audit_pre(struct audit_buffer *ab, void *ca)
+{
+       struct common_audit_data *sa = ca;
+       struct task_struct *tsk = sa->tsk ? sa->tsk : current;
+
+       if (aa_g_audit_header) {
+               audit_log_format(ab, "apparmor=");
+               audit_log_string(ab, aa_audit_type[sa->aad.type]);
+       }
+
+       if (sa->aad.op) {
+               audit_log_format(ab, " operation=");
+               audit_log_string(ab, op_table[sa->aad.op]);
+       }
+
+       if (sa->aad.info) {
+               audit_log_format(ab, " info=");
+               audit_log_string(ab, sa->aad.info);
+               if (sa->aad.error)
+                       audit_log_format(ab, " error=%d", sa->aad.error);
+       }
+
+       if (sa->aad.profile) {
+               struct aa_profile *profile = sa->aad.profile;
+               pid_t pid;
+               rcu_read_lock();
+               pid = tsk->real_parent->pid;
+               rcu_read_unlock();
+               audit_log_format(ab, " parent=%d", pid);
+               if (profile->ns != root_ns) {
+                       audit_log_format(ab, " namespace=");
+                       audit_log_untrustedstring(ab, profile->ns->base.hname);
+               }
+               audit_log_format(ab, " profile=");
+               audit_log_untrustedstring(ab, profile->base.hname);
+       }
+
+       if (sa->aad.name) {
+               audit_log_format(ab, " name=");
+               audit_log_untrustedstring(ab, sa->aad.name);
+       }
+}
+
+/**
+ * aa_audit_msg - Log a message to the audit subsystem
+ * @sa: audit event structure (NOT NULL)
+ * @cb: optional callback fn for type specific fields (MAYBE NULL)
+ */
+void aa_audit_msg(int type, struct common_audit_data *sa,
+                 void (*cb) (struct audit_buffer *, void *))
+{
+       sa->aad.type = type;
+       sa->lsm_pre_audit = audit_pre;
+       sa->lsm_post_audit = cb;
+       common_lsm_audit(sa);
+}
+
+/**
+ * aa_audit - Log a profile based audit event to the audit subsystem
+ * @type: audit type for the message
+ * @profile: profile to check against (NOT NULL)
+ * @gfp: allocation flags to use
+ * @sa: audit event (NOT NULL)
+ * @cb: optional callback fn for type specific fields (MAYBE NULL)
+ *
+ * Handle default message switching based off of audit mode flags
+ *
+ * Returns: error on failure
+ */
+int aa_audit(int type, struct aa_profile *profile, gfp_t gfp,
+            struct common_audit_data *sa,
+            void (*cb) (struct audit_buffer *, void *))
+{
+       BUG_ON(!profile);
+
+       if (type == AUDIT_APPARMOR_AUTO) {
+               if (likely(!sa->aad.error)) {
+                       if (AUDIT_MODE(profile) != AUDIT_ALL)
+                               return 0;
+                       type = AUDIT_APPARMOR_AUDIT;
+               } else if (COMPLAIN_MODE(profile))
+                       type = AUDIT_APPARMOR_ALLOWED;
+               else
+                       type = AUDIT_APPARMOR_DENIED;
+       }
+       if (AUDIT_MODE(profile) == AUDIT_QUIET ||
+           (type == AUDIT_APPARMOR_DENIED &&
+            AUDIT_MODE(profile) == AUDIT_QUIET))
+               return sa->aad.error;
+
+       if (KILL_MODE(profile) && type == AUDIT_APPARMOR_DENIED)
+               type = AUDIT_APPARMOR_KILL;
+
+       if (!unconfined(profile))
+               sa->aad.profile = profile;
+
+       aa_audit_msg(type, sa, cb);
+
+       if (sa->aad.type == AUDIT_APPARMOR_KILL)
+               (void)send_sig_info(SIGKILL, NULL, sa->tsk ? sa->tsk : current);
+
+       if (sa->aad.type == AUDIT_APPARMOR_ALLOWED)
+               return complain_error(sa->aad.error);
+
+       return sa->aad.error;
+}
diff --git a/security/apparmor/capability.c b/security/apparmor/capability.c
new file mode 100644 (file)
index 0000000..9982c48
--- /dev/null
@@ -0,0 +1,141 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor capability mediation functions
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/capability.h>
+#include <linux/errno.h>
+#include <linux/gfp.h>
+
+#include "include/apparmor.h"
+#include "include/capability.h"
+#include "include/context.h"
+#include "include/policy.h"
+#include "include/audit.h"
+
+/*
+ * Table of capability names: we generate it from capabilities.h.
+ */
+#include "capability_names.h"
+
+struct audit_cache {
+       struct aa_profile *profile;
+       kernel_cap_t caps;
+};
+
+static DEFINE_PER_CPU(struct audit_cache, audit_cache);
+
+/**
+ * audit_cb - call back for capability components of audit struct
+ * @ab - audit buffer   (NOT NULL)
+ * @va - audit struct to audit data from  (NOT NULL)
+ */
+static void audit_cb(struct audit_buffer *ab, void *va)
+{
+       struct common_audit_data *sa = va;
+       audit_log_format(ab, " capname=");
+       audit_log_untrustedstring(ab, capability_names[sa->u.cap]);
+}
+
+/**
+ * audit_caps - audit a capability
+ * @profile: profile confining task (NOT NULL)
+ * @task: task capability test was performed against (NOT NULL)
+ * @cap: capability tested
+ * @error: error code returned by test
+ *
+ * Do auditing of capability and handle, audit/complain/kill modes switching
+ * and duplicate message elimination.
+ *
+ * Returns: 0 or sa->error on success,  error code on failure
+ */
+static int audit_caps(struct aa_profile *profile, struct task_struct *task,
+                     int cap, int error)
+{
+       struct audit_cache *ent;
+       int type = AUDIT_APPARMOR_AUTO;
+       struct common_audit_data sa;
+       COMMON_AUDIT_DATA_INIT(&sa, CAP);
+       sa.tsk = task;
+       sa.u.cap = cap;
+       sa.aad.op = OP_CAPABLE;
+       sa.aad.error = error;
+
+       if (likely(!error)) {
+               /* test if auditing is being forced */
+               if (likely((AUDIT_MODE(profile) != AUDIT_ALL) &&
+                          !cap_raised(profile->caps.audit, cap)))
+                       return 0;
+               type = AUDIT_APPARMOR_AUDIT;
+       } else if (KILL_MODE(profile) ||
+                  cap_raised(profile->caps.kill, cap)) {
+               type = AUDIT_APPARMOR_KILL;
+       } else if (cap_raised(profile->caps.quiet, cap) &&
+                  AUDIT_MODE(profile) != AUDIT_NOQUIET &&
+                  AUDIT_MODE(profile) != AUDIT_ALL) {
+               /* quiet auditing */
+               return error;
+       }
+
+       /* Do simple duplicate message elimination */
+       ent = &get_cpu_var(audit_cache);
+       if (profile == ent->profile && cap_raised(ent->caps, cap)) {
+               put_cpu_var(audit_cache);
+               if (COMPLAIN_MODE(profile))
+                       return complain_error(error);
+               return error;
+       } else {
+               aa_put_profile(ent->profile);
+               ent->profile = aa_get_profile(profile);
+               cap_raise(ent->caps, cap);
+       }
+       put_cpu_var(audit_cache);
+
+       return aa_audit(type, profile, GFP_ATOMIC, &sa, audit_cb);
+}
+
+/**
+ * profile_capable - test if profile allows use of capability @cap
+ * @profile: profile being enforced    (NOT NULL, NOT unconfined)
+ * @cap: capability to test if allowed
+ *
+ * Returns: 0 if allowed else -EPERM
+ */
+static int profile_capable(struct aa_profile *profile, int cap)
+{
+       return cap_raised(profile->caps.allow, cap) ? 0 : -EPERM;
+}
+
+/**
+ * aa_capable - test permission to use capability
+ * @task: task doing capability test against (NOT NULL)
+ * @profile: profile confining @task (NOT NULL)
+ * @cap: capability to be tested
+ * @audit: whether an audit record should be generated
+ *
+ * Look up capability in profile capability set.
+ *
+ * Returns: 0 on success, or else an error code.
+ */
+int aa_capable(struct task_struct *task, struct aa_profile *profile, int cap,
+              int audit)
+{
+       int error = profile_capable(profile, cap);
+
+       if (!audit) {
+               if (COMPLAIN_MODE(profile))
+                       return complain_error(error);
+               return error;
+       }
+
+       return audit_caps(profile, task, cap, error);
+}
diff --git a/security/apparmor/context.c b/security/apparmor/context.c
new file mode 100644 (file)
index 0000000..8a9b502
--- /dev/null
@@ -0,0 +1,216 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor functions used to manipulate object security
+ * contexts.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ *
+ *
+ * AppArmor sets confinement on every task, via the the aa_task_cxt and
+ * the aa_task_cxt.profile, both of which are required and are not allowed
+ * to be NULL.  The aa_task_cxt is not reference counted and is unique
+ * to each cred (which is reference count).  The profile pointed to by
+ * the task_cxt is reference counted.
+ *
+ * TODO
+ * If a task uses change_hat it currently does not return to the old
+ * cred or task context but instead creates a new one.  Ideally the task
+ * should return to the previous cred if it has not been modified.
+ *
+ */
+
+#include "include/context.h"
+#include "include/policy.h"
+
+/**
+ * aa_alloc_task_context - allocate a new task_cxt
+ * @flags: gfp flags for allocation
+ *
+ * Returns: allocated buffer or NULL on failure
+ */
+struct aa_task_cxt *aa_alloc_task_context(gfp_t flags)
+{
+       return kzalloc(sizeof(struct aa_task_cxt), flags);
+}
+
+/**
+ * aa_free_task_context - free a task_cxt
+ * @cxt: task_cxt to free (MAYBE NULL)
+ */
+void aa_free_task_context(struct aa_task_cxt *cxt)
+{
+       if (cxt) {
+               aa_put_profile(cxt->profile);
+               aa_put_profile(cxt->previous);
+               aa_put_profile(cxt->onexec);
+
+               kzfree(cxt);
+       }
+}
+
+/**
+ * aa_dup_task_context - duplicate a task context, incrementing reference counts
+ * @new: a blank task context      (NOT NULL)
+ * @old: the task context to copy  (NOT NULL)
+ */
+void aa_dup_task_context(struct aa_task_cxt *new, const struct aa_task_cxt *old)
+{
+       *new = *old;
+       aa_get_profile(new->profile);
+       aa_get_profile(new->previous);
+       aa_get_profile(new->onexec);
+}
+
+/**
+ * aa_replace_current_profile - replace the current tasks profiles
+ * @profile: new profile  (NOT NULL)
+ *
+ * Returns: 0 or error on failure
+ */
+int aa_replace_current_profile(struct aa_profile *profile)
+{
+       struct aa_task_cxt *cxt = current_cred()->security;
+       struct cred *new;
+       BUG_ON(!profile);
+
+       if (cxt->profile == profile)
+               return 0;
+
+       new  = prepare_creds();
+       if (!new)
+               return -ENOMEM;
+
+       cxt = new->security;
+       if (unconfined(profile) || (cxt->profile->ns != profile->ns)) {
+               /* if switching to unconfined or a different profile namespace
+                * clear out context state
+                */
+               aa_put_profile(cxt->previous);
+               aa_put_profile(cxt->onexec);
+               cxt->previous = NULL;
+               cxt->onexec = NULL;
+               cxt->token = 0;
+       }
+       /* be careful switching cxt->profile, when racing replacement it
+        * is possible that cxt->profile->replacedby is the reference keeping
+        * @profile valid, so make sure to get its reference before dropping
+        * the reference on cxt->profile */
+       aa_get_profile(profile);
+       aa_put_profile(cxt->profile);
+       cxt->profile = profile;
+
+       commit_creds(new);
+       return 0;
+}
+
+/**
+ * aa_set_current_onexec - set the tasks change_profile to happen onexec
+ * @profile: system profile to set at exec  (MAYBE NULL to clear value)
+ *
+ * Returns: 0 or error on failure
+ */
+int aa_set_current_onexec(struct aa_profile *profile)
+{
+       struct aa_task_cxt *cxt;
+       struct cred *new = prepare_creds();
+       if (!new)
+               return -ENOMEM;
+
+       cxt = new->security;
+       aa_get_profile(profile);
+       aa_put_profile(cxt->onexec);
+       cxt->onexec = profile;
+
+       commit_creds(new);
+       return 0;
+}
+
+/**
+ * aa_set_current_hat - set the current tasks hat
+ * @profile: profile to set as the current hat  (NOT NULL)
+ * @token: token value that must be specified to change from the hat
+ *
+ * Do switch of tasks hat.  If the task is currently in a hat
+ * validate the token to match.
+ *
+ * Returns: 0 or error on failure
+ */
+int aa_set_current_hat(struct aa_profile *profile, u64 token)
+{
+       struct aa_task_cxt *cxt;
+       struct cred *new = prepare_creds();
+       if (!new)
+               return -ENOMEM;
+       BUG_ON(!profile);
+
+       cxt = new->security;
+       if (!cxt->previous) {
+               /* transfer refcount */
+               cxt->previous = cxt->profile;
+               cxt->token = token;
+       } else if (cxt->token == token) {
+               aa_put_profile(cxt->profile);
+       } else {
+               /* previous_profile && cxt->token != token */
+               abort_creds(new);
+               return -EACCES;
+       }
+       cxt->profile = aa_get_profile(aa_newest_version(profile));
+       /* clear exec on switching context */
+       aa_put_profile(cxt->onexec);
+       cxt->onexec = NULL;
+
+       commit_creds(new);
+       return 0;
+}
+
+/**
+ * aa_restore_previous_profile - exit from hat context restoring the profile
+ * @token: the token that must be matched to exit hat context
+ *
+ * Attempt to return out of a hat to the previous profile.  The token
+ * must match the stored token value.
+ *
+ * Returns: 0 or error of failure
+ */
+int aa_restore_previous_profile(u64 token)
+{
+       struct aa_task_cxt *cxt;
+       struct cred *new = prepare_creds();
+       if (!new)
+               return -ENOMEM;
+
+       cxt = new->security;
+       if (cxt->token != token) {
+               abort_creds(new);
+               return -EACCES;
+       }
+       /* ignore restores when there is no saved profile */
+       if (!cxt->previous) {
+               abort_creds(new);
+               return 0;
+       }
+
+       aa_put_profile(cxt->profile);
+       cxt->profile = aa_newest_version(cxt->previous);
+       BUG_ON(!cxt->profile);
+       if (unlikely(cxt->profile != cxt->previous)) {
+               aa_get_profile(cxt->profile);
+               aa_put_profile(cxt->previous);
+       }
+       /* clear exec && prev information when restoring to previous context */
+       cxt->previous = NULL;
+       cxt->token = 0;
+       aa_put_profile(cxt->onexec);
+       cxt->onexec = NULL;
+
+       commit_creds(new);
+       return 0;
+}
diff --git a/security/apparmor/domain.c b/security/apparmor/domain.c
new file mode 100644 (file)
index 0000000..c825c6e
--- /dev/null
@@ -0,0 +1,823 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor policy attachment and domain transitions
+ *
+ * Copyright (C) 2002-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/errno.h>
+#include <linux/fdtable.h>
+#include <linux/file.h>
+#include <linux/mount.h>
+#include <linux/syscalls.h>
+#include <linux/tracehook.h>
+#include <linux/personality.h>
+
+#include "include/audit.h"
+#include "include/apparmorfs.h"
+#include "include/context.h"
+#include "include/domain.h"
+#include "include/file.h"
+#include "include/ipc.h"
+#include "include/match.h"
+#include "include/path.h"
+#include "include/policy.h"
+
+/**
+ * aa_free_domain_entries - free entries in a domain table
+ * @domain: the domain table to free  (MAYBE NULL)
+ */
+void aa_free_domain_entries(struct aa_domain *domain)
+{
+       int i;
+       if (domain) {
+               if (!domain->table)
+                       return;
+
+               for (i = 0; i < domain->size; i++)
+                       kzfree(domain->table[i]);
+               kzfree(domain->table);
+               domain->table = NULL;
+       }
+}
+
+/**
+ * may_change_ptraced_domain - check if can change profile on ptraced task
+ * @task: task we want to change profile of   (NOT NULL)
+ * @to_profile: profile to change to  (NOT NULL)
+ *
+ * Check if the task is ptraced and if so if the tracing task is allowed
+ * to trace the new domain
+ *
+ * Returns: %0 or error if change not allowed
+ */
+static int may_change_ptraced_domain(struct task_struct *task,
+                                    struct aa_profile *to_profile)
+{
+       struct task_struct *tracer;
+       const struct cred *cred = NULL;
+       struct aa_profile *tracerp = NULL;
+       int error = 0;
+
+       rcu_read_lock();
+       tracer = tracehook_tracer_task(task);
+       if (tracer) {
+               /* released below */
+               cred = get_task_cred(tracer);
+               tracerp = aa_cred_profile(cred);
+       }
+       rcu_read_unlock();
+
+       /* not ptraced */
+       if (!tracer || unconfined(tracerp))
+               goto out;
+
+       error = aa_may_ptrace(tracer, tracerp, to_profile, PTRACE_MODE_ATTACH);
+
+out:
+       if (cred)
+               put_cred(cred);
+
+       return error;
+}
+
+/**
+ * change_profile_perms - find permissions for change_profile
+ * @profile: the current profile  (NOT NULL)
+ * @ns: the namespace being switched to  (NOT NULL)
+ * @name: the name of the profile to change to  (NOT NULL)
+ * @request: requested perms
+ * @start: state to start matching in
+ *
+ * Returns: permission set
+ */
+static struct file_perms change_profile_perms(struct aa_profile *profile,
+                                             struct aa_namespace *ns,
+                                             const char *name, u32 request,
+                                             unsigned int start)
+{
+       struct file_perms perms;
+       struct path_cond cond = { };
+       unsigned int state;
+
+       if (unconfined(profile)) {
+               perms.allow = AA_MAY_CHANGE_PROFILE | AA_MAY_ONEXEC;
+               perms.audit = perms.quiet = perms.kill = 0;
+               return perms;
+       } else if (!profile->file.dfa) {
+               return nullperms;
+       } else if ((ns == profile->ns)) {
+               /* try matching against rules with out namespace prepended */
+               aa_str_perms(profile->file.dfa, start, name, &cond, &perms);
+               if (COMBINED_PERM_MASK(perms) & request)
+                       return perms;
+       }
+
+       /* try matching with namespace name and then profile */
+       state = aa_dfa_match(profile->file.dfa, start, ns->base.name);
+       state = aa_dfa_match_len(profile->file.dfa, state, ":", 1);
+       aa_str_perms(profile->file.dfa, state, name, &cond, &perms);
+
+       return perms;
+}
+
+/**
+ * __attach_match_ - find an attachment match
+ * @name - to match against  (NOT NULL)
+ * @head - profile list to walk  (NOT NULL)
+ *
+ * Do a linear search on the profiles in the list.  There is a matching
+ * preference where an exact match is preferred over a name which uses
+ * expressions to match, and matching expressions with the greatest
+ * xmatch_len are preferred.
+ *
+ * Requires: @head not be shared or have appropriate locks held
+ *
+ * Returns: profile or NULL if no match found
+ */
+static struct aa_profile *__attach_match(const char *name,
+                                        struct list_head *head)
+{
+       int len = 0;
+       struct aa_profile *profile, *candidate = NULL;
+
+       list_for_each_entry(profile, head, base.list) {
+               if (profile->flags & PFLAG_NULL)
+                       continue;
+               if (profile->xmatch && profile->xmatch_len > len) {
+                       unsigned int state = aa_dfa_match(profile->xmatch,
+                                                         DFA_START, name);
+                       u32 perm = dfa_user_allow(profile->xmatch, state);
+                       /* any accepting state means a valid match. */
+                       if (perm & MAY_EXEC) {
+                               candidate = profile;
+                               len = profile->xmatch_len;
+                       }
+               } else if (!strcmp(profile->base.name, name))
+                       /* exact non-re match, no more searching required */
+                       return profile;
+       }
+
+       return candidate;
+}
+
+/**
+ * find_attach - do attachment search for unconfined processes
+ * @ns: the current namespace  (NOT NULL)
+ * @list: list to search  (NOT NULL)
+ * @name: the executable name to match against  (NOT NULL)
+ *
+ * Returns: profile or NULL if no match found
+ */
+static struct aa_profile *find_attach(struct aa_namespace *ns,
+                                     struct list_head *list, const char *name)
+{
+       struct aa_profile *profile;
+
+       read_lock(&ns->lock);
+       profile = aa_get_profile(__attach_match(name, list));
+       read_unlock(&ns->lock);
+
+       return profile;
+}
+
+/**
+ * separate_fqname - separate the namespace and profile names
+ * @fqname: the fqname name to split  (NOT NULL)
+ * @ns_name: the namespace name if it exists  (NOT NULL)
+ *
+ * This is the xtable equivalent routine of aa_split_fqname.  It finds the
+ * split in an xtable fqname which contains an embedded \0 instead of a :
+ * if a namespace is specified.  This is done so the xtable is constant and
+ * isn't re-split on every lookup.
+ *
+ * Either the profile or namespace name may be optional but if the namespace
+ * is specified the profile name termination must be present.  This results
+ * in the following possible encodings:
+ * profile_name\0
+ * :ns_name\0profile_name\0
+ * :ns_name\0\0
+ *
+ * NOTE: the xtable fqname is pre-validated at load time in unpack_trans_table
+ *
+ * Returns: profile name if it is specified else NULL
+ */
+static const char *separate_fqname(const char *fqname, const char **ns_name)
+{
+       const char *name;
+
+       if (fqname[0] == ':') {
+               /* In this case there is guaranteed to be two \0 terminators
+                * in the string.  They are verified at load time by
+                * by unpack_trans_table
+                */
+               *ns_name = fqname + 1;          /* skip : */
+               name = *ns_name + strlen(*ns_name) + 1;
+               if (!*name)
+                       name = NULL;
+       } else {
+               *ns_name = NULL;
+               name = fqname;
+       }
+
+       return name;
+}
+
+static const char *next_name(int xtype, const char *name)
+{
+       return NULL;
+}
+
+/**
+ * x_table_lookup - lookup an x transition name via transition table
+ * @profile: current profile (NOT NULL)
+ * @xindex: index into x transition table
+ *
+ * Returns: refcounted profile, or NULL on failure (MAYBE NULL)
+ */
+static struct aa_profile *x_table_lookup(struct aa_profile *profile, u32 xindex)
+{
+       struct aa_profile *new_profile = NULL;
+       struct aa_namespace *ns = profile->ns;
+       u32 xtype = xindex & AA_X_TYPE_MASK;
+       int index = xindex & AA_X_INDEX_MASK;
+       const char *name;
+
+       /* index is guaranteed to be in range, validated at load time */
+       for (name = profile->file.trans.table[index]; !new_profile && name;
+            name = next_name(xtype, name)) {
+               struct aa_namespace *new_ns;
+               const char *xname = NULL;
+
+               new_ns = NULL;
+               if (xindex & AA_X_CHILD) {
+                       /* release by caller */
+                       new_profile = aa_find_child(profile, name);
+                       continue;
+               } else if (*name == ':') {
+                       /* switching namespace */
+                       const char *ns_name;
+                       xname = name = separate_fqname(name, &ns_name);
+                       if (!xname)
+                               /* no name so use profile name */
+                               xname = profile->base.hname;
+                       if (*ns_name == '@') {
+                               /* TODO: variable support */
+                               ;
+                       }
+                       /* released below */
+                       new_ns = aa_find_namespace(ns, ns_name);
+                       if (!new_ns)
+                               continue;
+               } else if (*name == '@') {
+                       /* TODO: variable support */
+                       continue;
+               } else {
+                       /* basic namespace lookup */
+                       xname = name;
+               }
+
+               /* released by caller */
+               new_profile = aa_lookup_profile(new_ns ? new_ns : ns, xname);
+               aa_put_namespace(new_ns);
+       }
+
+       /* released by caller */
+       return new_profile;
+}
+
+/**
+ * x_to_profile - get target profile for a given xindex
+ * @profile: current profile  (NOT NULL)
+ * @name: name to lookup (NOT NULL)
+ * @xindex: index into x transition table
+ *
+ * find profile for a transition index
+ *
+ * Returns: refcounted profile or NULL if not found available
+ */
+static struct aa_profile *x_to_profile(struct aa_profile *profile,
+                                      const char *name, u32 xindex)
+{
+       struct aa_profile *new_profile = NULL;
+       struct aa_namespace *ns = profile->ns;
+       u32 xtype = xindex & AA_X_TYPE_MASK;
+
+       switch (xtype) {
+       case AA_X_NONE:
+               /* fail exec unless ix || ux fallback - handled by caller */
+               return NULL;
+       case AA_X_NAME:
+               if (xindex & AA_X_CHILD)
+                       /* released by caller */
+                       new_profile = find_attach(ns, &profile->base.profiles,
+                                                 name);
+               else
+                       /* released by caller */
+                       new_profile = find_attach(ns, &ns->base.profiles,
+                                                 name);
+               break;
+       case AA_X_TABLE:
+               /* released by caller */
+               new_profile = x_table_lookup(profile, xindex);
+               break;
+       }
+
+       /* released by caller */
+       return new_profile;
+}
+
+/**
+ * apparmor_bprm_set_creds - set the new creds on the bprm struct
+ * @bprm: binprm for the exec  (NOT NULL)
+ *
+ * Returns: %0 or error on failure
+ */
+int apparmor_bprm_set_creds(struct linux_binprm *bprm)
+{
+       struct aa_task_cxt *cxt;
+       struct aa_profile *profile, *new_profile = NULL;
+       struct aa_namespace *ns;
+       char *buffer = NULL;
+       unsigned int state;
+       struct file_perms perms = {};
+       struct path_cond cond = {
+               bprm->file->f_path.dentry->d_inode->i_uid,
+               bprm->file->f_path.dentry->d_inode->i_mode
+       };
+       const char *name = NULL, *target = NULL, *info = NULL;
+       int error = cap_bprm_set_creds(bprm);
+       if (error)
+               return error;
+
+       if (bprm->cred_prepared)
+               return 0;
+
+       cxt = bprm->cred->security;
+       BUG_ON(!cxt);
+
+       profile = aa_get_profile(aa_newest_version(cxt->profile));
+       /*
+        * get the namespace from the replacement profile as replacement
+        * can change the namespace
+        */
+       ns = profile->ns;
+       state = profile->file.start;
+
+       /* buffer freed below, name is pointer into buffer */
+       error = aa_get_name(&bprm->file->f_path, profile->path_flags, &buffer,
+                           &name);
+       if (error) {
+               if (profile->flags &
+                   (PFLAG_IX_ON_NAME_ERROR | PFLAG_UNCONFINED))
+                       error = 0;
+               info = "Exec failed name resolution";
+               name = bprm->filename;
+               goto audit;
+       }
+
+       /* Test for onexec first as onexec directives override other
+        * x transitions.
+        */
+       if (unconfined(profile)) {
+               /* unconfined task */
+               if (cxt->onexec)
+                       /* change_profile on exec already been granted */
+                       new_profile = aa_get_profile(cxt->onexec);
+               else
+                       new_profile = find_attach(ns, &ns->base.profiles, name);
+               if (!new_profile)
+                       goto cleanup;
+               goto apply;
+       }
+
+       /* find exec permissions for name */
+       state = aa_str_perms(profile->file.dfa, state, name, &cond, &perms);
+       if (cxt->onexec) {
+               struct file_perms cp;
+               info = "change_profile onexec";
+               if (!(perms.allow & AA_MAY_ONEXEC))
+                       goto audit;
+
+               /* test if this exec can be paired with change_profile onexec.
+                * onexec permission is linked to exec with a standard pairing
+                * exec\0change_profile
+                */
+               state = aa_dfa_null_transition(profile->file.dfa, state);
+               cp = change_profile_perms(profile, cxt->onexec->ns, name,
+                                         AA_MAY_ONEXEC, state);
+
+               if (!(cp.allow & AA_MAY_ONEXEC))
+                       goto audit;
+               new_profile = aa_get_profile(aa_newest_version(cxt->onexec));
+               goto apply;
+       }
+
+       if (perms.allow & MAY_EXEC) {
+               /* exec permission determine how to transition */
+               new_profile = x_to_profile(profile, name, perms.xindex);
+               if (!new_profile) {
+                       if (perms.xindex & AA_X_INHERIT) {
+                               /* (p|c|n)ix - don't change profile but do
+                                * use the newest version, which was picked
+                                * up above when getting profile
+                                */
+                               info = "ix fallback";
+                               new_profile = aa_get_profile(profile);
+                               goto x_clear;
+                       } else if (perms.xindex & AA_X_UNCONFINED) {
+                               new_profile = aa_get_profile(ns->unconfined);
+                               info = "ux fallback";
+                       } else {
+                               error = -ENOENT;
+                               info = "profile not found";
+                       }
+               }
+       } else if (COMPLAIN_MODE(profile)) {
+               /* no exec permission - are we in learning mode */
+               new_profile = aa_new_null_profile(profile, 0);
+               if (!new_profile) {
+                       error = -ENOMEM;
+                       info = "could not create null profile";
+               } else {
+                       error = -EACCES;
+                       target = new_profile->base.hname;
+               }
+               perms.xindex |= AA_X_UNSAFE;
+       } else
+               /* fail exec */
+               error = -EACCES;
+
+       if (!new_profile)
+               goto audit;
+
+       if (bprm->unsafe & LSM_UNSAFE_SHARE) {
+               /* FIXME: currently don't mediate shared state */
+               ;
+       }
+
+       if (bprm->unsafe & (LSM_UNSAFE_PTRACE | LSM_UNSAFE_PTRACE_CAP)) {
+               error = may_change_ptraced_domain(current, new_profile);
+               if (error) {
+                       aa_put_profile(new_profile);
+                       goto audit;
+               }
+       }
+
+       /* Determine if secure exec is needed.
+        * Can be at this point for the following reasons:
+        * 1. unconfined switching to confined
+        * 2. confined switching to different confinement
+        * 3. confined switching to unconfined
+        *
+        * Cases 2 and 3 are marked as requiring secure exec
+        * (unless policy specified "unsafe exec")
+        *
+        * bprm->unsafe is used to cache the AA_X_UNSAFE permission
+        * to avoid having to recompute in secureexec
+        */
+       if (!(perms.xindex & AA_X_UNSAFE)) {
+               AA_DEBUG("scrubbing environment variables for %s profile=%s\n",
+                        name, new_profile->base.hname);
+               bprm->unsafe |= AA_SECURE_X_NEEDED;
+       }
+apply:
+       target = new_profile->base.hname;
+       /* when transitioning profiles clear unsafe personality bits */
+       bprm->per_clear |= PER_CLEAR_ON_SETID;
+
+x_clear:
+       aa_put_profile(cxt->profile);
+       /* transfer new profile reference will be released when cxt is freed */
+       cxt->profile = new_profile;
+
+       /* clear out all temporary/transitional state from the context */
+       aa_put_profile(cxt->previous);
+       aa_put_profile(cxt->onexec);
+       cxt->previous = NULL;
+       cxt->onexec = NULL;
+       cxt->token = 0;
+
+audit:
+       error = aa_audit_file(profile, &perms, GFP_KERNEL, OP_EXEC, MAY_EXEC,
+                             name, target, cond.uid, info, error);
+
+cleanup:
+       aa_put_profile(profile);
+       kfree(buffer);
+
+       return error;
+}
+
+/**
+ * apparmor_bprm_secureexec - determine if secureexec is needed
+ * @bprm: binprm for exec  (NOT NULL)
+ *
+ * Returns: %1 if secureexec is needed else %0
+ */
+int apparmor_bprm_secureexec(struct linux_binprm *bprm)
+{
+       int ret = cap_bprm_secureexec(bprm);
+
+       /* the decision to use secure exec is computed in set_creds
+        * and stored in bprm->unsafe.
+        */
+       if (!ret && (bprm->unsafe & AA_SECURE_X_NEEDED))
+               ret = 1;
+
+       return ret;
+}
+
+/**
+ * apparmor_bprm_committing_creds - do task cleanup on committing new creds
+ * @bprm: binprm for the exec  (NOT NULL)
+ */
+void apparmor_bprm_committing_creds(struct linux_binprm *bprm)
+{
+       struct aa_profile *profile = __aa_current_profile();
+       struct aa_task_cxt *new_cxt = bprm->cred->security;
+
+       /* bail out if unconfined or not changing profile */
+       if ((new_cxt->profile == profile) ||
+           (unconfined(new_cxt->profile)))
+               return;
+
+       current->pdeath_signal = 0;
+
+       /* reset soft limits and set hard limits for the new profile */
+       __aa_transition_rlimits(profile, new_cxt->profile);
+}
+
+/**
+ * apparmor_bprm_commited_cred - do cleanup after new creds committed
+ * @bprm: binprm for the exec  (NOT NULL)
+ */
+void apparmor_bprm_committed_creds(struct linux_binprm *bprm)
+{
+       /* TODO: cleanup signals - ipc mediation */
+       return;
+}
+
+/*
+ * Functions for self directed profile change
+ */
+
+/**
+ * new_compound_name - create an hname with @n2 appended to @n1
+ * @n1: base of hname  (NOT NULL)
+ * @n2: name to append (NOT NULL)
+ *
+ * Returns: new name or NULL on error
+ */
+static char *new_compound_name(const char *n1, const char *n2)
+{
+       char *name = kmalloc(strlen(n1) + strlen(n2) + 3, GFP_KERNEL);
+       if (name)
+               sprintf(name, "%s//%s", n1, n2);
+       return name;
+}
+
+/**
+ * aa_change_hat - change hat to/from subprofile
+ * @hats: vector of hat names to try changing into (MAYBE NULL if @count == 0)
+ * @count: number of hat names in @hats
+ * @token: magic value to validate the hat change
+ * @permtest: true if this is just a permission test
+ *
+ * Change to the first profile specified in @hats that exists, and store
+ * the @hat_magic in the current task context.  If the count == 0 and the
+ * @token matches that stored in the current task context, return to the
+ * top level profile.
+ *
+ * Returns %0 on success, error otherwise.
+ */
+int aa_change_hat(const char *hats[], int count, u64 token, bool permtest)
+{
+       const struct cred *cred;
+       struct aa_task_cxt *cxt;
+       struct aa_profile *profile, *previous_profile, *hat = NULL;
+       char *name = NULL;
+       int i;
+       struct file_perms perms = {};
+       const char *target = NULL, *info = NULL;
+       int error = 0;
+
+       /* released below */
+       cred = get_current_cred();
+       cxt = cred->security;
+       profile = aa_cred_profile(cred);
+       previous_profile = cxt->previous;
+
+       if (unconfined(profile)) {
+               info = "unconfined";
+               error = -EPERM;
+               goto audit;
+       }
+
+       if (count) {
+               /* attempting to change into a new hat or switch to a sibling */
+               struct aa_profile *root;
+               root = PROFILE_IS_HAT(profile) ? profile->parent : profile;
+
+               /* find first matching hat */
+               for (i = 0; i < count && !hat; i++)
+                       /* released below */
+                       hat = aa_find_child(root, hats[i]);
+               if (!hat) {
+                       if (!COMPLAIN_MODE(root) || permtest) {
+                               if (list_empty(&root->base.profiles))
+                                       error = -ECHILD;
+                               else
+                                       error = -ENOENT;
+                               goto out;
+                       }
+
+                       /*
+                        * In complain mode and failed to match any hats.
+                        * Audit the failure is based off of the first hat
+                        * supplied.  This is done due how userspace
+                        * interacts with change_hat.
+                        *
+                        * TODO: Add logging of all failed hats
+                        */
+
+                       /* freed below */
+                       name = new_compound_name(root->base.hname, hats[0]);
+                       target = name;
+                       /* released below */
+                       hat = aa_new_null_profile(profile, 1);
+                       if (!hat) {
+                               info = "failed null profile create";
+                               error = -ENOMEM;
+                               goto audit;
+                       }
+               } else {
+                       target = hat->base.hname;
+                       if (!PROFILE_IS_HAT(hat)) {
+                               info = "target not hat";
+                               error = -EPERM;
+                               goto audit;
+                       }
+               }
+
+               error = may_change_ptraced_domain(current, hat);
+               if (error) {
+                       info = "ptraced";
+                       error = -EPERM;
+                       goto audit;
+               }
+
+               if (!permtest) {
+                       error = aa_set_current_hat(hat, token);
+                       if (error == -EACCES)
+                               /* kill task in case of brute force attacks */
+                               perms.kill = AA_MAY_CHANGEHAT;
+                       else if (name && !error)
+                               /* reset error for learning of new hats */
+                               error = -ENOENT;
+               }
+       } else if (previous_profile) {
+               /* Return to saved profile.  Kill task if restore fails
+                * to avoid brute force attacks
+                */
+               target = previous_profile->base.hname;
+               error = aa_restore_previous_profile(token);
+               perms.kill = AA_MAY_CHANGEHAT;
+       } else
+               /* ignore restores when there is no saved profile */
+               goto out;
+
+audit:
+       if (!permtest)
+               error = aa_audit_file(profile, &perms, GFP_KERNEL,
+                                     OP_CHANGE_HAT, AA_MAY_CHANGEHAT, NULL,
+                                     target, 0, info, error);
+
+out:
+       aa_put_profile(hat);
+       kfree(name);
+       put_cred(cred);
+
+       return error;
+}
+
+/**
+ * aa_change_profile - perform a one-way profile transition
+ * @ns_name: name of the profile namespace to change to (MAYBE NULL)
+ * @hname: name of profile to change to (MAYBE NULL)
+ * @onexec: whether this transition is to take place immediately or at exec
+ * @permtest: true if this is just a permission test
+ *
+ * Change to new profile @name.  Unlike with hats, there is no way
+ * to change back.  If @name isn't specified the current profile name is
+ * used.
+ * If @onexec then the transition is delayed until
+ * the next exec.
+ *
+ * Returns %0 on success, error otherwise.
+ */
+int aa_change_profile(const char *ns_name, const char *hname, bool onexec,
+                     bool permtest)
+{
+       const struct cred *cred;
+       struct aa_task_cxt *cxt;
+       struct aa_profile *profile, *target = NULL;
+       struct aa_namespace *ns = NULL;
+       struct file_perms perms = {};
+       const char *name = NULL, *info = NULL;
+       int op, error = 0;
+       u32 request;
+
+       if (!hname && !ns_name)
+               return -EINVAL;
+
+       if (onexec) {
+               request = AA_MAY_ONEXEC;
+               op = OP_CHANGE_ONEXEC;
+       } else {
+               request = AA_MAY_CHANGE_PROFILE;
+               op = OP_CHANGE_PROFILE;
+       }
+
+       cred = get_current_cred();
+       cxt = cred->security;
+       profile = aa_cred_profile(cred);
+
+       if (ns_name) {
+               /* released below */
+               ns = aa_find_namespace(profile->ns, ns_name);
+               if (!ns) {
+                       /* we don't create new namespace in complain mode */
+                       name = ns_name;
+                       info = "namespace not found";
+                       error = -ENOENT;
+                       goto audit;
+               }
+       } else
+               /* released below */
+               ns = aa_get_namespace(profile->ns);
+
+       /* if the name was not specified, use the name of the current profile */
+       if (!hname) {
+               if (unconfined(profile))
+                       hname = ns->unconfined->base.hname;
+               else
+                       hname = profile->base.hname;
+       }
+
+       perms = change_profile_perms(profile, ns, hname, request,
+                                    profile->file.start);
+       if (!(perms.allow & request)) {
+               error = -EACCES;
+               goto audit;
+       }
+
+       /* released below */
+       target = aa_lookup_profile(ns, hname);
+       if (!target) {
+               info = "profile not found";
+               error = -ENOENT;
+               if (permtest || !COMPLAIN_MODE(profile))
+                       goto audit;
+               /* released below */
+               target = aa_new_null_profile(profile, 0);
+               if (!target) {
+                       info = "failed null profile create";
+                       error = -ENOMEM;
+                       goto audit;
+               }
+       }
+
+       /* check if tracing task is allowed to trace target domain */
+       error = may_change_ptraced_domain(current, target);
+       if (error) {
+               info = "ptrace prevents transition";
+               goto audit;
+       }
+
+       if (permtest)
+               goto audit;
+
+       if (onexec)
+               error = aa_set_current_onexec(target);
+       else
+               error = aa_replace_current_profile(target);
+
+audit:
+       if (!permtest)
+               error = aa_audit_file(profile, &perms, GFP_KERNEL, op, request,
+                                     name, hname, 0, info, error);
+
+       aa_put_namespace(ns);
+       aa_put_profile(target);
+       put_cred(cred);
+
+       return error;
+}
diff --git a/security/apparmor/file.c b/security/apparmor/file.c
new file mode 100644 (file)
index 0000000..7312db7
--- /dev/null
@@ -0,0 +1,457 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor mediation of files
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include "include/apparmor.h"
+#include "include/audit.h"
+#include "include/file.h"
+#include "include/match.h"
+#include "include/path.h"
+#include "include/policy.h"
+
+struct file_perms nullperms;
+
+
+/**
+ * audit_file_mask - convert mask to permission string
+ * @buffer: buffer to write string to (NOT NULL)
+ * @mask: permission mask to convert
+ */
+static void audit_file_mask(struct audit_buffer *ab, u32 mask)
+{
+       char str[10];
+
+       char *m = str;
+
+       if (mask & AA_EXEC_MMAP)
+               *m++ = 'm';
+       if (mask & (MAY_READ | AA_MAY_META_READ))
+               *m++ = 'r';
+       if (mask & (MAY_WRITE | AA_MAY_META_WRITE | AA_MAY_CHMOD |
+                   AA_MAY_CHOWN))
+               *m++ = 'w';
+       else if (mask & MAY_APPEND)
+               *m++ = 'a';
+       if (mask & AA_MAY_CREATE)
+               *m++ = 'c';
+       if (mask & AA_MAY_DELETE)
+               *m++ = 'd';
+       if (mask & AA_MAY_LINK)
+               *m++ = 'l';
+       if (mask & AA_MAY_LOCK)
+               *m++ = 'k';
+       if (mask & MAY_EXEC)
+               *m++ = 'x';
+       *m = '\0';
+
+       audit_log_string(ab, str);
+}
+
+/**
+ * file_audit_cb - call back for file specific audit fields
+ * @ab: audit_buffer  (NOT NULL)
+ * @va: audit struct to audit values of  (NOT NULL)
+ */
+static void file_audit_cb(struct audit_buffer *ab, void *va)
+{
+       struct common_audit_data *sa = va;
+       uid_t fsuid = current_fsuid();
+
+       if (sa->aad.fs.request & AA_AUDIT_FILE_MASK) {
+               audit_log_format(ab, " requested_mask=");
+               audit_file_mask(ab, sa->aad.fs.request);
+       }
+       if (sa->aad.fs.denied & AA_AUDIT_FILE_MASK) {
+               audit_log_format(ab, " denied_mask=");
+               audit_file_mask(ab, sa->aad.fs.denied);
+       }
+       if (sa->aad.fs.request & AA_AUDIT_FILE_MASK) {
+               audit_log_format(ab, " fsuid=%d", fsuid);
+               audit_log_format(ab, " ouid=%d", sa->aad.fs.ouid);
+       }
+
+       if (sa->aad.fs.target) {
+               audit_log_format(ab, " target=");
+               audit_log_untrustedstring(ab, sa->aad.fs.target);
+       }
+}
+
+/**
+ * aa_audit_file - handle the auditing of file operations
+ * @profile: the profile being enforced  (NOT NULL)
+ * @perms: the permissions computed for the request (NOT NULL)
+ * @gfp: allocation flags
+ * @op: operation being mediated
+ * @request: permissions requested
+ * @name: name of object being mediated (MAYBE NULL)
+ * @target: name of target (MAYBE NULL)
+ * @ouid: object uid
+ * @info: extra information message (MAYBE NULL)
+ * @error: 0 if operation allowed else failure error code
+ *
+ * Returns: %0 or error on failure
+ */
+int aa_audit_file(struct aa_profile *profile, struct file_perms *perms,
+                 gfp_t gfp, int op, u32 request, const char *name,
+                 const char *target, uid_t ouid, const char *info, int error)
+{
+       int type = AUDIT_APPARMOR_AUTO;
+       struct common_audit_data sa;
+       COMMON_AUDIT_DATA_INIT(&sa, NONE);
+       sa.aad.op = op,
+       sa.aad.fs.request = request;
+       sa.aad.name = name;
+       sa.aad.fs.target = target;
+       sa.aad.fs.ouid = ouid;
+       sa.aad.info = info;
+       sa.aad.error = error;
+
+       if (likely(!sa.aad.error)) {
+               u32 mask = perms->audit;
+
+               if (unlikely(AUDIT_MODE(profile) == AUDIT_ALL))
+                       mask = 0xffff;
+
+               /* mask off perms that are not being force audited */
+               sa.aad.fs.request &= mask;
+
+               if (likely(!sa.aad.fs.request))
+                       return 0;
+               type = AUDIT_APPARMOR_AUDIT;
+       } else {
+               /* only report permissions that were denied */
+               sa.aad.fs.request = sa.aad.fs.request & ~perms->allow;
+
+               if (sa.aad.fs.request & perms->kill)
+                       type = AUDIT_APPARMOR_KILL;
+
+               /* quiet known rejects, assumes quiet and kill do not overlap */
+               if ((sa.aad.fs.request & perms->quiet) &&
+                   AUDIT_MODE(profile) != AUDIT_NOQUIET &&
+                   AUDIT_MODE(profile) != AUDIT_ALL)
+                       sa.aad.fs.request &= ~perms->quiet;
+
+               if (!sa.aad.fs.request)
+                       return COMPLAIN_MODE(profile) ? 0 : sa.aad.error;
+       }
+
+       sa.aad.fs.denied = sa.aad.fs.request & ~perms->allow;
+       return aa_audit(type, profile, gfp, &sa, file_audit_cb);
+}
+
+/**
+ * map_old_perms - map old file perms layout to the new layout
+ * @old: permission set in old mapping
+ *
+ * Returns: new permission mapping
+ */
+static u32 map_old_perms(u32 old)
+{
+       u32 new = old & 0xf;
+       if (old & MAY_READ)
+               new |= AA_MAY_META_READ;
+       if (old & MAY_WRITE)
+               new |= AA_MAY_META_WRITE | AA_MAY_CREATE | AA_MAY_DELETE |
+                       AA_MAY_CHMOD | AA_MAY_CHOWN;
+       if (old & 0x10)
+               new |= AA_MAY_LINK;
+       /* the old mapping lock and link_subset flags where overlaid
+        * and use was determined by part of a pair that they were in
+        */
+       if (old & 0x20)
+               new |= AA_MAY_LOCK | AA_LINK_SUBSET;
+       if (old & 0x40) /* AA_EXEC_MMAP */
+               new |= AA_EXEC_MMAP;
+
+       new |= AA_MAY_META_READ;
+
+       return new;
+}
+
+/**
+ * compute_perms - convert dfa compressed perms to internal perms
+ * @dfa: dfa to compute perms for   (NOT NULL)
+ * @state: state in dfa
+ * @cond:  conditions to consider  (NOT NULL)
+ *
+ * TODO: convert from dfa + state to permission entry, do computation conversion
+ *       at load time.
+ *
+ * Returns: computed permission set
+ */
+static struct file_perms compute_perms(struct aa_dfa *dfa, unsigned int state,
+                                      struct path_cond *cond)
+{
+       struct file_perms perms;
+
+       /* FIXME: change over to new dfa format
+        * currently file perms are encoded in the dfa, new format
+        * splits the permissions from the dfa.  This mapping can be
+        * done at profile load
+        */
+       perms.kill = 0;
+
+       if (current_fsuid() == cond->uid) {
+               perms.allow = map_old_perms(dfa_user_allow(dfa, state));
+               perms.audit = map_old_perms(dfa_user_audit(dfa, state));
+               perms.quiet = map_old_perms(dfa_user_quiet(dfa, state));
+               perms.xindex = dfa_user_xindex(dfa, state);
+       } else {
+               perms.allow = map_old_perms(dfa_other_allow(dfa, state));
+               perms.audit = map_old_perms(dfa_other_audit(dfa, state));
+               perms.quiet = map_old_perms(dfa_other_quiet(dfa, state));
+               perms.xindex = dfa_other_xindex(dfa, state);
+       }
+
+       /* change_profile wasn't determined by ownership in old mapping */
+       if (ACCEPT_TABLE(dfa)[state] & 0x80000000)
+               perms.allow |= AA_MAY_CHANGE_PROFILE;
+
+       return perms;
+}
+
+/**
+ * aa_str_perms - find permission that match @name
+ * @dfa: to match against  (MAYBE NULL)
+ * @state: state to start matching in
+ * @name: string to match against dfa  (NOT NULL)
+ * @cond: conditions to consider for permission set computation  (NOT NULL)
+ * @perms: Returns - the permissions found when matching @name
+ *
+ * Returns: the final state in @dfa when beginning @start and walking @name
+ */
+unsigned int aa_str_perms(struct aa_dfa *dfa, unsigned int start,
+                         const char *name, struct path_cond *cond,
+                         struct file_perms *perms)
+{
+       unsigned int state;
+       if (!dfa) {
+               *perms = nullperms;
+               return DFA_NOMATCH;
+       }
+
+       state = aa_dfa_match(dfa, start, name);
+       *perms = compute_perms(dfa, state, cond);
+
+       return state;
+}
+
+/**
+ * is_deleted - test if a file has been completely unlinked
+ * @dentry: dentry of file to test for deletion  (NOT NULL)
+ *
+ * Returns: %1 if deleted else %0
+ */
+static inline bool is_deleted(struct dentry *dentry)
+{
+       if (d_unlinked(dentry) && dentry->d_inode->i_nlink == 0)
+               return 1;
+       return 0;
+}
+
+/**
+ * aa_path_perm - do permissions check & audit for @path
+ * @op: operation being checked
+ * @profile: profile being enforced  (NOT NULL)
+ * @path: path to check permissions of  (NOT NULL)
+ * @flags: any additional path flags beyond what the profile specifies
+ * @request: requested permissions
+ * @cond: conditional info for this request  (NOT NULL)
+ *
+ * Returns: %0 else error if access denied or other error
+ */
+int aa_path_perm(int op, struct aa_profile *profile, struct path *path,
+                int flags, u32 request, struct path_cond *cond)
+{
+       char *buffer = NULL;
+       struct file_perms perms = {};
+       const char *name, *info = NULL;
+       int error;
+
+       flags |= profile->path_flags | (S_ISDIR(cond->mode) ? PATH_IS_DIR : 0);
+       error = aa_get_name(path, flags, &buffer, &name);
+       if (error) {
+               if (error == -ENOENT && is_deleted(path->dentry)) {
+                       /* Access to open files that are deleted are
+                        * give a pass (implicit delegation)
+                        */
+                       error = 0;
+                       perms.allow = request;
+               } else if (error == -ENOENT)
+                       info = "Failed name lookup - deleted entry";
+               else if (error == -ESTALE)
+                       info = "Failed name lookup - disconnected path";
+               else if (error == -ENAMETOOLONG)
+                       info = "Failed name lookup - name too long";
+               else
+                       info = "Failed name lookup";
+       } else {
+               aa_str_perms(profile->file.dfa, profile->file.start, name, cond,
+                            &perms);
+               if (request & ~perms.allow)
+                       error = -EACCES;
+       }
+       error = aa_audit_file(profile, &perms, GFP_KERNEL, op, request, name,
+                             NULL, cond->uid, info, error);
+       kfree(buffer);
+
+       return error;
+}
+
+/**
+ * xindex_is_subset - helper for aa_path_link
+ * @link: link permission set
+ * @target: target permission set
+ *
+ * test target x permissions are equal OR a subset of link x permissions
+ * this is done as part of the subset test, where a hardlink must have
+ * a subset of permissions that the target has.
+ *
+ * Returns: %1 if subset else %0
+ */
+static inline bool xindex_is_subset(u32 link, u32 target)
+{
+       if (((link & ~AA_X_UNSAFE) != (target & ~AA_X_UNSAFE)) ||
+           ((link & AA_X_UNSAFE) && !(target & AA_X_UNSAFE)))
+               return 0;
+
+       return 1;
+}
+
+/**
+ * aa_path_link - Handle hard link permission check
+ * @profile: the profile being enforced  (NOT NULL)
+ * @old_dentry: the target dentry  (NOT NULL)
+ * @new_dir: directory the new link will be created in  (NOT NULL)
+ * @new_dentry: the link being created  (NOT NULL)
+ *
+ * Handle the permission test for a link & target pair.  Permission
+ * is encoded as a pair where the link permission is determined
+ * first, and if allowed, the target is tested.  The target test
+ * is done from the point of the link match (not start of DFA)
+ * making the target permission dependent on the link permission match.
+ *
+ * The subset test if required forces that permissions granted
+ * on link are a subset of the permission granted to target.
+ *
+ * Returns: %0 if allowed else error
+ */
+int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
+                struct path *new_dir, struct dentry *new_dentry)
+{
+       struct path link = { new_dir->mnt, new_dentry };
+       struct path target = { new_dir->mnt, old_dentry };
+       struct path_cond cond = {
+               old_dentry->d_inode->i_uid,
+               old_dentry->d_inode->i_mode
+       };
+       char *buffer = NULL, *buffer2 = NULL;
+       const char *lname, *tname = NULL, *info = NULL;
+       struct file_perms lperms, perms;
+       u32 request = AA_MAY_LINK;
+       unsigned int state;
+       int error;
+
+       lperms = nullperms;
+
+       /* buffer freed below, lname is pointer in buffer */
+       error = aa_get_name(&link, profile->path_flags, &buffer, &lname);
+       if (error)
+               goto audit;
+
+       /* buffer2 freed below, tname is pointer in buffer2 */
+       error = aa_get_name(&target, profile->path_flags, &buffer2, &tname);
+       if (error)
+               goto audit;
+
+       error = -EACCES;
+       /* aa_str_perms - handles the case of the dfa being NULL */
+       state = aa_str_perms(profile->file.dfa, profile->file.start, lname,
+                            &cond, &lperms);
+
+       if (!(lperms.allow & AA_MAY_LINK))
+               goto audit;
+
+       /* test to see if target can be paired with link */
+       state = aa_dfa_null_transition(profile->file.dfa, state);
+       aa_str_perms(profile->file.dfa, state, tname, &cond, &perms);
+
+       /* force audit/quiet masks for link are stored in the second entry
+        * in the link pair.
+        */
+       lperms.audit = perms.audit;
+       lperms.quiet = perms.quiet;
+       lperms.kill = perms.kill;
+
+       if (!(perms.allow & AA_MAY_LINK)) {
+               info = "target restricted";
+               goto audit;
+       }
+
+       /* done if link subset test is not required */
+       if (!(perms.allow & AA_LINK_SUBSET))
+               goto done_tests;
+
+       /* Do link perm subset test requiring allowed permission on link are a
+        * subset of the allowed permissions on target.
+        */
+       aa_str_perms(profile->file.dfa, profile->file.start, tname, &cond,
+                    &perms);
+
+       /* AA_MAY_LINK is not considered in the subset test */
+       request = lperms.allow & ~AA_MAY_LINK;
+       lperms.allow &= perms.allow | AA_MAY_LINK;
+
+       request |= AA_AUDIT_FILE_MASK & (lperms.allow & ~perms.allow);
+       if (request & ~lperms.allow) {
+               goto audit;
+       } else if ((lperms.allow & MAY_EXEC) &&
+                  !xindex_is_subset(lperms.xindex, perms.xindex)) {
+               lperms.allow &= ~MAY_EXEC;
+               request |= MAY_EXEC;
+               info = "link not subset of target";
+               goto audit;
+       }
+
+done_tests:
+       error = 0;
+
+audit:
+       error = aa_audit_file(profile, &lperms, GFP_KERNEL, OP_LINK, request,
+                             lname, tname, cond.uid, info, error);
+       kfree(buffer);
+       kfree(buffer2);
+
+       return error;
+}
+
+/**
+ * aa_file_perm - do permission revalidation check & audit for @file
+ * @op: operation being checked
+ * @profile: profile being enforced   (NOT NULL)
+ * @file: file to revalidate access permissions on  (NOT NULL)
+ * @request: requested permissions
+ *
+ * Returns: %0 if access allowed else error
+ */
+int aa_file_perm(int op, struct aa_profile *profile, struct file *file,
+                u32 request)
+{
+       struct path_cond cond = {
+               .uid = file->f_path.dentry->d_inode->i_uid,
+               .mode = file->f_path.dentry->d_inode->i_mode
+       };
+
+       return aa_path_perm(op, profile, &file->f_path, PATH_DELEGATE_DELETED,
+                           request, &cond);
+}
diff --git a/security/apparmor/include/apparmor.h b/security/apparmor/include/apparmor.h
new file mode 100644 (file)
index 0000000..38ccaea
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor basic global and lib definitions
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __APPARMOR_H
+#define __APPARMOR_H
+
+#include <linux/fs.h>
+
+#include "match.h"
+
+/* Control parameters settable through module/boot flags */
+extern enum audit_mode aa_g_audit;
+extern int aa_g_audit_header;
+extern int aa_g_debug;
+extern int aa_g_lock_policy;
+extern int aa_g_logsyscall;
+extern int aa_g_paranoid_load;
+extern unsigned int aa_g_path_max;
+
+/*
+ * DEBUG remains global (no per profile flag) since it is mostly used in sysctl
+ * which is not related to profile accesses.
+ */
+
+#define AA_DEBUG(fmt, args...)                                         \
+       do {                                                            \
+               if (aa_g_debug && printk_ratelimit())                   \
+                       printk(KERN_DEBUG "AppArmor: " fmt, ##args);    \
+       } while (0)
+
+#define AA_ERROR(fmt, args...)                                         \
+       do {                                                            \
+               if (printk_ratelimit())                                 \
+                       printk(KERN_ERR "AppArmor: " fmt, ##args);      \
+       } while (0)
+
+/* Flag indicating whether initialization completed */
+extern int apparmor_initialized __initdata;
+
+/* fn's in lib */
+char *aa_split_fqname(char *args, char **ns_name);
+void aa_info_message(const char *str);
+void *kvmalloc(size_t size);
+void kvfree(void *buffer);
+
+
+/**
+ * aa_strneq - compare null terminated @str to a non null terminated substring
+ * @str: a null terminated string
+ * @sub: a substring, not necessarily null terminated
+ * @len: length of @sub to compare
+ *
+ * The @str string must be full consumed for this to be considered a match
+ */
+static inline bool aa_strneq(const char *str, const char *sub, int len)
+{
+       return !strncmp(str, sub, len) && !str[len];
+}
+
+/**
+ * aa_dfa_null_transition - step to next state after null character
+ * @dfa: the dfa to match against
+ * @start: the state of the dfa to start matching in
+ *
+ * aa_dfa_null_transition transitions to the next state after a null
+ * character which is not used in standard matching and is only
+ * used to separate pairs.
+ */
+static inline unsigned int aa_dfa_null_transition(struct aa_dfa *dfa,
+                                                 unsigned int start)
+{
+       /* the null transition only needs the string's null terminator byte */
+       return aa_dfa_match_len(dfa, start, "", 1);
+}
+
+static inline bool mediated_filesystem(struct inode *inode)
+{
+       return !(inode->i_sb->s_flags & MS_NOUSER);
+}
+
+#endif /* __APPARMOR_H */
diff --git a/security/apparmor/include/apparmorfs.h b/security/apparmor/include/apparmorfs.h
new file mode 100644 (file)
index 0000000..cb1e93a
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor filesystem definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_APPARMORFS_H
+#define __AA_APPARMORFS_H
+
+extern void __init aa_destroy_aafs(void);
+
+#endif /* __AA_APPARMORFS_H */
diff --git a/security/apparmor/include/audit.h b/security/apparmor/include/audit.h
new file mode 100644 (file)
index 0000000..1951786
--- /dev/null
@@ -0,0 +1,123 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor auditing function definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_AUDIT_H
+#define __AA_AUDIT_H
+
+#include <linux/audit.h>
+#include <linux/fs.h>
+#include <linux/lsm_audit.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+
+#include "file.h"
+
+struct aa_profile;
+
+extern const char *audit_mode_names[];
+#define AUDIT_MAX_INDEX 5
+
+#define AUDIT_APPARMOR_AUTO 0  /* auto choose audit message type */
+
+enum audit_mode {
+       AUDIT_NORMAL,           /* follow normal auditing of accesses */
+       AUDIT_QUIET_DENIED,     /* quiet all denied access messages */
+       AUDIT_QUIET,            /* quiet all messages */
+       AUDIT_NOQUIET,          /* do not quiet audit messages */
+       AUDIT_ALL               /* audit all accesses */
+};
+
+enum audit_type {
+       AUDIT_APPARMOR_AUDIT,
+       AUDIT_APPARMOR_ALLOWED,
+       AUDIT_APPARMOR_DENIED,
+       AUDIT_APPARMOR_HINT,
+       AUDIT_APPARMOR_STATUS,
+       AUDIT_APPARMOR_ERROR,
+       AUDIT_APPARMOR_KILL
+};
+
+extern const char *op_table[];
+enum aa_ops {
+       OP_NULL,
+
+       OP_SYSCTL,
+       OP_CAPABLE,
+
+       OP_UNLINK,
+       OP_MKDIR,
+       OP_RMDIR,
+       OP_MKNOD,
+       OP_TRUNC,
+       OP_LINK,
+       OP_SYMLINK,
+       OP_RENAME_SRC,
+       OP_RENAME_DEST,
+       OP_CHMOD,
+       OP_CHOWN,
+       OP_GETATTR,
+       OP_OPEN,
+
+       OP_FPERM,
+       OP_FLOCK,
+       OP_FMMAP,
+       OP_FMPROT,
+
+       OP_CREATE,
+       OP_POST_CREATE,
+       OP_BIND,
+       OP_CONNECT,
+       OP_LISTEN,
+       OP_ACCEPT,
+       OP_SENDMSG,
+       OP_RECVMSG,
+       OP_GETSOCKNAME,
+       OP_GETPEERNAME,
+       OP_GETSOCKOPT,
+       OP_SETSOCKOPT,
+       OP_SOCK_SHUTDOWN,
+
+       OP_PTRACE,
+
+       OP_EXEC,
+       OP_CHANGE_HAT,
+       OP_CHANGE_PROFILE,
+       OP_CHANGE_ONEXEC,
+
+       OP_SETPROCATTR,
+       OP_SETRLIMIT,
+
+       OP_PROF_REPL,
+       OP_PROF_LOAD,
+       OP_PROF_RM,
+};
+
+
+/* define a short hand for apparmor_audit_data portion of common_audit_data */
+#define aad apparmor_audit_data
+
+void aa_audit_msg(int type, struct common_audit_data *sa,
+                 void (*cb) (struct audit_buffer *, void *));
+int aa_audit(int type, struct aa_profile *profile, gfp_t gfp,
+            struct common_audit_data *sa,
+            void (*cb) (struct audit_buffer *, void *));
+
+static inline int complain_error(int error)
+{
+       if (error == -EPERM || error == -EACCES)
+               return 0;
+       return error;
+}
+
+#endif /* __AA_AUDIT_H */
diff --git a/security/apparmor/include/capability.h b/security/apparmor/include/capability.h
new file mode 100644 (file)
index 0000000..c24d295
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor capability mediation definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_CAPABILITY_H
+#define __AA_CAPABILITY_H
+
+#include <linux/sched.h>
+
+struct aa_profile;
+
+/* aa_caps - confinement data for capabilities
+ * @allowed: capabilities mask
+ * @audit: caps that are to be audited
+ * @quiet: caps that should not be audited
+ * @kill: caps that when requested will result in the task being killed
+ * @extended: caps that are subject finer grained mediation
+ */
+struct aa_caps {
+       kernel_cap_t allow;
+       kernel_cap_t audit;
+       kernel_cap_t quiet;
+       kernel_cap_t kill;
+       kernel_cap_t extended;
+};
+
+int aa_capable(struct task_struct *task, struct aa_profile *profile, int cap,
+              int audit);
+
+static inline void aa_free_cap_rules(struct aa_caps *caps)
+{
+       /* NOP */
+}
+
+#endif /* __AA_CAPBILITY_H */
diff --git a/security/apparmor/include/context.h b/security/apparmor/include/context.h
new file mode 100644 (file)
index 0000000..a9cbee4
--- /dev/null
@@ -0,0 +1,154 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor contexts used to associate "labels" to objects.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_CONTEXT_H
+#define __AA_CONTEXT_H
+
+#include <linux/cred.h>
+#include <linux/slab.h>
+#include <linux/sched.h>
+
+#include "policy.h"
+
+/* struct aa_file_cxt - the AppArmor context the file was opened in
+ * @perms: the permission the file was opened with
+ *
+ * The file_cxt could currently be directly stored in file->f_security
+ * as the profile reference is now stored in the f_cred.  However the
+ * cxt struct will expand in the future so we keep the struct.
+ */
+struct aa_file_cxt {
+       u16 allow;
+};
+
+/**
+ * aa_alloc_file_context - allocate file_cxt
+ * @gfp: gfp flags for allocation
+ *
+ * Returns: file_cxt or NULL on failure
+ */
+static inline struct aa_file_cxt *aa_alloc_file_context(gfp_t gfp)
+{
+       return kzalloc(sizeof(struct aa_file_cxt), gfp);
+}
+
+/**
+ * aa_free_file_context - free a file_cxt
+ * @cxt: file_cxt to free  (MAYBE_NULL)
+ */
+static inline void aa_free_file_context(struct aa_file_cxt *cxt)
+{
+       if (cxt)
+               kzfree(cxt);
+}
+
+/**
+ * struct aa_task_cxt - primary label for confined tasks
+ * @profile: the current profile   (NOT NULL)
+ * @exec: profile to transition to on next exec  (MAYBE NULL)
+ * @previous: profile the task may return to     (MAYBE NULL)
+ * @token: magic value the task must know for returning to @previous_profile
+ *
+ * Contains the task's current profile (which could change due to
+ * change_hat).  Plus the hat_magic needed during change_hat.
+ *
+ * TODO: make so a task can be confined by a stack of contexts
+ */
+struct aa_task_cxt {
+       struct aa_profile *profile;
+       struct aa_profile *onexec;
+       struct aa_profile *previous;
+       u64 token;
+};
+
+struct aa_task_cxt *aa_alloc_task_context(gfp_t flags);
+void aa_free_task_context(struct aa_task_cxt *cxt);
+void aa_dup_task_context(struct aa_task_cxt *new,
+                        const struct aa_task_cxt *old);
+int aa_replace_current_profile(struct aa_profile *profile);
+int aa_set_current_onexec(struct aa_profile *profile);
+int aa_set_current_hat(struct aa_profile *profile, u64 token);
+int aa_restore_previous_profile(u64 cookie);
+
+/**
+ * __aa_task_is_confined - determine if @task has any confinement
+ * @task: task to check confinement of  (NOT NULL)
+ *
+ * If @task != current needs to be called in RCU safe critical section
+ */
+static inline bool __aa_task_is_confined(struct task_struct *task)
+{
+       struct aa_task_cxt *cxt = __task_cred(task)->security;
+
+       BUG_ON(!cxt || !cxt->profile);
+       if (unconfined(aa_newest_version(cxt->profile)))
+               return 0;
+
+       return 1;
+}
+
+/**
+ * aa_cred_profile - obtain cred's profiles
+ * @cred: cred to obtain profiles from  (NOT NULL)
+ *
+ * Returns: confining profile
+ *
+ * does NOT increment reference count
+ */
+static inline struct aa_profile *aa_cred_profile(const struct cred *cred)
+{
+       struct aa_task_cxt *cxt = cred->security;
+       BUG_ON(!cxt || !cxt->profile);
+       return aa_newest_version(cxt->profile);
+}
+
+/**
+ * __aa_current_profile - find the current tasks confining profile
+ *
+ * Returns: up to date confining profile or the ns unconfined profile (NOT NULL)
+ *
+ * This fn will not update the tasks cred to the most up to date version
+ * of the profile so it is safe to call when inside of locks.
+ */
+static inline struct aa_profile *__aa_current_profile(void)
+{
+       return aa_cred_profile(current_cred());
+}
+
+/**
+ * aa_current_profile - find the current tasks confining profile and do updates
+ *
+ * Returns: up to date confining profile or the ns unconfined profile (NOT NULL)
+ *
+ * This fn will update the tasks cred structure if the profile has been
+ * replaced.  Not safe to call inside locks
+ */
+static inline struct aa_profile *aa_current_profile(void)
+{
+       const struct aa_task_cxt *cxt = current_cred()->security;
+       struct aa_profile *profile;
+       BUG_ON(!cxt || !cxt->profile);
+
+       profile = aa_newest_version(cxt->profile);
+       /*
+        * Whether or not replacement succeeds, use newest profile so
+        * there is no need to update it after replacement.
+        */
+       if (unlikely((cxt->profile != profile)))
+               aa_replace_current_profile(profile);
+
+       return profile;
+}
+
+#endif /* __AA_CONTEXT_H */
diff --git a/security/apparmor/include/domain.h b/security/apparmor/include/domain.h
new file mode 100644 (file)
index 0000000..de04464
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor security domain transition function definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/binfmts.h>
+#include <linux/types.h>
+
+#ifndef __AA_DOMAIN_H
+#define __AA_DOMAIN_H
+
+struct aa_domain {
+       int size;
+       char **table;
+};
+
+int apparmor_bprm_set_creds(struct linux_binprm *bprm);
+int apparmor_bprm_secureexec(struct linux_binprm *bprm);
+void apparmor_bprm_committing_creds(struct linux_binprm *bprm);
+void apparmor_bprm_committed_creds(struct linux_binprm *bprm);
+
+void aa_free_domain_entries(struct aa_domain *domain);
+int aa_change_hat(const char *hats[], int count, u64 token, bool permtest);
+int aa_change_profile(const char *ns_name, const char *name, bool onexec,
+                     bool permtest);
+
+#endif /* __AA_DOMAIN_H */
diff --git a/security/apparmor/include/file.h b/security/apparmor/include/file.h
new file mode 100644 (file)
index 0000000..be36fea
--- /dev/null
@@ -0,0 +1,217 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor file mediation function definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_FILE_H
+#define __AA_FILE_H
+
+#include <linux/path.h>
+
+#include "domain.h"
+#include "match.h"
+
+struct aa_profile;
+
+/*
+ * We use MAY_EXEC, MAY_WRITE, MAY_READ, MAY_APPEND and the following flags
+ * for profile permissions
+ */
+#define AA_MAY_CREATE                  0x0010
+#define AA_MAY_DELETE                  0x0020
+#define AA_MAY_META_WRITE              0x0040
+#define AA_MAY_META_READ               0x0080
+
+#define AA_MAY_CHMOD                   0x0100
+#define AA_MAY_CHOWN                   0x0200
+#define AA_MAY_LOCK                    0x0400
+#define AA_EXEC_MMAP                   0x0800
+
+#define AA_MAY_LINK                    0x1000
+#define AA_LINK_SUBSET                 AA_MAY_LOCK     /* overlaid */
+#define AA_MAY_ONEXEC                  0x40000000      /* exec allows onexec */
+#define AA_MAY_CHANGE_PROFILE          0x80000000
+#define AA_MAY_CHANGEHAT               0x80000000      /* ctrl auditing only */
+
+#define AA_AUDIT_FILE_MASK     (MAY_READ | MAY_WRITE | MAY_EXEC | MAY_APPEND |\
+                                AA_MAY_CREATE | AA_MAY_DELETE |        \
+                                AA_MAY_META_READ | AA_MAY_META_WRITE | \
+                                AA_MAY_CHMOD | AA_MAY_CHOWN | AA_MAY_LOCK | \
+                                AA_EXEC_MMAP | AA_MAY_LINK)
+
+/*
+ * The xindex is broken into 3 parts
+ * - index - an index into either the exec name table or the variable table
+ * - exec type - which determines how the executable name and index are used
+ * - flags - which modify how the destination name is applied
+ */
+#define AA_X_INDEX_MASK                0x03ff
+
+#define AA_X_TYPE_MASK         0x0c00
+#define AA_X_TYPE_SHIFT                10
+#define AA_X_NONE              0x0000
+#define AA_X_NAME              0x0400  /* use executable name px */
+#define AA_X_TABLE             0x0800  /* use a specified name ->n# */
+
+#define AA_X_UNSAFE            0x1000
+#define AA_X_CHILD             0x2000  /* make >AA_X_NONE apply to children */
+#define AA_X_INHERIT           0x4000
+#define AA_X_UNCONFINED                0x8000
+
+/* AA_SECURE_X_NEEDED - is passed in the bprm->unsafe field */
+#define AA_SECURE_X_NEEDED     0x8000
+
+/* need to make conditional which ones are being set */
+struct path_cond {
+       uid_t uid;
+       umode_t mode;
+};
+
+/* struct file_perms - file permission
+ * @allow: mask of permissions that are allowed
+ * @audit: mask of permissions to force an audit message for
+ * @quiet: mask of permissions to quiet audit messages for
+ * @kill: mask of permissions that when matched will kill the task
+ * @xindex: exec transition index if @allow contains MAY_EXEC
+ *
+ * The @audit and @queit mask should be mutually exclusive.
+ */
+struct file_perms {
+       u32 allow;
+       u32 audit;
+       u32 quiet;
+       u32 kill;
+       u16 xindex;
+};
+
+extern struct file_perms nullperms;
+
+#define COMBINED_PERM_MASK(X) ((X).allow | (X).audit | (X).quiet | (X).kill)
+
+/* FIXME: split perms from dfa and match this to description
+ *        also add delegation info.
+ */
+static inline u16 dfa_map_xindex(u16 mask)
+{
+       u16 old_index = (mask >> 10) & 0xf;
+       u16 index = 0;
+
+       if (mask & 0x100)
+               index |= AA_X_UNSAFE;
+       if (mask & 0x200)
+               index |= AA_X_INHERIT;
+       if (mask & 0x80)
+               index |= AA_X_UNCONFINED;
+
+       if (old_index == 1) {
+               index |= AA_X_UNCONFINED;
+       } else if (old_index == 2) {
+               index |= AA_X_NAME;
+       } else if (old_index == 3) {
+               index |= AA_X_NAME | AA_X_CHILD;
+       } else {
+               index |= AA_X_TABLE;
+               index |= old_index - 4;
+       }
+
+       return index;
+}
+
+/*
+ * map old dfa inline permissions to new format
+ */
+#define dfa_user_allow(dfa, state) (((ACCEPT_TABLE(dfa)[state]) & 0x7f) | \
+                                   ((ACCEPT_TABLE(dfa)[state]) & 0x80000000))
+#define dfa_user_audit(dfa, state) ((ACCEPT_TABLE2(dfa)[state]) & 0x7f)
+#define dfa_user_quiet(dfa, state) (((ACCEPT_TABLE2(dfa)[state]) >> 7) & 0x7f)
+#define dfa_user_xindex(dfa, state) \
+       (dfa_map_xindex(ACCEPT_TABLE(dfa)[state] & 0x3fff))
+
+#define dfa_other_allow(dfa, state) ((((ACCEPT_TABLE(dfa)[state]) >> 14) & \
+                                     0x7f) |                           \
+                                    ((ACCEPT_TABLE(dfa)[state]) & 0x80000000))
+#define dfa_other_audit(dfa, state) (((ACCEPT_TABLE2(dfa)[state]) >> 14) & 0x7f)
+#define dfa_other_quiet(dfa, state) \
+       ((((ACCEPT_TABLE2(dfa)[state]) >> 7) >> 14) & 0x7f)
+#define dfa_other_xindex(dfa, state) \
+       dfa_map_xindex((ACCEPT_TABLE(dfa)[state] >> 14) & 0x3fff)
+
+int aa_audit_file(struct aa_profile *profile, struct file_perms *perms,
+                 gfp_t gfp, int op, u32 request, const char *name,
+                 const char *target, uid_t ouid, const char *info, int error);
+
+/**
+ * struct aa_file_rules - components used for file rule permissions
+ * @dfa: dfa to match path names and conditionals against
+ * @perms: permission table indexed by the matched state accept entry of @dfa
+ * @trans: transition table for indexed by named x transitions
+ *
+ * File permission are determined by matching a path against @dfa and then
+ * then using the value of the accept entry for the matching state as
+ * an index into @perms.  If a named exec transition is required it is
+ * looked up in the transition table.
+ */
+struct aa_file_rules {
+       unsigned int start;
+       struct aa_dfa *dfa;
+       /* struct perms perms; */
+       struct aa_domain trans;
+       /* TODO: add delegate table */
+};
+
+unsigned int aa_str_perms(struct aa_dfa *dfa, unsigned int start,
+                         const char *name, struct path_cond *cond,
+                         struct file_perms *perms);
+
+int aa_path_perm(int op, struct aa_profile *profile, struct path *path,
+                int flags, u32 request, struct path_cond *cond);
+
+int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
+                struct path *new_dir, struct dentry *new_dentry);
+
+int aa_file_perm(int op, struct aa_profile *profile, struct file *file,
+                u32 request);
+
+static inline void aa_free_file_rules(struct aa_file_rules *rules)
+{
+       aa_put_dfa(rules->dfa);
+       aa_free_domain_entries(&rules->trans);
+}
+
+#define ACC_FMODE(x) (("\000\004\002\006"[(x)&O_ACCMODE]) | (((x) << 1) & 0x40))
+
+/* from namei.c */
+#define MAP_OPEN_FLAGS(x) ((((x) + 1) & O_ACCMODE) ? (x) + 1 : (x))
+
+/**
+ * aa_map_file_perms - map file flags to AppArmor permissions
+ * @file: open file to map flags to AppArmor permissions
+ *
+ * Returns: apparmor permission set for the file
+ */
+static inline u32 aa_map_file_to_perms(struct file *file)
+{
+       int flags = MAP_OPEN_FLAGS(file->f_flags);
+       u32 perms = ACC_FMODE(file->f_mode);
+
+       if ((flags & O_APPEND) && (perms & MAY_WRITE))
+               perms = (perms & ~MAY_WRITE) | MAY_APPEND;
+       /* trunc implies write permission */
+       if (flags & O_TRUNC)
+               perms |= MAY_WRITE;
+       if (flags & O_CREAT)
+               perms |= AA_MAY_CREATE;
+
+       return perms;
+}
+
+#endif /* __AA_FILE_H */
diff --git a/security/apparmor/include/ipc.h b/security/apparmor/include/ipc.h
new file mode 100644 (file)
index 0000000..aeda0fb
--- /dev/null
@@ -0,0 +1,28 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor ipc mediation function definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_IPC_H
+#define __AA_IPC_H
+
+#include <linux/sched.h>
+
+struct aa_profile;
+
+int aa_may_ptrace(struct task_struct *tracer_task, struct aa_profile *tracer,
+                 struct aa_profile *tracee, unsigned int mode);
+
+int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee,
+             unsigned int mode);
+
+#endif /* __AA_IPC_H */
diff --git a/security/apparmor/include/match.h b/security/apparmor/include/match.h
new file mode 100644 (file)
index 0000000..734a6d3
--- /dev/null
@@ -0,0 +1,132 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor policy dfa matching engine definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_MATCH_H
+#define __AA_MATCH_H
+
+#include <linux/workqueue.h>
+
+#define DFA_NOMATCH                    0
+#define DFA_START                      1
+
+#define DFA_VALID_PERM_MASK            0xffffffff
+#define DFA_VALID_PERM2_MASK           0xffffffff
+
+/**
+ * The format used for transition tables is based on the GNU flex table
+ * file format (--tables-file option; see Table File Format in the flex
+ * info pages and the flex sources for documentation). The magic number
+ * used in the header is 0x1B5E783D insted of 0xF13C57B1 though, because
+ * the YY_ID_CHK (check) and YY_ID_DEF (default) tables are used
+ * slightly differently (see the apparmor-parser package).
+ */
+
+#define YYTH_MAGIC     0x1B5E783D
+#define YYTH_DEF_RECURSE 0x1                   /* DEF Table is recursive */
+
+struct table_set_header {
+       u32 th_magic;           /* YYTH_MAGIC */
+       u32 th_hsize;
+       u32 th_ssize;
+       u16 th_flags;
+       char th_version[];
+};
+
+/* The YYTD_ID are one less than flex table mappings.  The flex id
+ * has 1 subtracted at table load time, this allows us to directly use the
+ * ID's as indexes.
+ */
+#define        YYTD_ID_ACCEPT  0
+#define YYTD_ID_BASE   1
+#define YYTD_ID_CHK    2
+#define YYTD_ID_DEF    3
+#define YYTD_ID_EC     4
+#define YYTD_ID_META   5
+#define YYTD_ID_ACCEPT2 6
+#define YYTD_ID_NXT    7
+#define YYTD_ID_TSIZE  8
+
+#define YYTD_DATA8     1
+#define YYTD_DATA16    2
+#define YYTD_DATA32    4
+#define YYTD_DATA64    8
+
+/* Each ACCEPT2 table gets 6 dedicated flags, YYTD_DATAX define the
+ * first flags
+ */
+#define ACCEPT1_FLAGS(X) ((X) & 0x3f)
+#define ACCEPT2_FLAGS(X) ACCEPT1_FLAGS((X) >> YYTD_ID_ACCEPT2)
+#define TO_ACCEPT1_FLAG(X) ACCEPT1_FLAGS(X)
+#define TO_ACCEPT2_FLAG(X) (ACCEPT1_FLAGS(X) << YYTD_ID_ACCEPT2)
+#define DFA_FLAG_VERIFY_STATES 0x1000
+
+struct table_header {
+       u16 td_id;
+       u16 td_flags;
+       u32 td_hilen;
+       u32 td_lolen;
+       char td_data[];
+};
+
+#define DEFAULT_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_DEF]->td_data))
+#define BASE_TABLE(DFA) ((u32 *)((DFA)->tables[YYTD_ID_BASE]->td_data))
+#define NEXT_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_NXT]->td_data))
+#define CHECK_TABLE(DFA) ((u16 *)((DFA)->tables[YYTD_ID_CHK]->td_data))
+#define EQUIV_TABLE(DFA) ((u8 *)((DFA)->tables[YYTD_ID_EC]->td_data))
+#define ACCEPT_TABLE(DFA) ((u32 *)((DFA)->tables[YYTD_ID_ACCEPT]->td_data))
+#define ACCEPT_TABLE2(DFA) ((u32 *)((DFA)->tables[YYTD_ID_ACCEPT2]->td_data))
+
+struct aa_dfa {
+       struct kref count;
+       u16 flags;
+       struct table_header *tables[YYTD_ID_TSIZE];
+};
+
+#define byte_to_byte(X) (X)
+
+#define UNPACK_ARRAY(TABLE, BLOB, LEN, TYPE, NTOHX) \
+       do { \
+               typeof(LEN) __i; \
+               TYPE *__t = (TYPE *) TABLE; \
+               TYPE *__b = (TYPE *) BLOB; \
+               for (__i = 0; __i < LEN; __i++) { \
+                       __t[__i] = NTOHX(__b[__i]); \
+               } \
+       } while (0)
+
+static inline size_t table_size(size_t len, size_t el_size)
+{
+       return ALIGN(sizeof(struct table_header) + len * el_size, 8);
+}
+
+struct aa_dfa *aa_dfa_unpack(void *blob, size_t size, int flags);
+unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start,
+                             const char *str, int len);
+unsigned int aa_dfa_match(struct aa_dfa *dfa, unsigned int start,
+                         const char *str);
+void aa_dfa_free_kref(struct kref *kref);
+
+/**
+ * aa_put_dfa - put a dfa refcount
+ * @dfa: dfa to put refcount   (MAYBE NULL)
+ *
+ * Requires: if @dfa != NULL that a valid refcount be held
+ */
+static inline void aa_put_dfa(struct aa_dfa *dfa)
+{
+       if (dfa)
+               kref_put(&dfa->count, aa_dfa_free_kref);
+}
+
+#endif /* __AA_MATCH_H */
diff --git a/security/apparmor/include/path.h b/security/apparmor/include/path.h
new file mode 100644 (file)
index 0000000..27b327a
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor basic path manipulation function definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_PATH_H
+#define __AA_PATH_H
+
+
+enum path_flags {
+       PATH_IS_DIR = 0x1,              /* path is a directory */
+       PATH_CONNECT_PATH = 0x4,        /* connect disconnected paths to / */
+       PATH_CHROOT_REL = 0x8,          /* do path lookup relative to chroot */
+       PATH_CHROOT_NSCONNECT = 0x10,   /* connect paths that are at ns root */
+
+       PATH_DELEGATE_DELETED = 0x08000, /* delegate deleted files */
+       PATH_MEDIATE_DELETED = 0x10000, /* mediate deleted paths */
+};
+
+int aa_get_name(struct path *path, int flags, char **buffer, const char **name);
+
+#endif /* __AA_PATH_H */
diff --git a/security/apparmor/include/policy.h b/security/apparmor/include/policy.h
new file mode 100644 (file)
index 0000000..aeda5cf
--- /dev/null
@@ -0,0 +1,305 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor policy definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_POLICY_H
+#define __AA_POLICY_H
+
+#include <linux/capability.h>
+#include <linux/cred.h>
+#include <linux/kref.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/socket.h>
+
+#include "apparmor.h"
+#include "audit.h"
+#include "capability.h"
+#include "domain.h"
+#include "file.h"
+#include "resource.h"
+
+extern const char *profile_mode_names[];
+#define APPARMOR_NAMES_MAX_INDEX 3
+
+#define COMPLAIN_MODE(_profile)        \
+       ((aa_g_profile_mode == APPARMOR_COMPLAIN) || \
+        ((_profile)->mode == APPARMOR_COMPLAIN))
+
+#define KILL_MODE(_profile) \
+       ((aa_g_profile_mode == APPARMOR_KILL) || \
+        ((_profile)->mode == APPARMOR_KILL))
+
+#define PROFILE_IS_HAT(_profile) ((_profile)->flags & PFLAG_HAT)
+
+/*
+ * FIXME: currently need a clean way to replace and remove profiles as a
+ * set.  It should be done at the namespace level.
+ * Either, with a set of profiles loaded at the namespace level or via
+ * a mark and remove marked interface.
+ */
+enum profile_mode {
+       APPARMOR_ENFORCE,       /* enforce access rules */
+       APPARMOR_COMPLAIN,      /* allow and log access violations */
+       APPARMOR_KILL,          /* kill task on access violation */
+};
+
+enum profile_flags {
+       PFLAG_HAT = 1,                  /* profile is a hat */
+       PFLAG_UNCONFINED = 2,           /* profile is an unconfined profile */
+       PFLAG_NULL = 4,                 /* profile is null learning profile */
+       PFLAG_IX_ON_NAME_ERROR = 8,     /* fallback to ix on name lookup fail */
+       PFLAG_IMMUTABLE = 0x10,         /* don't allow changes/replacement */
+       PFLAG_USER_DEFINED = 0x20,      /* user based profile - lower privs */
+       PFLAG_NO_LIST_REF = 0x40,       /* list doesn't keep profile ref */
+       PFLAG_OLD_NULL_TRANS = 0x100,   /* use // as the null transition */
+
+       /* These flags must correspond with PATH_flags */
+       PFLAG_MEDIATE_DELETED = 0x10000, /* mediate instead delegate deleted */
+};
+
+struct aa_profile;
+
+/* struct aa_policy - common part of both namespaces and profiles
+ * @name: name of the object
+ * @hname - The hierarchical name
+ * @count: reference count of the obj
+ * @list: list policy object is on
+ * @profiles: head of the profiles list contained in the object
+ */
+struct aa_policy {
+       char *name;
+       char *hname;
+       struct kref count;
+       struct list_head list;
+       struct list_head profiles;
+};
+
+/* struct aa_ns_acct - accounting of profiles in namespace
+ * @max_size: maximum space allowed for all profiles in namespace
+ * @max_count: maximum number of profiles that can be in this namespace
+ * @size: current size of profiles
+ * @count: current count of profiles (includes null profiles)
+ */
+struct aa_ns_acct {
+       int max_size;
+       int max_count;
+       int size;
+       int count;
+};
+
+/* struct aa_namespace - namespace for a set of profiles
+ * @base: common policy
+ * @parent: parent of namespace
+ * @lock: lock for modifying the object
+ * @acct: accounting for the namespace
+ * @unconfined: special unconfined profile for the namespace
+ * @sub_ns: list of namespaces under the current namespace.
+ *
+ * An aa_namespace defines the set profiles that are searched to determine
+ * which profile to attach to a task.  Profiles can not be shared between
+ * aa_namespaces and profile names within a namespace are guaranteed to be
+ * unique.  When profiles in separate namespaces have the same name they
+ * are NOT considered to be equivalent.
+ *
+ * Namespaces are hierarchical and only namespaces and profiles below the
+ * current namespace are visible.
+ *
+ * Namespace names must be unique and can not contain the characters :/\0
+ *
+ * FIXME TODO: add vserver support of namespaces (can it all be done in
+ *             userspace?)
+ */
+struct aa_namespace {
+       struct aa_policy base;
+       struct aa_namespace *parent;
+       rwlock_t lock;
+       struct aa_ns_acct acct;
+       struct aa_profile *unconfined;
+       struct list_head sub_ns;
+};
+
+/* struct aa_profile - basic confinement data
+ * @base - base components of the profile (name, refcount, lists, lock ...)
+ * @parent: parent of profile
+ * @ns: namespace the profile is in
+ * @replacedby: is set to the profile that replaced this profile
+ * @rename: optional profile name that this profile renamed
+ * @xmatch: optional extended matching for unconfined executables names
+ * @xmatch_len: xmatch prefix len, used to determine xmatch priority
+ * @sid: the unique security id number of this profile
+ * @audit: the auditing mode of the profile
+ * @mode: the enforcement mode of the profile
+ * @flags: flags controlling profile behavior
+ * @path_flags: flags controlling path generation behavior
+ * @size: the memory consumed by this profiles rules
+ * @file: The set of rules governing basic file access and domain transitions
+ * @caps: capabilities for the profile
+ * @rlimits: rlimits for the profile
+ *
+ * The AppArmor profile contains the basic confinement data.  Each profile
+ * has a name, and exists in a namespace.  The @name and @exec_match are
+ * used to determine profile attachment against unconfined tasks.  All other
+ * attachments are determined by profile X transition rules.
+ *
+ * The @replacedby field is write protected by the profile lock.  Reads
+ * are assumed to be atomic, and are done without locking.
+ *
+ * Profiles have a hierarchy where hats and children profiles keep
+ * a reference to their parent.
+ *
+ * Profile names can not begin with a : and can not contain the \0
+ * character.  If a profile name begins with / it will be considered when
+ * determining profile attachment on "unconfined" tasks.
+ */
+struct aa_profile {
+       struct aa_policy base;
+       struct aa_profile *parent;
+
+       struct aa_namespace *ns;
+       struct aa_profile *replacedby;
+       const char *rename;
+
+       struct aa_dfa *xmatch;
+       int xmatch_len;
+       u32 sid;
+       enum audit_mode audit;
+       enum profile_mode mode;
+       u32 flags;
+       u32 path_flags;
+       int size;
+
+       struct aa_file_rules file;
+       struct aa_caps caps;
+       struct aa_rlimit rlimits;
+};
+
+extern struct aa_namespace *root_ns;
+extern enum profile_mode aa_g_profile_mode;
+
+void aa_add_profile(struct aa_policy *common, struct aa_profile *profile);
+
+bool aa_ns_visible(struct aa_namespace *curr, struct aa_namespace *view);
+const char *aa_ns_name(struct aa_namespace *parent, struct aa_namespace *child);
+int aa_alloc_root_ns(void);
+void aa_free_root_ns(void);
+void aa_free_namespace_kref(struct kref *kref);
+
+struct aa_namespace *aa_find_namespace(struct aa_namespace *root,
+                                      const char *name);
+
+static inline struct aa_policy *aa_get_common(struct aa_policy *c)
+{
+       if (c)
+               kref_get(&c->count);
+
+       return c;
+}
+
+/**
+ * aa_get_namespace - increment references count on @ns
+ * @ns: namespace to increment reference count of (MAYBE NULL)
+ *
+ * Returns: pointer to @ns, if @ns is NULL returns NULL
+ * Requires: @ns must be held with valid refcount when called
+ */
+static inline struct aa_namespace *aa_get_namespace(struct aa_namespace *ns)
+{
+       if (ns)
+               kref_get(&(ns->base.count));
+
+       return ns;
+}
+
+/**
+ * aa_put_namespace - decrement refcount on @ns
+ * @ns: namespace to put reference of
+ *
+ * Decrement reference count of @ns and if no longer in use free it
+ */
+static inline void aa_put_namespace(struct aa_namespace *ns)
+{
+       if (ns)
+               kref_put(&ns->base.count, aa_free_namespace_kref);
+}
+
+struct aa_profile *aa_alloc_profile(const char *name);
+struct aa_profile *aa_new_null_profile(struct aa_profile *parent, int hat);
+void aa_free_profile_kref(struct kref *kref);
+struct aa_profile *aa_find_child(struct aa_profile *parent, const char *name);
+struct aa_profile *aa_lookup_profile(struct aa_namespace *ns, const char *name);
+struct aa_profile *aa_match_profile(struct aa_namespace *ns, const char *name);
+
+ssize_t aa_replace_profiles(void *udata, size_t size, bool noreplace);
+ssize_t aa_remove_profiles(char *name, size_t size);
+
+#define PROF_ADD 1
+#define PROF_REPLACE 0
+
+#define unconfined(X) ((X)->flags & PFLAG_UNCONFINED)
+
+/**
+ * aa_newest_version - find the newest version of @profile
+ * @profile: the profile to check for newer versions of (NOT NULL)
+ *
+ * Returns: newest version of @profile, if @profile is the newest version
+ *          return @profile.
+ *
+ * NOTE: the profile returned is not refcounted, The refcount on @profile
+ * must be held until the caller decides what to do with the returned newest
+ * version.
+ */
+static inline struct aa_profile *aa_newest_version(struct aa_profile *profile)
+{
+       while (profile->replacedby)
+               profile = profile->replacedby;
+
+       return profile;
+}
+
+/**
+ * aa_get_profile - increment refcount on profile @p
+ * @p: profile  (MAYBE NULL)
+ *
+ * Returns: pointer to @p if @p is NULL will return NULL
+ * Requires: @p must be held with valid refcount when called
+ */
+static inline struct aa_profile *aa_get_profile(struct aa_profile *p)
+{
+       if (p)
+               kref_get(&(p->base.count));
+
+       return p;
+}
+
+/**
+ * aa_put_profile - decrement refcount on profile @p
+ * @p: profile  (MAYBE NULL)
+ */
+static inline void aa_put_profile(struct aa_profile *p)
+{
+       if (p)
+               kref_put(&p->base.count, aa_free_profile_kref);
+}
+
+static inline int AUDIT_MODE(struct aa_profile *profile)
+{
+       if (aa_g_audit != AUDIT_NORMAL)
+               return aa_g_audit;
+
+       return profile->audit;
+}
+
+bool aa_may_manage_policy(int op);
+
+#endif /* __AA_POLICY_H */
diff --git a/security/apparmor/include/policy_unpack.h b/security/apparmor/include/policy_unpack.h
new file mode 100644 (file)
index 0000000..a2dccca
--- /dev/null
@@ -0,0 +1,20 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor policy loading interface function definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __POLICY_INTERFACE_H
+#define __POLICY_INTERFACE_H
+
+struct aa_profile *aa_unpack(void *udata, size_t size, const char **ns);
+
+#endif /* __POLICY_INTERFACE_H */
diff --git a/security/apparmor/include/procattr.h b/security/apparmor/include/procattr.h
new file mode 100644 (file)
index 0000000..544aa6b
--- /dev/null
@@ -0,0 +1,26 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor /proc/<pid>/attr/ interface function definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_PROCATTR_H
+#define __AA_PROCATTR_H
+
+#define AA_DO_TEST 1
+#define AA_ONEXEC  1
+
+int aa_getprocattr(struct aa_profile *profile, char **string);
+int aa_setprocattr_changehat(char *args, size_t size, int test);
+int aa_setprocattr_changeprofile(char *fqname, bool onexec, int test);
+int aa_setprocattr_permipc(char *fqname);
+
+#endif /* __AA_PROCATTR_H */
diff --git a/security/apparmor/include/resource.h b/security/apparmor/include/resource.h
new file mode 100644 (file)
index 0000000..3c88be9
--- /dev/null
@@ -0,0 +1,46 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor resource limits function definitions.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_RESOURCE_H
+#define __AA_RESOURCE_H
+
+#include <linux/resource.h>
+#include <linux/sched.h>
+
+struct aa_profile;
+
+/* struct aa_rlimit - rlimit settings for the profile
+ * @mask: which hard limits to set
+ * @limits: rlimit values that override task limits
+ *
+ * AppArmor rlimits are used to set confined task rlimits.  Only the
+ * limits specified in @mask will be controlled by apparmor.
+ */
+struct aa_rlimit {
+       unsigned int mask;
+       struct rlimit limits[RLIM_NLIMITS];
+};
+
+int aa_map_resource(int resource);
+int aa_task_setrlimit(struct aa_profile *profile, unsigned int resource,
+                     struct rlimit *new_rlim);
+
+void __aa_transition_rlimits(struct aa_profile *old, struct aa_profile *new);
+
+static inline void aa_free_rlimit_rules(struct aa_rlimit *rlims)
+{
+       /* NOP */
+}
+
+#endif /* __AA_RESOURCE_H */
diff --git a/security/apparmor/include/sid.h b/security/apparmor/include/sid.h
new file mode 100644 (file)
index 0000000..020db35
--- /dev/null
@@ -0,0 +1,24 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor security identifier (sid) definitions
+ *
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#ifndef __AA_SID_H
+#define __AA_SID_H
+
+#include <linux/types.h>
+
+struct aa_profile;
+
+u32 aa_alloc_sid(void);
+void aa_free_sid(u32 sid);
+
+#endif /* __AA_SID_H */
diff --git a/security/apparmor/ipc.c b/security/apparmor/ipc.c
new file mode 100644 (file)
index 0000000..649fad8
--- /dev/null
@@ -0,0 +1,114 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor ipc mediation
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/gfp.h>
+#include <linux/ptrace.h>
+
+#include "include/audit.h"
+#include "include/capability.h"
+#include "include/context.h"
+#include "include/policy.h"
+
+/* call back to audit ptrace fields */
+static void audit_cb(struct audit_buffer *ab, void *va)
+{
+       struct common_audit_data *sa = va;
+       audit_log_format(ab, " target=");
+       audit_log_untrustedstring(ab, sa->aad.target);
+}
+
+/**
+ * aa_audit_ptrace - do auditing for ptrace
+ * @profile: profile being enforced  (NOT NULL)
+ * @target: profile being traced (NOT NULL)
+ * @error: error condition
+ *
+ * Returns: %0 or error code
+ */
+static int aa_audit_ptrace(struct aa_profile *profile,
+                          struct aa_profile *target, int error)
+{
+       struct common_audit_data sa;
+       COMMON_AUDIT_DATA_INIT(&sa, NONE);
+       sa.aad.op = OP_PTRACE;
+       sa.aad.target = target;
+       sa.aad.error = error;
+
+       return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_ATOMIC, &sa,
+                       audit_cb);
+}
+
+/**
+ * aa_may_ptrace - test if tracer task can trace the tracee
+ * @tracer_task: task who will do the tracing  (NOT NULL)
+ * @tracer: profile of the task doing the tracing  (NOT NULL)
+ * @tracee: task to be traced
+ * @mode: whether PTRACE_MODE_READ || PTRACE_MODE_ATTACH
+ *
+ * Returns: %0 else error code if permission denied or error
+ */
+int aa_may_ptrace(struct task_struct *tracer_task, struct aa_profile *tracer,
+                 struct aa_profile *tracee, unsigned int mode)
+{
+       /* TODO: currently only based on capability, not extended ptrace
+        *       rules,
+        *       Test mode for PTRACE_MODE_READ || PTRACE_MODE_ATTACH
+        */
+
+       if (unconfined(tracer) || tracer == tracee)
+               return 0;
+       /* log this capability request */
+       return aa_capable(tracer_task, tracer, CAP_SYS_PTRACE, 1);
+}
+
+/**
+ * aa_ptrace - do ptrace permission check and auditing
+ * @tracer: task doing the tracing (NOT NULL)
+ * @tracee: task being traced (NOT NULL)
+ * @mode: ptrace mode either PTRACE_MODE_READ || PTRACE_MODE_ATTACH
+ *
+ * Returns: %0 else error code if permission denied or error
+ */
+int aa_ptrace(struct task_struct *tracer, struct task_struct *tracee,
+             unsigned int mode)
+{
+       /*
+        * tracer can ptrace tracee when
+        * - tracer is unconfined ||
+        *   - tracer is in complain mode
+        *   - tracer has rules allowing it to trace tracee currently this is:
+        *       - confined by the same profile ||
+        *       - tracer profile has CAP_SYS_PTRACE
+        */
+
+       struct aa_profile *tracer_p;
+       /* cred released below */
+       const struct cred *cred = get_task_cred(tracer);
+       int error = 0;
+       tracer_p = aa_cred_profile(cred);
+
+       if (!unconfined(tracer_p)) {
+               /* lcred released below */
+               const struct cred *lcred = get_task_cred(tracee);
+               struct aa_profile *tracee_p = aa_cred_profile(lcred);
+
+               error = aa_may_ptrace(tracer, tracer_p, tracee_p, mode);
+               error = aa_audit_ptrace(tracer_p, tracee_p, error);
+
+               put_cred(lcred);
+       }
+       put_cred(cred);
+
+       return error;
+}
diff --git a/security/apparmor/lib.c b/security/apparmor/lib.c
new file mode 100644 (file)
index 0000000..6e85cdb
--- /dev/null
@@ -0,0 +1,133 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains basic common functions used in AppArmor
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/slab.h>
+#include <linux/string.h>
+#include <linux/vmalloc.h>
+
+#include "include/audit.h"
+
+
+/**
+ * aa_split_fqname - split a fqname into a profile and namespace name
+ * @fqname: a full qualified name in namespace profile format (NOT NULL)
+ * @ns_name: pointer to portion of the string containing the ns name (NOT NULL)
+ *
+ * Returns: profile name or NULL if one is not specified
+ *
+ * Split a namespace name from a profile name (see policy.c for naming
+ * description).  If a portion of the name is missing it returns NULL for
+ * that portion.
+ *
+ * NOTE: may modify the @fqname string.  The pointers returned point
+ *       into the @fqname string.
+ */
+char *aa_split_fqname(char *fqname, char **ns_name)
+{
+       char *name = strim(fqname);
+
+       *ns_name = NULL;
+       if (name[0] == ':') {
+               char *split = strchr(&name[1], ':');
+               if (split) {
+                       /* overwrite ':' with \0 */
+                       *split = 0;
+                       name = skip_spaces(split + 1);
+               } else
+                       /* a ns name without a following profile is allowed */
+                       name = NULL;
+               *ns_name = &name[1];
+       }
+       if (name && *name == 0)
+               name = NULL;
+
+       return name;
+}
+
+/**
+ * aa_info_message - log a none profile related status message
+ * @str: message to log
+ */
+void aa_info_message(const char *str)
+{
+       if (audit_enabled) {
+               struct common_audit_data sa;
+               COMMON_AUDIT_DATA_INIT(&sa, NONE);
+               sa.aad.info = str;
+               aa_audit_msg(AUDIT_APPARMOR_STATUS, &sa, NULL);
+       }
+       printk(KERN_INFO "AppArmor: %s\n", str);
+}
+
+/**
+ * kvmalloc - do allocation preferring kmalloc but falling back to vmalloc
+ * @size: size of allocation
+ *
+ * Return: allocated buffer or NULL if failed
+ *
+ * It is possible that policy being loaded from the user is larger than
+ * what can be allocated by kmalloc, in those cases fall back to vmalloc.
+ */
+void *kvmalloc(size_t size)
+{
+       void *buffer = NULL;
+
+       if (size == 0)
+               return NULL;
+
+       /* do not attempt kmalloc if we need more than 16 pages at once */
+       if (size <= (16*PAGE_SIZE))
+               buffer = kmalloc(size, GFP_NOIO | __GFP_NOWARN);
+       if (!buffer) {
+               /* see kvfree for why size must be at least work_struct size
+                * when allocated via vmalloc
+                */
+               if (size < sizeof(struct work_struct))
+                       size = sizeof(struct work_struct);
+               buffer = vmalloc(size);
+       }
+       return buffer;
+}
+
+/**
+ * do_vfree - workqueue routine for freeing vmalloced memory
+ * @work: data to be freed
+ *
+ * The work_struct is overlaid to the data being freed, as at the point
+ * the work is scheduled the data is no longer valid, be its freeing
+ * needs to be delayed until safe.
+ */
+static void do_vfree(struct work_struct *work)
+{
+       vfree(work);
+}
+
+/**
+ * kvfree - free an allocation do by kvmalloc
+ * @buffer: buffer to free (MAYBE_NULL)
+ *
+ * Free a buffer allocated by kvmalloc
+ */
+void kvfree(void *buffer)
+{
+       if (is_vmalloc_addr(buffer)) {
+               /* Data is no longer valid so just use the allocated space
+                * as the work_struct
+                */
+               struct work_struct *work = (struct work_struct *) buffer;
+               INIT_WORK(work, do_vfree);
+               schedule_work(work);
+       } else
+               kfree(buffer);
+}
diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
new file mode 100644 (file)
index 0000000..8db33a8
--- /dev/null
@@ -0,0 +1,938 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor LSM hooks.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/security.h>
+#include <linux/moduleparam.h>
+#include <linux/mm.h>
+#include <linux/mman.h>
+#include <linux/mount.h>
+#include <linux/namei.h>
+#include <linux/ptrace.h>
+#include <linux/ctype.h>
+#include <linux/sysctl.h>
+#include <linux/audit.h>
+#include <net/sock.h>
+
+#include "include/apparmor.h"
+#include "include/apparmorfs.h"
+#include "include/audit.h"
+#include "include/capability.h"
+#include "include/context.h"
+#include "include/file.h"
+#include "include/ipc.h"
+#include "include/path.h"
+#include "include/policy.h"
+#include "include/procattr.h"
+
+/* Flag indicating whether initialization completed */
+int apparmor_initialized __initdata;
+
+/*
+ * LSM hook functions
+ */
+
+/*
+ * free the associated aa_task_cxt and put its profiles
+ */
+static void apparmor_cred_free(struct cred *cred)
+{
+       aa_free_task_context(cred->security);
+       cred->security = NULL;
+}
+
+/*
+ * allocate the apparmor part of blank credentials
+ */
+static int apparmor_cred_alloc_blank(struct cred *cred, gfp_t gfp)
+{
+       /* freed by apparmor_cred_free */
+       struct aa_task_cxt *cxt = aa_alloc_task_context(gfp);
+       if (!cxt)
+               return -ENOMEM;
+
+       cred->security = cxt;
+       return 0;
+}
+
+/*
+ * prepare new aa_task_cxt for modification by prepare_cred block
+ */
+static int apparmor_cred_prepare(struct cred *new, const struct cred *old,
+                                gfp_t gfp)
+{
+       /* freed by apparmor_cred_free */
+       struct aa_task_cxt *cxt = aa_alloc_task_context(gfp);
+       if (!cxt)
+               return -ENOMEM;
+
+       aa_dup_task_context(cxt, old->security);
+       new->security = cxt;
+       return 0;
+}
+
+/*
+ * transfer the apparmor data to a blank set of creds
+ */
+static void apparmor_cred_transfer(struct cred *new, const struct cred *old)
+{
+       const struct aa_task_cxt *old_cxt = old->security;
+       struct aa_task_cxt *new_cxt = new->security;
+
+       aa_dup_task_context(new_cxt, old_cxt);
+}
+
+static int apparmor_ptrace_access_check(struct task_struct *child,
+                                       unsigned int mode)
+{
+       int error = cap_ptrace_access_check(child, mode);
+       if (error)
+               return error;
+
+       return aa_ptrace(current, child, mode);
+}
+
+static int apparmor_ptrace_traceme(struct task_struct *parent)
+{
+       int error = cap_ptrace_traceme(parent);
+       if (error)
+               return error;
+
+       return aa_ptrace(parent, current, PTRACE_MODE_ATTACH);
+}
+
+/* Derived from security/commoncap.c:cap_capget */
+static int apparmor_capget(struct task_struct *target, kernel_cap_t *effective,
+                          kernel_cap_t *inheritable, kernel_cap_t *permitted)
+{
+       struct aa_profile *profile;
+       const struct cred *cred;
+
+       rcu_read_lock();
+       cred = __task_cred(target);
+       profile = aa_cred_profile(cred);
+
+       *effective = cred->cap_effective;
+       *inheritable = cred->cap_inheritable;
+       *permitted = cred->cap_permitted;
+
+       if (!unconfined(profile)) {
+               *effective = cap_intersect(*effective, profile->caps.allow);
+               *permitted = cap_intersect(*permitted, profile->caps.allow);
+       }
+       rcu_read_unlock();
+
+       return 0;
+}
+
+static int apparmor_capable(struct task_struct *task, const struct cred *cred,
+                           int cap, int audit)
+{
+       struct aa_profile *profile;
+       /* cap_capable returns 0 on success, else -EPERM */
+       int error = cap_capable(task, cred, cap, audit);
+       if (!error) {
+               profile = aa_cred_profile(cred);
+               if (!unconfined(profile))
+                       error = aa_capable(task, profile, cap, audit);
+       }
+       return error;
+}
+
+/**
+ * common_perm - basic common permission check wrapper fn for paths
+ * @op: operation being checked
+ * @path: path to check permission of  (NOT NULL)
+ * @mask: requested permissions mask
+ * @cond: conditional info for the permission request  (NOT NULL)
+ *
+ * Returns: %0 else error code if error or permission denied
+ */
+static int common_perm(int op, struct path *path, u32 mask,
+                      struct path_cond *cond)
+{
+       struct aa_profile *profile;
+       int error = 0;
+
+       profile = __aa_current_profile();
+       if (!unconfined(profile))
+               error = aa_path_perm(op, profile, path, 0, mask, cond);
+
+       return error;
+}
+
+/**
+ * common_perm_dir_dentry - common permission wrapper when path is dir, dentry
+ * @op: operation being checked
+ * @dir: directory of the dentry  (NOT NULL)
+ * @dentry: dentry to check  (NOT NULL)
+ * @mask: requested permissions mask
+ * @cond: conditional info for the permission request  (NOT NULL)
+ *
+ * Returns: %0 else error code if error or permission denied
+ */
+static int common_perm_dir_dentry(int op, struct path *dir,
+                                 struct dentry *dentry, u32 mask,
+                                 struct path_cond *cond)
+{
+       struct path path = { dir->mnt, dentry };
+
+       return common_perm(op, &path, mask, cond);
+}
+
+/**
+ * common_perm_mnt_dentry - common permission wrapper when mnt, dentry
+ * @op: operation being checked
+ * @mnt: mount point of dentry (NOT NULL)
+ * @dentry: dentry to check  (NOT NULL)
+ * @mask: requested permissions mask
+ *
+ * Returns: %0 else error code if error or permission denied
+ */
+static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
+                                 struct dentry *dentry, u32 mask)
+{
+       struct path path = { mnt, dentry };
+       struct path_cond cond = { dentry->d_inode->i_uid,
+                                 dentry->d_inode->i_mode
+       };
+
+       return common_perm(op, &path, mask, &cond);
+}
+
+/**
+ * common_perm_rm - common permission wrapper for operations doing rm
+ * @op: operation being checked
+ * @dir: directory that the dentry is in  (NOT NULL)
+ * @dentry: dentry being rm'd  (NOT NULL)
+ * @mask: requested permission mask
+ *
+ * Returns: %0 else error code if error or permission denied
+ */
+static int common_perm_rm(int op, struct path *dir,
+                         struct dentry *dentry, u32 mask)
+{
+       struct inode *inode = dentry->d_inode;
+       struct path_cond cond = { };
+
+       if (!inode || !dir->mnt || !mediated_filesystem(inode))
+               return 0;
+
+       cond.uid = inode->i_uid;
+       cond.mode = inode->i_mode;
+
+       return common_perm_dir_dentry(op, dir, dentry, mask, &cond);
+}
+
+/**
+ * common_perm_create - common permission wrapper for operations doing create
+ * @op: operation being checked
+ * @dir: directory that dentry will be created in  (NOT NULL)
+ * @dentry: dentry to create   (NOT NULL)
+ * @mask: request permission mask
+ * @mode: created file mode
+ *
+ * Returns: %0 else error code if error or permission denied
+ */
+static int common_perm_create(int op, struct path *dir, struct dentry *dentry,
+                             u32 mask, umode_t mode)
+{
+       struct path_cond cond = { current_fsuid(), mode };
+
+       if (!dir->mnt || !mediated_filesystem(dir->dentry->d_inode))
+               return 0;
+
+       return common_perm_dir_dentry(op, dir, dentry, mask, &cond);
+}
+
+static int apparmor_path_unlink(struct path *dir, struct dentry *dentry)
+{
+       return common_perm_rm(OP_UNLINK, dir, dentry, AA_MAY_DELETE);
+}
+
+static int apparmor_path_mkdir(struct path *dir, struct dentry *dentry,
+                              int mode)
+{
+       return common_perm_create(OP_MKDIR, dir, dentry, AA_MAY_CREATE,
+                                 S_IFDIR);
+}
+
+static int apparmor_path_rmdir(struct path *dir, struct dentry *dentry)
+{
+       return common_perm_rm(OP_RMDIR, dir, dentry, AA_MAY_DELETE);
+}
+
+static int apparmor_path_mknod(struct path *dir, struct dentry *dentry,
+                              int mode, unsigned int dev)
+{
+       return common_perm_create(OP_MKNOD, dir, dentry, AA_MAY_CREATE, mode);
+}
+
+static int apparmor_path_truncate(struct path *path)
+{
+       struct path_cond cond = { path->dentry->d_inode->i_uid,
+                                 path->dentry->d_inode->i_mode
+       };
+
+       if (!path->mnt || !mediated_filesystem(path->dentry->d_inode))
+               return 0;
+
+       return common_perm(OP_TRUNC, path, MAY_WRITE | AA_MAY_META_WRITE,
+                          &cond);
+}
+
+static int apparmor_path_symlink(struct path *dir, struct dentry *dentry,
+                                const char *old_name)
+{
+       return common_perm_create(OP_SYMLINK, dir, dentry, AA_MAY_CREATE,
+                                 S_IFLNK);
+}
+
+static int apparmor_path_link(struct dentry *old_dentry, struct path *new_dir,
+                             struct dentry *new_dentry)
+{
+       struct aa_profile *profile;
+       int error = 0;
+
+       if (!mediated_filesystem(old_dentry->d_inode))
+               return 0;
+
+       profile = aa_current_profile();
+       if (!unconfined(profile))
+               error = aa_path_link(profile, old_dentry, new_dir, new_dentry);
+       return error;
+}
+
+static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
+                               struct path *new_dir, struct dentry *new_dentry)
+{
+       struct aa_profile *profile;
+       int error = 0;
+
+       if (!mediated_filesystem(old_dentry->d_inode))
+               return 0;
+
+       profile = aa_current_profile();
+       if (!unconfined(profile)) {
+               struct path old_path = { old_dir->mnt, old_dentry };
+               struct path new_path = { new_dir->mnt, new_dentry };
+               struct path_cond cond = { old_dentry->d_inode->i_uid,
+                                         old_dentry->d_inode->i_mode
+               };
+
+               error = aa_path_perm(OP_RENAME_SRC, profile, &old_path, 0,
+                                    MAY_READ | AA_MAY_META_READ | MAY_WRITE |
+                                    AA_MAY_META_WRITE | AA_MAY_DELETE,
+                                    &cond);
+               if (!error)
+                       error = aa_path_perm(OP_RENAME_DEST, profile, &new_path,
+                                            0, MAY_WRITE | AA_MAY_META_WRITE |
+                                            AA_MAY_CREATE, &cond);
+
+       }
+       return error;
+}
+
+static int apparmor_path_chmod(struct dentry *dentry, struct vfsmount *mnt,
+                              mode_t mode)
+{
+       if (!mediated_filesystem(dentry->d_inode))
+               return 0;
+
+       return common_perm_mnt_dentry(OP_CHMOD, mnt, dentry, AA_MAY_CHMOD);
+}
+
+static int apparmor_path_chown(struct path *path, uid_t uid, gid_t gid)
+{
+       struct path_cond cond =  { path->dentry->d_inode->i_uid,
+                                  path->dentry->d_inode->i_mode
+       };
+
+       if (!mediated_filesystem(path->dentry->d_inode))
+               return 0;
+
+       return common_perm(OP_CHOWN, path, AA_MAY_CHOWN, &cond);
+}
+
+static int apparmor_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
+{
+       if (!mediated_filesystem(dentry->d_inode))
+               return 0;
+
+       return common_perm_mnt_dentry(OP_GETATTR, mnt, dentry,
+                                     AA_MAY_META_READ);
+}
+
+static int apparmor_dentry_open(struct file *file, const struct cred *cred)
+{
+       struct aa_file_cxt *fcxt = file->f_security;
+       struct aa_profile *profile;
+       int error = 0;
+
+       if (!mediated_filesystem(file->f_path.dentry->d_inode))
+               return 0;
+
+       /* If in exec, permission is handled by bprm hooks.
+        * Cache permissions granted by the previous exec check, with
+        * implicit read and executable mmap which are required to
+        * actually execute the image.
+        */
+       if (current->in_execve) {
+               fcxt->allow = MAY_EXEC | MAY_READ | AA_EXEC_MMAP;
+               return 0;
+       }
+
+       profile = aa_cred_profile(cred);
+       if (!unconfined(profile)) {
+               struct inode *inode = file->f_path.dentry->d_inode;
+               struct path_cond cond = { inode->i_uid, inode->i_mode };
+
+               error = aa_path_perm(OP_OPEN, profile, &file->f_path, 0,
+                                    aa_map_file_to_perms(file), &cond);
+               /* todo cache full allowed permissions set and state */
+               fcxt->allow = aa_map_file_to_perms(file);
+       }
+
+       return error;
+}
+
+static int apparmor_file_alloc_security(struct file *file)
+{
+       /* freed by apparmor_file_free_security */
+       file->f_security = aa_alloc_file_context(GFP_KERNEL);
+       if (!file->f_security)
+               return -ENOMEM;
+       return 0;
+
+}
+
+static void apparmor_file_free_security(struct file *file)
+{
+       struct aa_file_cxt *cxt = file->f_security;
+
+       aa_free_file_context(cxt);
+}
+
+static int common_file_perm(int op, struct file *file, u32 mask)
+{
+       struct aa_file_cxt *fcxt = file->f_security;
+       struct aa_profile *profile, *fprofile = aa_cred_profile(file->f_cred);
+       int error = 0;
+
+       BUG_ON(!fprofile);
+
+       if (!file->f_path.mnt ||
+           !mediated_filesystem(file->f_path.dentry->d_inode))
+               return 0;
+
+       profile = __aa_current_profile();
+
+       /* revalidate access, if task is unconfined, or the cached cred
+        * doesn't match or if the request is for more permissions than
+        * was granted.
+        *
+        * Note: the test for !unconfined(fprofile) is to handle file
+        *       delegation from unconfined tasks
+        */
+       if (!unconfined(profile) && !unconfined(fprofile) &&
+           ((fprofile != profile) || (mask & ~fcxt->allow)))
+               error = aa_file_perm(op, profile, file, mask);
+
+       return error;
+}
+
+static int apparmor_file_permission(struct file *file, int mask)
+{
+       return common_file_perm(OP_FPERM, file, mask);
+}
+
+static int apparmor_file_lock(struct file *file, unsigned int cmd)
+{
+       u32 mask = AA_MAY_LOCK;
+
+       if (cmd == F_WRLCK)
+               mask |= MAY_WRITE;
+
+       return common_file_perm(OP_FLOCK, file, mask);
+}
+
+static int common_mmap(int op, struct file *file, unsigned long prot,
+                      unsigned long flags)
+{
+       struct dentry *dentry;
+       int mask = 0;
+
+       if (!file || !file->f_security)
+               return 0;
+
+       if (prot & PROT_READ)
+               mask |= MAY_READ;
+       /*
+        * Private mappings don't require write perms since they don't
+        * write back to the files
+        */
+       if ((prot & PROT_WRITE) && !(flags & MAP_PRIVATE))
+               mask |= MAY_WRITE;
+       if (prot & PROT_EXEC)
+               mask |= AA_EXEC_MMAP;
+
+       dentry = file->f_path.dentry;
+       return common_file_perm(op, file, mask);
+}
+
+static int apparmor_file_mmap(struct file *file, unsigned long reqprot,
+                             unsigned long prot, unsigned long flags,
+                             unsigned long addr, unsigned long addr_only)
+{
+       int rc = 0;
+
+       /* do DAC check */
+       rc = cap_file_mmap(file, reqprot, prot, flags, addr, addr_only);
+       if (rc || addr_only)
+               return rc;
+
+       return common_mmap(OP_FMMAP, file, prot, flags);
+}
+
+static int apparmor_file_mprotect(struct vm_area_struct *vma,
+                                 unsigned long reqprot, unsigned long prot)
+{
+       return common_mmap(OP_FMPROT, vma->vm_file, prot,
+                          !(vma->vm_flags & VM_SHARED) ? MAP_PRIVATE : 0);
+}
+
+static int apparmor_getprocattr(struct task_struct *task, char *name,
+                               char **value)
+{
+       int error = -ENOENT;
+       struct aa_profile *profile;
+       /* released below */
+       const struct cred *cred = get_task_cred(task);
+       struct aa_task_cxt *cxt = cred->security;
+       profile = aa_cred_profile(cred);
+
+       if (strcmp(name, "current") == 0)
+               error = aa_getprocattr(aa_newest_version(cxt->profile),
+                                      value);
+       else if (strcmp(name, "prev") == 0  && cxt->previous)
+               error = aa_getprocattr(aa_newest_version(cxt->previous),
+                                      value);
+       else if (strcmp(name, "exec") == 0 && cxt->onexec)
+               error = aa_getprocattr(aa_newest_version(cxt->onexec),
+                                      value);
+       else
+               error = -EINVAL;
+
+       put_cred(cred);
+
+       return error;
+}
+
+static int apparmor_setprocattr(struct task_struct *task, char *name,
+                               void *value, size_t size)
+{
+       char *command, *args = value;
+       size_t arg_size;
+       int error;
+
+       if (size == 0)
+               return -EINVAL;
+       /* args points to a PAGE_SIZE buffer, AppArmor requires that
+        * the buffer must be null terminated or have size <= PAGE_SIZE -1
+        * so that AppArmor can null terminate them
+        */
+       if (args[size - 1] != '\0') {
+               if (size == PAGE_SIZE)
+                       return -EINVAL;
+               args[size] = '\0';
+       }
+
+       /* task can only write its own attributes */
+       if (current != task)
+               return -EACCES;
+
+       args = value;
+       args = strim(args);
+       command = strsep(&args, " ");
+       if (!args)
+               return -EINVAL;
+       args = skip_spaces(args);
+       if (!*args)
+               return -EINVAL;
+
+       arg_size = size - (args - (char *) value);
+       if (strcmp(name, "current") == 0) {
+               if (strcmp(command, "changehat") == 0) {
+                       error = aa_setprocattr_changehat(args, arg_size,
+                                                        !AA_DO_TEST);
+               } else if (strcmp(command, "permhat") == 0) {
+                       error = aa_setprocattr_changehat(args, arg_size,
+                                                        AA_DO_TEST);
+               } else if (strcmp(command, "changeprofile") == 0) {
+                       error = aa_setprocattr_changeprofile(args, !AA_ONEXEC,
+                                                            !AA_DO_TEST);
+               } else if (strcmp(command, "permprofile") == 0) {
+                       error = aa_setprocattr_changeprofile(args, !AA_ONEXEC,
+                                                            AA_DO_TEST);
+               } else if (strcmp(command, "permipc") == 0) {
+                       error = aa_setprocattr_permipc(args);
+               } else {
+                       struct common_audit_data sa;
+                       COMMON_AUDIT_DATA_INIT(&sa, NONE);
+                       sa.aad.op = OP_SETPROCATTR;
+                       sa.aad.info = name;
+                       sa.aad.error = -EINVAL;
+                       return aa_audit(AUDIT_APPARMOR_DENIED, NULL, GFP_KERNEL,
+                                       &sa, NULL);
+               }
+       } else if (strcmp(name, "exec") == 0) {
+               error = aa_setprocattr_changeprofile(args, AA_ONEXEC,
+                                                    !AA_DO_TEST);
+       } else {
+               /* only support the "current" and "exec" process attributes */
+               return -EINVAL;
+       }
+       if (!error)
+               error = size;
+       return error;
+}
+
+static int apparmor_task_setrlimit(unsigned int resource,
+                                  struct rlimit *new_rlim)
+{
+       struct aa_profile *profile = aa_current_profile();
+       int error = 0;
+
+       if (!unconfined(profile))
+               error = aa_task_setrlimit(profile, resource, new_rlim);
+
+       return error;
+}
+
+static struct security_operations apparmor_ops = {
+       .name =                         "apparmor",
+
+       .ptrace_access_check =          apparmor_ptrace_access_check,
+       .ptrace_traceme =               apparmor_ptrace_traceme,
+       .capget =                       apparmor_capget,
+       .capable =                      apparmor_capable,
+
+       .path_link =                    apparmor_path_link,
+       .path_unlink =                  apparmor_path_unlink,
+       .path_symlink =                 apparmor_path_symlink,
+       .path_mkdir =                   apparmor_path_mkdir,
+       .path_rmdir =                   apparmor_path_rmdir,
+       .path_mknod =                   apparmor_path_mknod,
+       .path_rename =                  apparmor_path_rename,
+       .path_chmod =                   apparmor_path_chmod,
+       .path_chown =                   apparmor_path_chown,
+       .path_truncate =                apparmor_path_truncate,
+       .dentry_open =                  apparmor_dentry_open,
+       .inode_getattr =                apparmor_inode_getattr,
+
+       .file_permission =              apparmor_file_permission,
+       .file_alloc_security =          apparmor_file_alloc_security,
+       .file_free_security =           apparmor_file_free_security,
+       .file_mmap =                    apparmor_file_mmap,
+       .file_mprotect =                apparmor_file_mprotect,
+       .file_lock =                    apparmor_file_lock,
+
+       .getprocattr =                  apparmor_getprocattr,
+       .setprocattr =                  apparmor_setprocattr,
+
+       .cred_alloc_blank =             apparmor_cred_alloc_blank,
+       .cred_free =                    apparmor_cred_free,
+       .cred_prepare =                 apparmor_cred_prepare,
+       .cred_transfer =                apparmor_cred_transfer,
+
+       .bprm_set_creds =               apparmor_bprm_set_creds,
+       .bprm_committing_creds =        apparmor_bprm_committing_creds,
+       .bprm_committed_creds =         apparmor_bprm_committed_creds,
+       .bprm_secureexec =              apparmor_bprm_secureexec,
+
+       .task_setrlimit =               apparmor_task_setrlimit,
+};
+
+/*
+ * AppArmor sysfs module parameters
+ */
+
+static int param_set_aabool(const char *val, struct kernel_param *kp);
+static int param_get_aabool(char *buffer, struct kernel_param *kp);
+#define param_check_aabool(name, p) __param_check(name, p, int)
+
+static int param_set_aauint(const char *val, struct kernel_param *kp);
+static int param_get_aauint(char *buffer, struct kernel_param *kp);
+#define param_check_aauint(name, p) __param_check(name, p, int)
+
+static int param_set_aalockpolicy(const char *val, struct kernel_param *kp);
+static int param_get_aalockpolicy(char *buffer, struct kernel_param *kp);
+#define param_check_aalockpolicy(name, p) __param_check(name, p, int)
+
+static int param_set_audit(const char *val, struct kernel_param *kp);
+static int param_get_audit(char *buffer, struct kernel_param *kp);
+#define param_check_audit(name, p) __param_check(name, p, int)
+
+static int param_set_mode(const char *val, struct kernel_param *kp);
+static int param_get_mode(char *buffer, struct kernel_param *kp);
+#define param_check_mode(name, p) __param_check(name, p, int)
+
+/* Flag values, also controllable via /sys/module/apparmor/parameters
+ * We define special types as we want to do additional mediation.
+ */
+
+/* AppArmor global enforcement switch - complain, enforce, kill */
+enum profile_mode aa_g_profile_mode = APPARMOR_ENFORCE;
+module_param_call(mode, param_set_mode, param_get_mode,
+                 &aa_g_profile_mode, S_IRUSR | S_IWUSR);
+
+/* Debug mode */
+int aa_g_debug;
+module_param_named(debug, aa_g_debug, aabool, S_IRUSR | S_IWUSR);
+
+/* Audit mode */
+enum audit_mode aa_g_audit;
+module_param_call(audit, param_set_audit, param_get_audit,
+                 &aa_g_audit, S_IRUSR | S_IWUSR);
+
+/* Determines if audit header is included in audited messages.  This
+ * provides more context if the audit daemon is not running
+ */
+int aa_g_audit_header = 1;
+module_param_named(audit_header, aa_g_audit_header, aabool,
+                  S_IRUSR | S_IWUSR);
+
+/* lock out loading/removal of policy
+ * TODO: add in at boot loading of policy, which is the only way to
+ *       load policy, if lock_policy is set
+ */
+int aa_g_lock_policy;
+module_param_named(lock_policy, aa_g_lock_policy, aalockpolicy,
+                  S_IRUSR | S_IWUSR);
+
+/* Syscall logging mode */
+int aa_g_logsyscall;
+module_param_named(logsyscall, aa_g_logsyscall, aabool, S_IRUSR | S_IWUSR);
+
+/* Maximum pathname length before accesses will start getting rejected */
+unsigned int aa_g_path_max = 2 * PATH_MAX;
+module_param_named(path_max, aa_g_path_max, aauint, S_IRUSR | S_IWUSR);
+
+/* Determines how paranoid loading of policy is and how much verification
+ * on the loaded policy is done.
+ */
+int aa_g_paranoid_load = 1;
+module_param_named(paranoid_load, aa_g_paranoid_load, aabool,
+                  S_IRUSR | S_IWUSR);
+
+/* Boot time disable flag */
+static unsigned int apparmor_enabled = CONFIG_SECURITY_APPARMOR_BOOTPARAM_VALUE;
+module_param_named(enabled, apparmor_enabled, aabool, S_IRUSR);
+
+static int __init apparmor_enabled_setup(char *str)
+{
+       unsigned long enabled;
+       int error = strict_strtoul(str, 0, &enabled);
+       if (!error)
+               apparmor_enabled = enabled ? 1 : 0;
+       return 1;
+}
+
+__setup("apparmor=", apparmor_enabled_setup);
+
+/* set global flag turning off the ability to load policy */
+static int param_set_aalockpolicy(const char *val, struct kernel_param *kp)
+{
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+       if (aa_g_lock_policy)
+               return -EACCES;
+       return param_set_bool(val, kp);
+}
+
+static int param_get_aalockpolicy(char *buffer, struct kernel_param *kp)
+{
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+       return param_get_bool(buffer, kp);
+}
+
+static int param_set_aabool(const char *val, struct kernel_param *kp)
+{
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+       return param_set_bool(val, kp);
+}
+
+static int param_get_aabool(char *buffer, struct kernel_param *kp)
+{
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+       return param_get_bool(buffer, kp);
+}
+
+static int param_set_aauint(const char *val, struct kernel_param *kp)
+{
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+       return param_set_uint(val, kp);
+}
+
+static int param_get_aauint(char *buffer, struct kernel_param *kp)
+{
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+       return param_get_uint(buffer, kp);
+}
+
+static int param_get_audit(char *buffer, struct kernel_param *kp)
+{
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
+       if (!apparmor_enabled)
+               return -EINVAL;
+
+       return sprintf(buffer, "%s", audit_mode_names[aa_g_audit]);
+}
+
+static int param_set_audit(const char *val, struct kernel_param *kp)
+{
+       int i;
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
+       if (!apparmor_enabled)
+               return -EINVAL;
+
+       if (!val)
+               return -EINVAL;
+
+       for (i = 0; i < AUDIT_MAX_INDEX; i++) {
+               if (strcmp(val, audit_mode_names[i]) == 0) {
+                       aa_g_audit = i;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+static int param_get_mode(char *buffer, struct kernel_param *kp)
+{
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
+       if (!apparmor_enabled)
+               return -EINVAL;
+
+       return sprintf(buffer, "%s", profile_mode_names[aa_g_profile_mode]);
+}
+
+static int param_set_mode(const char *val, struct kernel_param *kp)
+{
+       int i;
+       if (!capable(CAP_MAC_ADMIN))
+               return -EPERM;
+
+       if (!apparmor_enabled)
+               return -EINVAL;
+
+       if (!val)
+               return -EINVAL;
+
+       for (i = 0; i < APPARMOR_NAMES_MAX_INDEX; i++) {
+               if (strcmp(val, profile_mode_names[i]) == 0) {
+                       aa_g_profile_mode = i;
+                       return 0;
+               }
+       }
+
+       return -EINVAL;
+}
+
+/*
+ * AppArmor init functions
+ */
+
+/**
+ * set_init_cxt - set a task context and profile on the first task.
+ *
+ * TODO: allow setting an alternate profile than unconfined
+ */
+static int __init set_init_cxt(void)
+{
+       struct cred *cred = (struct cred *)current->real_cred;
+       struct aa_task_cxt *cxt;
+
+       cxt = aa_alloc_task_context(GFP_KERNEL);
+       if (!cxt)
+               return -ENOMEM;
+
+       cxt->profile = aa_get_profile(root_ns->unconfined);
+       cred->security = cxt;
+
+       return 0;
+}
+
+static int __init apparmor_init(void)
+{
+       int error;
+
+       if (!apparmor_enabled || !security_module_enable(&apparmor_ops)) {
+               aa_info_message("AppArmor disabled by boot time parameter");
+               apparmor_enabled = 0;
+               return 0;
+       }
+
+       error = aa_alloc_root_ns();
+       if (error) {
+               AA_ERROR("Unable to allocate default profile namespace\n");
+               goto alloc_out;
+       }
+
+       error = set_init_cxt();
+       if (error) {
+               AA_ERROR("Failed to set context on init task\n");
+               goto register_security_out;
+       }
+
+       error = register_security(&apparmor_ops);
+       if (error) {
+               AA_ERROR("Unable to register AppArmor\n");
+               goto register_security_out;
+       }
+
+       /* Report that AppArmor successfully initialized */
+       apparmor_initialized = 1;
+       if (aa_g_profile_mode == APPARMOR_COMPLAIN)
+               aa_info_message("AppArmor initialized: complain mode enabled");
+       else if (aa_g_profile_mode == APPARMOR_KILL)
+               aa_info_message("AppArmor initialized: kill mode enabled");
+       else
+               aa_info_message("AppArmor initialized");
+
+       return error;
+
+register_security_out:
+       aa_free_root_ns();
+
+alloc_out:
+       aa_destroy_aafs();
+
+       apparmor_enabled = 0;
+       return error;
+
+}
+
+security_initcall(apparmor_init);
diff --git a/security/apparmor/match.c b/security/apparmor/match.c
new file mode 100644 (file)
index 0000000..5cb4dc1
--- /dev/null
@@ -0,0 +1,353 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor dfa based regular expression matching engine
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/errno.h>
+#include <linux/kernel.h>
+#include <linux/mm.h>
+#include <linux/slab.h>
+#include <linux/vmalloc.h>
+#include <linux/err.h>
+#include <linux/kref.h>
+
+#include "include/apparmor.h"
+#include "include/match.h"
+
+/**
+ * unpack_table - unpack a dfa table (one of accept, default, base, next check)
+ * @blob: data to unpack (NOT NULL)
+ * @bsize: size of blob
+ *
+ * Returns: pointer to table else NULL on failure
+ *
+ * NOTE: must be freed by kvfree (not kmalloc)
+ */
+static struct table_header *unpack_table(char *blob, size_t bsize)
+{
+       struct table_header *table = NULL;
+       struct table_header th;
+       size_t tsize;
+
+       if (bsize < sizeof(struct table_header))
+               goto out;
+
+       /* loaded td_id's start at 1, subtract 1 now to avoid doing
+        * it every time we use td_id as an index
+        */
+       th.td_id = be16_to_cpu(*(u16 *) (blob)) - 1;
+       th.td_flags = be16_to_cpu(*(u16 *) (blob + 2));
+       th.td_lolen = be32_to_cpu(*(u32 *) (blob + 8));
+       blob += sizeof(struct table_header);
+
+       if (!(th.td_flags == YYTD_DATA16 || th.td_flags == YYTD_DATA32 ||
+             th.td_flags == YYTD_DATA8))
+               goto out;
+
+       tsize = table_size(th.td_lolen, th.td_flags);
+       if (bsize < tsize)
+               goto out;
+
+       table = kvmalloc(tsize);
+       if (table) {
+               *table = th;
+               if (th.td_flags == YYTD_DATA8)
+                       UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
+                                    u8, byte_to_byte);
+               else if (th.td_flags == YYTD_DATA16)
+                       UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
+                                    u16, be16_to_cpu);
+               else if (th.td_flags == YYTD_DATA32)
+                       UNPACK_ARRAY(table->td_data, blob, th.td_lolen,
+                                    u32, be32_to_cpu);
+               else
+                       goto fail;
+       }
+
+out:
+       /* if table was vmalloced make sure the page tables are synced
+        * before it is used, as it goes live to all cpus.
+        */
+       if (is_vmalloc_addr(table))
+               vm_unmap_aliases();
+       return table;
+fail:
+       kvfree(table);
+       return NULL;
+}
+
+/**
+ * verify_dfa - verify that transitions and states in the tables are in bounds.
+ * @dfa: dfa to test  (NOT NULL)
+ * @flags: flags controlling what type of accept table are acceptable
+ *
+ * Assumes dfa has gone through the first pass verification done by unpacking
+ * NOTE: this does not valid accept table values
+ *
+ * Returns: %0 else error code on failure to verify
+ */
+static int verify_dfa(struct aa_dfa *dfa, int flags)
+{
+       size_t i, state_count, trans_count;
+       int error = -EPROTO;
+
+       /* check that required tables exist */
+       if (!(dfa->tables[YYTD_ID_DEF] &&
+             dfa->tables[YYTD_ID_BASE] &&
+             dfa->tables[YYTD_ID_NXT] && dfa->tables[YYTD_ID_CHK]))
+               goto out;
+
+       /* accept.size == default.size == base.size */
+       state_count = dfa->tables[YYTD_ID_BASE]->td_lolen;
+       if (ACCEPT1_FLAGS(flags)) {
+               if (!dfa->tables[YYTD_ID_ACCEPT])
+                       goto out;
+               if (state_count != dfa->tables[YYTD_ID_ACCEPT]->td_lolen)
+                       goto out;
+       }
+       if (ACCEPT2_FLAGS(flags)) {
+               if (!dfa->tables[YYTD_ID_ACCEPT2])
+                       goto out;
+               if (state_count != dfa->tables[YYTD_ID_ACCEPT2]->td_lolen)
+                       goto out;
+       }
+       if (state_count != dfa->tables[YYTD_ID_DEF]->td_lolen)
+               goto out;
+
+       /* next.size == chk.size */
+       trans_count = dfa->tables[YYTD_ID_NXT]->td_lolen;
+       if (trans_count != dfa->tables[YYTD_ID_CHK]->td_lolen)
+               goto out;
+
+       /* if equivalence classes then its table size must be 256 */
+       if (dfa->tables[YYTD_ID_EC] &&
+           dfa->tables[YYTD_ID_EC]->td_lolen != 256)
+               goto out;
+
+       if (flags & DFA_FLAG_VERIFY_STATES) {
+               for (i = 0; i < state_count; i++) {
+                       if (DEFAULT_TABLE(dfa)[i] >= state_count)
+                               goto out;
+                       /* TODO: do check that DEF state recursion terminates */
+                       if (BASE_TABLE(dfa)[i] + 255 >= trans_count) {
+                               printk(KERN_ERR "AppArmor DFA next/check upper "
+                                      "bounds error\n");
+                               goto out;
+                       }
+               }
+
+               for (i = 0; i < trans_count; i++) {
+                       if (NEXT_TABLE(dfa)[i] >= state_count)
+                               goto out;
+                       if (CHECK_TABLE(dfa)[i] >= state_count)
+                               goto out;
+               }
+       }
+
+       error = 0;
+out:
+       return error;
+}
+
+/**
+ * dfa_free - free a dfa allocated by aa_dfa_unpack
+ * @dfa: the dfa to free  (MAYBE NULL)
+ *
+ * Requires: reference count to dfa == 0
+ */
+static void dfa_free(struct aa_dfa *dfa)
+{
+       if (dfa) {
+               int i;
+
+               for (i = 0; i < ARRAY_SIZE(dfa->tables); i++) {
+                       kvfree(dfa->tables[i]);
+                       dfa->tables[i] = NULL;
+               }
+               kfree(dfa);
+       }
+}
+
+/**
+ * aa_dfa_free_kref - free aa_dfa by kref (called by aa_put_dfa)
+ * @kr: kref callback for freeing of a dfa  (NOT NULL)
+ */
+void aa_dfa_free_kref(struct kref *kref)
+{
+       struct aa_dfa *dfa = container_of(kref, struct aa_dfa, count);
+       dfa_free(dfa);
+}
+
+/**
+ * aa_dfa_unpack - unpack the binary tables of a serialized dfa
+ * @blob: aligned serialized stream of data to unpack  (NOT NULL)
+ * @size: size of data to unpack
+ * @flags: flags controlling what type of accept tables are acceptable
+ *
+ * Unpack a dfa that has been serialized.  To find information on the dfa
+ * format look in Documentation/apparmor.txt
+ * Assumes the dfa @blob stream has been aligned on a 8 byte boundry
+ *
+ * Returns: an unpacked dfa ready for matching or ERR_PTR on failure
+ */
+struct aa_dfa *aa_dfa_unpack(void *blob, size_t size, int flags)
+{
+       int hsize;
+       int error = -ENOMEM;
+       char *data = blob;
+       struct table_header *table = NULL;
+       struct aa_dfa *dfa = kzalloc(sizeof(struct aa_dfa), GFP_KERNEL);
+       if (!dfa)
+               goto fail;
+
+       kref_init(&dfa->count);
+
+       error = -EPROTO;
+
+       /* get dfa table set header */
+       if (size < sizeof(struct table_set_header))
+               goto fail;
+
+       if (ntohl(*(u32 *) data) != YYTH_MAGIC)
+               goto fail;
+
+       hsize = ntohl(*(u32 *) (data + 4));
+       if (size < hsize)
+               goto fail;
+
+       dfa->flags = ntohs(*(u16 *) (data + 12));
+       data += hsize;
+       size -= hsize;
+
+       while (size > 0) {
+               table = unpack_table(data, size);
+               if (!table)
+                       goto fail;
+
+               switch (table->td_id) {
+               case YYTD_ID_ACCEPT:
+                       if (!(table->td_flags & ACCEPT1_FLAGS(flags)))
+                               goto fail;
+                       break;
+               case YYTD_ID_ACCEPT2:
+                       if (!(table->td_flags & ACCEPT2_FLAGS(flags)))
+                               goto fail;
+                       break;
+               case YYTD_ID_BASE:
+                       if (table->td_flags != YYTD_DATA32)
+                               goto fail;
+                       break;
+               case YYTD_ID_DEF:
+               case YYTD_ID_NXT:
+               case YYTD_ID_CHK:
+                       if (table->td_flags != YYTD_DATA16)
+                               goto fail;
+                       break;
+               case YYTD_ID_EC:
+                       if (table->td_flags != YYTD_DATA8)
+                               goto fail;
+                       break;
+               default:
+                       goto fail;
+               }
+               /* check for duplicate table entry */
+               if (dfa->tables[table->td_id])
+                       goto fail;
+               dfa->tables[table->td_id] = table;
+               data += table_size(table->td_lolen, table->td_flags);
+               size -= table_size(table->td_lolen, table->td_flags);
+               table = NULL;
+       }
+
+       error = verify_dfa(dfa, flags);
+       if (error)
+               goto fail;
+
+       return dfa;
+
+fail:
+       kvfree(table);
+       dfa_free(dfa);
+       return ERR_PTR(error);
+}
+
+/**
+ * aa_dfa_match_len - traverse @dfa to find state @str stops at
+ * @dfa: the dfa to match @str against  (NOT NULL)
+ * @start: the state of the dfa to start matching in
+ * @str: the string of bytes to match against the dfa  (NOT NULL)
+ * @len: length of the string of bytes to match
+ *
+ * aa_dfa_match_len will match @str against the dfa and return the state it
+ * finished matching in. The final state can be used to look up the accepting
+ * label, or as the start state of a continuing match.
+ *
+ * This function will happily match again the 0 byte and only finishes
+ * when @len input is consumed.
+ *
+ * Returns: final state reached after input is consumed
+ */
+unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start,
+                             const char *str, int len)
+{
+       u16 *def = DEFAULT_TABLE(dfa);
+       u32 *base = BASE_TABLE(dfa);
+       u16 *next = NEXT_TABLE(dfa);
+       u16 *check = CHECK_TABLE(dfa);
+       unsigned int state = start, pos;
+
+       if (state == 0)
+               return 0;
+
+       /* current state is <state>, matching character *str */
+       if (dfa->tables[YYTD_ID_EC]) {
+               /* Equivalence class table defined */
+               u8 *equiv = EQUIV_TABLE(dfa);
+               /* default is direct to next state */
+               for (; len; len--) {
+                       pos = base[state] + equiv[(u8) *str++];
+                       if (check[pos] == state)
+                               state = next[pos];
+                       else
+                               state = def[state];
+               }
+       } else {
+               /* default is direct to next state */
+               for (; len; len--) {
+                       pos = base[state] + (u8) *str++;
+                       if (check[pos] == state)
+                               state = next[pos];
+                       else
+                               state = def[state];
+               }
+       }
+
+       return state;
+}
+
+/**
+ * aa_dfa_next_state - traverse @dfa to find state @str stops at
+ * @dfa: the dfa to match @str against  (NOT NULL)
+ * @start: the state of the dfa to start matching in
+ * @str: the null terminated string of bytes to match against the dfa (NOT NULL)
+ *
+ * aa_dfa_next_state will match @str against the dfa and return the state it
+ * finished matching in. The final state can be used to look up the accepting
+ * label, or as the start state of a continuing match.
+ *
+ * Returns: final state reached after input is consumed
+ */
+unsigned int aa_dfa_match(struct aa_dfa *dfa, unsigned int start,
+                         const char *str)
+{
+       return aa_dfa_match_len(dfa, start, str, strlen(str));
+}
diff --git a/security/apparmor/path.c b/security/apparmor/path.c
new file mode 100644 (file)
index 0000000..96bab94
--- /dev/null
@@ -0,0 +1,235 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor function for pathnames
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/magic.h>
+#include <linux/mnt_namespace.h>
+#include <linux/mount.h>
+#include <linux/namei.h>
+#include <linux/nsproxy.h>
+#include <linux/path.h>
+#include <linux/sched.h>
+#include <linux/slab.h>
+#include <linux/fs_struct.h>
+
+#include "include/apparmor.h"
+#include "include/path.h"
+#include "include/policy.h"
+
+
+/* modified from dcache.c */
+static int prepend(char **buffer, int buflen, const char *str, int namelen)
+{
+       buflen -= namelen;
+       if (buflen < 0)
+               return -ENAMETOOLONG;
+       *buffer -= namelen;
+       memcpy(*buffer, str, namelen);
+       return 0;
+}
+
+#define CHROOT_NSCONNECT (PATH_CHROOT_REL | PATH_CHROOT_NSCONNECT)
+
+/**
+ * d_namespace_path - lookup a name associated with a given path
+ * @path: path to lookup  (NOT NULL)
+ * @buf:  buffer to store path to  (NOT NULL)
+ * @buflen: length of @buf
+ * @name: Returns - pointer for start of path name with in @buf (NOT NULL)
+ * @flags: flags controlling path lookup
+ *
+ * Handle path name lookup.
+ *
+ * Returns: %0 else error code if path lookup fails
+ *          When no error the path name is returned in @name which points to
+ *          to a position in @buf
+ */
+static int d_namespace_path(struct path *path, char *buf, int buflen,
+                           char **name, int flags)
+{
+       struct path root, tmp;
+       char *res;
+       int deleted, connected;
+       int error = 0;
+
+       /* Get the root we want to resolve too */
+       if (flags & PATH_CHROOT_REL) {
+               /* resolve paths relative to chroot */
+               read_lock(&current->fs->lock);
+               root = current->fs->root;
+               /* released below */
+               path_get(&root);
+               read_unlock(&current->fs->lock);
+       } else {
+               /* resolve paths relative to namespace */
+               root.mnt = current->nsproxy->mnt_ns->root;
+               root.dentry = root.mnt->mnt_root;
+               /* released below */
+               path_get(&root);
+       }
+
+       spin_lock(&dcache_lock);
+       /* There is a race window between path lookup here and the
+        * need to strip the " (deleted) string that __d_path applies
+        * Detect the race and relookup the path
+        *
+        * The stripping of (deleted) is a hack that could be removed
+        * with an updated __d_path
+        */
+       do {
+               tmp = root;
+               deleted = d_unlinked(path->dentry);
+               res = __d_path(path, &tmp, buf, buflen);
+
+       } while (deleted != d_unlinked(path->dentry));
+       spin_unlock(&dcache_lock);
+
+       *name = res;
+       /* handle error conditions - and still allow a partial path to
+        * be returned.
+        */
+       if (IS_ERR(res)) {
+               error = PTR_ERR(res);
+               *name = buf;
+               goto out;
+       }
+       if (deleted) {
+               /* On some filesystems, newly allocated dentries appear to the
+                * security_path hooks as a deleted dentry except without an
+                * inode allocated.
+                *
+                * Remove the appended deleted text and return as string for
+                * normal mediation, or auditing.  The (deleted) string is
+                * guaranteed to be added in this case, so just strip it.
+                */
+               buf[buflen - 11] = 0;   /* - (len(" (deleted)") +\0) */
+
+               if (path->dentry->d_inode && !(flags & PATH_MEDIATE_DELETED)) {
+                       error = -ENOENT;
+                       goto out;
+               }
+       }
+
+       /* Determine if the path is connected to the expected root */
+       connected = tmp.dentry == root.dentry && tmp.mnt == root.mnt;
+
+       /* If the path is not connected,
+        * check if it is a sysctl and handle specially else remove any
+        * leading / that __d_path may have returned.
+        * Unless
+        *     specifically directed to connect the path,
+        * OR
+        *     if in a chroot and doing chroot relative paths and the path
+        *     resolves to the namespace root (would be connected outside
+        *     of chroot) and specifically directed to connect paths to
+        *     namespace root.
+        */
+       if (!connected) {
+               /* is the disconnect path a sysctl? */
+               if (tmp.dentry->d_sb->s_magic == PROC_SUPER_MAGIC &&
+                   strncmp(*name, "/sys/", 5) == 0) {
+                       /* TODO: convert over to using a per namespace
+                        * control instead of hard coded /proc
+                        */
+                       error = prepend(name, *name - buf, "/proc", 5);
+               } else if (!(flags & PATH_CONNECT_PATH) &&
+                          !(((flags & CHROOT_NSCONNECT) == CHROOT_NSCONNECT) &&
+                            (tmp.mnt == current->nsproxy->mnt_ns->root &&
+                             tmp.dentry == tmp.mnt->mnt_root))) {
+                       /* disconnected path, don't return pathname starting
+                        * with '/'
+                        */
+                       error = -ESTALE;
+                       if (*res == '/')
+                               *name = res + 1;
+               }
+       }
+
+out:
+       path_put(&root);
+
+       return error;
+}
+
+/**
+ * get_name_to_buffer - get the pathname to a buffer ensure dir / is appended
+ * @path: path to get name for  (NOT NULL)
+ * @flags: flags controlling path lookup
+ * @buffer: buffer to put name in  (NOT NULL)
+ * @size: size of buffer
+ * @name: Returns - contains position of path name in @buffer (NOT NULL)
+ *
+ * Returns: %0 else error on failure
+ */
+static int get_name_to_buffer(struct path *path, int flags, char *buffer,
+                             int size, char **name)
+{
+       int adjust = (flags & PATH_IS_DIR) ? 1 : 0;
+       int error = d_namespace_path(path, buffer, size - adjust, name, flags);
+
+       if (!error && (flags & PATH_IS_DIR) && (*name)[1] != '\0')
+               /*
+                * Append "/" to the pathname.  The root directory is a special
+                * case; it already ends in slash.
+                */
+               strcpy(&buffer[size - 2], "/");
+
+       return error;
+}
+
+/**
+ * aa_get_name - compute the pathname of a file
+ * @path: path the file  (NOT NULL)
+ * @flags: flags controlling path name generation
+ * @buffer: buffer that aa_get_name() allocated  (NOT NULL)
+ * @name: Returns - the generated path name if !error (NOT NULL)
+ *
+ * @name is a pointer to the beginning of the pathname (which usually differs
+ * from the beginning of the buffer), or NULL.  If there is an error @name
+ * may contain a partial or invalid name that can be used for audit purposes,
+ * but it can not be used for mediation.
+ *
+ * We need PATH_IS_DIR to indicate whether the file is a directory or not
+ * because the file may not yet exist, and so we cannot check the inode's
+ * file type.
+ *
+ * Returns: %0 else error code if could retrieve name
+ */
+int aa_get_name(struct path *path, int flags, char **buffer, const char **name)
+{
+       char *buf, *str = NULL;
+       int size = 256;
+       int error;
+
+       *name = NULL;
+       *buffer = NULL;
+       for (;;) {
+               /* freed by caller */
+               buf = kmalloc(size, GFP_KERNEL);
+               if (!buf)
+                       return -ENOMEM;
+
+               error = get_name_to_buffer(path, flags, buf, size, &str);
+               if (error != -ENAMETOOLONG)
+                       break;
+
+               kfree(buf);
+               size <<= 1;
+               if (size > aa_g_path_max)
+                       return -ENAMETOOLONG;
+       }
+       *buffer = buf;
+       *name = str;
+
+       return error;
+}
diff --git a/security/apparmor/policy.c b/security/apparmor/policy.c
new file mode 100644 (file)
index 0000000..3cdc1ad
--- /dev/null
@@ -0,0 +1,1184 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor policy manipulation functions
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ *
+ *
+ * AppArmor policy is based around profiles, which contain the rules a
+ * task is confined by.  Every task in the system has a profile attached
+ * to it determined either by matching "unconfined" tasks against the
+ * visible set of profiles or by following a profiles attachment rules.
+ *
+ * Each profile exists in a profile namespace which is a container of
+ * visible profiles.  Each namespace contains a special "unconfined" profile,
+ * which doesn't enforce any confinement on a task beyond DAC.
+ *
+ * Namespace and profile names can be written together in either
+ * of two syntaxes.
+ *     :namespace:profile - used by kernel interfaces for easy detection
+ *     namespace://profile - used by policy
+ *
+ * Profile names can not start with : or @ or ^ and may not contain \0
+ *
+ * Reserved profile names
+ *     unconfined - special automatically generated unconfined profile
+ *     inherit - special name to indicate profile inheritance
+ *     null-XXXX-YYYY - special automatically generated learning profiles
+ *
+ * Namespace names may not start with / or @ and may not contain \0 or :
+ * Reserved namespace names
+ *     user-XXXX - user defined profiles
+ *
+ * a // in a profile or namespace name indicates a hierarchical name with the
+ * name before the // being the parent and the name after the child.
+ *
+ * Profile and namespace hierarchies serve two different but similar purposes.
+ * The namespace contains the set of visible profiles that are considered
+ * for attachment.  The hierarchy of namespaces allows for virtualizing
+ * the namespace so that for example a chroot can have its own set of profiles
+ * which may define some local user namespaces.
+ * The profile hierarchy severs two distinct purposes,
+ * -  it allows for sub profiles or hats, which allows an application to run
+ *    subprograms under its own profile with different restriction than it
+ *    self, and not have it use the system profile.
+ *    eg. if a mail program starts an editor, the policy might make the
+ *        restrictions tighter on the editor tighter than the mail program,
+ *        and definitely different than general editor restrictions
+ * - it allows for binary hierarchy of profiles, so that execution history
+ *   is preserved.  This feature isn't exploited by AppArmor reference policy
+ *   but is allowed.  NOTE: this is currently suboptimal because profile
+ *   aliasing is not currently implemented so that a profile for each
+ *   level must be defined.
+ *   eg. /bin/bash///bin/ls as a name would indicate /bin/ls was started
+ *       from /bin/bash
+ *
+ *   A profile or namespace name that can contain one or more // separators
+ *   is referred to as an hname (hierarchical).
+ *   eg.  /bin/bash//bin/ls
+ *
+ *   An fqname is a name that may contain both namespace and profile hnames.
+ *   eg. :ns:/bin/bash//bin/ls
+ *
+ * NOTES:
+ *   - locking of profile lists is currently fairly coarse.  All profile
+ *     lists within a namespace use the namespace lock.
+ * FIXME: move profile lists to using rcu_lists
+ */
+
+#include <linux/slab.h>
+#include <linux/spinlock.h>
+#include <linux/string.h>
+
+#include "include/apparmor.h"
+#include "include/capability.h"
+#include "include/context.h"
+#include "include/file.h"
+#include "include/ipc.h"
+#include "include/match.h"
+#include "include/path.h"
+#include "include/policy.h"
+#include "include/policy_unpack.h"
+#include "include/resource.h"
+#include "include/sid.h"
+
+
+/* root profile namespace */
+struct aa_namespace *root_ns;
+
+const char *profile_mode_names[] = {
+       "enforce",
+       "complain",
+       "kill",
+};
+
+/**
+ * hname_tail - find the last component of an hname
+ * @name: hname to find the base profile name component of  (NOT NULL)
+ *
+ * Returns: the tail (base profile name) name component of an hname
+ */
+static const char *hname_tail(const char *hname)
+{
+       char *split;
+       hname = strim((char *)hname);
+       for (split = strstr(hname, "//"); split; split = strstr(hname, "//"))
+               hname = split + 2;
+
+       return hname;
+}
+
+/**
+ * policy_init - initialize a policy structure
+ * @policy: policy to initialize  (NOT NULL)
+ * @prefix: prefix name if any is required.  (MAYBE NULL)
+ * @name: name of the policy, init will make a copy of it  (NOT NULL)
+ *
+ * Note: this fn creates a copy of strings passed in
+ *
+ * Returns: true if policy init successful
+ */
+static bool policy_init(struct aa_policy *policy, const char *prefix,
+                       const char *name)
+{
+       /* freed by policy_free */
+       if (prefix) {
+               policy->hname = kmalloc(strlen(prefix) + strlen(name) + 3,
+                                       GFP_KERNEL);
+               if (policy->hname)
+                       sprintf(policy->hname, "%s//%s", prefix, name);
+       } else
+               policy->hname = kstrdup(name, GFP_KERNEL);
+       if (!policy->hname)
+               return 0;
+       /* base.name is a substring of fqname */
+       policy->name = (char *)hname_tail(policy->hname);
+       INIT_LIST_HEAD(&policy->list);
+       INIT_LIST_HEAD(&policy->profiles);
+       kref_init(&policy->count);
+
+       return 1;
+}
+
+/**
+ * policy_destroy - free the elements referenced by @policy
+ * @policy: policy that is to have its elements freed  (NOT NULL)
+ */
+static void policy_destroy(struct aa_policy *policy)
+{
+       /* still contains profiles -- invalid */
+       if (!list_empty(&policy->profiles)) {
+               AA_ERROR("%s: internal error, "
+                        "policy '%s' still contains profiles\n",
+                        __func__, policy->name);
+               BUG();
+       }
+       if (!list_empty(&policy->list)) {
+               AA_ERROR("%s: internal error, policy '%s' still on list\n",
+                        __func__, policy->name);
+               BUG();
+       }
+
+       /* don't free name as its a subset of hname */
+       kzfree(policy->hname);
+}
+
+/**
+ * __policy_find - find a policy by @name on a policy list
+ * @head: list to search  (NOT NULL)
+ * @name: name to search for  (NOT NULL)
+ *
+ * Requires: correct locks for the @head list be held
+ *
+ * Returns: unrefcounted policy that match @name or NULL if not found
+ */
+static struct aa_policy *__policy_find(struct list_head *head, const char *name)
+{
+       struct aa_policy *policy;
+
+       list_for_each_entry(policy, head, list) {
+               if (!strcmp(policy->name, name))
+                       return policy;
+       }
+       return NULL;
+}
+
+/**
+ * __policy_strn_find - find a policy that's name matches @len chars of @str
+ * @head: list to search  (NOT NULL)
+ * @str: string to search for  (NOT NULL)
+ * @len: length of match required
+ *
+ * Requires: correct locks for the @head list be held
+ *
+ * Returns: unrefcounted policy that match @str or NULL if not found
+ *
+ * if @len == strlen(@strlen) then this is equiv to __policy_find
+ * other wise it allows searching for policy by a partial match of name
+ */
+static struct aa_policy *__policy_strn_find(struct list_head *head,
+                                           const char *str, int len)
+{
+       struct aa_policy *policy;
+
+       list_for_each_entry(policy, head, list) {
+               if (aa_strneq(policy->name, str, len))
+                       return policy;
+       }
+
+       return NULL;
+}
+
+/*
+ * Routines for AppArmor namespaces
+ */
+
+static const char *hidden_ns_name = "---";
+/**
+ * aa_ns_visible - test if @view is visible from @curr
+ * @curr: namespace to treat as the parent (NOT NULL)
+ * @view:  namespace to test if visible from @curr (NOT NULL)
+ *
+ * Returns: true if @view is visible from @curr else false
+ */
+bool aa_ns_visible(struct aa_namespace *curr, struct aa_namespace *view)
+{
+       if (curr == view)
+               return true;
+
+       for ( ; view; view = view->parent) {
+               if (view->parent == curr)
+                       return true;
+       }
+       return false;
+}
+
+/**
+ * aa_na_name - Find the ns name to display for @view from @curr
+ * @curr - current namespace (NOT NULL)
+ * @view - namespace attempting to view (NOT NULL)
+ *
+ * Returns: name of @view visible from @curr
+ */
+const char *aa_ns_name(struct aa_namespace *curr, struct aa_namespace *view)
+{
+       /* if view == curr then the namespace name isn't displayed */
+       if (curr == view)
+               return "";
+
+       if (aa_ns_visible(curr, view)) {
+               /* at this point if a ns is visible it is in a view ns
+                * thus the curr ns.hname is a prefix of its name.
+                * Only output the virtualized portion of the name
+                * Add + 2 to skip over // separating curr hname prefix
+                * from the visible tail of the views hname
+                */
+               return view->base.hname + strlen(curr->base.hname) + 2;
+       } else
+               return hidden_ns_name;
+}
+
+/**
+ * alloc_namespace - allocate, initialize and return a new namespace
+ * @prefix: parent namespace name (MAYBE NULL)
+ * @name: a preallocated name  (NOT NULL)
+ *
+ * Returns: refcounted namespace or NULL on failure.
+ */
+static struct aa_namespace *alloc_namespace(const char *prefix,
+                                           const char *name)
+{
+       struct aa_namespace *ns;
+
+       ns = kzalloc(sizeof(*ns), GFP_KERNEL);
+       AA_DEBUG("%s(%p)\n", __func__, ns);
+       if (!ns)
+               return NULL;
+       if (!policy_init(&ns->base, prefix, name))
+               goto fail_ns;
+
+       INIT_LIST_HEAD(&ns->sub_ns);
+       rwlock_init(&ns->lock);
+
+       /* released by free_namespace */
+       ns->unconfined = aa_alloc_profile("unconfined");
+       if (!ns->unconfined)
+               goto fail_unconfined;
+
+       ns->unconfined->sid = aa_alloc_sid();
+       ns->unconfined->flags = PFLAG_UNCONFINED | PFLAG_IX_ON_NAME_ERROR |
+           PFLAG_IMMUTABLE;
+
+       /*
+        * released by free_namespace, however __remove_namespace breaks
+        * the cyclic references (ns->unconfined, and unconfined->ns) and
+        * replaces with refs to parent namespace unconfined
+        */
+       ns->unconfined->ns = aa_get_namespace(ns);
+
+       return ns;
+
+fail_unconfined:
+       kzfree(ns->base.name);
+fail_ns:
+       kzfree(ns);
+       return NULL;
+}
+
+/**
+ * free_namespace - free a profile namespace
+ * @ns: the namespace to free  (MAYBE NULL)
+ *
+ * Requires: All references to the namespace must have been put, if the
+ *           namespace was referenced by a profile confining a task,
+ */
+static void free_namespace(struct aa_namespace *ns)
+{
+       if (!ns)
+               return;
+
+       policy_destroy(&ns->base);
+       aa_put_namespace(ns->parent);
+
+       if (ns->unconfined && ns->unconfined->ns == ns)
+               ns->unconfined->ns = NULL;
+
+       aa_put_profile(ns->unconfined);
+       kzfree(ns);
+}
+
+/**
+ * aa_free_namespace_kref - free aa_namespace by kref (see aa_put_namespace)
+ * @kr: kref callback for freeing of a namespace  (NOT NULL)
+ */
+void aa_free_namespace_kref(struct kref *kref)
+{
+       free_namespace(container_of(kref, struct aa_namespace, base.count));
+}
+
+/**
+ * __aa_find_namespace - find a namespace on a list by @name
+ * @head: list to search for namespace on  (NOT NULL)
+ * @name: name of namespace to look for  (NOT NULL)
+ *
+ * Returns: unrefcounted namespace
+ *
+ * Requires: ns lock be held
+ */
+static struct aa_namespace *__aa_find_namespace(struct list_head *head,
+                                               const char *name)
+{
+       return (struct aa_namespace *)__policy_find(head, name);
+}
+
+/**
+ * aa_find_namespace  -  look up a profile namespace on the namespace list
+ * @root: namespace to search in  (NOT NULL)
+ * @name: name of namespace to find  (NOT NULL)
+ *
+ * Returns: a refcounted namespace on the list, or NULL if no namespace
+ *          called @name exists.
+ *
+ * refcount released by caller
+ */
+struct aa_namespace *aa_find_namespace(struct aa_namespace *root,
+                                      const char *name)
+{
+       struct aa_namespace *ns = NULL;
+
+       read_lock(&root->lock);
+       ns = aa_get_namespace(__aa_find_namespace(&root->sub_ns, name));
+       read_unlock(&root->lock);
+
+       return ns;
+}
+
+/**
+ * aa_prepare_namespace - find an existing or create a new namespace of @name
+ * @name: the namespace to find or add  (MAYBE NULL)
+ *
+ * Returns: refcounted namespace or NULL if failed to create one
+ */
+static struct aa_namespace *aa_prepare_namespace(const char *name)
+{
+       struct aa_namespace *ns, *root;
+
+       root = aa_current_profile()->ns;
+
+       write_lock(&root->lock);
+
+       /* if name isn't specified the profile is loaded to the current ns */
+       if (!name) {
+               /* released by caller */
+               ns = aa_get_namespace(root);
+               goto out;
+       }
+
+       /* try and find the specified ns and if it doesn't exist create it */
+       /* released by caller */
+       ns = aa_get_namespace(__aa_find_namespace(&root->sub_ns, name));
+       if (!ns) {
+               /* namespace not found */
+               struct aa_namespace *new_ns;
+               write_unlock(&root->lock);
+               new_ns = alloc_namespace(root->base.hname, name);
+               if (!new_ns)
+                       return NULL;
+               write_lock(&root->lock);
+               /* test for race when new_ns was allocated */
+               ns = __aa_find_namespace(&root->sub_ns, name);
+               if (!ns) {
+                       /* add parent ref */
+                       new_ns->parent = aa_get_namespace(root);
+
+                       list_add(&new_ns->base.list, &root->sub_ns);
+                       /* add list ref */
+                       ns = aa_get_namespace(new_ns);
+               } else {
+                       /* raced so free the new one */
+                       free_namespace(new_ns);
+                       /* get reference on namespace */
+                       aa_get_namespace(ns);
+               }
+       }
+out:
+       write_unlock(&root->lock);
+
+       /* return ref */
+       return ns;
+}
+
+/**
+ * __list_add_profile - add a profile to a list
+ * @list: list to add it to  (NOT NULL)
+ * @profile: the profile to add  (NOT NULL)
+ *
+ * refcount @profile, should be put by __list_remove_profile
+ *
+ * Requires: namespace lock be held, or list not be shared
+ */
+static void __list_add_profile(struct list_head *list,
+                              struct aa_profile *profile)
+{
+       list_add(&profile->base.list, list);
+       /* get list reference */
+       aa_get_profile(profile);
+}
+
+/**
+ * __list_remove_profile - remove a profile from the list it is on
+ * @profile: the profile to remove  (NOT NULL)
+ *
+ * remove a profile from the list, warning generally removal should
+ * be done with __replace_profile as most profile removals are
+ * replacements to the unconfined profile.
+ *
+ * put @profile list refcount
+ *
+ * Requires: namespace lock be held, or list not have been live
+ */
+static void __list_remove_profile(struct aa_profile *profile)
+{
+       list_del_init(&profile->base.list);
+       if (!(profile->flags & PFLAG_NO_LIST_REF))
+               /* release list reference */
+               aa_put_profile(profile);
+}
+
+/**
+ * __replace_profile - replace @old with @new on a list
+ * @old: profile to be replaced  (NOT NULL)
+ * @new: profile to replace @old with  (NOT NULL)
+ *
+ * Will duplicate and refcount elements that @new inherits from @old
+ * and will inherit @old children.
+ *
+ * refcount @new for list, put @old list refcount
+ *
+ * Requires: namespace list lock be held, or list not be shared
+ */
+static void __replace_profile(struct aa_profile *old, struct aa_profile *new)
+{
+       struct aa_policy *policy;
+       struct aa_profile *child, *tmp;
+
+       if (old->parent)
+               policy = &old->parent->base;
+       else
+               policy = &old->ns->base;
+
+       /* released when @new is freed */
+       new->parent = aa_get_profile(old->parent);
+       new->ns = aa_get_namespace(old->ns);
+       new->sid = old->sid;
+       __list_add_profile(&policy->profiles, new);
+       /* inherit children */
+       list_for_each_entry_safe(child, tmp, &old->base.profiles, base.list) {
+               aa_put_profile(child->parent);
+               child->parent = aa_get_profile(new);
+               /* list refcount transferred to @new*/
+               list_move(&child->base.list, &new->base.profiles);
+       }
+
+       /* released by free_profile */
+       old->replacedby = aa_get_profile(new);
+       __list_remove_profile(old);
+}
+
+static void __profile_list_release(struct list_head *head);
+
+/**
+ * __remove_profile - remove old profile, and children
+ * @profile: profile to be replaced  (NOT NULL)
+ *
+ * Requires: namespace list lock be held, or list not be shared
+ */
+static void __remove_profile(struct aa_profile *profile)
+{
+       /* release any children lists first */
+       __profile_list_release(&profile->base.profiles);
+       /* released by free_profile */
+       profile->replacedby = aa_get_profile(profile->ns->unconfined);
+       __list_remove_profile(profile);
+}
+
+/**
+ * __profile_list_release - remove all profiles on the list and put refs
+ * @head: list of profiles  (NOT NULL)
+ *
+ * Requires: namespace lock be held
+ */
+static void __profile_list_release(struct list_head *head)
+{
+       struct aa_profile *profile, *tmp;
+       list_for_each_entry_safe(profile, tmp, head, base.list)
+               __remove_profile(profile);
+}
+
+static void __ns_list_release(struct list_head *head);
+
+/**
+ * destroy_namespace - remove everything contained by @ns
+ * @ns: namespace to have it contents removed  (NOT NULL)
+ */
+static void destroy_namespace(struct aa_namespace *ns)
+{
+       if (!ns)
+               return;
+
+       write_lock(&ns->lock);
+       /* release all profiles in this namespace */
+       __profile_list_release(&ns->base.profiles);
+
+       /* release all sub namespaces */
+       __ns_list_release(&ns->sub_ns);
+
+       write_unlock(&ns->lock);
+}
+
+/**
+ * __remove_namespace - remove a namespace and all its children
+ * @ns: namespace to be removed  (NOT NULL)
+ *
+ * Requires: ns->parent->lock be held and ns removed from parent.
+ */
+static void __remove_namespace(struct aa_namespace *ns)
+{
+       struct aa_profile *unconfined = ns->unconfined;
+
+       /* remove ns from namespace list */
+       list_del_init(&ns->base.list);
+
+       /*
+        * break the ns, unconfined profile cyclic reference and forward
+        * all new unconfined profiles requests to the parent namespace
+        * This will result in all confined tasks that have a profile
+        * being removed, inheriting the parent->unconfined profile.
+        */
+       if (ns->parent)
+               ns->unconfined = aa_get_profile(ns->parent->unconfined);
+
+       destroy_namespace(ns);
+
+       /* release original ns->unconfined ref */
+       aa_put_profile(unconfined);
+       /* release ns->base.list ref, from removal above */
+       aa_put_namespace(ns);
+}
+
+/**
+ * __ns_list_release - remove all profile namespaces on the list put refs
+ * @head: list of profile namespaces  (NOT NULL)
+ *
+ * Requires: namespace lock be held
+ */
+static void __ns_list_release(struct list_head *head)
+{
+       struct aa_namespace *ns, *tmp;
+       list_for_each_entry_safe(ns, tmp, head, base.list)
+               __remove_namespace(ns);
+
+}
+
+/**
+ * aa_alloc_root_ns - allocate the root profile namespace
+ *
+ * Returns: %0 on success else error
+ *
+ */
+int __init aa_alloc_root_ns(void)
+{
+       /* released by aa_free_root_ns - used as list ref*/
+       root_ns = alloc_namespace(NULL, "root");
+       if (!root_ns)
+               return -ENOMEM;
+
+       return 0;
+}
+
+ /**
+  * aa_free_root_ns - free the root profile namespace
+  */
+void __init aa_free_root_ns(void)
+ {
+        struct aa_namespace *ns = root_ns;
+        root_ns = NULL;
+
+        destroy_namespace(ns);
+        aa_put_namespace(ns);
+}
+
+/**
+ * aa_alloc_profile - allocate, initialize and return a new profile
+ * @hname: name of the profile  (NOT NULL)
+ *
+ * Returns: refcount profile or NULL on failure
+ */
+struct aa_profile *aa_alloc_profile(const char *hname)
+{
+       struct aa_profile *profile;
+
+       /* freed by free_profile - usually through aa_put_profile */
+       profile = kzalloc(sizeof(*profile), GFP_KERNEL);
+       if (!profile)
+               return NULL;
+
+       if (!policy_init(&profile->base, NULL, hname)) {
+               kzfree(profile);
+               return NULL;
+       }
+
+       /* refcount released by caller */
+       return profile;
+}
+
+/**
+ * aa_new_null_profile - create a new null-X learning profile
+ * @parent: profile that caused this profile to be created (NOT NULL)
+ * @hat: true if the null- learning profile is a hat
+ *
+ * Create a null- complain mode profile used in learning mode.  The name of
+ * the profile is unique and follows the format of parent//null-sid.
+ *
+ * null profiles are added to the profile list but the list does not
+ * hold a count on them so that they are automatically released when
+ * not in use.
+ *
+ * Returns: new refcounted profile else NULL on failure
+ */
+struct aa_profile *aa_new_null_profile(struct aa_profile *parent, int hat)
+{
+       struct aa_profile *profile = NULL;
+       char *name;
+       u32 sid = aa_alloc_sid();
+
+       /* freed below */
+       name = kmalloc(strlen(parent->base.hname) + 2 + 7 + 8, GFP_KERNEL);
+       if (!name)
+               goto fail;
+       sprintf(name, "%s//null-%x", parent->base.hname, sid);
+
+       profile = aa_alloc_profile(name);
+       kfree(name);
+       if (!profile)
+               goto fail;
+
+       profile->sid = sid;
+       profile->mode = APPARMOR_COMPLAIN;
+       profile->flags = PFLAG_NULL;
+       if (hat)
+               profile->flags |= PFLAG_HAT;
+
+       /* released on free_profile */
+       profile->parent = aa_get_profile(parent);
+       profile->ns = aa_get_namespace(parent->ns);
+
+       write_lock(&profile->ns->lock);
+       __list_add_profile(&parent->base.profiles, profile);
+       write_unlock(&profile->ns->lock);
+
+       /* refcount released by caller */
+       return profile;
+
+fail:
+       aa_free_sid(sid);
+       return NULL;
+}
+
+/**
+ * free_profile - free a profile
+ * @profile: the profile to free  (MAYBE NULL)
+ *
+ * Free a profile, its hats and null_profile. All references to the profile,
+ * its hats and null_profile must have been put.
+ *
+ * If the profile was referenced from a task context, free_profile() will
+ * be called from an rcu callback routine, so we must not sleep here.
+ */
+static void free_profile(struct aa_profile *profile)
+{
+       AA_DEBUG("%s(%p)\n", __func__, profile);
+
+       if (!profile)
+               return;
+
+       if (!list_empty(&profile->base.list)) {
+               AA_ERROR("%s: internal error, "
+                        "profile '%s' still on ns list\n",
+                        __func__, profile->base.name);
+               BUG();
+       }
+
+       /* free children profiles */
+       policy_destroy(&profile->base);
+       aa_put_profile(profile->parent);
+
+       aa_put_namespace(profile->ns);
+       kzfree(profile->rename);
+
+       aa_free_file_rules(&profile->file);
+       aa_free_cap_rules(&profile->caps);
+       aa_free_rlimit_rules(&profile->rlimits);
+
+       aa_free_sid(profile->sid);
+       aa_put_dfa(profile->xmatch);
+
+       aa_put_profile(profile->replacedby);
+
+       kzfree(profile);
+}
+
+/**
+ * aa_free_profile_kref - free aa_profile by kref (called by aa_put_profile)
+ * @kr: kref callback for freeing of a profile  (NOT NULL)
+ */
+void aa_free_profile_kref(struct kref *kref)
+{
+       struct aa_profile *p = container_of(kref, struct aa_profile,
+                                           base.count);
+
+       free_profile(p);
+}
+
+/* TODO: profile accounting - setup in remove */
+
+/**
+ * __find_child - find a profile on @head list with a name matching @name
+ * @head: list to search  (NOT NULL)
+ * @name: name of profile (NOT NULL)
+ *
+ * Requires: ns lock protecting list be held
+ *
+ * Returns: unrefcounted profile ptr, or NULL if not found
+ */
+static struct aa_profile *__find_child(struct list_head *head, const char *name)
+{
+       return (struct aa_profile *)__policy_find(head, name);
+}
+
+/**
+ * __strn_find_child - find a profile on @head list using substring of @name
+ * @head: list to search  (NOT NULL)
+ * @name: name of profile (NOT NULL)
+ * @len: length of @name substring to match
+ *
+ * Requires: ns lock protecting list be held
+ *
+ * Returns: unrefcounted profile ptr, or NULL if not found
+ */
+static struct aa_profile *__strn_find_child(struct list_head *head,
+                                           const char *name, int len)
+{
+       return (struct aa_profile *)__policy_strn_find(head, name, len);
+}
+
+/**
+ * aa_find_child - find a profile by @name in @parent
+ * @parent: profile to search  (NOT NULL)
+ * @name: profile name to search for  (NOT NULL)
+ *
+ * Returns: a refcounted profile or NULL if not found
+ */
+struct aa_profile *aa_find_child(struct aa_profile *parent, const char *name)
+{
+       struct aa_profile *profile;
+
+       read_lock(&parent->ns->lock);
+       profile = aa_get_profile(__find_child(&parent->base.profiles, name));
+       read_unlock(&parent->ns->lock);
+
+       /* refcount released by caller */
+       return profile;
+}
+
+/**
+ * __lookup_parent - lookup the parent of a profile of name @hname
+ * @ns: namespace to lookup profile in  (NOT NULL)
+ * @hname: hierarchical profile name to find parent of  (NOT NULL)
+ *
+ * Lookups up the parent of a fully qualified profile name, the profile
+ * that matches hname does not need to exist, in general this
+ * is used to load a new profile.
+ *
+ * Requires: ns->lock be held
+ *
+ * Returns: unrefcounted policy or NULL if not found
+ */
+static struct aa_policy *__lookup_parent(struct aa_namespace *ns,
+                                        const char *hname)
+{
+       struct aa_policy *policy;
+       struct aa_profile *profile = NULL;
+       char *split;
+
+       policy = &ns->base;
+
+       for (split = strstr(hname, "//"); split;) {
+               profile = __strn_find_child(&policy->profiles, hname,
+                                           split - hname);
+               if (!profile)
+                       return NULL;
+               policy = &profile->base;
+               hname = split + 2;
+               split = strstr(hname, "//");
+       }
+       if (!profile)
+               return &ns->base;
+       return &profile->base;
+}
+
+/**
+ * __lookup_profile - lookup the profile matching @hname
+ * @base: base list to start looking up profile name from  (NOT NULL)
+ * @hname: hierarchical profile name  (NOT NULL)
+ *
+ * Requires: ns->lock be held
+ *
+ * Returns: unrefcounted profile pointer or NULL if not found
+ *
+ * Do a relative name lookup, recursing through profile tree.
+ */
+static struct aa_profile *__lookup_profile(struct aa_policy *base,
+                                          const char *hname)
+{
+       struct aa_profile *profile = NULL;
+       char *split;
+
+       for (split = strstr(hname, "//"); split;) {
+               profile = __strn_find_child(&base->profiles, hname,
+                                           split - hname);
+               if (!profile)
+                       return NULL;
+
+               base = &profile->base;
+               hname = split + 2;
+               split = strstr(hname, "//");
+       }
+
+       profile = __find_child(&base->profiles, hname);
+
+       return profile;
+}
+
+/**
+ * aa_lookup_profile - find a profile by its full or partial name
+ * @ns: the namespace to start from (NOT NULL)
+ * @hname: name to do lookup on.  Does not contain namespace prefix (NOT NULL)
+ *
+ * Returns: refcounted profile or NULL if not found
+ */
+struct aa_profile *aa_lookup_profile(struct aa_namespace *ns, const char *hname)
+{
+       struct aa_profile *profile;
+
+       read_lock(&ns->lock);
+       profile = aa_get_profile(__lookup_profile(&ns->base, hname));
+       read_unlock(&ns->lock);
+
+       /* refcount released by caller */
+       return profile;
+}
+
+/**
+ * replacement_allowed - test to see if replacement is allowed
+ * @profile: profile to test if it can be replaced  (MAYBE NULL)
+ * @noreplace: true if replacement shouldn't be allowed but addition is okay
+ * @info: Returns - info about why replacement failed (NOT NULL)
+ *
+ * Returns: %0 if replacement allowed else error code
+ */
+static int replacement_allowed(struct aa_profile *profile, int noreplace,
+                              const char **info)
+{
+       if (profile) {
+               if (profile->flags & PFLAG_IMMUTABLE) {
+                       *info = "cannot replace immutible profile";
+                       return -EPERM;
+               } else if (noreplace) {
+                       *info = "profile already exists";
+                       return -EEXIST;
+               }
+       }
+       return 0;
+}
+
+/**
+ * __add_new_profile - simple wrapper around __list_add_profile
+ * @ns: namespace that profile is being added to  (NOT NULL)
+ * @policy: the policy container to add the profile to  (NOT NULL)
+ * @profile: profile to add  (NOT NULL)
+ *
+ * add a profile to a list and do other required basic allocations
+ */
+static void __add_new_profile(struct aa_namespace *ns, struct aa_policy *policy,
+                             struct aa_profile *profile)
+{
+       if (policy != &ns->base)
+               /* released on profile replacement or free_profile */
+               profile->parent = aa_get_profile((struct aa_profile *) policy);
+       __list_add_profile(&policy->profiles, profile);
+       /* released on free_profile */
+       profile->sid = aa_alloc_sid();
+       profile->ns = aa_get_namespace(ns);
+}
+
+/**
+ * aa_audit_policy - Do auditing of policy changes
+ * @op: policy operation being performed
+ * @gfp: memory allocation flags
+ * @name: name of profile being manipulated (NOT NULL)
+ * @info: any extra information to be audited (MAYBE NULL)
+ * @error: error code
+ *
+ * Returns: the error to be returned after audit is done
+ */
+static int audit_policy(int op, gfp_t gfp, const char *name, const char *info,
+                       int error)
+{
+       struct common_audit_data sa;
+       COMMON_AUDIT_DATA_INIT(&sa, NONE);
+       sa.aad.op = op;
+       sa.aad.name = name;
+       sa.aad.info = info;
+       sa.aad.error = error;
+
+       return aa_audit(AUDIT_APPARMOR_STATUS, __aa_current_profile(), gfp,
+                       &sa, NULL);
+}
+
+/**
+ * aa_may_manage_policy - can the current task manage policy
+ * @op: the policy manipulation operation being done
+ *
+ * Returns: true if the task is allowed to manipulate policy
+ */
+bool aa_may_manage_policy(int op)
+{
+       /* check if loading policy is locked out */
+       if (aa_g_lock_policy) {
+               audit_policy(op, GFP_KERNEL, NULL, "policy_locked", -EACCES);
+               return 0;
+       }
+
+       if (!capable(CAP_MAC_ADMIN)) {
+               audit_policy(op, GFP_KERNEL, NULL, "not policy admin", -EACCES);
+               return 0;
+       }
+
+       return 1;
+}
+
+/**
+ * aa_replace_profiles - replace profile(s) on the profile list
+ * @udata: serialized data stream  (NOT NULL)
+ * @size: size of the serialized data stream
+ * @noreplace: true if only doing addition, no replacement allowed
+ *
+ * unpack and replace a profile on the profile list and uses of that profile
+ * by any aa_task_cxt.  If the profile does not exist on the profile list
+ * it is added.
+ *
+ * Returns: size of data consumed else error code on failure.
+ */
+ssize_t aa_replace_profiles(void *udata, size_t size, bool noreplace)
+{
+       struct aa_policy *policy;
+       struct aa_profile *old_profile = NULL, *new_profile = NULL;
+       struct aa_profile *rename_profile = NULL;
+       struct aa_namespace *ns = NULL;
+       const char *ns_name, *name = NULL, *info = NULL;
+       int op = OP_PROF_REPL;
+       ssize_t error;
+
+       /* released below */
+       new_profile = aa_unpack(udata, size, &ns_name);
+       if (IS_ERR(new_profile)) {
+               error = PTR_ERR(new_profile);
+               new_profile = NULL;
+               goto fail;
+       }
+
+       /* released below */
+       ns = aa_prepare_namespace(ns_name);
+       if (!ns) {
+               info = "failed to prepare namespace";
+               error = -ENOMEM;
+               name = ns_name;
+               goto fail;
+       }
+
+       name = new_profile->base.hname;
+
+       write_lock(&ns->lock);
+       /* no ref on policy only use inside lock */
+       policy = __lookup_parent(ns, new_profile->base.hname);
+
+       if (!policy) {
+               info = "parent does not exist";
+               error = -ENOENT;
+               goto audit;
+       }
+
+       old_profile = __find_child(&policy->profiles, new_profile->base.name);
+       /* released below */
+       aa_get_profile(old_profile);
+
+       if (new_profile->rename) {
+               rename_profile = __lookup_profile(&ns->base,
+                                                 new_profile->rename);
+               /* released below */
+               aa_get_profile(rename_profile);
+
+               if (!rename_profile) {
+                       info = "profile to rename does not exist";
+                       name = new_profile->rename;
+                       error = -ENOENT;
+                       goto audit;
+               }
+       }
+
+       error = replacement_allowed(old_profile, noreplace, &info);
+       if (error)
+               goto audit;
+
+       error = replacement_allowed(rename_profile, noreplace, &info);
+       if (error)
+               goto audit;
+
+audit:
+       if (!old_profile && !rename_profile)
+               op = OP_PROF_LOAD;
+
+       error = audit_policy(op, GFP_ATOMIC, name, info, error);
+
+       if (!error) {
+               if (rename_profile)
+                       __replace_profile(rename_profile, new_profile);
+               if (old_profile) {
+                       /* when there are both rename and old profiles
+                        * inherit old profiles sid
+                        */
+                       if (rename_profile)
+                               aa_free_sid(new_profile->sid);
+                       __replace_profile(old_profile, new_profile);
+               }
+               if (!(old_profile || rename_profile))
+                       __add_new_profile(ns, policy, new_profile);
+       }
+       write_unlock(&ns->lock);
+
+out:
+       aa_put_namespace(ns);
+       aa_put_profile(rename_profile);
+       aa_put_profile(old_profile);
+       aa_put_profile(new_profile);
+       if (error)
+               return error;
+       return size;
+
+fail:
+       error = audit_policy(op, GFP_KERNEL, name, info, error);
+       goto out;
+}
+
+/**
+ * aa_remove_profiles - remove profile(s) from the system
+ * @fqname: name of the profile or namespace to remove  (NOT NULL)
+ * @size: size of the name
+ *
+ * Remove a profile or sub namespace from the current namespace, so that
+ * they can not be found anymore and mark them as replaced by unconfined
+ *
+ * NOTE: removing confinement does not restore rlimits to preconfinemnet values
+ *
+ * Returns: size of data consume else error code if fails
+ */
+ssize_t aa_remove_profiles(char *fqname, size_t size)
+{
+       struct aa_namespace *root, *ns = NULL;
+       struct aa_profile *profile = NULL;
+       const char *name = fqname, *info = NULL;
+       ssize_t error = 0;
+
+       if (*fqname == 0) {
+               info = "no profile specified";
+               error = -ENOENT;
+               goto fail;
+       }
+
+       root = aa_current_profile()->ns;
+
+       if (fqname[0] == ':') {
+               char *ns_name;
+               name = aa_split_fqname(fqname, &ns_name);
+               if (ns_name) {
+                       /* released below */
+                       ns = aa_find_namespace(root, ns_name);
+                       if (!ns) {
+                               info = "namespace does not exist";
+                               error = -ENOENT;
+                               goto fail;
+                       }
+               }
+       } else
+               /* released below */
+               ns = aa_get_namespace(root);
+
+       write_lock(&ns->lock);
+       if (!name) {
+               /* remove namespace - can only happen if fqname[0] == ':' */
+               __remove_namespace(ns);
+       } else {
+               /* remove profile */
+               profile = aa_get_profile(__lookup_profile(&ns->base, name));
+               if (!profile) {
+                       error = -ENOENT;
+                       info = "profile does not exist";
+                       goto fail_ns_lock;
+               }
+               name = profile->base.hname;
+               __remove_profile(profile);
+       }
+       write_unlock(&ns->lock);
+
+       /* don't fail removal if audit fails */
+       (void) audit_policy(OP_PROF_RM, GFP_KERNEL, name, info, error);
+       aa_put_namespace(ns);
+       aa_put_profile(profile);
+       return size;
+
+fail_ns_lock:
+       write_unlock(&ns->lock);
+       aa_put_namespace(ns);
+
+fail:
+       (void) audit_policy(OP_PROF_RM, GFP_KERNEL, name, info, error);
+       return error;
+}
diff --git a/security/apparmor/policy_unpack.c b/security/apparmor/policy_unpack.c
new file mode 100644 (file)
index 0000000..eb3700e
--- /dev/null
@@ -0,0 +1,703 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor functions for unpacking policy loaded from
+ * userspace.
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ *
+ * AppArmor uses a serialized binary format for loading policy.
+ * To find policy format documentation look in Documentation/apparmor.txt
+ * All policy is validated before it is used.
+ */
+
+#include <asm/unaligned.h>
+#include <linux/ctype.h>
+#include <linux/errno.h>
+
+#include "include/apparmor.h"
+#include "include/audit.h"
+#include "include/context.h"
+#include "include/match.h"
+#include "include/policy.h"
+#include "include/policy_unpack.h"
+#include "include/sid.h"
+
+/*
+ * The AppArmor interface treats data as a type byte followed by the
+ * actual data.  The interface has the notion of a a named entry
+ * which has a name (AA_NAME typecode followed by name string) followed by
+ * the entries typecode and data.  Named types allow for optional
+ * elements and extensions to be added and tested for without breaking
+ * backwards compatibility.
+ */
+
+enum aa_code {
+       AA_U8,
+       AA_U16,
+       AA_U32,
+       AA_U64,
+       AA_NAME,                /* same as string except it is items name */
+       AA_STRING,
+       AA_BLOB,
+       AA_STRUCT,
+       AA_STRUCTEND,
+       AA_LIST,
+       AA_LISTEND,
+       AA_ARRAY,
+       AA_ARRAYEND,
+};
+
+/*
+ * aa_ext is the read of the buffer containing the serialized profile.  The
+ * data is copied into a kernel buffer in apparmorfs and then handed off to
+ * the unpack routines.
+ */
+struct aa_ext {
+       void *start;
+       void *end;
+       void *pos;              /* pointer to current position in the buffer */
+       u32 version;
+};
+
+/* audit callback for unpack fields */
+static void audit_cb(struct audit_buffer *ab, void *va)
+{
+       struct common_audit_data *sa = va;
+       if (sa->aad.iface.target) {
+               struct aa_profile *name = sa->aad.iface.target;
+               audit_log_format(ab, " name=");
+               audit_log_untrustedstring(ab, name->base.hname);
+       }
+       if (sa->aad.iface.pos)
+               audit_log_format(ab, " offset=%ld", sa->aad.iface.pos);
+}
+
+/**
+ * audit_iface - do audit message for policy unpacking/load/replace/remove
+ * @new: profile if it has been allocated (MAYBE NULL)
+ * @name: name of the profile being manipulated (MAYBE NULL)
+ * @info: any extra info about the failure (MAYBE NULL)
+ * @e: buffer position info (NOT NULL)
+ * @error: error code
+ *
+ * Returns: %0 or error
+ */
+static int audit_iface(struct aa_profile *new, const char *name,
+                      const char *info, struct aa_ext *e, int error)
+{
+       struct aa_profile *profile = __aa_current_profile();
+       struct common_audit_data sa;
+       COMMON_AUDIT_DATA_INIT(&sa, NONE);
+       sa.aad.iface.pos = e->pos - e->start;
+       sa.aad.iface.target = new;
+       sa.aad.name = name;
+       sa.aad.info = info;
+       sa.aad.error = error;
+
+       return aa_audit(AUDIT_APPARMOR_STATUS, profile, GFP_KERNEL, &sa,
+                       audit_cb);
+}
+
+/* test if read will be in packed data bounds */
+static bool inbounds(struct aa_ext *e, size_t size)
+{
+       return (size <= e->end - e->pos);
+}
+
+/**
+ * aa_u16_chunck - test and do bounds checking for a u16 size based chunk
+ * @e: serialized data read head (NOT NULL)
+ * @chunk: start address for chunk of data (NOT NULL)
+ *
+ * Returns: the size of chunk found with the read head at the end of the chunk.
+ */
+static size_t unpack_u16_chunk(struct aa_ext *e, char **chunk)
+{
+       size_t size = 0;
+
+       if (!inbounds(e, sizeof(u16)))
+               return 0;
+       size = le16_to_cpu(get_unaligned((u16 *) e->pos));
+       e->pos += sizeof(u16);
+       if (!inbounds(e, size))
+               return 0;
+       *chunk = e->pos;
+       e->pos += size;
+       return size;
+}
+
+/* unpack control byte */
+static bool unpack_X(struct aa_ext *e, enum aa_code code)
+{
+       if (!inbounds(e, 1))
+               return 0;
+       if (*(u8 *) e->pos != code)
+               return 0;
+       e->pos++;
+       return 1;
+}
+
+/**
+ * unpack_nameX - check is the next element is of type X with a name of @name
+ * @e: serialized data extent information  (NOT NULL)
+ * @code: type code
+ * @name: name to match to the serialized element.  (MAYBE NULL)
+ *
+ * check that the next serialized data element is of type X and has a tag
+ * name @name.  If @name is specified then there must be a matching
+ * name element in the stream.  If @name is NULL any name element will be
+ * skipped and only the typecode will be tested.
+ *
+ * Returns 1 on success (both type code and name tests match) and the read
+ * head is advanced past the headers
+ *
+ * Returns: 0 if either match fails, the read head does not move
+ */
+static bool unpack_nameX(struct aa_ext *e, enum aa_code code, const char *name)
+{
+       /*
+        * May need to reset pos if name or type doesn't match
+        */
+       void *pos = e->pos;
+       /*
+        * Check for presence of a tagname, and if present name size
+        * AA_NAME tag value is a u16.
+        */
+       if (unpack_X(e, AA_NAME)) {
+               char *tag = NULL;
+               size_t size = unpack_u16_chunk(e, &tag);
+               /* if a name is specified it must match. otherwise skip tag */
+               if (name && (!size || strcmp(name, tag)))
+                       goto fail;
+       } else if (name) {
+               /* if a name is specified and there is no name tag fail */
+               goto fail;
+       }
+
+       /* now check if type code matches */
+       if (unpack_X(e, code))
+               return 1;
+
+fail:
+       e->pos = pos;
+       return 0;
+}
+
+static bool unpack_u32(struct aa_ext *e, u32 *data, const char *name)
+{
+       if (unpack_nameX(e, AA_U32, name)) {
+               if (!inbounds(e, sizeof(u32)))
+                       return 0;
+               if (data)
+                       *data = le32_to_cpu(get_unaligned((u32 *) e->pos));
+               e->pos += sizeof(u32);
+               return 1;
+       }
+       return 0;
+}
+
+static bool unpack_u64(struct aa_ext *e, u64 *data, const char *name)
+{
+       if (unpack_nameX(e, AA_U64, name)) {
+               if (!inbounds(e, sizeof(u64)))
+                       return 0;
+               if (data)
+                       *data = le64_to_cpu(get_unaligned((u64 *) e->pos));
+               e->pos += sizeof(u64);
+               return 1;
+       }
+       return 0;
+}
+
+static size_t unpack_array(struct aa_ext *e, const char *name)
+{
+       if (unpack_nameX(e, AA_ARRAY, name)) {
+               int size;
+               if (!inbounds(e, sizeof(u16)))
+                       return 0;
+               size = (int)le16_to_cpu(get_unaligned((u16 *) e->pos));
+               e->pos += sizeof(u16);
+               return size;
+       }
+       return 0;
+}
+
+static size_t unpack_blob(struct aa_ext *e, char **blob, const char *name)
+{
+       if (unpack_nameX(e, AA_BLOB, name)) {
+               u32 size;
+               if (!inbounds(e, sizeof(u32)))
+                       return 0;
+               size = le32_to_cpu(get_unaligned((u32 *) e->pos));
+               e->pos += sizeof(u32);
+               if (inbounds(e, (size_t) size)) {
+                       *blob = e->pos;
+                       e->pos += size;
+                       return size;
+               }
+       }
+       return 0;
+}
+
+static int unpack_str(struct aa_ext *e, const char **string, const char *name)
+{
+       char *src_str;
+       size_t size = 0;
+       void *pos = e->pos;
+       *string = NULL;
+       if (unpack_nameX(e, AA_STRING, name)) {
+               size = unpack_u16_chunk(e, &src_str);
+               if (size) {
+                       /* strings are null terminated, length is size - 1 */
+                       if (src_str[size - 1] != 0)
+                               goto fail;
+                       *string = src_str;
+               }
+       }
+       return size;
+
+fail:
+       e->pos = pos;
+       return 0;
+}
+
+static int unpack_strdup(struct aa_ext *e, char **string, const char *name)
+{
+       const char *tmp;
+       void *pos = e->pos;
+       int res = unpack_str(e, &tmp, name);
+       *string = NULL;
+
+       if (!res)
+               return 0;
+
+       *string = kmemdup(tmp, res, GFP_KERNEL);
+       if (!*string) {
+               e->pos = pos;
+               return 0;
+       }
+
+       return res;
+}
+
+/**
+ * verify_accept - verify the accept tables of a dfa
+ * @dfa: dfa to verify accept tables of (NOT NULL)
+ * @flags: flags governing dfa
+ *
+ * Returns: 1 if valid accept tables else 0 if error
+ */
+static bool verify_accept(struct aa_dfa *dfa, int flags)
+{
+       int i;
+
+       /* verify accept permissions */
+       for (i = 0; i < dfa->tables[YYTD_ID_ACCEPT]->td_lolen; i++) {
+               int mode = ACCEPT_TABLE(dfa)[i];
+
+               if (mode & ~DFA_VALID_PERM_MASK)
+                       return 0;
+
+               if (ACCEPT_TABLE2(dfa)[i] & ~DFA_VALID_PERM2_MASK)
+                       return 0;
+       }
+       return 1;
+}
+
+/**
+ * unpack_dfa - unpack a file rule dfa
+ * @e: serialized data extent information (NOT NULL)
+ *
+ * returns dfa or ERR_PTR or NULL if no dfa
+ */
+static struct aa_dfa *unpack_dfa(struct aa_ext *e)
+{
+       char *blob = NULL;
+       size_t size;
+       struct aa_dfa *dfa = NULL;
+
+       size = unpack_blob(e, &blob, "aadfa");
+       if (size) {
+               /*
+                * The dfa is aligned with in the blob to 8 bytes
+                * from the beginning of the stream.
+                */
+               size_t sz = blob - (char *)e->start;
+               size_t pad = ALIGN(sz, 8) - sz;
+               int flags = TO_ACCEPT1_FLAG(YYTD_DATA32) |
+                       TO_ACCEPT2_FLAG(YYTD_DATA32);
+
+
+               if (aa_g_paranoid_load)
+                       flags |= DFA_FLAG_VERIFY_STATES;
+
+               dfa = aa_dfa_unpack(blob + pad, size - pad, flags);
+
+               if (IS_ERR(dfa))
+                       return dfa;
+
+               if (!verify_accept(dfa, flags))
+                       goto fail;
+       }
+
+       return dfa;
+
+fail:
+       aa_put_dfa(dfa);
+       return ERR_PTR(-EPROTO);
+}
+
+/**
+ * unpack_trans_table - unpack a profile transition table
+ * @e: serialized data extent information  (NOT NULL)
+ * @profile: profile to add the accept table to (NOT NULL)
+ *
+ * Returns: 1 if table succesfully unpacked
+ */
+static bool unpack_trans_table(struct aa_ext *e, struct aa_profile *profile)
+{
+       void *pos = e->pos;
+
+       /* exec table is optional */
+       if (unpack_nameX(e, AA_STRUCT, "xtable")) {
+               int i, size;
+
+               size = unpack_array(e, NULL);
+               /* currently 4 exec bits and entries 0-3 are reserved iupcx */
+               if (size > 16 - 4)
+                       goto fail;
+               profile->file.trans.table = kzalloc(sizeof(char *) * size,
+                                                   GFP_KERNEL);
+               if (!profile->file.trans.table)
+                       goto fail;
+
+               profile->file.trans.size = size;
+               for (i = 0; i < size; i++) {
+                       char *str;
+                       int c, j, size = unpack_strdup(e, &str, NULL);
+                       /* unpack_strdup verifies that the last character is
+                        * null termination byte.
+                        */
+                       if (!size)
+                               goto fail;
+                       profile->file.trans.table[i] = str;
+                       /* verify that name doesn't start with space */
+                       if (isspace(*str))
+                               goto fail;
+
+                       /* count internal #  of internal \0 */
+                       for (c = j = 0; j < size - 2; j++) {
+                               if (!str[j])
+                                       c++;
+                       }
+                       if (*str == ':') {
+                               /* beginning with : requires an embedded \0,
+                                * verify that exactly 1 internal \0 exists
+                                * trailing \0 already verified by unpack_strdup
+                                */
+                               if (c != 1)
+                                       goto fail;
+                               /* first character after : must be valid */
+                               if (!str[1])
+                                       goto fail;
+                       } else if (c)
+                               /* fail - all other cases with embedded \0 */
+                               goto fail;
+               }
+               if (!unpack_nameX(e, AA_ARRAYEND, NULL))
+                       goto fail;
+               if (!unpack_nameX(e, AA_STRUCTEND, NULL))
+                       goto fail;
+       }
+       return 1;
+
+fail:
+       aa_free_domain_entries(&profile->file.trans);
+       e->pos = pos;
+       return 0;
+}
+
+static bool unpack_rlimits(struct aa_ext *e, struct aa_profile *profile)
+{
+       void *pos = e->pos;
+
+       /* rlimits are optional */
+       if (unpack_nameX(e, AA_STRUCT, "rlimits")) {
+               int i, size;
+               u32 tmp = 0;
+               if (!unpack_u32(e, &tmp, NULL))
+                       goto fail;
+               profile->rlimits.mask = tmp;
+
+               size = unpack_array(e, NULL);
+               if (size > RLIM_NLIMITS)
+                       goto fail;
+               for (i = 0; i < size; i++) {
+                       u64 tmp = 0;
+                       int a = aa_map_resource(i);
+                       if (!unpack_u64(e, &tmp, NULL))
+                               goto fail;
+                       profile->rlimits.limits[a].rlim_max = tmp;
+               }
+               if (!unpack_nameX(e, AA_ARRAYEND, NULL))
+                       goto fail;
+               if (!unpack_nameX(e, AA_STRUCTEND, NULL))
+                       goto fail;
+       }
+       return 1;
+
+fail:
+       e->pos = pos;
+       return 0;
+}
+
+/**
+ * unpack_profile - unpack a serialized profile
+ * @e: serialized data extent information (NOT NULL)
+ *
+ * NOTE: unpack profile sets audit struct if there is a failure
+ */
+static struct aa_profile *unpack_profile(struct aa_ext *e)
+{
+       struct aa_profile *profile = NULL;
+       const char *name = NULL;
+       int error = -EPROTO;
+       kernel_cap_t tmpcap;
+       u32 tmp;
+
+       /* check that we have the right struct being passed */
+       if (!unpack_nameX(e, AA_STRUCT, "profile"))
+               goto fail;
+       if (!unpack_str(e, &name, NULL))
+               goto fail;
+
+       profile = aa_alloc_profile(name);
+       if (!profile)
+               return ERR_PTR(-ENOMEM);
+
+       /* profile renaming is optional */
+       (void) unpack_str(e, &profile->rename, "rename");
+
+       /* xmatch is optional and may be NULL */
+       profile->xmatch = unpack_dfa(e);
+       if (IS_ERR(profile->xmatch)) {
+               error = PTR_ERR(profile->xmatch);
+               profile->xmatch = NULL;
+               goto fail;
+       }
+       /* xmatch_len is not optional if xmatch is set */
+       if (profile->xmatch) {
+               if (!unpack_u32(e, &tmp, NULL))
+                       goto fail;
+               profile->xmatch_len = tmp;
+       }
+
+       /* per profile debug flags (complain, audit) */
+       if (!unpack_nameX(e, AA_STRUCT, "flags"))
+               goto fail;
+       if (!unpack_u32(e, &tmp, NULL))
+               goto fail;
+       if (tmp)
+               profile->flags |= PFLAG_HAT;
+       if (!unpack_u32(e, &tmp, NULL))
+               goto fail;
+       if (tmp)
+               profile->mode = APPARMOR_COMPLAIN;
+       if (!unpack_u32(e, &tmp, NULL))
+               goto fail;
+       if (tmp)
+               profile->audit = AUDIT_ALL;
+
+       if (!unpack_nameX(e, AA_STRUCTEND, NULL))
+               goto fail;
+
+       /* path_flags is optional */
+       if (unpack_u32(e, &profile->path_flags, "path_flags"))
+               profile->path_flags |= profile->flags & PFLAG_MEDIATE_DELETED;
+       else
+               /* set a default value if path_flags field is not present */
+               profile->path_flags = PFLAG_MEDIATE_DELETED;
+
+       if (!unpack_u32(e, &(profile->caps.allow.cap[0]), NULL))
+               goto fail;
+       if (!unpack_u32(e, &(profile->caps.audit.cap[0]), NULL))
+               goto fail;
+       if (!unpack_u32(e, &(profile->caps.quiet.cap[0]), NULL))
+               goto fail;
+       if (!unpack_u32(e, &tmpcap.cap[0], NULL))
+               goto fail;
+
+       if (unpack_nameX(e, AA_STRUCT, "caps64")) {
+               /* optional upper half of 64 bit caps */
+               if (!unpack_u32(e, &(profile->caps.allow.cap[1]), NULL))
+                       goto fail;
+               if (!unpack_u32(e, &(profile->caps.audit.cap[1]), NULL))
+                       goto fail;
+               if (!unpack_u32(e, &(profile->caps.quiet.cap[1]), NULL))
+                       goto fail;
+               if (!unpack_u32(e, &(tmpcap.cap[1]), NULL))
+                       goto fail;
+               if (!unpack_nameX(e, AA_STRUCTEND, NULL))
+                       goto fail;
+       }
+
+       if (unpack_nameX(e, AA_STRUCT, "capsx")) {
+               /* optional extended caps mediation mask */
+               if (!unpack_u32(e, &(profile->caps.extended.cap[0]), NULL))
+                       goto fail;
+               if (!unpack_u32(e, &(profile->caps.extended.cap[1]), NULL))
+                       goto fail;
+       }
+
+       if (!unpack_rlimits(e, profile))
+               goto fail;
+
+       /* get file rules */
+       profile->file.dfa = unpack_dfa(e);
+       if (IS_ERR(profile->file.dfa)) {
+               error = PTR_ERR(profile->file.dfa);
+               profile->file.dfa = NULL;
+               goto fail;
+       }
+
+       if (!unpack_u32(e, &profile->file.start, "dfa_start"))
+               /* default start state */
+               profile->file.start = DFA_START;
+
+       if (!unpack_trans_table(e, profile))
+               goto fail;
+
+       if (!unpack_nameX(e, AA_STRUCTEND, NULL))
+               goto fail;
+
+       return profile;
+
+fail:
+       if (profile)
+               name = NULL;
+       else if (!name)
+               name = "unknown";
+       audit_iface(profile, name, "failed to unpack profile", e, error);
+       aa_put_profile(profile);
+
+       return ERR_PTR(error);
+}
+
+/**
+ * verify_head - unpack serialized stream header
+ * @e: serialized data read head (NOT NULL)
+ * @ns: Returns - namespace if one is specified else NULL (NOT NULL)
+ *
+ * Returns: error or 0 if header is good
+ */
+static int verify_header(struct aa_ext *e, const char **ns)
+{
+       int error = -EPROTONOSUPPORT;
+       /* get the interface version */
+       if (!unpack_u32(e, &e->version, "version")) {
+               audit_iface(NULL, NULL, "invalid profile format", e, error);
+               return error;
+       }
+
+       /* check that the interface version is currently supported */
+       if (e->version != 5) {
+               audit_iface(NULL, NULL, "unsupported interface version", e,
+                           error);
+               return error;
+       }
+
+       /* read the namespace if present */
+       if (!unpack_str(e, ns, "namespace"))
+               *ns = NULL;
+
+       return 0;
+}
+
+static bool verify_xindex(int xindex, int table_size)
+{
+       int index, xtype;
+       xtype = xindex & AA_X_TYPE_MASK;
+       index = xindex & AA_X_INDEX_MASK;
+       if (xtype == AA_X_TABLE && index > table_size)
+               return 0;
+       return 1;
+}
+
+/* verify dfa xindexes are in range of transition tables */
+static bool verify_dfa_xindex(struct aa_dfa *dfa, int table_size)
+{
+       int i;
+       for (i = 0; i < dfa->tables[YYTD_ID_ACCEPT]->td_lolen; i++) {
+               if (!verify_xindex(dfa_user_xindex(dfa, i), table_size))
+                       return 0;
+               if (!verify_xindex(dfa_other_xindex(dfa, i), table_size))
+                       return 0;
+       }
+       return 1;
+}
+
+/**
+ * verify_profile - Do post unpack analysis to verify profile consistency
+ * @profile: profile to verify (NOT NULL)
+ *
+ * Returns: 0 if passes verification else error
+ */
+static int verify_profile(struct aa_profile *profile)
+{
+       if (aa_g_paranoid_load) {
+               if (profile->file.dfa &&
+                   !verify_dfa_xindex(profile->file.dfa,
+                                      profile->file.trans.size)) {
+                       audit_iface(profile, NULL, "Invalid named transition",
+                                   NULL, -EPROTO);
+                       return -EPROTO;
+               }
+       }
+
+       return 0;
+}
+
+/**
+ * aa_unpack - unpack packed binary profile data loaded from user space
+ * @udata: user data copied to kmem  (NOT NULL)
+ * @size: the size of the user data
+ * @ns: Returns namespace profile is in if specified else NULL (NOT NULL)
+ *
+ * Unpack user data and return refcounted allocated profile or ERR_PTR
+ *
+ * Returns: profile else error pointer if fails to unpack
+ */
+struct aa_profile *aa_unpack(void *udata, size_t size, const char **ns)
+{
+       struct aa_profile *profile = NULL;
+       int error;
+       struct aa_ext e = {
+               .start = udata,
+               .end = udata + size,
+               .pos = udata,
+       };
+
+       error = verify_header(&e, ns);
+       if (error)
+               return ERR_PTR(error);
+
+       profile = unpack_profile(&e);
+       if (IS_ERR(profile))
+               return profile;
+
+       error = verify_profile(profile);
+       if (error) {
+               aa_put_profile(profile);
+               profile = ERR_PTR(error);
+       }
+
+       /* return refcount */
+       return profile;
+}
diff --git a/security/apparmor/procattr.c b/security/apparmor/procattr.c
new file mode 100644 (file)
index 0000000..04a2cf8
--- /dev/null
@@ -0,0 +1,170 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor /proc/<pid>/attr/ interface functions
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include "include/apparmor.h"
+#include "include/context.h"
+#include "include/policy.h"
+#include "include/domain.h"
+
+
+/**
+ * aa_getprocattr - Return the profile information for @profile
+ * @profile: the profile to print profile info about  (NOT NULL)
+ * @string: Returns - string containing the profile info (NOT NULL)
+ *
+ * Returns: length of @string on success else error on failure
+ *
+ * Requires: profile != NULL
+ *
+ * Creates a string containing the namespace_name://profile_name for
+ * @profile.
+ *
+ * Returns: size of string placed in @string else error code on failure
+ */
+int aa_getprocattr(struct aa_profile *profile, char **string)
+{
+       char *str;
+       int len = 0, mode_len = 0, ns_len = 0, name_len;
+       const char *mode_str = profile_mode_names[profile->mode];
+       const char *ns_name = NULL;
+       struct aa_namespace *ns = profile->ns;
+       struct aa_namespace *current_ns = __aa_current_profile()->ns;
+       char *s;
+
+       if (!aa_ns_visible(current_ns, ns))
+               return -EACCES;
+
+       ns_name = aa_ns_name(current_ns, ns);
+       ns_len = strlen(ns_name);
+
+       /* if the visible ns_name is > 0 increase size for : :// seperator */
+       if (ns_len)
+               ns_len += 4;
+
+       /* unconfined profiles don't have a mode string appended */
+       if (!unconfined(profile))
+               mode_len = strlen(mode_str) + 3;        /* + 3 for _() */
+
+       name_len = strlen(profile->base.hname);
+       len = mode_len + ns_len + name_len + 1;     /* + 1 for \n */
+       s = str = kmalloc(len + 1, GFP_KERNEL);     /* + 1 \0 */
+       if (!str)
+               return -ENOMEM;
+
+       if (ns_len) {
+               /* skip over prefix current_ns->base.hname and separating // */
+               sprintf(s, ":%s://", ns_name);
+               s += ns_len;
+       }
+       if (unconfined(profile))
+               /* mode string not being appended */
+               sprintf(s, "%s\n", profile->base.hname);
+       else
+               sprintf(s, "%s (%s)\n", profile->base.hname, mode_str);
+       *string = str;
+
+       /* NOTE: len does not include \0 of string, not saved as part of file */
+       return len;
+}
+
+/**
+ * split_token_from_name - separate a string of form  <token>^<name>
+ * @op: operation being checked
+ * @args: string to parse  (NOT NULL)
+ * @token: stores returned parsed token value  (NOT NULL)
+ *
+ * Returns: start position of name after token else NULL on failure
+ */
+static char *split_token_from_name(int op, char *args, u64 * token)
+{
+       char *name;
+
+       *token = simple_strtoull(args, &name, 16);
+       if ((name == args) || *name != '^') {
+               AA_ERROR("%s: Invalid input '%s'", op_table[op], args);
+               return ERR_PTR(-EINVAL);
+       }
+
+       name++;                 /* skip ^ */
+       if (!*name)
+               name = NULL;
+       return name;
+}
+
+/**
+ * aa_setprocattr_chagnehat - handle procattr interface to change_hat
+ * @args: args received from writing to /proc/<pid>/attr/current (NOT NULL)
+ * @size: size of the args
+ * @test: true if this is a test of change_hat permissions
+ *
+ * Returns: %0 or error code if change_hat fails
+ */
+int aa_setprocattr_changehat(char *args, size_t size, int test)
+{
+       char *hat;
+       u64 token;
+       const char *hats[16];           /* current hard limit on # of names */
+       int count = 0;
+
+       hat = split_token_from_name(OP_CHANGE_HAT, args, &token);
+       if (IS_ERR(hat))
+               return PTR_ERR(hat);
+
+       if (!hat && !token) {
+               AA_ERROR("change_hat: Invalid input, NULL hat and NULL magic");
+               return -EINVAL;
+       }
+
+       if (hat) {
+               /* set up hat name vector, args guaranteed null terminated
+                * at args[size] by setprocattr.
+                *
+                * If there are multiple hat names in the buffer each is
+                * separated by a \0.  Ie. userspace writes them pre tokenized
+                */
+               char *end = args + size;
+               for (count = 0; (hat < end) && count < 16; ++count) {
+                       char *next = hat + strlen(hat) + 1;
+                       hats[count] = hat;
+                       hat = next;
+               }
+       }
+
+       AA_DEBUG("%s: Magic 0x%llx Hat '%s'\n",
+                __func__, token, hat ? hat : NULL);
+
+       return aa_change_hat(hats, count, token, test);
+}
+
+/**
+ * aa_setprocattr_changeprofile - handle procattr interface to changeprofile
+ * @fqname: args received from writting to /proc/<pid>/attr/current (NOT NULL)
+ * @onexec: true if change_profile should be delayed until exec
+ * @test: true if this is a test of change_profile permissions
+ *
+ * Returns: %0 or error code if change_profile fails
+ */
+int aa_setprocattr_changeprofile(char *fqname, bool onexec, int test)
+{
+       char *name, *ns_name;
+
+       name = aa_split_fqname(fqname, &ns_name);
+       return aa_change_profile(ns_name, name, onexec, test);
+}
+
+int aa_setprocattr_permipc(char *fqname)
+{
+       /* TODO: add ipc permission querying */
+       return -ENOTSUPP;
+}
diff --git a/security/apparmor/resource.c b/security/apparmor/resource.c
new file mode 100644 (file)
index 0000000..4a368f1
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor resource mediation and attachment
+ *
+ * Copyright (C) 1998-2008 Novell/SUSE
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ */
+
+#include <linux/audit.h>
+
+#include "include/audit.h"
+#include "include/resource.h"
+#include "include/policy.h"
+
+/*
+ * Table of rlimit names: we generate it from resource.h.
+ */
+#include "rlim_names.h"
+
+/* audit callback for resource specific fields */
+static void audit_cb(struct audit_buffer *ab, void *va)
+{
+       struct common_audit_data *sa = va;
+
+       audit_log_format(ab, " rlimit=%s value=%lu",
+                        rlim_names[sa->aad.rlim.rlim], sa->aad.rlim.max);
+}
+
+/**
+ * audit_resource - audit setting resource limit
+ * @profile: profile being enforced  (NOT NULL)
+ * @resoure: rlimit being auditing
+ * @value: value being set
+ * @error: error value
+ *
+ * Returns: 0 or sa->error else other error code on failure
+ */
+static int audit_resource(struct aa_profile *profile, unsigned int resource,
+                         unsigned long value, int error)
+{
+       struct common_audit_data sa;
+
+       COMMON_AUDIT_DATA_INIT(&sa, NONE);
+       sa.aad.op = OP_SETRLIMIT,
+       sa.aad.rlim.rlim = resource;
+       sa.aad.rlim.max = value;
+       sa.aad.error = error;
+       return aa_audit(AUDIT_APPARMOR_AUTO, profile, GFP_KERNEL, &sa,
+                       audit_cb);
+}
+
+/**
+ * aa_map_resouce - map compiled policy resource to internal #
+ * @resource: flattened policy resource number
+ *
+ * Returns: resource # for the current architecture.
+ *
+ * rlimit resource can vary based on architecture, map the compiled policy
+ * resource # to the internal representation for the architecture.
+ */
+int aa_map_resource(int resource)
+{
+       return rlim_map[resource];
+}
+
+/**
+ * aa_task_setrlimit - test permission to set an rlimit
+ * @profile - profile confining the task  (NOT NULL)
+ * @resource - the resource being set
+ * @new_rlim - the new resource limit  (NOT NULL)
+ *
+ * Control raising the processes hard limit.
+ *
+ * Returns: 0 or error code if setting resource failed
+ */
+int aa_task_setrlimit(struct aa_profile *profile, unsigned int resource,
+                     struct rlimit *new_rlim)
+{
+       int error = 0;
+
+       if (profile->rlimits.mask & (1 << resource) &&
+           new_rlim->rlim_max > profile->rlimits.limits[resource].rlim_max)
+
+               error = audit_resource(profile, resource, new_rlim->rlim_max,
+                       -EACCES);
+
+       return error;
+}
+
+/**
+ * __aa_transition_rlimits - apply new profile rlimits
+ * @old: old profile on task  (NOT NULL)
+ * @new: new profile with rlimits to apply  (NOT NULL)
+ */
+void __aa_transition_rlimits(struct aa_profile *old, struct aa_profile *new)
+{
+       unsigned int mask = 0;
+       struct rlimit *rlim, *initrlim;
+       int i;
+
+       /* for any rlimits the profile controlled reset the soft limit
+        * to the less of the tasks hard limit and the init tasks soft limit
+        */
+       if (old->rlimits.mask) {
+               for (i = 0, mask = 1; i < RLIM_NLIMITS; i++, mask <<= 1) {
+                       if (old->rlimits.mask & mask) {
+                               rlim = current->signal->rlim + i;
+                               initrlim = init_task.signal->rlim + i;
+                               rlim->rlim_cur = min(rlim->rlim_max,
+                                                    initrlim->rlim_cur);
+                       }
+               }
+       }
+
+       /* set any new hard limits as dictated by the new profile */
+       if (!new->rlimits.mask)
+               return;
+       for (i = 0, mask = 1; i < RLIM_NLIMITS; i++, mask <<= 1) {
+               if (!(new->rlimits.mask & mask))
+                       continue;
+
+               rlim = current->signal->rlim + i;
+               rlim->rlim_max = min(rlim->rlim_max,
+                                    new->rlimits.limits[i].rlim_max);
+               /* soft limit should not exceed hard limit */
+               rlim->rlim_cur = min(rlim->rlim_cur, rlim->rlim_max);
+       }
+}
diff --git a/security/apparmor/sid.c b/security/apparmor/sid.c
new file mode 100644 (file)
index 0000000..f0b34f7
--- /dev/null
@@ -0,0 +1,55 @@
+/*
+ * AppArmor security module
+ *
+ * This file contains AppArmor security identifier (sid) manipulation fns
+ *
+ * Copyright 2009-2010 Canonical Ltd.
+ *
+ * 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, version 2 of the
+ * License.
+ *
+ *
+ * AppArmor allocates a unique sid for every profile loaded.  If a profile
+ * is replaced it receives the sid of the profile it is replacing.
+ *
+ * The sid value of 0 is invalid.
+ */
+
+#include <linux/spinlock.h>
+#include <linux/errno.h>
+#include <linux/err.h>
+
+#include "include/sid.h"
+
+/* global counter from which sids are allocated */
+static u32 global_sid;
+static DEFINE_SPINLOCK(sid_lock);
+
+/* TODO FIXME: add sid to profile mapping, and sid recycling */
+
+/**
+ * aa_alloc_sid - allocate a new sid for a profile
+ */
+u32 aa_alloc_sid(void)
+{
+       u32 sid;
+
+       /*
+        * TODO FIXME: sid recycling - part of profile mapping table
+        */
+       spin_lock(&sid_lock);
+       sid = (++global_sid);
+       spin_unlock(&sid_lock);
+       return sid;
+}
+
+/**
+ * aa_free_sid - free a sid
+ * @sid: sid to free
+ */
+void aa_free_sid(u32 sid)
+{
+       ;                       /* NOP ATM */
+}
index 8168e3ecd5bf9d43eb5b0c2b3e94636e992d7861..a0bbf30fb6dc93de4fe29da540be3533e797dede 100644 (file)
@@ -27,7 +27,7 @@ static int cap_quota_on(struct dentry *dentry)
        return 0;
 }
 
-static int cap_bprm_check_security (struct linux_binprm *bprm)
+static int cap_bprm_check_security(struct linux_binprm *bprm)
 {
        return 0;
 }
@@ -268,8 +268,7 @@ static int cap_path_rename(struct path *old_path, struct dentry *old_dentry,
        return 0;
 }
 
-static int cap_path_truncate(struct path *path, loff_t length,
-                            unsigned int time_attrs)
+static int cap_path_truncate(struct path *path)
 {
        return 0;
 }
index 1c812e874504ef90e1b8748e28d6d9e73d6a5912..8c777f022ad132eca07eed38503ea1af716f8dfd 100644 (file)
@@ -86,7 +86,7 @@ static int mknod(struct inode *dir, struct dentry *dentry,
                         int mode, dev_t dev)
 {
        struct inode *inode;
-       int error = -EPERM;
+       int error = -ENOMEM;
 
        if (dentry->d_inode)
                return -EEXIST;
@@ -166,6 +166,8 @@ static int create_by_name(const char *name, mode_t mode,
                        error = mkdir(parent->d_inode, *dentry, mode);
                else
                        error = create(parent->d_inode, *dentry, mode);
+               if (error)
+                       dput(*dentry);
        } else
                error = PTR_ERR(*dentry);
        mutex_unlock(&parent->d_inode->i_mutex);
index 8fe736aabe71264d3018f35a1a3c7d64806411bb..ef21b96a0b4231638c4d932747174bbda2b73309 100644 (file)
@@ -45,7 +45,8 @@ static ssize_t ima_show_htable_violations(struct file *filp,
 }
 
 static const struct file_operations ima_htable_violations_ops = {
-       .read = ima_show_htable_violations
+       .read = ima_show_htable_violations,
+       .llseek = generic_file_llseek,
 };
 
 static ssize_t ima_show_measurements_count(struct file *filp,
@@ -57,7 +58,8 @@ static ssize_t ima_show_measurements_count(struct file *filp,
 }
 
 static const struct file_operations ima_measurements_count_ops = {
-       .read = ima_show_measurements_count
+       .read = ima_show_measurements_count,
+       .llseek = generic_file_llseek,
 };
 
 /* returns pointer to hlist_node */
@@ -319,7 +321,8 @@ static int ima_release_policy(struct inode *inode, struct file *file)
 static const struct file_operations ima_measure_policy_ops = {
        .open = ima_open_policy,
        .write = ima_write_policy,
-       .release = ima_release_policy
+       .release = ima_release_policy,
+       .llseek = generic_file_llseek,
 };
 
 int __init ima_fs_init(void)
index 38783dcf6c61fb6e380131c40c8abbbf1414a5dd..addb67b169f443f136e3baf28846710e82fd0ff1 100644 (file)
@@ -114,6 +114,10 @@ extern key_ref_t keyring_search_aux(key_ref_t keyring_ref,
                                    const void *description,
                                    key_match_func_t match);
 
+extern key_ref_t search_my_process_keyrings(struct key_type *type,
+                                           const void *description,
+                                           key_match_func_t match,
+                                           const struct cred *cred);
 extern key_ref_t search_process_keyrings(struct key_type *type,
                                         const void *description,
                                         key_match_func_t match,
@@ -134,6 +138,7 @@ extern struct key *request_key_and_link(struct key_type *type,
                                        struct key *dest_keyring,
                                        unsigned long flags);
 
+extern int lookup_user_key_possessed(const struct key *key, const void *target);
 extern key_ref_t lookup_user_key(key_serial_t id, unsigned long flags,
                                 key_perm_t perm);
 #define KEY_LOOKUP_CREATE      0x01
index 6261745e44591acd65bb47e18e9f65b9e842bfe5..b2b0998d6abda7759433d7032d255eb0a317c126 100644 (file)
@@ -505,13 +505,11 @@ okay:
 
        ret = snprintf(tmpbuf, PAGE_SIZE - 1,
                       "%s;%d;%d;%08x;%s",
-                      key_ref_to_ptr(key_ref)->type->name,
-                      key_ref_to_ptr(key_ref)->uid,
-                      key_ref_to_ptr(key_ref)->gid,
-                      key_ref_to_ptr(key_ref)->perm,
-                      key_ref_to_ptr(key_ref)->description ?
-                      key_ref_to_ptr(key_ref)->description : ""
-                      );
+                      key->type->name,
+                      key->uid,
+                      key->gid,
+                      key->perm,
+                      key->description ?: "");
 
        /* include a NUL char at the end of the data */
        if (ret > PAGE_SIZE - 1)
@@ -1091,7 +1089,7 @@ error:
 long keyctl_set_timeout(key_serial_t id, unsigned timeout)
 {
        struct timespec now;
-       struct key *key;
+       struct key *key, *instkey;
        key_ref_t key_ref;
        time_t expiry;
        long ret;
@@ -1099,10 +1097,25 @@ long keyctl_set_timeout(key_serial_t id, unsigned timeout)
        key_ref = lookup_user_key(id, KEY_LOOKUP_CREATE | KEY_LOOKUP_PARTIAL,
                                  KEY_SETATTR);
        if (IS_ERR(key_ref)) {
+               /* setting the timeout on a key under construction is permitted
+                * if we have the authorisation token handy */
+               if (PTR_ERR(key_ref) == -EACCES) {
+                       instkey = key_get_instantiation_authkey(id);
+                       if (!IS_ERR(instkey)) {
+                               key_put(instkey);
+                               key_ref = lookup_user_key(id,
+                                                         KEY_LOOKUP_PARTIAL,
+                                                         0);
+                               if (!IS_ERR(key_ref))
+                                       goto okay;
+                       }
+               }
+
                ret = PTR_ERR(key_ref);
                goto error;
        }
 
+okay:
        key = key_ref_to_ptr(key_ref);
 
        /* make the changes with the locks held to prevent races */
index 068b66ea2f1bbf17dd2c9062530b9d1c64e19612..70373966816e9845594919d870fca1f3e441ca65 100644 (file)
@@ -184,20 +184,36 @@ static void proc_keys_stop(struct seq_file *p, void *v)
 
 static int proc_keys_show(struct seq_file *m, void *v)
 {
+       const struct cred *cred = current_cred();
        struct rb_node *_p = v;
        struct key *key = rb_entry(_p, struct key, serial_node);
        struct timespec now;
        unsigned long timo;
+       key_ref_t key_ref, skey_ref;
        char xbuf[12];
        int rc;
 
+       key_ref = make_key_ref(key, 0);
+
+       /* determine if the key is possessed by this process (a test we can
+        * skip if the key does not indicate the possessor can view it
+        */
+       if (key->perm & KEY_POS_VIEW) {
+               skey_ref = search_my_process_keyrings(key->type, key,
+                                                     lookup_user_key_possessed,
+                                                     cred);
+               if (!IS_ERR(skey_ref)) {
+                       key_ref_put(skey_ref);
+                       key_ref = make_key_ref(key, 1);
+               }
+       }
+
        /* check whether the current task is allowed to view the key (assuming
         * non-possession)
         * - the caller holds a spinlock, and thus the RCU read lock, making our
         *   access to __current_cred() safe
         */
-       rc = key_task_permission(make_key_ref(key, 0), current_cred(),
-                                KEY_VIEW);
+       rc = key_task_permission(key_ref, cred, KEY_VIEW);
        if (rc < 0)
                return 0;
 
index 6b8e4ff4cc68cfebe2bb845dda44d8d4b8542635..f8e7251ae2c8f081ed25bf9920fa8aa33c8f287a 100644 (file)
@@ -309,22 +309,19 @@ void key_fsgid_changed(struct task_struct *tsk)
 
 /*****************************************************************************/
 /*
- * search the process keyrings for the first matching key
+ * search only my process keyrings for the first matching key
  * - we use the supplied match function to see if the description (or other
  *   feature of interest) matches
  * - we return -EAGAIN if we didn't find any matching key
  * - we return -ENOKEY if we found only negative matching keys
  */
-key_ref_t search_process_keyrings(struct key_type *type,
-                                 const void *description,
-                                 key_match_func_t match,
-                                 const struct cred *cred)
+key_ref_t search_my_process_keyrings(struct key_type *type,
+                                    const void *description,
+                                    key_match_func_t match,
+                                    const struct cred *cred)
 {
-       struct request_key_auth *rka;
        key_ref_t key_ref, ret, err;
 
-       might_sleep();
-
        /* we want to return -EAGAIN or -ENOKEY if any of the keyrings were
         * searchable, but we failed to find a key or we found a negative key;
         * otherwise we want to return a sample error (probably -EACCES) if
@@ -424,6 +421,36 @@ key_ref_t search_process_keyrings(struct key_type *type,
                }
        }
 
+       /* no key - decide on the error we're going to go for */
+       key_ref = ret ? ret : err;
+
+found:
+       return key_ref;
+}
+
+/*****************************************************************************/
+/*
+ * search the process keyrings for the first matching key
+ * - we use the supplied match function to see if the description (or other
+ *   feature of interest) matches
+ * - we return -EAGAIN if we didn't find any matching key
+ * - we return -ENOKEY if we found only negative matching keys
+ */
+key_ref_t search_process_keyrings(struct key_type *type,
+                                 const void *description,
+                                 key_match_func_t match,
+                                 const struct cred *cred)
+{
+       struct request_key_auth *rka;
+       key_ref_t key_ref, ret = ERR_PTR(-EACCES), err;
+
+       might_sleep();
+
+       key_ref = search_my_process_keyrings(type, description, match, cred);
+       if (!IS_ERR(key_ref))
+               goto found;
+       err = key_ref;
+
        /* if this process has an instantiation authorisation key, then we also
         * search the keyrings of the process mentioned there
         * - we don't permit access to request_key auth keys via this method
@@ -446,24 +473,19 @@ key_ref_t search_process_keyrings(struct key_type *type,
                        if (!IS_ERR(key_ref))
                                goto found;
 
-                       switch (PTR_ERR(key_ref)) {
-                       case -EAGAIN: /* no key */
-                               if (ret)
-                                       break;
-                       case -ENOKEY: /* negative key */
-                               ret = key_ref;
-                               break;
-                       default:
-                               err = key_ref;
-                               break;
-                       }
+                       ret = key_ref;
                } else {
                        up_read(&cred->request_key_auth->sem);
                }
        }
 
        /* no key - decide on the error we're going to go for */
-       key_ref = ret ? ret : err;
+       if (err == ERR_PTR(-ENOKEY) || ret == ERR_PTR(-ENOKEY))
+               key_ref = ERR_PTR(-ENOKEY);
+       else if (err == ERR_PTR(-EACCES))
+               key_ref = ret;
+       else
+               key_ref = err;
 
 found:
        return key_ref;
@@ -474,7 +496,7 @@ found:
 /*
  * see if the key we're looking at is the target key
  */
-static int lookup_user_key_possessed(const struct key *key, const void *target)
+int lookup_user_key_possessed(const struct key *key, const void *target)
 {
        return key == target;
 
index f5ec9ac5d57cf6af80f90eb90427ecb98385ae4f..0d26f689bd7726f7d253607a0f5899c00e947fcc 100644 (file)
@@ -144,6 +144,7 @@ static int call_sbin_request_key(struct key_construction *cons,
        prkey = 0;
        if (cred->tgcred->process_keyring)
                prkey = cred->tgcred->process_keyring->serial;
+       sprintf(keyring_str[1], "%d", prkey);
 
        rcu_read_lock();
        session = rcu_dereference(cred->tgcred->session_keyring);
index 351942a4ca0e79b0c21ccd35c31e442928792f47..e8c87b8601b4560bda565064212b79d0004d46ed 100644 (file)
@@ -417,12 +417,11 @@ int security_path_rename(struct path *old_dir, struct dentry *old_dentry,
                                         new_dentry);
 }
 
-int security_path_truncate(struct path *path, loff_t length,
-                          unsigned int time_attrs)
+int security_path_truncate(struct path *path)
 {
        if (unlikely(IS_PRIVATE(path->dentry->d_inode)))
                return 0;
-       return security_ops->path_truncate(path, length, time_attrs);
+       return security_ops->path_truncate(path);
 }
 
 int security_path_chmod(struct dentry *dentry, struct vfsmount *mnt,
index 7f1a304712a9690e419e575d816e4d14e697b0b7..9da6420e2056541f330d85e41be66f4742691e2b 100644 (file)
@@ -288,7 +288,6 @@ static struct avc_node *avc_alloc_node(void)
        if (!node)
                goto out;
 
-       INIT_RCU_HEAD(&node->rhead);
        INIT_HLIST_NODE(&node->list);
        avc_cache_stats_incr(allocations);
 
@@ -489,9 +488,29 @@ void avc_audit(u32 ssid, u32 tsid,
        struct common_audit_data stack_data;
        u32 denied, audited;
        denied = requested & ~avd->allowed;
-       if (denied)
+       if (denied) {
                audited = denied & avd->auditdeny;
-       else if (result)
+               /*
+                * a->selinux_audit_data.auditdeny is TRICKY!  Setting a bit in
+                * this field means that ANY denials should NOT be audited if
+                * the policy contains an explicit dontaudit rule for that
+                * permission.  Take notice that this is unrelated to the
+                * actual permissions that were denied.  As an example lets
+                * assume:
+                *
+                * denied == READ
+                * avd.auditdeny & ACCESS == 0 (not set means explicit rule)
+                * selinux_audit_data.auditdeny & ACCESS == 1
+                *
+                * We will NOT audit the denial even though the denied
+                * permission was READ and the auditdeny checks were for
+                * ACCESS
+                */
+               if (a &&
+                   a->selinux_audit_data.auditdeny &&
+                   !(a->selinux_audit_data.auditdeny & avd->auditdeny))
+                       audited = 0;
+       } else if (result)
                audited = denied = requested;
        else
                audited = requested & avd->auditallow;
index 5c9f25ba1c9537faa8e1ea91a482dd8960cb745e..9b40f4c0ac7032e3d80d2508ba96024fd28d2512 100644 (file)
@@ -87,9 +87,6 @@
 #include "netlabel.h"
 #include "audit.h"
 
-#define XATTR_SELINUX_SUFFIX "selinux"
-#define XATTR_NAME_SELINUX XATTR_SECURITY_PREFIX XATTR_SELINUX_SUFFIX
-
 #define NUM_SEL_MNT_OPTS 5
 
 extern int selinux_nlmsg_lookup(u16 sclass, u16 nlmsg_type, u32 *perm);
@@ -188,7 +185,7 @@ static inline u32 task_sid(const struct task_struct *task)
  */
 static inline u32 current_sid(void)
 {
-       const struct task_security_struct *tsec = current_cred()->security;
+       const struct task_security_struct *tsec = current_security();
 
        return tsec->sid;
 }
@@ -279,32 +276,6 @@ static void superblock_free_security(struct super_block *sb)
        kfree(sbsec);
 }
 
-static int sk_alloc_security(struct sock *sk, int family, gfp_t priority)
-{
-       struct sk_security_struct *sksec;
-
-       sksec = kzalloc(sizeof(*sksec), priority);
-       if (!sksec)
-               return -ENOMEM;
-
-       sksec->peer_sid = SECINITSID_UNLABELED;
-       sksec->sid = SECINITSID_UNLABELED;
-       sk->sk_security = sksec;
-
-       selinux_netlbl_sk_security_reset(sksec);
-
-       return 0;
-}
-
-static void sk_free_security(struct sock *sk)
-{
-       struct sk_security_struct *sksec = sk->sk_security;
-
-       sk->sk_security = NULL;
-       selinux_netlbl_sk_security_free(sksec);
-       kfree(sksec);
-}
-
 /* The security server must be initialized before
    any labeling or access decisions can be provided. */
 extern int ss_initialized;
@@ -1584,8 +1555,7 @@ static int may_create(struct inode *dir,
                      struct dentry *dentry,
                      u16 tclass)
 {
-       const struct cred *cred = current_cred();
-       const struct task_security_struct *tsec = cred->security;
+       const struct task_security_struct *tsec = current_security();
        struct inode_security_struct *dsec;
        struct superblock_security_struct *sbsec;
        u32 sid, newsid;
@@ -1806,27 +1776,9 @@ static inline u32 open_file_to_av(struct file *file)
 {
        u32 av = file_to_av(file);
 
-       if (selinux_policycap_openperm) {
-               mode_t mode = file->f_path.dentry->d_inode->i_mode;
-               /*
-                * lnk files and socks do not really have an 'open'
-                */
-               if (S_ISREG(mode))
-                       av |= FILE__OPEN;
-               else if (S_ISCHR(mode))
-                       av |= CHR_FILE__OPEN;
-               else if (S_ISBLK(mode))
-                       av |= BLK_FILE__OPEN;
-               else if (S_ISFIFO(mode))
-                       av |= FIFO_FILE__OPEN;
-               else if (S_ISDIR(mode))
-                       av |= DIR__OPEN;
-               else if (S_ISSOCK(mode))
-                       av |= SOCK_FILE__OPEN;
-               else
-                       printk(KERN_ERR "SELinux: WARNING: inside %s with "
-                               "unknown mode:%o\n", __func__, mode);
-       }
+       if (selinux_policycap_openperm)
+               av |= FILE__OPEN;
+
        return av;
 }
 
@@ -2183,8 +2135,7 @@ static int selinux_bprm_set_creds(struct linux_binprm *bprm)
 
 static int selinux_bprm_secureexec(struct linux_binprm *bprm)
 {
-       const struct cred *cred = current_cred();
-       const struct task_security_struct *tsec = cred->security;
+       const struct task_security_struct *tsec = current_security();
        u32 sid, osid;
        int atsecure = 0;
 
@@ -2559,8 +2510,7 @@ static int selinux_inode_init_security(struct inode *inode, struct inode *dir,
                                       char **name, void **value,
                                       size_t *len)
 {
-       const struct cred *cred = current_cred();
-       const struct task_security_struct *tsec = cred->security;
+       const struct task_security_struct *tsec = current_security();
        struct inode_security_struct *dsec;
        struct superblock_security_struct *sbsec;
        u32 sid, newsid, clen;
@@ -2676,14 +2626,26 @@ static int selinux_inode_follow_link(struct dentry *dentry, struct nameidata *na
 static int selinux_inode_permission(struct inode *inode, int mask)
 {
        const struct cred *cred = current_cred();
+       struct common_audit_data ad;
+       u32 perms;
+       bool from_access;
 
-       if (!mask) {
-               /* No permission to check.  Existence test. */
+       from_access = mask & MAY_ACCESS;
+       mask &= (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND);
+
+       /* No permission to check.  Existence test. */
+       if (!mask)
                return 0;
-       }
 
-       return inode_has_perm(cred, inode,
-                             file_mask_to_av(inode->i_mode, mask), NULL);
+       COMMON_AUDIT_DATA_INIT(&ad, FS);
+       ad.u.fs.inode = inode;
+
+       if (from_access)
+               ad.selinux_audit_data.auditdeny |= FILE__AUDIT_ACCESS;
+
+       perms = file_mask_to_av(inode->i_mode, mask);
+
+       return inode_has_perm(cred, inode, perms, &ad);
 }
 
 static int selinux_inode_setattr(struct dentry *dentry, struct iattr *iattr)
@@ -3671,71 +3633,54 @@ static int selinux_skb_peerlbl_sid(struct sk_buff *skb, u16 family, u32 *sid)
 }
 
 /* socket security operations */
-static int socket_has_perm(struct task_struct *task, struct socket *sock,
-                          u32 perms)
+
+static u32 socket_sockcreate_sid(const struct task_security_struct *tsec)
 {
-       struct inode_security_struct *isec;
-       struct common_audit_data ad;
-       u32 sid;
-       int err = 0;
+       return tsec->sockcreate_sid ? : tsec->sid;
+}
 
-       isec = SOCK_INODE(sock)->i_security;
+static int sock_has_perm(struct task_struct *task, struct sock *sk, u32 perms)
+{
+       struct sk_security_struct *sksec = sk->sk_security;
+       struct common_audit_data ad;
+       u32 tsid = task_sid(task);
 
-       if (isec->sid == SECINITSID_KERNEL)
-               goto out;
-       sid = task_sid(task);
+       if (sksec->sid == SECINITSID_KERNEL)
+               return 0;
 
        COMMON_AUDIT_DATA_INIT(&ad, NET);
-       ad.u.net.sk = sock->sk;
-       err = avc_has_perm(sid, isec->sid, isec->sclass, perms, &ad);
+       ad.u.net.sk = sk;
 
-out:
-       return err;
+       return avc_has_perm(tsid, sksec->sid, sksec->sclass, perms, &ad);
 }
 
 static int selinux_socket_create(int family, int type,
                                 int protocol, int kern)
 {
-       const struct cred *cred = current_cred();
-       const struct task_security_struct *tsec = cred->security;
-       u32 sid, newsid;
+       const struct task_security_struct *tsec = current_security();
+       u32 newsid;
        u16 secclass;
-       int err = 0;
 
        if (kern)
-               goto out;
-
-       sid = tsec->sid;
-       newsid = tsec->sockcreate_sid ?: sid;
+               return 0;
 
+       newsid = socket_sockcreate_sid(tsec);
        secclass = socket_type_to_security_class(family, type, protocol);
-       err = avc_has_perm(sid, newsid, secclass, SOCKET__CREATE, NULL);
-
-out:
-       return err;
+       return avc_has_perm(tsec->sid, newsid, secclass, SOCKET__CREATE, NULL);
 }
 
 static int selinux_socket_post_create(struct socket *sock, int family,
                                      int type, int protocol, int kern)
 {
-       const struct cred *cred = current_cred();
-       const struct task_security_struct *tsec = cred->security;
-       struct inode_security_struct *isec;
+       const struct task_security_struct *tsec = current_security();
+       struct inode_security_struct *isec = SOCK_INODE(sock)->i_security;
        struct sk_security_struct *sksec;
-       u32 sid, newsid;
        int err = 0;
 
-       sid = tsec->sid;
-       newsid = tsec->sockcreate_sid;
-
-       isec = SOCK_INODE(sock)->i_security;
-
        if (kern)
                isec->sid = SECINITSID_KERNEL;
-       else if (newsid)
-               isec->sid = newsid;
        else
-               isec->sid = sid;
+               isec->sid = socket_sockcreate_sid(tsec);
 
        isec->sclass = socket_type_to_security_class(family, type, protocol);
        isec->initialized = 1;
@@ -3756,10 +3701,11 @@ static int selinux_socket_post_create(struct socket *sock, int family,
 
 static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
 {
+       struct sock *sk = sock->sk;
        u16 family;
        int err;
 
-       err = socket_has_perm(current, sock, SOCKET__BIND);
+       err = sock_has_perm(current, sk, SOCKET__BIND);
        if (err)
                goto out;
 
@@ -3768,19 +3714,16 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
         * Multiple address binding for SCTP is not supported yet: we just
         * check the first address now.
         */
-       family = sock->sk->sk_family;
+       family = sk->sk_family;
        if (family == PF_INET || family == PF_INET6) {
                char *addrp;
-               struct inode_security_struct *isec;
+               struct sk_security_struct *sksec = sk->sk_security;
                struct common_audit_data ad;
                struct sockaddr_in *addr4 = NULL;
                struct sockaddr_in6 *addr6 = NULL;
                unsigned short snum;
-               struct sock *sk = sock->sk;
                u32 sid, node_perm;
 
-               isec = SOCK_INODE(sock)->i_security;
-
                if (family == PF_INET) {
                        addr4 = (struct sockaddr_in *)address;
                        snum = ntohs(addr4->sin_port);
@@ -3804,15 +3747,15 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
                                COMMON_AUDIT_DATA_INIT(&ad, NET);
                                ad.u.net.sport = htons(snum);
                                ad.u.net.family = family;
-                               err = avc_has_perm(isec->sid, sid,
-                                                  isec->sclass,
+                               err = avc_has_perm(sksec->sid, sid,
+                                                  sksec->sclass,
                                                   SOCKET__NAME_BIND, &ad);
                                if (err)
                                        goto out;
                        }
                }
 
-               switch (isec->sclass) {
+               switch (sksec->sclass) {
                case SECCLASS_TCP_SOCKET:
                        node_perm = TCP_SOCKET__NODE_BIND;
                        break;
@@ -3843,8 +3786,8 @@ static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, in
                else
                        ipv6_addr_copy(&ad.u.net.v6info.saddr, &addr6->sin6_addr);
 
-               err = avc_has_perm(isec->sid, sid,
-                                  isec->sclass, node_perm, &ad);
+               err = avc_has_perm(sksec->sid, sid,
+                                  sksec->sclass, node_perm, &ad);
                if (err)
                        goto out;
        }
@@ -3855,19 +3798,18 @@ out:
 static int selinux_socket_connect(struct socket *sock, struct sockaddr *address, int addrlen)
 {
        struct sock *sk = sock->sk;
-       struct inode_security_struct *isec;
+       struct sk_security_struct *sksec = sk->sk_security;
        int err;
 
-       err = socket_has_perm(current, sock, SOCKET__CONNECT);
+       err = sock_has_perm(current, sk, SOCKET__CONNECT);
        if (err)
                return err;
 
        /*
         * If a TCP or DCCP socket, check name_connect permission for the port.
         */
-       isec = SOCK_INODE(sock)->i_security;
-       if (isec->sclass == SECCLASS_TCP_SOCKET ||
-           isec->sclass == SECCLASS_DCCP_SOCKET) {
+       if (sksec->sclass == SECCLASS_TCP_SOCKET ||
+           sksec->sclass == SECCLASS_DCCP_SOCKET) {
                struct common_audit_data ad;
                struct sockaddr_in *addr4 = NULL;
                struct sockaddr_in6 *addr6 = NULL;
@@ -3890,13 +3832,13 @@ static int selinux_socket_connect(struct socket *sock, struct sockaddr *address,
                if (err)
                        goto out;
 
-               perm = (isec->sclass == SECCLASS_TCP_SOCKET) ?
+               perm = (sksec->sclass == SECCLASS_TCP_SOCKET) ?
                       TCP_SOCKET__NAME_CONNECT : DCCP_SOCKET__NAME_CONNECT;
 
                COMMON_AUDIT_DATA_INIT(&ad, NET);
                ad.u.net.dport = htons(snum);
                ad.u.net.family = sk->sk_family;
-               err = avc_has_perm(isec->sid, sid, isec->sclass, perm, &ad);
+               err = avc_has_perm(sksec->sid, sid, sksec->sclass, perm, &ad);
                if (err)
                        goto out;
        }
@@ -3909,7 +3851,7 @@ out:
 
 static int selinux_socket_listen(struct socket *sock, int backlog)
 {
-       return socket_has_perm(current, sock, SOCKET__LISTEN);
+       return sock_has_perm(current, sock->sk, SOCKET__LISTEN);
 }
 
 static int selinux_socket_accept(struct socket *sock, struct socket *newsock)
@@ -3918,7 +3860,7 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock)
        struct inode_security_struct *isec;
        struct inode_security_struct *newisec;
 
-       err = socket_has_perm(current, sock, SOCKET__ACCEPT);
+       err = sock_has_perm(current, sock->sk, SOCKET__ACCEPT);
        if (err)
                return err;
 
@@ -3935,30 +3877,30 @@ static int selinux_socket_accept(struct socket *sock, struct socket *newsock)
 static int selinux_socket_sendmsg(struct socket *sock, struct msghdr *msg,
                                  int size)
 {
-       return socket_has_perm(current, sock, SOCKET__WRITE);
+       return sock_has_perm(current, sock->sk, SOCKET__WRITE);
 }
 
 static int selinux_socket_recvmsg(struct socket *sock, struct msghdr *msg,
                                  int size, int flags)
 {
-       return socket_has_perm(current, sock, SOCKET__READ);
+       return sock_has_perm(current, sock->sk, SOCKET__READ);
 }
 
 static int selinux_socket_getsockname(struct socket *sock)
 {
-       return socket_has_perm(current, sock, SOCKET__GETATTR);
+       return sock_has_perm(current, sock->sk, SOCKET__GETATTR);
 }
 
 static int selinux_socket_getpeername(struct socket *sock)
 {
-       return socket_has_perm(current, sock, SOCKET__GETATTR);
+       return sock_has_perm(current, sock->sk, SOCKET__GETATTR);
 }
 
 static int selinux_socket_setsockopt(struct socket *sock, int level, int optname)
 {
        int err;
 
-       err = socket_has_perm(current, sock, SOCKET__SETOPT);
+       err = sock_has_perm(current, sock->sk, SOCKET__SETOPT);
        if (err)
                return err;
 
@@ -3968,68 +3910,58 @@ static int selinux_socket_setsockopt(struct socket *sock, int level, int optname
 static int selinux_socket_getsockopt(struct socket *sock, int level,
                                     int optname)
 {
-       return socket_has_perm(current, sock, SOCKET__GETOPT);
+       return sock_has_perm(current, sock->sk, SOCKET__GETOPT);
 }
 
 static int selinux_socket_shutdown(struct socket *sock, int how)
 {
-       return socket_has_perm(current, sock, SOCKET__SHUTDOWN);
+       return sock_has_perm(current, sock->sk, SOCKET__SHUTDOWN);
 }
 
 static int selinux_socket_unix_stream_connect(struct socket *sock,
                                              struct socket *other,
                                              struct sock *newsk)
 {
-       struct sk_security_struct *sksec;
-       struct inode_security_struct *isec;
-       struct inode_security_struct *other_isec;
+       struct sk_security_struct *sksec_sock = sock->sk->sk_security;
+       struct sk_security_struct *sksec_other = other->sk->sk_security;
+       struct sk_security_struct *sksec_new = newsk->sk_security;
        struct common_audit_data ad;
        int err;
 
-       isec = SOCK_INODE(sock)->i_security;
-       other_isec = SOCK_INODE(other)->i_security;
-
        COMMON_AUDIT_DATA_INIT(&ad, NET);
        ad.u.net.sk = other->sk;
 
-       err = avc_has_perm(isec->sid, other_isec->sid,
-                          isec->sclass,
+       err = avc_has_perm(sksec_sock->sid, sksec_other->sid,
+                          sksec_other->sclass,
                           UNIX_STREAM_SOCKET__CONNECTTO, &ad);
        if (err)
                return err;
 
-       /* connecting socket */
-       sksec = sock->sk->sk_security;
-       sksec->peer_sid = other_isec->sid;
-
        /* server child socket */
-       sksec = newsk->sk_security;
-       sksec->peer_sid = isec->sid;
-       err = security_sid_mls_copy(other_isec->sid, sksec->peer_sid, &sksec->sid);
+       sksec_new->peer_sid = sksec_sock->sid;
+       err = security_sid_mls_copy(sksec_other->sid, sksec_sock->sid,
+                                   &sksec_new->sid);
+       if (err)
+               return err;
 
-       return err;
+       /* connecting socket */
+       sksec_sock->peer_sid = sksec_new->sid;
+
+       return 0;
 }
 
 static int selinux_socket_unix_may_send(struct socket *sock,
                                        struct socket *other)
 {
-       struct inode_security_struct *isec;
-       struct inode_security_struct *other_isec;
+       struct sk_security_struct *ssec = sock->sk->sk_security;
+       struct sk_security_struct *osec = other->sk->sk_security;
        struct common_audit_data ad;
-       int err;
-
-       isec = SOCK_INODE(sock)->i_security;
-       other_isec = SOCK_INODE(other)->i_security;
 
        COMMON_AUDIT_DATA_INIT(&ad, NET);
        ad.u.net.sk = other->sk;
 
-       err = avc_has_perm(isec->sid, other_isec->sid,
-                          isec->sclass, SOCKET__SENDTO, &ad);
-       if (err)
-               return err;
-
-       return 0;
+       return avc_has_perm(ssec->sid, osec->sid, osec->sclass, SOCKET__SENDTO,
+                           &ad);
 }
 
 static int selinux_inet_sys_rcv_skb(int ifindex, char *addrp, u16 family,
@@ -4168,26 +4100,18 @@ static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *op
        int err = 0;
        char *scontext;
        u32 scontext_len;
-       struct sk_security_struct *sksec;
-       struct inode_security_struct *isec;
+       struct sk_security_struct *sksec = sock->sk->sk_security;
        u32 peer_sid = SECSID_NULL;
 
-       isec = SOCK_INODE(sock)->i_security;
-
-       if (isec->sclass == SECCLASS_UNIX_STREAM_SOCKET ||
-           isec->sclass == SECCLASS_TCP_SOCKET) {
-               sksec = sock->sk->sk_security;
+       if (sksec->sclass == SECCLASS_UNIX_STREAM_SOCKET ||
+           sksec->sclass == SECCLASS_TCP_SOCKET)
                peer_sid = sksec->peer_sid;
-       }
-       if (peer_sid == SECSID_NULL) {
-               err = -ENOPROTOOPT;
-               goto out;
-       }
+       if (peer_sid == SECSID_NULL)
+               return -ENOPROTOOPT;
 
        err = security_sid_to_context(peer_sid, &scontext, &scontext_len);
-
        if (err)
-               goto out;
+               return err;
 
        if (scontext_len > len) {
                err = -ERANGE;
@@ -4200,9 +4124,7 @@ static int selinux_socket_getpeersec_stream(struct socket *sock, char __user *op
 out_len:
        if (put_user(scontext_len, optlen))
                err = -EFAULT;
-
        kfree(scontext);
-out:
        return err;
 }
 
@@ -4234,12 +4156,27 @@ out:
 
 static int selinux_sk_alloc_security(struct sock *sk, int family, gfp_t priority)
 {
-       return sk_alloc_security(sk, family, priority);
+       struct sk_security_struct *sksec;
+
+       sksec = kzalloc(sizeof(*sksec), priority);
+       if (!sksec)
+               return -ENOMEM;
+
+       sksec->peer_sid = SECINITSID_UNLABELED;
+       sksec->sid = SECINITSID_UNLABELED;
+       selinux_netlbl_sk_security_reset(sksec);
+       sk->sk_security = sksec;
+
+       return 0;
 }
 
 static void selinux_sk_free_security(struct sock *sk)
 {
-       sk_free_security(sk);
+       struct sk_security_struct *sksec = sk->sk_security;
+
+       sk->sk_security = NULL;
+       selinux_netlbl_sk_security_free(sksec);
+       kfree(sksec);
 }
 
 static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk)
@@ -4399,8 +4336,7 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
        int err = 0;
        u32 perm;
        struct nlmsghdr *nlh;
-       struct socket *sock = sk->sk_socket;
-       struct inode_security_struct *isec = SOCK_INODE(sock)->i_security;
+       struct sk_security_struct *sksec = sk->sk_security;
 
        if (skb->len < NLMSG_SPACE(0)) {
                err = -EINVAL;
@@ -4408,13 +4344,13 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
        }
        nlh = nlmsg_hdr(skb);
 
-       err = selinux_nlmsg_lookup(isec->sclass, nlh->nlmsg_type, &perm);
+       err = selinux_nlmsg_lookup(sksec->sclass, nlh->nlmsg_type, &perm);
        if (err) {
                if (err == -EINVAL) {
                        audit_log(current->audit_context, GFP_KERNEL, AUDIT_SELINUX_ERR,
                                  "SELinux:  unrecognized netlink message"
                                  " type=%hu for sclass=%hu\n",
-                                 nlh->nlmsg_type, isec->sclass);
+                                 nlh->nlmsg_type, sksec->sclass);
                        if (!selinux_enforcing || security_get_allow_unknown())
                                err = 0;
                }
@@ -4425,7 +4361,7 @@ static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
                goto out;
        }
 
-       err = socket_has_perm(current, sock, perm);
+       err = sock_has_perm(current, sk, perm);
 out:
        return err;
 }
index 8b32e959bb2e47cc559e29aaf7468576d63974a5..b4c9eb4bd6f9127a506e2a4483c592362c8fcafa 100644 (file)
@@ -2,7 +2,8 @@
     "getattr", "setattr", "lock", "relabelfrom", "relabelto", "append"
 
 #define COMMON_FILE_PERMS COMMON_FILE_SOCK_PERMS, "unlink", "link", \
-    "rename", "execute", "swapon", "quotaon", "mounton"
+    "rename", "execute", "swapon", "quotaon", "mounton", "audit_access", \
+    "open", "execmod"
 
 #define COMMON_SOCK_PERMS COMMON_FILE_SOCK_PERMS, "bind", "connect", \
     "listen", "accept", "getopt", "setopt", "shutdown", "recvfrom",  \
@@ -43,22 +44,21 @@ struct security_class_mapping secclass_map[] = {
            "quotaget", NULL } },
        { "file",
          { COMMON_FILE_PERMS,
-           "execute_no_trans", "entrypoint", "execmod", "open", NULL } },
+           "execute_no_trans", "entrypoint", NULL } },
        { "dir",
          { COMMON_FILE_PERMS, "add_name", "remove_name",
-           "reparent", "search", "rmdir", "open", NULL } },
+           "reparent", "search", "rmdir", NULL } },
        { "fd", { "use", NULL } },
        { "lnk_file",
          { COMMON_FILE_PERMS, NULL } },
        { "chr_file",
-         { COMMON_FILE_PERMS,
-           "execute_no_trans", "entrypoint", "execmod", "open", NULL } },
+         { COMMON_FILE_PERMS, NULL } },
        { "blk_file",
-         { COMMON_FILE_PERMS, "open", NULL } },
+         { COMMON_FILE_PERMS, NULL } },
        { "sock_file",
-         { COMMON_FILE_PERMS, "open", NULL } },
+         { COMMON_FILE_PERMS, NULL } },
        { "fifo_file",
-         { COMMON_FILE_PERMS, "open", NULL } },
+         { COMMON_FILE_PERMS, NULL } },
        { "socket",
          { COMMON_SOCK_PERMS, NULL } },
        { "tcp_socket",
index dc92792271f1d8e59e01e9f4e9000d4f0090b2c0..65ebfe954f85395f490ce74d694d73a859b523ac 100644 (file)
@@ -183,8 +183,6 @@ static void sel_netnode_insert(struct sel_netnode *node)
                BUG();
        }
 
-       INIT_RCU_HEAD(&node->rcu);
-
        /* we need to impose a limit on the growth of the hash table so check
         * this bucket to make sure it is within the specified bounds */
        list_add_rcu(&node->list, &sel_netnode_hash[idx].list);
index 0293843f7eda7d41e7722bd55e41bbc5ea0110a3..79a1bb635662fbc7f65a306e10b5b67e534fcf1c 100644 (file)
@@ -184,6 +184,7 @@ out:
 static const struct file_operations sel_enforce_ops = {
        .read           = sel_read_enforce,
        .write          = sel_write_enforce,
+       .llseek         = generic_file_llseek,
 };
 
 static ssize_t sel_read_handle_unknown(struct file *filp, char __user *buf,
@@ -201,6 +202,7 @@ static ssize_t sel_read_handle_unknown(struct file *filp, char __user *buf,
 
 static const struct file_operations sel_handle_unknown_ops = {
        .read           = sel_read_handle_unknown,
+       .llseek         = generic_file_llseek,
 };
 
 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
@@ -251,6 +253,7 @@ out:
 
 static const struct file_operations sel_disable_ops = {
        .write          = sel_write_disable,
+       .llseek         = generic_file_llseek,
 };
 
 static ssize_t sel_read_policyvers(struct file *filp, char __user *buf,
@@ -265,6 +268,7 @@ static ssize_t sel_read_policyvers(struct file *filp, char __user *buf,
 
 static const struct file_operations sel_policyvers_ops = {
        .read           = sel_read_policyvers,
+       .llseek         = generic_file_llseek,
 };
 
 /* declaration for sel_write_load */
@@ -289,6 +293,7 @@ static ssize_t sel_read_mls(struct file *filp, char __user *buf,
 
 static const struct file_operations sel_mls_ops = {
        .read           = sel_read_mls,
+       .llseek         = generic_file_llseek,
 };
 
 static ssize_t sel_write_load(struct file *file, const char __user *buf,
@@ -356,6 +361,7 @@ out:
 
 static const struct file_operations sel_load_ops = {
        .write          = sel_write_load,
+       .llseek         = generic_file_llseek,
 };
 
 static ssize_t sel_write_context(struct file *file, char *buf, size_t size)
@@ -437,6 +443,7 @@ out:
 static const struct file_operations sel_checkreqprot_ops = {
        .read           = sel_read_checkreqprot,
        .write          = sel_write_checkreqprot,
+       .llseek         = generic_file_llseek,
 };
 
 /*
@@ -482,6 +489,7 @@ static const struct file_operations transaction_ops = {
        .write          = selinux_transaction_write,
        .read           = simple_transaction_read,
        .release        = simple_transaction_release,
+       .llseek         = generic_file_llseek,
 };
 
 /*
@@ -883,6 +891,7 @@ out:
 static const struct file_operations sel_bool_ops = {
        .read           = sel_read_bool,
        .write          = sel_write_bool,
+       .llseek         = generic_file_llseek,
 };
 
 static ssize_t sel_commit_bools_write(struct file *filep,
@@ -935,6 +944,7 @@ out:
 
 static const struct file_operations sel_commit_bools_ops = {
        .write          = sel_commit_bools_write,
+       .llseek         = generic_file_llseek,
 };
 
 static void sel_remove_entries(struct dentry *de)
@@ -1127,10 +1137,12 @@ out:
 static const struct file_operations sel_avc_cache_threshold_ops = {
        .read           = sel_read_avc_cache_threshold,
        .write          = sel_write_avc_cache_threshold,
+       .llseek         = generic_file_llseek,
 };
 
 static const struct file_operations sel_avc_hash_stats_ops = {
        .read           = sel_read_avc_hash_stats,
+       .llseek         = generic_file_llseek,
 };
 
 #ifdef CONFIG_SECURITY_SELINUX_AVC_STATS
@@ -1255,6 +1267,7 @@ static ssize_t sel_read_initcon(struct file *file, char __user *buf,
 
 static const struct file_operations sel_initcon_ops = {
        .read           = sel_read_initcon,
+       .llseek         = generic_file_llseek,
 };
 
 static int sel_make_initcon_files(struct dentry *dir)
@@ -1330,6 +1343,7 @@ out:
 
 static const struct file_operations sel_class_ops = {
        .read           = sel_read_class,
+       .llseek         = generic_file_llseek,
 };
 
 static ssize_t sel_read_perm(struct file *file, char __user *buf,
@@ -1354,6 +1368,7 @@ out:
 
 static const struct file_operations sel_perm_ops = {
        .read           = sel_read_perm,
+       .llseek         = generic_file_llseek,
 };
 
 static ssize_t sel_read_policycap(struct file *file, char __user *buf,
@@ -1372,6 +1387,7 @@ static ssize_t sel_read_policycap(struct file *file, char __user *buf,
 
 static const struct file_operations sel_policycap_ops = {
        .read           = sel_read_policycap,
+       .llseek         = generic_file_llseek,
 };
 
 static int sel_make_perm_files(char *objclass, int classvalue,
index 1215b8e47dba669a6d86519b342de621b2efbfd2..929480c6c4306e874eff82db107045b944cdd33b 100644 (file)
@@ -342,20 +342,20 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
 
        if (vers < POLICYDB_VERSION_AVTAB) {
                rc = next_entry(buf32, fp, sizeof(u32));
-               if (rc < 0) {
+               if (rc) {
                        printk(KERN_ERR "SELinux: avtab: truncated entry\n");
-                       return -1;
+                       return rc;
                }
                items2 = le32_to_cpu(buf32[0]);
                if (items2 > ARRAY_SIZE(buf32)) {
                        printk(KERN_ERR "SELinux: avtab: entry overflow\n");
-                       return -1;
+                       return -EINVAL;
 
                }
                rc = next_entry(buf32, fp, sizeof(u32)*items2);
-               if (rc < 0) {
+               if (rc) {
                        printk(KERN_ERR "SELinux: avtab: truncated entry\n");
-                       return -1;
+                       return rc;
                }
                items = 0;
 
@@ -363,19 +363,19 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
                key.source_type = (u16)val;
                if (key.source_type != val) {
                        printk(KERN_ERR "SELinux: avtab: truncated source type\n");
-                       return -1;
+                       return -EINVAL;
                }
                val = le32_to_cpu(buf32[items++]);
                key.target_type = (u16)val;
                if (key.target_type != val) {
                        printk(KERN_ERR "SELinux: avtab: truncated target type\n");
-                       return -1;
+                       return -EINVAL;
                }
                val = le32_to_cpu(buf32[items++]);
                key.target_class = (u16)val;
                if (key.target_class != val) {
                        printk(KERN_ERR "SELinux: avtab: truncated target class\n");
-                       return -1;
+                       return -EINVAL;
                }
 
                val = le32_to_cpu(buf32[items++]);
@@ -383,12 +383,12 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
 
                if (!(val & (AVTAB_AV | AVTAB_TYPE))) {
                        printk(KERN_ERR "SELinux: avtab: null entry\n");
-                       return -1;
+                       return -EINVAL;
                }
                if ((val & AVTAB_AV) &&
                    (val & AVTAB_TYPE)) {
                        printk(KERN_ERR "SELinux: avtab: entry has both access vectors and types\n");
-                       return -1;
+                       return -EINVAL;
                }
 
                for (i = 0; i < ARRAY_SIZE(spec_order); i++) {
@@ -403,15 +403,15 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
 
                if (items != items2) {
                        printk(KERN_ERR "SELinux: avtab: entry only had %d items, expected %d\n", items2, items);
-                       return -1;
+                       return -EINVAL;
                }
                return 0;
        }
 
        rc = next_entry(buf16, fp, sizeof(u16)*4);
-       if (rc < 0) {
+       if (rc) {
                printk(KERN_ERR "SELinux: avtab: truncated entry\n");
-               return -1;
+               return rc;
        }
 
        items = 0;
@@ -424,7 +424,7 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
            !policydb_type_isvalid(pol, key.target_type) ||
            !policydb_class_isvalid(pol, key.target_class)) {
                printk(KERN_ERR "SELinux: avtab: invalid type or class\n");
-               return -1;
+               return -EINVAL;
        }
 
        set = 0;
@@ -434,19 +434,19 @@ int avtab_read_item(struct avtab *a, void *fp, struct policydb *pol,
        }
        if (!set || set > 1) {
                printk(KERN_ERR "SELinux:  avtab:  more than one specifier\n");
-               return -1;
+               return -EINVAL;
        }
 
        rc = next_entry(buf32, fp, sizeof(u32));
-       if (rc < 0) {
+       if (rc) {
                printk(KERN_ERR "SELinux: avtab: truncated entry\n");
-               return -1;
+               return rc;
        }
        datum.data = le32_to_cpu(*buf32);
        if ((key.specified & AVTAB_TYPE) &&
            !policydb_type_isvalid(pol, datum.data)) {
                printk(KERN_ERR "SELinux: avtab: invalid type\n");
-               return -1;
+               return -EINVAL;
        }
        return insertf(a, &key, &datum, p);
 }
@@ -487,8 +487,7 @@ int avtab_read(struct avtab *a, void *fp, struct policydb *pol)
                                printk(KERN_ERR "SELinux: avtab: out of memory\n");
                        else if (rc == -EEXIST)
                                printk(KERN_ERR "SELinux: avtab: duplicate entry\n");
-                       else
-                               rc = -EINVAL;
+
                        goto bad;
                }
        }
index 4a4e35cac22bfc2a7426dd85e582ce113e07e843..c91e150c3087d78127eb8ca6cc6faccf04e9cd32 100644 (file)
@@ -117,10 +117,14 @@ int evaluate_cond_node(struct policydb *p, struct cond_node *node)
 
 int cond_policydb_init(struct policydb *p)
 {
+       int rc;
+
        p->bool_val_to_struct = NULL;
        p->cond_list = NULL;
-       if (avtab_init(&p->te_cond_avtab))
-               return -1;
+
+       rc = avtab_init(&p->te_cond_avtab);
+       if (rc)
+               return rc;
 
        return 0;
 }
@@ -219,34 +223,37 @@ int cond_read_bool(struct policydb *p, struct hashtab *h, void *fp)
 
        booldatum = kzalloc(sizeof(struct cond_bool_datum), GFP_KERNEL);
        if (!booldatum)
-               return -1;
+               return -ENOMEM;
 
        rc = next_entry(buf, fp, sizeof buf);
-       if (rc < 0)
+       if (rc)
                goto err;
 
        booldatum->value = le32_to_cpu(buf[0]);
        booldatum->state = le32_to_cpu(buf[1]);
 
+       rc = -EINVAL;
        if (!bool_isvalid(booldatum))
                goto err;
 
        len = le32_to_cpu(buf[2]);
 
+       rc = -ENOMEM;
        key = kmalloc(len + 1, GFP_KERNEL);
        if (!key)
                goto err;
        rc = next_entry(key, fp, len);
-       if (rc < 0)
+       if (rc)
                goto err;
        key[len] = '\0';
-       if (hashtab_insert(h, key, booldatum))
+       rc = hashtab_insert(h, key, booldatum);
+       if (rc)
                goto err;
 
        return 0;
 err:
        cond_destroy_bool(key, booldatum, NULL);
-       return -1;
+       return rc;
 }
 
 struct cond_insertf_data {
@@ -263,7 +270,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
        struct cond_av_list *other = data->other, *list, *cur;
        struct avtab_node *node_ptr;
        u8 found;
-
+       int rc = -EINVAL;
 
        /*
         * For type rules we have to make certain there aren't any
@@ -313,12 +320,15 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
        node_ptr = avtab_insert_nonunique(&p->te_cond_avtab, k, d);
        if (!node_ptr) {
                printk(KERN_ERR "SELinux: could not insert rule.\n");
+               rc = -ENOMEM;
                goto err;
        }
 
        list = kzalloc(sizeof(struct cond_av_list), GFP_KERNEL);
-       if (!list)
+       if (!list) {
+               rc = -ENOMEM;
                goto err;
+       }
 
        list->node = node_ptr;
        if (!data->head)
@@ -331,7 +341,7 @@ static int cond_insertf(struct avtab *a, struct avtab_key *k, struct avtab_datum
 err:
        cond_av_list_destroy(data->head);
        data->head = NULL;
-       return -1;
+       return rc;
 }
 
 static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list **ret_list, struct cond_av_list *other)
@@ -345,8 +355,8 @@ static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list *
 
        len = 0;
        rc = next_entry(buf, fp, sizeof(u32));
-       if (rc < 0)
-               return -1;
+       if (rc)
+               return rc;
 
        len = le32_to_cpu(buf[0]);
        if (len == 0)
@@ -361,7 +371,6 @@ static int cond_read_av_list(struct policydb *p, void *fp, struct cond_av_list *
                                     &data);
                if (rc)
                        return rc;
-
        }
 
        *ret_list = data.head;
@@ -390,24 +399,25 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
        struct cond_expr *expr = NULL, *last = NULL;
 
        rc = next_entry(buf, fp, sizeof(u32));
-       if (rc < 0)
-               return -1;
+       if (rc)
+               return rc;
 
        node->cur_state = le32_to_cpu(buf[0]);
 
        len = 0;
        rc = next_entry(buf, fp, sizeof(u32));
-       if (rc < 0)
-               return -1;
+       if (rc)
+               return rc;
 
        /* expr */
        len = le32_to_cpu(buf[0]);
 
        for (i = 0; i < len; i++) {
                rc = next_entry(buf, fp, sizeof(u32) * 2);
-               if (rc < 0)
+               if (rc)
                        goto err;
 
+               rc = -ENOMEM;
                expr = kzalloc(sizeof(struct cond_expr), GFP_KERNEL);
                if (!expr)
                        goto err;
@@ -416,6 +426,7 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
                expr->bool = le32_to_cpu(buf[1]);
 
                if (!expr_isvalid(p, expr)) {
+                       rc = -EINVAL;
                        kfree(expr);
                        goto err;
                }
@@ -427,14 +438,16 @@ static int cond_read_node(struct policydb *p, struct cond_node *node, void *fp)
                last = expr;
        }
 
-       if (cond_read_av_list(p, fp, &node->true_list, NULL) != 0)
+       rc = cond_read_av_list(p, fp, &node->true_list, NULL);
+       if (rc)
                goto err;
-       if (cond_read_av_list(p, fp, &node->false_list, node->true_list) != 0)
+       rc = cond_read_av_list(p, fp, &node->false_list, node->true_list);
+       if (rc)
                goto err;
        return 0;
 err:
        cond_node_destroy(node);
-       return -1;
+       return rc;
 }
 
 int cond_read_list(struct policydb *p, void *fp)
@@ -445,8 +458,8 @@ int cond_read_list(struct policydb *p, void *fp)
        int rc;
 
        rc = next_entry(buf, fp, sizeof buf);
-       if (rc < 0)
-               return -1;
+       if (rc)
+               return rc;
 
        len = le32_to_cpu(buf[0]);
 
@@ -455,11 +468,13 @@ int cond_read_list(struct policydb *p, void *fp)
                goto err;
 
        for (i = 0; i < len; i++) {
+               rc = -ENOMEM;
                node = kzalloc(sizeof(struct cond_node), GFP_KERNEL);
                if (!node)
                        goto err;
 
-               if (cond_read_node(p, node, fp) != 0)
+               rc = cond_read_node(p, node, fp);
+               if (rc)
                        goto err;
 
                if (i == 0)
@@ -472,7 +487,7 @@ int cond_read_list(struct policydb *p, void *fp)
 err:
        cond_list_destroy(p->cond_list);
        p->cond_list = NULL;
-       return -1;
+       return rc;
 }
 
 /* Determine whether additional permissions are granted by the conditional
index c57802a164d5d3b840a287a06a15e58793610c4a..3a29704be8ce10f4409dd0a3d4f0bea8bb0d1086 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/string.h>
 #include <linux/errno.h>
 #include <linux/audit.h>
+#include <linux/flex_array.h>
 #include "security.h"
 
 #include "policydb.h"
@@ -655,6 +656,9 @@ static int range_tr_destroy(void *key, void *datum, void *p)
 
 static void ocontext_destroy(struct ocontext *c, int i)
 {
+       if (!c)
+               return;
+
        context_destroy(&c->context[0]);
        context_destroy(&c->context[1]);
        if (i == OCON_ISID || i == OCON_FS ||
@@ -736,11 +740,17 @@ void policydb_destroy(struct policydb *p)
        hashtab_map(p->range_tr, range_tr_destroy, NULL);
        hashtab_destroy(p->range_tr);
 
-       if (p->type_attr_map) {
-               for (i = 0; i < p->p_types.nprim; i++)
-                       ebitmap_destroy(&p->type_attr_map[i]);
+       if (p->type_attr_map_array) {
+               for (i = 0; i < p->p_types.nprim; i++) {
+                       struct ebitmap *e;
+
+                       e = flex_array_get(p->type_attr_map_array, i);
+                       if (!e)
+                               continue;
+                       ebitmap_destroy(e);
+               }
+               flex_array_free(p->type_attr_map_array);
        }
-       kfree(p->type_attr_map);
        ebitmap_destroy(&p->policycaps);
        ebitmap_destroy(&p->permissive_map);
 
@@ -1701,6 +1711,333 @@ u32 string_to_av_perm(struct policydb *p, u16 tclass, const char *name)
        return 1U << (perdatum->value-1);
 }
 
+static int range_read(struct policydb *p, void *fp)
+{
+       struct range_trans *rt = NULL;
+       struct mls_range *r = NULL;
+       int i, rc;
+       __le32 buf[2];
+       u32 nel;
+
+       if (p->policyvers < POLICYDB_VERSION_MLS)
+               return 0;
+
+       rc = next_entry(buf, fp, sizeof(u32));
+       if (rc)
+               goto out;
+
+       nel = le32_to_cpu(buf[0]);
+       for (i = 0; i < nel; i++) {
+               rc = -ENOMEM;
+               rt = kzalloc(sizeof(*rt), GFP_KERNEL);
+               if (!rt)
+                       goto out;
+
+               rc = next_entry(buf, fp, (sizeof(u32) * 2));
+               if (rc)
+                       goto out;
+
+               rt->source_type = le32_to_cpu(buf[0]);
+               rt->target_type = le32_to_cpu(buf[1]);
+               if (p->policyvers >= POLICYDB_VERSION_RANGETRANS) {
+                       rc = next_entry(buf, fp, sizeof(u32));
+                       if (rc)
+                               goto out;
+                       rt->target_class = le32_to_cpu(buf[0]);
+               } else
+                       rt->target_class = p->process_class;
+
+               rc = -EINVAL;
+               if (!policydb_type_isvalid(p, rt->source_type) ||
+                   !policydb_type_isvalid(p, rt->target_type) ||
+                   !policydb_class_isvalid(p, rt->target_class))
+                       goto out;
+
+               rc = -ENOMEM;
+               r = kzalloc(sizeof(*r), GFP_KERNEL);
+               if (!r)
+                       goto out;
+
+               rc = mls_read_range_helper(r, fp);
+               if (rc)
+                       goto out;
+
+               rc = -EINVAL;
+               if (!mls_range_isvalid(p, r)) {
+                       printk(KERN_WARNING "SELinux:  rangetrans:  invalid range\n");
+                       goto out;
+               }
+
+               rc = hashtab_insert(p->range_tr, rt, r);
+               if (rc)
+                       goto out;
+
+               rt = NULL;
+               r = NULL;
+       }
+       rangetr_hash_eval(p->range_tr);
+       rc = 0;
+out:
+       kfree(rt);
+       kfree(r);
+       return rc;
+}
+
+static int genfs_read(struct policydb *p, void *fp)
+{
+       int i, j, rc;
+       u32 nel, nel2, len, len2;
+       __le32 buf[1];
+       struct ocontext *l, *c;
+       struct ocontext *newc = NULL;
+       struct genfs *genfs_p, *genfs;
+       struct genfs *newgenfs = NULL;
+
+       rc = next_entry(buf, fp, sizeof(u32));
+       if (rc)
+               goto out;
+       nel = le32_to_cpu(buf[0]);
+
+       for (i = 0; i < nel; i++) {
+               rc = next_entry(buf, fp, sizeof(u32));
+               if (rc)
+                       goto out;
+               len = le32_to_cpu(buf[0]);
+
+               rc = -ENOMEM;
+               newgenfs = kzalloc(sizeof(*newgenfs), GFP_KERNEL);
+               if (!newgenfs)
+                       goto out;
+
+               rc = -ENOMEM;
+               newgenfs->fstype = kmalloc(len + 1, GFP_KERNEL);
+               if (!newgenfs->fstype)
+                       goto out;
+
+               rc = next_entry(newgenfs->fstype, fp, len);
+               if (rc)
+                       goto out;
+
+               newgenfs->fstype[len] = 0;
+
+               for (genfs_p = NULL, genfs = p->genfs; genfs;
+                    genfs_p = genfs, genfs = genfs->next) {
+                       rc = -EINVAL;
+                       if (strcmp(newgenfs->fstype, genfs->fstype) == 0) {
+                               printk(KERN_ERR "SELinux:  dup genfs fstype %s\n",
+                                      newgenfs->fstype);
+                               goto out;
+                       }
+                       if (strcmp(newgenfs->fstype, genfs->fstype) < 0)
+                               break;
+               }
+               newgenfs->next = genfs;
+               if (genfs_p)
+                       genfs_p->next = newgenfs;
+               else
+                       p->genfs = newgenfs;
+               genfs = newgenfs;
+               newgenfs = NULL;
+
+               rc = next_entry(buf, fp, sizeof(u32));
+               if (rc)
+                       goto out;
+
+               nel2 = le32_to_cpu(buf[0]);
+               for (j = 0; j < nel2; j++) {
+                       rc = next_entry(buf, fp, sizeof(u32));
+                       if (rc)
+                               goto out;
+                       len = le32_to_cpu(buf[0]);
+
+                       rc = -ENOMEM;
+                       newc = kzalloc(sizeof(*newc), GFP_KERNEL);
+                       if (!newc)
+                               goto out;
+
+                       rc = -ENOMEM;
+                       newc->u.name = kmalloc(len + 1, GFP_KERNEL);
+                       if (!newc->u.name)
+                               goto out;
+
+                       rc = next_entry(newc->u.name, fp, len);
+                       if (rc)
+                               goto out;
+                       newc->u.name[len] = 0;
+
+                       rc = next_entry(buf, fp, sizeof(u32));
+                       if (rc)
+                               goto out;
+
+                       newc->v.sclass = le32_to_cpu(buf[0]);
+                       rc = context_read_and_validate(&newc->context[0], p, fp);
+                       if (rc)
+                               goto out;
+
+                       for (l = NULL, c = genfs->head; c;
+                            l = c, c = c->next) {
+                               rc = -EINVAL;
+                               if (!strcmp(newc->u.name, c->u.name) &&
+                                   (!c->v.sclass || !newc->v.sclass ||
+                                    newc->v.sclass == c->v.sclass)) {
+                                       printk(KERN_ERR "SELinux:  dup genfs entry (%s,%s)\n",
+                                              genfs->fstype, c->u.name);
+                                       goto out;
+                               }
+                               len = strlen(newc->u.name);
+                               len2 = strlen(c->u.name);
+                               if (len > len2)
+                                       break;
+                       }
+
+                       newc->next = c;
+                       if (l)
+                               l->next = newc;
+                       else
+                               genfs->head = newc;
+                       newc = NULL;
+               }
+       }
+       rc = 0;
+out:
+       if (newgenfs)
+               kfree(newgenfs->fstype);
+       kfree(newgenfs);
+       ocontext_destroy(newc, OCON_FSUSE);
+
+       return rc;
+}
+
+static int ocontext_read(struct policydb *p, struct policydb_compat_info *info,
+                        void *fp)
+{
+       int i, j, rc;
+       u32 nel, len;
+       __le32 buf[3];
+       struct ocontext *l, *c;
+       u32 nodebuf[8];
+
+       for (i = 0; i < info->ocon_num; i++) {
+               rc = next_entry(buf, fp, sizeof(u32));
+               if (rc)
+                       goto out;
+               nel = le32_to_cpu(buf[0]);
+
+               l = NULL;
+               for (j = 0; j < nel; j++) {
+                       rc = -ENOMEM;
+                       c = kzalloc(sizeof(*c), GFP_KERNEL);
+                       if (!c)
+                               goto out;
+                       if (l)
+                               l->next = c;
+                       else
+                               p->ocontexts[i] = c;
+                       l = c;
+
+                       switch (i) {
+                       case OCON_ISID:
+                               rc = next_entry(buf, fp, sizeof(u32));
+                               if (rc)
+                                       goto out;
+
+                               c->sid[0] = le32_to_cpu(buf[0]);
+                               rc = context_read_and_validate(&c->context[0], p, fp);
+                               if (rc)
+                                       goto out;
+                               break;
+                       case OCON_FS:
+                       case OCON_NETIF:
+                               rc = next_entry(buf, fp, sizeof(u32));
+                               if (rc)
+                                       goto out;
+                               len = le32_to_cpu(buf[0]);
+
+                               rc = -ENOMEM;
+                               c->u.name = kmalloc(len + 1, GFP_KERNEL);
+                               if (!c->u.name)
+                                       goto out;
+
+                               rc = next_entry(c->u.name, fp, len);
+                               if (rc)
+                                       goto out;
+
+                               c->u.name[len] = 0;
+                               rc = context_read_and_validate(&c->context[0], p, fp);
+                               if (rc)
+                                       goto out;
+                               rc = context_read_and_validate(&c->context[1], p, fp);
+                               if (rc)
+                                       goto out;
+                               break;
+                       case OCON_PORT:
+                               rc = next_entry(buf, fp, sizeof(u32)*3);
+                               if (rc)
+                                       goto out;
+                               c->u.port.protocol = le32_to_cpu(buf[0]);
+                               c->u.port.low_port = le32_to_cpu(buf[1]);
+                               c->u.port.high_port = le32_to_cpu(buf[2]);
+                               rc = context_read_and_validate(&c->context[0], p, fp);
+                               if (rc)
+                                       goto out;
+                               break;
+                       case OCON_NODE:
+                               rc = next_entry(nodebuf, fp, sizeof(u32) * 2);
+                               if (rc)
+                                       goto out;
+                               c->u.node.addr = nodebuf[0]; /* network order */
+                               c->u.node.mask = nodebuf[1]; /* network order */
+                               rc = context_read_and_validate(&c->context[0], p, fp);
+                               if (rc)
+                                       goto out;
+                               break;
+                       case OCON_FSUSE:
+                               rc = next_entry(buf, fp, sizeof(u32)*2);
+                               if (rc)
+                                       goto out;
+
+                               rc = -EINVAL;
+                               c->v.behavior = le32_to_cpu(buf[0]);
+                               if (c->v.behavior > SECURITY_FS_USE_NONE)
+                                       goto out;
+
+                               rc = -ENOMEM;
+                               len = le32_to_cpu(buf[1]);
+                               c->u.name = kmalloc(len + 1, GFP_KERNEL);
+                               if (!c->u.name)
+                                       goto out;
+
+                               rc = next_entry(c->u.name, fp, len);
+                               if (rc)
+                                       goto out;
+                               c->u.name[len] = 0;
+                               rc = context_read_and_validate(&c->context[0], p, fp);
+                               if (rc)
+                                       goto out;
+                               break;
+                       case OCON_NODE6: {
+                               int k;
+
+                               rc = next_entry(nodebuf, fp, sizeof(u32) * 8);
+                               if (rc)
+                                       goto out;
+                               for (k = 0; k < 4; k++)
+                                       c->u.node6.addr[k] = nodebuf[k];
+                               for (k = 0; k < 4; k++)
+                                       c->u.node6.mask[k] = nodebuf[k+4];
+                               rc = context_read_and_validate(&c->context[0], p, fp);
+                               if (rc)
+                                       goto out;
+                               break;
+                       }
+                       }
+               }
+       }
+       rc = 0;
+out:
+       return rc;
+}
+
 /*
  * Read the configuration data from a policy database binary
  * representation file into a policy database structure.
@@ -1709,16 +2046,12 @@ int policydb_read(struct policydb *p, void *fp)
 {
        struct role_allow *ra, *lra;
        struct role_trans *tr, *ltr;
-       struct ocontext *l, *c, *newc;
-       struct genfs *genfs_p, *genfs, *newgenfs;
        int i, j, rc;
        __le32 buf[4];
-       u32 nodebuf[8];
-       u32 len, len2, nprim, nel, nel2;
+       u32 len, nprim, nel;
+
        char *policydb_str;
        struct policydb_compat_info *info;
-       struct range_trans *rt;
-       struct mls_range *r;
 
        rc = policydb_init(p);
        if (rc)
@@ -1919,294 +2252,45 @@ int policydb_read(struct policydb *p, void *fp)
        if (!p->process_trans_perms)
                goto bad;
 
-       for (i = 0; i < info->ocon_num; i++) {
-               rc = next_entry(buf, fp, sizeof(u32));
-               if (rc < 0)
-                       goto bad;
-               nel = le32_to_cpu(buf[0]);
-               l = NULL;
-               for (j = 0; j < nel; j++) {
-                       c = kzalloc(sizeof(*c), GFP_KERNEL);
-                       if (!c) {
-                               rc = -ENOMEM;
-                               goto bad;
-                       }
-                       if (l)
-                               l->next = c;
-                       else
-                               p->ocontexts[i] = c;
-                       l = c;
-                       rc = -EINVAL;
-                       switch (i) {
-                       case OCON_ISID:
-                               rc = next_entry(buf, fp, sizeof(u32));
-                               if (rc < 0)
-                                       goto bad;
-                               c->sid[0] = le32_to_cpu(buf[0]);
-                               rc = context_read_and_validate(&c->context[0], p, fp);
-                               if (rc)
-                                       goto bad;
-                               break;
-                       case OCON_FS:
-                       case OCON_NETIF:
-                               rc = next_entry(buf, fp, sizeof(u32));
-                               if (rc < 0)
-                                       goto bad;
-                               len = le32_to_cpu(buf[0]);
-                               c->u.name = kmalloc(len + 1, GFP_KERNEL);
-                               if (!c->u.name) {
-                                       rc = -ENOMEM;
-                                       goto bad;
-                               }
-                               rc = next_entry(c->u.name, fp, len);
-                               if (rc < 0)
-                                       goto bad;
-                               c->u.name[len] = 0;
-                               rc = context_read_and_validate(&c->context[0], p, fp);
-                               if (rc)
-                                       goto bad;
-                               rc = context_read_and_validate(&c->context[1], p, fp);
-                               if (rc)
-                                       goto bad;
-                               break;
-                       case OCON_PORT:
-                               rc = next_entry(buf, fp, sizeof(u32)*3);
-                               if (rc < 0)
-                                       goto bad;
-                               c->u.port.protocol = le32_to_cpu(buf[0]);
-                               c->u.port.low_port = le32_to_cpu(buf[1]);
-                               c->u.port.high_port = le32_to_cpu(buf[2]);
-                               rc = context_read_and_validate(&c->context[0], p, fp);
-                               if (rc)
-                                       goto bad;
-                               break;
-                       case OCON_NODE:
-                               rc = next_entry(nodebuf, fp, sizeof(u32) * 2);
-                               if (rc < 0)
-                                       goto bad;
-                               c->u.node.addr = nodebuf[0]; /* network order */
-                               c->u.node.mask = nodebuf[1]; /* network order */
-                               rc = context_read_and_validate(&c->context[0], p, fp);
-                               if (rc)
-                                       goto bad;
-                               break;
-                       case OCON_FSUSE:
-                               rc = next_entry(buf, fp, sizeof(u32)*2);
-                               if (rc < 0)
-                                       goto bad;
-                               c->v.behavior = le32_to_cpu(buf[0]);
-                               if (c->v.behavior > SECURITY_FS_USE_NONE)
-                                       goto bad;
-                               len = le32_to_cpu(buf[1]);
-                               c->u.name = kmalloc(len + 1, GFP_KERNEL);
-                               if (!c->u.name) {
-                                       rc = -ENOMEM;
-                                       goto bad;
-                               }
-                               rc = next_entry(c->u.name, fp, len);
-                               if (rc < 0)
-                                       goto bad;
-                               c->u.name[len] = 0;
-                               rc = context_read_and_validate(&c->context[0], p, fp);
-                               if (rc)
-                                       goto bad;
-                               break;
-                       case OCON_NODE6: {
-                               int k;
-
-                               rc = next_entry(nodebuf, fp, sizeof(u32) * 8);
-                               if (rc < 0)
-                                       goto bad;
-                               for (k = 0; k < 4; k++)
-                                       c->u.node6.addr[k] = nodebuf[k];
-                               for (k = 0; k < 4; k++)
-                                       c->u.node6.mask[k] = nodebuf[k+4];
-                               if (context_read_and_validate(&c->context[0], p, fp))
-                                       goto bad;
-                               break;
-                       }
-                       }
-               }
-       }
-
-       rc = next_entry(buf, fp, sizeof(u32));
-       if (rc < 0)
+       rc = ocontext_read(p, info, fp);
+       if (rc)
                goto bad;
-       nel = le32_to_cpu(buf[0]);
-       genfs_p = NULL;
-       rc = -EINVAL;
-       for (i = 0; i < nel; i++) {
-               rc = next_entry(buf, fp, sizeof(u32));
-               if (rc < 0)
-                       goto bad;
-               len = le32_to_cpu(buf[0]);
-               newgenfs = kzalloc(sizeof(*newgenfs), GFP_KERNEL);
-               if (!newgenfs) {
-                       rc = -ENOMEM;
-                       goto bad;
-               }
 
-               newgenfs->fstype = kmalloc(len + 1, GFP_KERNEL);
-               if (!newgenfs->fstype) {
-                       rc = -ENOMEM;
-                       kfree(newgenfs);
-                       goto bad;
-               }
-               rc = next_entry(newgenfs->fstype, fp, len);
-               if (rc < 0) {
-                       kfree(newgenfs->fstype);
-                       kfree(newgenfs);
-                       goto bad;
-               }
-               newgenfs->fstype[len] = 0;
-               for (genfs_p = NULL, genfs = p->genfs; genfs;
-                    genfs_p = genfs, genfs = genfs->next) {
-                       if (strcmp(newgenfs->fstype, genfs->fstype) == 0) {
-                               printk(KERN_ERR "SELinux:  dup genfs "
-                                      "fstype %s\n", newgenfs->fstype);
-                               kfree(newgenfs->fstype);
-                               kfree(newgenfs);
-                               goto bad;
-                       }
-                       if (strcmp(newgenfs->fstype, genfs->fstype) < 0)
-                               break;
-               }
-               newgenfs->next = genfs;
-               if (genfs_p)
-                       genfs_p->next = newgenfs;
-               else
-                       p->genfs = newgenfs;
-               rc = next_entry(buf, fp, sizeof(u32));
-               if (rc < 0)
-                       goto bad;
-               nel2 = le32_to_cpu(buf[0]);
-               for (j = 0; j < nel2; j++) {
-                       rc = next_entry(buf, fp, sizeof(u32));
-                       if (rc < 0)
-                               goto bad;
-                       len = le32_to_cpu(buf[0]);
-
-                       newc = kzalloc(sizeof(*newc), GFP_KERNEL);
-                       if (!newc) {
-                               rc = -ENOMEM;
-                               goto bad;
-                       }
-
-                       newc->u.name = kmalloc(len + 1, GFP_KERNEL);
-                       if (!newc->u.name) {
-                               rc = -ENOMEM;
-                               goto bad_newc;
-                       }
-                       rc = next_entry(newc->u.name, fp, len);
-                       if (rc < 0)
-                               goto bad_newc;
-                       newc->u.name[len] = 0;
-                       rc = next_entry(buf, fp, sizeof(u32));
-                       if (rc < 0)
-                               goto bad_newc;
-                       newc->v.sclass = le32_to_cpu(buf[0]);
-                       if (context_read_and_validate(&newc->context[0], p, fp))
-                               goto bad_newc;
-                       for (l = NULL, c = newgenfs->head; c;
-                            l = c, c = c->next) {
-                               if (!strcmp(newc->u.name, c->u.name) &&
-                                   (!c->v.sclass || !newc->v.sclass ||
-                                    newc->v.sclass == c->v.sclass)) {
-                                       printk(KERN_ERR "SELinux:  dup genfs "
-                                              "entry (%s,%s)\n",
-                                              newgenfs->fstype, c->u.name);
-                                       goto bad_newc;
-                               }
-                               len = strlen(newc->u.name);
-                               len2 = strlen(c->u.name);
-                               if (len > len2)
-                                       break;
-                       }
+       rc = genfs_read(p, fp);
+       if (rc)
+               goto bad;
 
-                       newc->next = c;
-                       if (l)
-                               l->next = newc;
-                       else
-                               newgenfs->head = newc;
-               }
-       }
+       rc = range_read(p, fp);
+       if (rc)
+               goto bad;
 
-       if (p->policyvers >= POLICYDB_VERSION_MLS) {
-               int new_rangetr = p->policyvers >= POLICYDB_VERSION_RANGETRANS;
-               rc = next_entry(buf, fp, sizeof(u32));
-               if (rc < 0)
-                       goto bad;
-               nel = le32_to_cpu(buf[0]);
-               for (i = 0; i < nel; i++) {
-                       rt = kzalloc(sizeof(*rt), GFP_KERNEL);
-                       if (!rt) {
-                               rc = -ENOMEM;
-                               goto bad;
-                       }
-                       rc = next_entry(buf, fp, (sizeof(u32) * 2));
-                       if (rc < 0) {
-                               kfree(rt);
-                               goto bad;
-                       }
-                       rt->source_type = le32_to_cpu(buf[0]);
-                       rt->target_type = le32_to_cpu(buf[1]);
-                       if (new_rangetr) {
-                               rc = next_entry(buf, fp, sizeof(u32));
-                               if (rc < 0) {
-                                       kfree(rt);
-                                       goto bad;
-                               }
-                               rt->target_class = le32_to_cpu(buf[0]);
-                       } else
-                               rt->target_class = p->process_class;
-                       if (!policydb_type_isvalid(p, rt->source_type) ||
-                           !policydb_type_isvalid(p, rt->target_type) ||
-                           !policydb_class_isvalid(p, rt->target_class)) {
-                               kfree(rt);
-                               rc = -EINVAL;
-                               goto bad;
-                       }
-                       r = kzalloc(sizeof(*r), GFP_KERNEL);
-                       if (!r) {
-                               kfree(rt);
-                               rc = -ENOMEM;
-                               goto bad;
-                       }
-                       rc = mls_read_range_helper(r, fp);
-                       if (rc) {
-                               kfree(rt);
-                               kfree(r);
-                               goto bad;
-                       }
-                       if (!mls_range_isvalid(p, r)) {
-                               printk(KERN_WARNING "SELinux:  rangetrans:  invalid range\n");
-                               kfree(rt);
-                               kfree(r);
-                               goto bad;
-                       }
-                       rc = hashtab_insert(p->range_tr, rt, r);
-                       if (rc) {
-                               kfree(rt);
-                               kfree(r);
-                               goto bad;
-                       }
-               }
-               rangetr_hash_eval(p->range_tr);
-       }
+       rc = -ENOMEM;
+       p->type_attr_map_array = flex_array_alloc(sizeof(struct ebitmap),
+                                                 p->p_types.nprim,
+                                                 GFP_KERNEL | __GFP_ZERO);
+       if (!p->type_attr_map_array)
+               goto bad;
 
-       p->type_attr_map = kmalloc(p->p_types.nprim * sizeof(struct ebitmap), GFP_KERNEL);
-       if (!p->type_attr_map)
+       /* preallocate so we don't have to worry about the put ever failing */
+       rc = flex_array_prealloc(p->type_attr_map_array, 0, p->p_types.nprim - 1,
+                                GFP_KERNEL | __GFP_ZERO);
+       if (rc)
                goto bad;
 
        for (i = 0; i < p->p_types.nprim; i++) {
-               ebitmap_init(&p->type_attr_map[i]);
+               struct ebitmap *e = flex_array_get(p->type_attr_map_array, i);
+
+               BUG_ON(!e);
+               ebitmap_init(e);
                if (p->policyvers >= POLICYDB_VERSION_AVTAB) {
-                       if (ebitmap_read(&p->type_attr_map[i], fp))
+                       rc = ebitmap_read(e, fp);
+                       if (rc)
                                goto bad;
                }
                /* add the type itself as the degenerate case */
-               if (ebitmap_set_bit(&p->type_attr_map[i], i, 1))
-                               goto bad;
+               rc = ebitmap_set_bit(e, i, 1);
+               if (rc)
+                       goto bad;
        }
 
        rc = policydb_bounds_sanity_check(p);
@@ -2216,8 +2300,6 @@ int policydb_read(struct policydb *p, void *fp)
        rc = 0;
 out:
        return rc;
-bad_newc:
-       ocontext_destroy(newc, OCON_FSUSE);
 bad:
        if (!rc)
                rc = -EINVAL;
index 26d9adf8542b313982df291d6357d04415192b03..310e94442cb8b3535a8774b952de45ba0180794e 100644 (file)
@@ -24,6 +24,8 @@
 #ifndef _SS_POLICYDB_H_
 #define _SS_POLICYDB_H_
 
+#include <linux/flex_array.h>
+
 #include "symtab.h"
 #include "avtab.h"
 #include "sidtab.h"
@@ -246,7 +248,7 @@ struct policydb {
        struct hashtab *range_tr;
 
        /* type -> attribute reverse mapping */
-       struct ebitmap *type_attr_map;
+       struct flex_array *type_attr_map_array;
 
        struct ebitmap policycaps;
 
index 1de60ce90d9a237cd4cbfda6a4a34adb6c1de618..9ea2feca3cd4f7b572361543fdf1b265002cecfb 100644 (file)
@@ -50,6 +50,7 @@
 #include <linux/audit.h>
 #include <linux/mutex.h>
 #include <linux/selinux.h>
+#include <linux/flex_array.h>
 #include <net/netlabel.h>
 
 #include "flask.h"
@@ -626,8 +627,10 @@ static void context_struct_compute_av(struct context *scontext,
         */
        avkey.target_class = tclass;
        avkey.specified = AVTAB_AV;
-       sattr = &policydb.type_attr_map[scontext->type - 1];
-       tattr = &policydb.type_attr_map[tcontext->type - 1];
+       sattr = flex_array_get(policydb.type_attr_map_array, scontext->type - 1);
+       BUG_ON(!sattr);
+       tattr = flex_array_get(policydb.type_attr_map_array, tcontext->type - 1);
+       BUG_ON(!tattr);
        ebitmap_for_each_positive_bit(sattr, snode, i) {
                ebitmap_for_each_positive_bit(tattr, tnode, j) {
                        avkey.source_type = i + 1;
index bcf9f620426e04dfd102895bcf89b7f5d6b761bc..160326ee99e58b0d47388dcb98493a7d1bb0905f 100644 (file)
@@ -36,7 +36,7 @@ int symtab_init(struct symtab *s, unsigned int size)
 {
        s->table = hashtab_create(symhash, symcmp, size);
        if (!s->table)
-               return -1;
+               return -ENOMEM;
        s->nprim = 0;
        return 0;
 }
index c6e9acae72e4b74b9e75f037845e54b61fce6163..43ae747a5aa4e60746fdc7cdb15ec5cd3bb42b52 100644 (file)
@@ -123,16 +123,6 @@ struct smack_known {
 #define SMK_FSHAT      "smackfshat="
 #define SMK_FSROOT     "smackfsroot="
 
-/*
- * xattr names
- */
-#define XATTR_SMACK_SUFFIX     "SMACK64"
-#define XATTR_SMACK_IPIN       "SMACK64IPIN"
-#define XATTR_SMACK_IPOUT      "SMACK64IPOUT"
-#define XATTR_NAME_SMACK       XATTR_SECURITY_PREFIX XATTR_SMACK_SUFFIX
-#define XATTR_NAME_SMACKIPIN   XATTR_SECURITY_PREFIX XATTR_SMACK_IPIN
-#define XATTR_NAME_SMACKIPOUT  XATTR_SECURITY_PREFIX XATTR_SMACK_IPOUT
-
 #define SMACK_CIPSO_OPTION     "-CIPSO"
 
 /*
index 0f2fc480fc612f08e9701d319018efad76ded438..9192ba366a4c90971c11ed25904ee9bc7e4d675d 100644 (file)
@@ -598,6 +598,8 @@ static int smack_inode_rename(struct inode *old_inode,
 static int smack_inode_permission(struct inode *inode, int mask)
 {
        struct smk_audit_info ad;
+
+       mask &= (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND);
        /*
         * No permission to check. Existence test. Yup, it's there.
         */
@@ -2191,7 +2193,7 @@ static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
 
 /**
  * smack_d_instantiate - Make sure the blob is correct on an inode
- * @opt_dentry: unused
+ * @opt_dentry: dentry where inode will be attached
  * @inode: the object
  *
  * Set the inode's security blob if it hasn't been done already.
@@ -2310,20 +2312,10 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
                /*
                 * Get the dentry for xattr.
                 */
-               if (opt_dentry == NULL) {
-                       dp = d_find_alias(inode);
-                       if (dp == NULL)
-                               break;
-               } else {
-                       dp = dget(opt_dentry);
-                       if (dp == NULL)
-                               break;
-               }
-
+               dp = dget(opt_dentry);
                fetched = smk_fetch(inode, dp);
                if (fetched != NULL)
                        final = fetched;
-
                dput(dp);
                break;
        }
index 4fb39030f6bd196e3d8f0b9aa64c7120dead18ec..91640e96bd065776af1ffeffa23f06b5208ff368 100644 (file)
@@ -1 +1 @@
-obj-y = common.o realpath.o tomoyo.o domain.o file.o gc.o path_group.o
+obj-y = common.o domain.o file.o gc.o group.o load_policy.o memory.o mount.o realpath.o securityfs_if.o tomoyo.o util.o
index b5dbdc9ff73c944b7ecd0583fa786c3d29f72726..ef43995119a453401dd768adfa5ae41a2602dd3a 100644 (file)
  *
  * Common functions for TOMOYO.
  *
- * Copyright (C) 2005-2009  NTT DATA CORPORATION
- *
- * Version: 2.2.0   2009/04/01
- *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
  */
 
 #include <linux/uaccess.h>
 #include <linux/slab.h>
 #include <linux/security.h>
-#include <linux/hardirq.h>
 #include "common.h"
 
-/* Lock for protecting policy. */
-DEFINE_MUTEX(tomoyo_policy_lock);
+static struct tomoyo_profile tomoyo_default_profile = {
+       .learning = &tomoyo_default_profile.preference,
+       .permissive = &tomoyo_default_profile.preference,
+       .enforcing = &tomoyo_default_profile.preference,
+       .preference.enforcing_verbose = true,
+       .preference.learning_max_entry = 2048,
+       .preference.learning_verbose = false,
+       .preference.permissive_verbose = true
+};
 
-/* Has loading policy done? */
-bool tomoyo_policy_loaded;
+/* Profile version. Currently only 20090903 is defined. */
+static unsigned int tomoyo_profile_version;
+
+/* Profile table. Memory is allocated as needed. */
+static struct tomoyo_profile *tomoyo_profile_ptr[TOMOYO_MAX_PROFILES];
 
 /* String table for functionality that takes 4 modes. */
-static const char *tomoyo_mode_4[4] = {
+static const char *tomoyo_mode[4] = {
        "disabled", "learning", "permissive", "enforcing"
 };
-/* String table for functionality that takes 2 modes. */
-static const char *tomoyo_mode_2[4] = {
-       "disabled", "enabled", "enabled", "enabled"
-};
 
-/*
- * tomoyo_control_array is a static data which contains
- *
- *  (1) functionality name used by /sys/kernel/security/tomoyo/profile .
- *  (2) initial values for "struct tomoyo_profile".
- *  (3) max values for "struct tomoyo_profile".
- */
-static struct {
-       const char *keyword;
-       unsigned int current_value;
-       const unsigned int max_value;
-} tomoyo_control_array[TOMOYO_MAX_CONTROL_INDEX] = {
-       [TOMOYO_MAC_FOR_FILE]     = { "MAC_FOR_FILE",        0,       3 },
-       [TOMOYO_MAX_ACCEPT_ENTRY] = { "MAX_ACCEPT_ENTRY", 2048, INT_MAX },
-       [TOMOYO_VERBOSE]          = { "TOMOYO_VERBOSE",      1,       1 },
+/* String table for /sys/kernel/security/tomoyo/profile */
+static const char *tomoyo_mac_keywords[TOMOYO_MAX_MAC_INDEX
+                                      + TOMOYO_MAX_MAC_CATEGORY_INDEX] = {
+       [TOMOYO_MAC_FILE_EXECUTE]    = "file::execute",
+       [TOMOYO_MAC_FILE_OPEN]       = "file::open",
+       [TOMOYO_MAC_FILE_CREATE]     = "file::create",
+       [TOMOYO_MAC_FILE_UNLINK]     = "file::unlink",
+       [TOMOYO_MAC_FILE_MKDIR]      = "file::mkdir",
+       [TOMOYO_MAC_FILE_RMDIR]      = "file::rmdir",
+       [TOMOYO_MAC_FILE_MKFIFO]     = "file::mkfifo",
+       [TOMOYO_MAC_FILE_MKSOCK]     = "file::mksock",
+       [TOMOYO_MAC_FILE_TRUNCATE]   = "file::truncate",
+       [TOMOYO_MAC_FILE_SYMLINK]    = "file::symlink",
+       [TOMOYO_MAC_FILE_REWRITE]    = "file::rewrite",
+       [TOMOYO_MAC_FILE_MKBLOCK]    = "file::mkblock",
+       [TOMOYO_MAC_FILE_MKCHAR]     = "file::mkchar",
+       [TOMOYO_MAC_FILE_LINK]       = "file::link",
+       [TOMOYO_MAC_FILE_RENAME]     = "file::rename",
+       [TOMOYO_MAC_FILE_CHMOD]      = "file::chmod",
+       [TOMOYO_MAC_FILE_CHOWN]      = "file::chown",
+       [TOMOYO_MAC_FILE_CHGRP]      = "file::chgrp",
+       [TOMOYO_MAC_FILE_IOCTL]      = "file::ioctl",
+       [TOMOYO_MAC_FILE_CHROOT]     = "file::chroot",
+       [TOMOYO_MAC_FILE_MOUNT]      = "file::mount",
+       [TOMOYO_MAC_FILE_UMOUNT]     = "file::umount",
+       [TOMOYO_MAC_FILE_PIVOT_ROOT] = "file::pivot_root",
+       [TOMOYO_MAX_MAC_INDEX + TOMOYO_MAC_CATEGORY_FILE] = "file",
 };
 
-/*
- * tomoyo_profile is a structure which is used for holding the mode of access
- * controls. TOMOYO has 4 modes: disabled, learning, permissive, enforcing.
- * An administrator can define up to 256 profiles.
- * The ->profile of "struct tomoyo_domain_info" is used for remembering
- * the profile's number (0 - 255) assigned to that domain.
- */
-static struct tomoyo_profile {
-       unsigned int value[TOMOYO_MAX_CONTROL_INDEX];
-       const struct tomoyo_path_info *comment;
-} *tomoyo_profile_ptr[TOMOYO_MAX_PROFILES];
-
 /* Permit policy management by non-root user? */
 static bool tomoyo_manage_by_non_root;
 
 /* Utility functions. */
 
-/* Open operation for /sys/kernel/security/tomoyo/ interface. */
-static int tomoyo_open_control(const u8 type, struct file *file);
-/* Close /sys/kernel/security/tomoyo/ interface. */
-static int tomoyo_close_control(struct file *file);
-/* Read operation for /sys/kernel/security/tomoyo/ interface. */
-static int tomoyo_read_control(struct file *file, char __user *buffer,
-                              const int buffer_len);
-/* Write operation for /sys/kernel/security/tomoyo/ interface. */
-static int tomoyo_write_control(struct file *file, const char __user *buffer,
-                               const int buffer_len);
-
-/**
- * tomoyo_parse_name_union - Parse a tomoyo_name_union.
- *
- * @filename: Name or name group.
- * @ptr:      Pointer to "struct tomoyo_name_union".
- *
- * Returns true on success, false otherwise.
- */
-bool tomoyo_parse_name_union(const char *filename,
-                            struct tomoyo_name_union *ptr)
-{
-       if (!tomoyo_is_correct_path(filename, 0, 0, 0))
-               return false;
-       if (filename[0] == '@') {
-               ptr->group = tomoyo_get_path_group(filename + 1);
-               ptr->is_group = true;
-               return ptr->group != NULL;
-       }
-       ptr->filename = tomoyo_get_name(filename);
-       ptr->is_group = false;
-       return ptr->filename != NULL;
-}
-
 /**
- * tomoyo_print_name_union - Print a tomoyo_name_union.
+ * tomoyo_yesno - Return "yes" or "no".
  *
- * @head: Pointer to "struct tomoyo_io_buffer".
- * @ptr:  Pointer to "struct tomoyo_name_union".
- *
- * Returns true on success, false otherwise.
+ * @value: Bool value.
  */
-static bool tomoyo_print_name_union(struct tomoyo_io_buffer *head,
-                                const struct tomoyo_name_union *ptr)
+static const char *tomoyo_yesno(const unsigned int value)
 {
-       int pos = head->read_avail;
-       if (pos && head->read_buf[pos - 1] == ' ')
-               head->read_avail--;
-       if (ptr->is_group)
-               return tomoyo_io_printf(head, " @%s",
-                                       ptr->group->group_name->name);
-       return tomoyo_io_printf(head, " %s", ptr->filename->name);
+       return value ? "yes" : "no";
 }
 
-/**
- * tomoyo_is_byte_range - Check whether the string isa \ooo style octal value.
- *
- * @str: Pointer to the string.
- *
- * Returns true if @str is a \ooo style octal value, false otherwise.
- *
- * TOMOYO uses \ooo style representation for 0x01 - 0x20 and 0x7F - 0xFF.
- * This function verifies that \ooo is in valid range.
- */
-static inline bool tomoyo_is_byte_range(const char *str)
+static void tomoyo_addprintf(char *buffer, int len, const char *fmt, ...)
 {
-       return *str >= '0' && *str++ <= '3' &&
-               *str >= '0' && *str++ <= '7' &&
-               *str >= '0' && *str <= '7';
-}
-
-/**
- * tomoyo_is_alphabet_char - Check whether the character is an alphabet.
- *
- * @c: The character to check.
- *
- * Returns true if @c is an alphabet character, false otherwise.
- */
-static inline bool tomoyo_is_alphabet_char(const char c)
-{
-       return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
-}
-
-/**
- * tomoyo_make_byte - Make byte value from three octal characters.
- *
- * @c1: The first character.
- * @c2: The second character.
- * @c3: The third character.
- *
- * Returns byte value.
- */
-static inline u8 tomoyo_make_byte(const u8 c1, const u8 c2, const u8 c3)
-{
-       return ((c1 - '0') << 6) + ((c2 - '0') << 3) + (c3 - '0');
+       va_list args;
+       const int pos = strlen(buffer);
+       va_start(args, fmt);
+       vsnprintf(buffer + pos, len - pos - 1, fmt, args);
+       va_end(args);
 }
 
 /**
- * tomoyo_str_starts - Check whether the given string starts with the given keyword.
- *
- * @src:  Pointer to pointer to the string.
- * @find: Pointer to the keyword.
+ * tomoyo_flush - Flush queued string to userspace's buffer.
  *
- * Returns true if @src starts with @find, false otherwise.
+ * @head:   Pointer to "struct tomoyo_io_buffer".
  *
- * The @src is updated to point the first character after the @find
- * if @src starts with @find.
+ * Returns true if all data was flushed, false otherwise.
  */
-static bool tomoyo_str_starts(char **src, const char *find)
+static bool tomoyo_flush(struct tomoyo_io_buffer *head)
 {
-       const int len = strlen(find);
-       char *tmp = *src;
-
-       if (strncmp(tmp, find, len))
-               return false;
-       tmp += len;
-       *src = tmp;
+       while (head->r.w_pos) {
+               const char *w = head->r.w[0];
+               int len = strlen(w);
+               if (len) {
+                       if (len > head->read_user_buf_avail)
+                               len = head->read_user_buf_avail;
+                       if (!len)
+                               return false;
+                       if (copy_to_user(head->read_user_buf, w, len))
+                               return false;
+                       head->read_user_buf_avail -= len;
+                       head->read_user_buf += len;
+                       w += len;
+               }
+               if (*w) {
+                       head->r.w[0] = w;
+                       return false;
+               }
+               /* Add '\0' for query. */
+               if (head->poll) {
+                       if (!head->read_user_buf_avail ||
+                           copy_to_user(head->read_user_buf, "", 1))
+                               return false;
+                       head->read_user_buf_avail--;
+                       head->read_user_buf++;
+               }
+               head->r.w_pos--;
+               for (len = 0; len < head->r.w_pos; len++)
+                       head->r.w[len] = head->r.w[len + 1];
+       }
+       head->r.avail = 0;
        return true;
 }
 
 /**
- * tomoyo_normalize_line - Format string.
- *
- * @buffer: The line to normalize.
+ * tomoyo_set_string - Queue string to "struct tomoyo_io_buffer" structure.
  *
- * Leading and trailing whitespaces are removed.
- * Multiple whitespaces are packed into single space.
+ * @head:   Pointer to "struct tomoyo_io_buffer".
+ * @string: String to print.
  *
- * Returns nothing.
+ * Note that @string has to be kept valid until @head is kfree()d.
+ * This means that char[] allocated on stack memory cannot be passed to
+ * this function. Use tomoyo_io_printf() for char[] allocated on stack memory.
  */
-static void tomoyo_normalize_line(unsigned char *buffer)
+static void tomoyo_set_string(struct tomoyo_io_buffer *head, const char *string)
 {
-       unsigned char *sp = buffer;
-       unsigned char *dp = buffer;
-       bool first = true;
-
-       while (tomoyo_is_invalid(*sp))
-               sp++;
-       while (*sp) {
-               if (!first)
-                       *dp++ = ' ';
-               first = false;
-               while (tomoyo_is_valid(*sp))
-                       *dp++ = *sp++;
-               while (tomoyo_is_invalid(*sp))
-                       sp++;
-       }
-       *dp = '\0';
+       if (head->r.w_pos < TOMOYO_MAX_IO_READ_QUEUE) {
+               head->r.w[head->r.w_pos++] = string;
+               tomoyo_flush(head);
+       } else
+               WARN_ON(1);
 }
 
 /**
- * tomoyo_tokenize - Tokenize string.
+ * tomoyo_io_printf - printf() to "struct tomoyo_io_buffer" structure.
  *
- * @buffer: The line to tokenize.
- * @w:      Pointer to "char *".
- * @size:   Sizeof @w .
- *
- * Returns true on success, false otherwise.
- */
-bool tomoyo_tokenize(char *buffer, char *w[], size_t size)
-{
-       int count = size / sizeof(char *);
-       int i;
-       for (i = 0; i < count; i++)
-               w[i] = "";
-       for (i = 0; i < count; i++) {
-               char *cp = strchr(buffer, ' ');
-               if (cp)
-                       *cp = '\0';
-               w[i] = buffer;
-               if (!cp)
-                       break;
-               buffer = cp + 1;
-       }
-       return i < count || !*buffer;
-}
-
-/**
- * tomoyo_is_correct_path - Validate a pathname.
- * @filename:     The pathname to check.
- * @start_type:   Should the pathname start with '/'?
- *                1 = must / -1 = must not / 0 = don't care
- * @pattern_type: Can the pathname contain a wildcard?
- *                1 = must / -1 = must not / 0 = don't care
- * @end_type:     Should the pathname end with '/'?
- *                1 = must / -1 = must not / 0 = don't care
- *
- * Check whether the given filename follows the naming rules.
- * Returns true if @filename follows the naming rules, false otherwise.
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ * @fmt:  The printf()'s format string, followed by parameters.
  */
-bool tomoyo_is_correct_path(const char *filename, const s8 start_type,
-                           const s8 pattern_type, const s8 end_type)
+void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
 {
-       const char *const start = filename;
-       bool in_repetition = false;
-       bool contains_pattern = false;
-       unsigned char c;
-       unsigned char d;
-       unsigned char e;
-
-       if (!filename)
-               goto out;
-       c = *filename;
-       if (start_type == 1) { /* Must start with '/' */
-               if (c != '/')
-                       goto out;
-       } else if (start_type == -1) { /* Must not start with '/' */
-               if (c == '/')
-                       goto out;
-       }
-       if (c)
-               c = *(filename + strlen(filename) - 1);
-       if (end_type == 1) { /* Must end with '/' */
-               if (c != '/')
-                       goto out;
-       } else if (end_type == -1) { /* Must not end with '/' */
-               if (c == '/')
-                       goto out;
-       }
-       while (1) {
-               c = *filename++;
-               if (!c)
-                       break;
-               if (c == '\\') {
-                       c = *filename++;
-                       switch (c) {
-                       case '\\':  /* "\\" */
-                               continue;
-                       case '$':   /* "\$" */
-                       case '+':   /* "\+" */
-                       case '?':   /* "\?" */
-                       case '*':   /* "\*" */
-                       case '@':   /* "\@" */
-                       case 'x':   /* "\x" */
-                       case 'X':   /* "\X" */
-                       case 'a':   /* "\a" */
-                       case 'A':   /* "\A" */
-                       case '-':   /* "\-" */
-                               if (pattern_type == -1)
-                                       break; /* Must not contain pattern */
-                               contains_pattern = true;
-                               continue;
-                       case '{':   /* "/\{" */
-                               if (filename - 3 < start ||
-                                   *(filename - 3) != '/')
-                                       break;
-                               if (pattern_type == -1)
-                                       break; /* Must not contain pattern */
-                               contains_pattern = true;
-                               in_repetition = true;
-                               continue;
-                       case '}':   /* "\}/" */
-                               if (*filename != '/')
-                                       break;
-                               if (!in_repetition)
-                                       break;
-                               in_repetition = false;
-                               continue;
-                       case '0':   /* "\ooo" */
-                       case '1':
-                       case '2':
-                       case '3':
-                               d = *filename++;
-                               if (d < '0' || d > '7')
-                                       break;
-                               e = *filename++;
-                               if (e < '0' || e > '7')
-                                       break;
-                               c = tomoyo_make_byte(c, d, e);
-                               if (tomoyo_is_invalid(c))
-                                       continue; /* pattern is not \000 */
-                       }
-                       goto out;
-               } else if (in_repetition && c == '/') {
-                       goto out;
-               } else if (tomoyo_is_invalid(c)) {
-                       goto out;
-               }
-       }
-       if (pattern_type == 1) { /* Must contain pattern */
-               if (!contains_pattern)
-                       goto out;
+       va_list args;
+       int len;
+       int pos = head->r.avail;
+       int size = head->readbuf_size - pos;
+       if (size <= 0)
+               return;
+       va_start(args, fmt);
+       len = vsnprintf(head->read_buf + pos, size, fmt, args) + 1;
+       va_end(args);
+       if (pos + len >= head->readbuf_size) {
+               WARN_ON(1);
+               return;
        }
-       if (in_repetition)
-               goto out;
-       return true;
- out:
-       return false;
+       head->r.avail += len;
+       tomoyo_set_string(head, head->read_buf + pos);
 }
 
-/**
- * tomoyo_is_correct_domain - Check whether the given domainname follows the naming rules.
- * @domainname:   The domainname to check.
- *
- * Returns true if @domainname follows the naming rules, false otherwise.
- */
-bool tomoyo_is_correct_domain(const unsigned char *domainname)
+static void tomoyo_set_space(struct tomoyo_io_buffer *head)
 {
-       unsigned char c;
-       unsigned char d;
-       unsigned char e;
-
-       if (!domainname || strncmp(domainname, TOMOYO_ROOT_NAME,
-                                  TOMOYO_ROOT_NAME_LEN))
-               goto out;
-       domainname += TOMOYO_ROOT_NAME_LEN;
-       if (!*domainname)
-               return true;
-       do {
-               if (*domainname++ != ' ')
-                       goto out;
-               if (*domainname++ != '/')
-                       goto out;
-               while ((c = *domainname) != '\0' && c != ' ') {
-                       domainname++;
-                       if (c == '\\') {
-                               c = *domainname++;
-                               switch ((c)) {
-                               case '\\':  /* "\\" */
-                                       continue;
-                               case '0':   /* "\ooo" */
-                               case '1':
-                               case '2':
-                               case '3':
-                                       d = *domainname++;
-                                       if (d < '0' || d > '7')
-                                               break;
-                                       e = *domainname++;
-                                       if (e < '0' || e > '7')
-                                               break;
-                                       c = tomoyo_make_byte(c, d, e);
-                                       if (tomoyo_is_invalid(c))
-                                               /* pattern is not \000 */
-                                               continue;
-                               }
-                               goto out;
-                       } else if (tomoyo_is_invalid(c)) {
-                               goto out;
-                       }
-               }
-       } while (*domainname);
-       return true;
- out:
-       return false;
+       tomoyo_set_string(head, " ");
 }
 
-/**
- * tomoyo_is_domain_def - Check whether the given token can be a domainname.
- *
- * @buffer: The token to check.
- *
- * Returns true if @buffer possibly be a domainname, false otherwise.
- */
-bool tomoyo_is_domain_def(const unsigned char *buffer)
+static bool tomoyo_set_lf(struct tomoyo_io_buffer *head)
 {
-       return !strncmp(buffer, TOMOYO_ROOT_NAME, TOMOYO_ROOT_NAME_LEN);
+       tomoyo_set_string(head, "\n");
+       return !head->r.w_pos;
 }
 
 /**
- * tomoyo_find_domain - Find a domain by the given name.
- *
- * @domainname: The domainname to find.
- *
- * Returns pointer to "struct tomoyo_domain_info" if found, NULL otherwise.
+ * tomoyo_print_name_union - Print a tomoyo_name_union.
  *
- * Caller holds tomoyo_read_lock().
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ * @ptr:  Pointer to "struct tomoyo_name_union".
  */
-struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname)
+static void tomoyo_print_name_union(struct tomoyo_io_buffer *head,
+                                   const struct tomoyo_name_union *ptr)
 {
-       struct tomoyo_domain_info *domain;
-       struct tomoyo_path_info name;
-
-       name.name = domainname;
-       tomoyo_fill_path_info(&name);
-       list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
-               if (!domain->is_deleted &&
-                   !tomoyo_pathcmp(&name, domain->domainname))
-                       return domain;
+       tomoyo_set_space(head);
+       if (ptr->is_group) {
+               tomoyo_set_string(head, "@");
+               tomoyo_set_string(head, ptr->group->group_name->name);
+       } else {
+               tomoyo_set_string(head, ptr->filename->name);
        }
-       return NULL;
 }
 
 /**
- * tomoyo_const_part_length - Evaluate the initial length without a pattern in a token.
+ * tomoyo_print_number_union - Print a tomoyo_number_union.
  *
- * @filename: The string to evaluate.
- *
- * Returns the initial length without a pattern in @filename.
+ * @head:       Pointer to "struct tomoyo_io_buffer".
+ * @ptr:        Pointer to "struct tomoyo_number_union".
  */
-static int tomoyo_const_part_length(const char *filename)
+static void tomoyo_print_number_union(struct tomoyo_io_buffer *head,
+                                     const struct tomoyo_number_union *ptr)
 {
-       char c;
-       int len = 0;
-
-       if (!filename)
-               return 0;
-       while ((c = *filename++) != '\0') {
-               if (c != '\\') {
-                       len++;
-                       continue;
-               }
-               c = *filename++;
-               switch (c) {
-               case '\\':  /* "\\" */
-                       len += 2;
-                       continue;
-               case '0':   /* "\ooo" */
-               case '1':
-               case '2':
-               case '3':
-                       c = *filename++;
-                       if (c < '0' || c > '7')
+       tomoyo_set_space(head);
+       if (ptr->is_group) {
+               tomoyo_set_string(head, "@");
+               tomoyo_set_string(head, ptr->group->group_name->name);
+       } else {
+               int i;
+               unsigned long min = ptr->values[0];
+               const unsigned long max = ptr->values[1];
+               u8 min_type = ptr->min_type;
+               const u8 max_type = ptr->max_type;
+               char buffer[128];
+               buffer[0] = '\0';
+               for (i = 0; i < 2; i++) {
+                       switch (min_type) {
+                       case TOMOYO_VALUE_TYPE_HEXADECIMAL:
+                               tomoyo_addprintf(buffer, sizeof(buffer),
+                                                "0x%lX", min);
                                break;
-                       c = *filename++;
-                       if (c < '0' || c > '7')
+                       case TOMOYO_VALUE_TYPE_OCTAL:
+                               tomoyo_addprintf(buffer, sizeof(buffer),
+                                                "0%lo", min);
                                break;
-                       len += 4;
-                       continue;
-               }
-               break;
-       }
-       return len;
-}
-
-/**
- * tomoyo_fill_path_info - Fill in "struct tomoyo_path_info" members.
- *
- * @ptr: Pointer to "struct tomoyo_path_info" to fill in.
- *
- * The caller sets "struct tomoyo_path_info"->name.
- */
-void tomoyo_fill_path_info(struct tomoyo_path_info *ptr)
-{
-       const char *name = ptr->name;
-       const int len = strlen(name);
-
-       ptr->const_len = tomoyo_const_part_length(name);
-       ptr->is_dir = len && (name[len - 1] == '/');
-       ptr->is_patterned = (ptr->const_len < len);
-       ptr->hash = full_name_hash(name, len);
-}
-
-/**
- * tomoyo_file_matches_pattern2 - Pattern matching without '/' character
- * and "\-" pattern.
- *
- * @filename:     The start of string to check.
- * @filename_end: The end of string to check.
- * @pattern:      The start of pattern to compare.
- * @pattern_end:  The end of pattern to compare.
- *
- * Returns true if @filename matches @pattern, false otherwise.
- */
-static bool tomoyo_file_matches_pattern2(const char *filename,
-                                        const char *filename_end,
-                                        const char *pattern,
-                                        const char *pattern_end)
-{
-       while (filename < filename_end && pattern < pattern_end) {
-               char c;
-               if (*pattern != '\\') {
-                       if (*filename++ != *pattern++)
-                               return false;
-                       continue;
-               }
-               c = *filename;
-               pattern++;
-               switch (*pattern) {
-                       int i;
-                       int j;
-               case '?':
-                       if (c == '/') {
-                               return false;
-                       } else if (c == '\\') {
-                               if (filename[1] == '\\')
-                                       filename++;
-                               else if (tomoyo_is_byte_range(filename + 1))
-                                       filename += 3;
-                               else
-                                       return false;
-                       }
-                       break;
-               case '\\':
-                       if (c != '\\')
-                               return false;
-                       if (*++filename != '\\')
-                               return false;
-                       break;
-               case '+':
-                       if (!isdigit(c))
-                               return false;
-                       break;
-               case 'x':
-                       if (!isxdigit(c))
-                               return false;
-                       break;
-               case 'a':
-                       if (!tomoyo_is_alphabet_char(c))
-                               return false;
-                       break;
-               case '0':
-               case '1':
-               case '2':
-               case '3':
-                       if (c == '\\' && tomoyo_is_byte_range(filename + 1)
-                           && strncmp(filename + 1, pattern, 3) == 0) {
-                               filename += 3;
-                               pattern += 2;
+                       default:
+                               tomoyo_addprintf(buffer, sizeof(buffer),
+                                                "%lu", min);
                                break;
                        }
-                       return false; /* Not matched. */
-               case '*':
-               case '@':
-                       for (i = 0; i <= filename_end - filename; i++) {
-                               if (tomoyo_file_matches_pattern2(
-                                                   filename + i, filename_end,
-                                                   pattern + 1, pattern_end))
-                                       return true;
-                               c = filename[i];
-                               if (c == '.' && *pattern == '@')
-                                       break;
-                               if (c != '\\')
-                                       continue;
-                               if (filename[i + 1] == '\\')
-                                       i++;
-                               else if (tomoyo_is_byte_range(filename + i + 1))
-                                       i += 3;
-                               else
-                                       break; /* Bad pattern. */
-                       }
-                       return false; /* Not matched. */
-               default:
-                       j = 0;
-                       c = *pattern;
-                       if (c == '$') {
-                               while (isdigit(filename[j]))
-                                       j++;
-                       } else if (c == 'X') {
-                               while (isxdigit(filename[j]))
-                                       j++;
-                       } else if (c == 'A') {
-                               while (tomoyo_is_alphabet_char(filename[j]))
-                                       j++;
-                       }
-                       for (i = 1; i <= j; i++) {
-                               if (tomoyo_file_matches_pattern2(
-                                                   filename + i, filename_end,
-                                                   pattern + 1, pattern_end))
-                                       return true;
-                       }
-                       return false; /* Not matched or bad pattern. */
+                       if (min == max && min_type == max_type)
+                               break;
+                       tomoyo_addprintf(buffer, sizeof(buffer), "-");
+                       min_type = max_type;
+                       min = max;
                }
-               filename++;
-               pattern++;
+               tomoyo_io_printf(head, "%s", buffer);
        }
-       while (*pattern == '\\' &&
-              (*(pattern + 1) == '*' || *(pattern + 1) == '@'))
-               pattern += 2;
-       return filename == filename_end && pattern == pattern_end;
 }
 
 /**
- * tomoyo_file_matches_pattern - Pattern matching without without '/' character.
- *
- * @filename:     The start of string to check.
- * @filename_end: The end of string to check.
- * @pattern:      The start of pattern to compare.
- * @pattern_end:  The end of pattern to compare.
+ * tomoyo_assign_profile - Create a new profile.
  *
- * Returns true if @filename matches @pattern, false otherwise.
- */
-static bool tomoyo_file_matches_pattern(const char *filename,
-                                          const char *filename_end,
-                                          const char *pattern,
-                                          const char *pattern_end)
-{
-       const char *pattern_start = pattern;
-       bool first = true;
-       bool result;
-
-       while (pattern < pattern_end - 1) {
-               /* Split at "\-" pattern. */
-               if (*pattern++ != '\\' || *pattern++ != '-')
-                       continue;
-               result = tomoyo_file_matches_pattern2(filename,
-                                                     filename_end,
-                                                     pattern_start,
-                                                     pattern - 2);
-               if (first)
-                       result = !result;
-               if (result)
-                       return false;
-               first = false;
-               pattern_start = pattern;
-       }
-       result = tomoyo_file_matches_pattern2(filename, filename_end,
-                                             pattern_start, pattern_end);
-       return first ? result : !result;
-}
-
-/**
- * tomoyo_path_matches_pattern2 - Do pathname pattern matching.
- *
- * @f: The start of string to check.
- * @p: The start of pattern to compare.
+ * @profile: Profile number to create.
  *
- * Returns true if @f matches @p, false otherwise.
+ * Returns pointer to "struct tomoyo_profile" on success, NULL otherwise.
  */
-static bool tomoyo_path_matches_pattern2(const char *f, const char *p)
+static struct tomoyo_profile *tomoyo_assign_profile(const unsigned int profile)
 {
-       const char *f_delimiter;
-       const char *p_delimiter;
-
-       while (*f && *p) {
-               f_delimiter = strchr(f, '/');
-               if (!f_delimiter)
-                       f_delimiter = f + strlen(f);
-               p_delimiter = strchr(p, '/');
-               if (!p_delimiter)
-                       p_delimiter = p + strlen(p);
-               if (*p == '\\' && *(p + 1) == '{')
-                       goto recursive;
-               if (!tomoyo_file_matches_pattern(f, f_delimiter, p,
-                                                p_delimiter))
-                       return false;
-               f = f_delimiter;
-               if (*f)
-                       f++;
-               p = p_delimiter;
-               if (*p)
-                       p++;
+       struct tomoyo_profile *ptr;
+       struct tomoyo_profile *entry;
+       if (profile >= TOMOYO_MAX_PROFILES)
+               return NULL;
+       ptr = tomoyo_profile_ptr[profile];
+       if (ptr)
+               return ptr;
+       entry = kzalloc(sizeof(*entry), GFP_NOFS);
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               goto out;
+       ptr = tomoyo_profile_ptr[profile];
+       if (!ptr && tomoyo_memory_ok(entry)) {
+               ptr = entry;
+               ptr->learning = &tomoyo_default_profile.preference;
+               ptr->permissive = &tomoyo_default_profile.preference;
+               ptr->enforcing = &tomoyo_default_profile.preference;
+               ptr->default_config = TOMOYO_CONFIG_DISABLED;
+               memset(ptr->config, TOMOYO_CONFIG_USE_DEFAULT,
+                      sizeof(ptr->config));
+               mb(); /* Avoid out-of-order execution. */
+               tomoyo_profile_ptr[profile] = ptr;
+               entry = NULL;
        }
-       /* Ignore trailing "\*" and "\@" in @pattern. */
-       while (*p == '\\' &&
-              (*(p + 1) == '*' || *(p + 1) == '@'))
-               p += 2;
-       return !*f && !*p;
- recursive:
-       /*
-        * The "\{" pattern is permitted only after '/' character.
-        * This guarantees that below "*(p - 1)" is safe.
-        * Also, the "\}" pattern is permitted only before '/' character
-        * so that "\{" + "\}" pair will not break the "\-" operator.
-        */
-       if (*(p - 1) != '/' || p_delimiter <= p + 3 || *p_delimiter != '/' ||
-           *(p_delimiter - 1) != '}' || *(p_delimiter - 2) != '\\')
-               return false; /* Bad pattern. */
-       do {
-               /* Compare current component with pattern. */
-               if (!tomoyo_file_matches_pattern(f, f_delimiter, p + 2,
-                                                p_delimiter - 2))
-                       break;
-               /* Proceed to next component. */
-               f = f_delimiter;
-               if (!*f)
-                       break;
-               f++;
-               /* Continue comparison. */
-               if (tomoyo_path_matches_pattern2(f, p_delimiter + 1))
-                       return true;
-               f_delimiter = strchr(f, '/');
-       } while (f_delimiter);
-       return false; /* Not matched. */
-}
-
-/**
- * tomoyo_path_matches_pattern - Check whether the given filename matches the given pattern.
- *
- * @filename: The filename to check.
- * @pattern:  The pattern to compare.
- *
- * Returns true if matches, false otherwise.
- *
- * The following patterns are available.
- *   \\     \ itself.
- *   \ooo   Octal representation of a byte.
- *   \*     Zero or more repetitions of characters other than '/'.
- *   \@     Zero or more repetitions of characters other than '/' or '.'.
- *   \?     1 byte character other than '/'.
- *   \$     One or more repetitions of decimal digits.
- *   \+     1 decimal digit.
- *   \X     One or more repetitions of hexadecimal digits.
- *   \x     1 hexadecimal digit.
- *   \A     One or more repetitions of alphabet characters.
- *   \a     1 alphabet character.
- *
- *   \-     Subtraction operator.
- *
- *   /\{dir\}/   '/' + 'One or more repetitions of dir/' (e.g. /dir/ /dir/dir/
- *               /dir/dir/dir/ ).
- */
-bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
-                                const struct tomoyo_path_info *pattern)
-{
-       const char *f = filename->name;
-       const char *p = pattern->name;
-       const int len = pattern->const_len;
-
-       /* If @pattern doesn't contain pattern, I can use strcmp(). */
-       if (!pattern->is_patterned)
-               return !tomoyo_pathcmp(filename, pattern);
-       /* Don't compare directory and non-directory. */
-       if (filename->is_dir != pattern->is_dir)
-               return false;
-       /* Compare the initial length without patterns. */
-       if (strncmp(f, p, len))
-               return false;
-       f += len;
-       p += len;
-       return tomoyo_path_matches_pattern2(f, p);
+       mutex_unlock(&tomoyo_policy_lock);
+ out:
+       kfree(entry);
+       return ptr;
 }
 
 /**
- * tomoyo_io_printf - Transactional printf() to "struct tomoyo_io_buffer" structure.
- *
- * @head: Pointer to "struct tomoyo_io_buffer".
- * @fmt:  The printf()'s format string, followed by parameters.
+ * tomoyo_profile - Find a profile.
  *
- * Returns true if output was written, false otherwise.
+ * @profile: Profile number to find.
  *
- * The snprintf() will truncate, but tomoyo_io_printf() won't.
+ * Returns pointer to "struct tomoyo_profile".
  */
-bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
+struct tomoyo_profile *tomoyo_profile(const u8 profile)
 {
-       va_list args;
-       int len;
-       int pos = head->read_avail;
-       int size = head->readbuf_size - pos;
-
-       if (size <= 0)
-               return false;
-       va_start(args, fmt);
-       len = vsnprintf(head->read_buf + pos, size, fmt, args);
-       va_end(args);
-       if (pos + len >= head->readbuf_size)
-               return false;
-       head->read_avail += len;
-       return true;
+       struct tomoyo_profile *ptr = tomoyo_profile_ptr[profile];
+       if (!tomoyo_policy_loaded)
+               return &tomoyo_default_profile;
+       BUG_ON(!ptr);
+       return ptr;
 }
 
-/**
- * tomoyo_get_exe - Get tomoyo_realpath() of current process.
- *
- * Returns the tomoyo_realpath() of current process on success, NULL otherwise.
- *
- * This function uses kzalloc(), so the caller must call kfree()
- * if this function didn't return NULL.
- */
-static const char *tomoyo_get_exe(void)
+static s8 tomoyo_find_yesno(const char *string, const char *find)
 {
-       struct mm_struct *mm = current->mm;
-       struct vm_area_struct *vma;
-       const char *cp = NULL;
-
-       if (!mm)
-               return NULL;
-       down_read(&mm->mmap_sem);
-       for (vma = mm->mmap; vma; vma = vma->vm_next) {
-               if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) {
-                       cp = tomoyo_realpath_from_path(&vma->vm_file->f_path);
-                       break;
-               }
+       const char *cp = strstr(string, find);
+       if (cp) {
+               cp += strlen(find);
+               if (!strncmp(cp, "=yes", 4))
+                       return 1;
+               else if (!strncmp(cp, "=no", 3))
+                       return 0;
        }
-       up_read(&mm->mmap_sem);
-       return cp;
+       return -1;
 }
 
-/**
- * tomoyo_get_msg - Get warning message.
- *
- * @is_enforce: Is it enforcing mode?
- *
- * Returns "ERROR" or "WARNING".
- */
-const char *tomoyo_get_msg(const bool is_enforce)
+static void tomoyo_set_bool(bool *b, const char *string, const char *find)
 {
-       if (is_enforce)
-               return "ERROR";
-       else
-               return "WARNING";
+       switch (tomoyo_find_yesno(string, find)) {
+       case 1:
+               *b = true;
+               break;
+       case 0:
+               *b = false;
+               break;
+       }
 }
 
-/**
- * tomoyo_check_flags - Check mode for specified functionality.
- *
- * @domain: Pointer to "struct tomoyo_domain_info".
- * @index:  The functionality to check mode.
- *
- * TOMOYO checks only process context.
- * This code disables TOMOYO's enforcement in case the function is called from
- * interrupt context.
- */
-unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
-                               const u8 index)
+static void tomoyo_set_uint(unsigned int *i, const char *string,
+                           const char *find)
 {
-       const u8 profile = domain->profile;
-
-       if (WARN_ON(in_interrupt()))
-               return 0;
-       return tomoyo_policy_loaded && index < TOMOYO_MAX_CONTROL_INDEX
-#if TOMOYO_MAX_PROFILES != 256
-               && profile < TOMOYO_MAX_PROFILES
-#endif
-               && tomoyo_profile_ptr[profile] ?
-               tomoyo_profile_ptr[profile]->value[index] : 0;
-}
-
-/**
- * tomoyo_verbose_mode - Check whether TOMOYO is verbose mode.
- *
- * @domain: Pointer to "struct tomoyo_domain_info".
- *
- * Returns true if domain policy violation warning should be printed to
- * console.
- */
-bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain)
-{
-       return tomoyo_check_flags(domain, TOMOYO_VERBOSE) != 0;
+       const char *cp = strstr(string, find);
+       if (cp)
+               sscanf(cp + strlen(find), "=%u", i);
 }
 
-/**
- * tomoyo_domain_quota_is_ok - Check for domain's quota.
- *
- * @domain: Pointer to "struct tomoyo_domain_info".
- *
- * Returns true if the domain is not exceeded quota, false otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain)
+static void tomoyo_set_pref(const char *name, const char *value,
+                           const bool use_default,
+                           struct tomoyo_profile *profile)
 {
-       unsigned int count = 0;
-       struct tomoyo_acl_info *ptr;
-
-       if (!domain)
-               return true;
-       list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
-               switch (ptr->type) {
-                       struct tomoyo_path_acl *acl;
-                       u32 perm;
-                       u8 i;
-               case TOMOYO_TYPE_PATH_ACL:
-                       acl = container_of(ptr, struct tomoyo_path_acl, head);
-                       perm = acl->perm | (((u32) acl->perm_high) << 16);
-                       for (i = 0; i < TOMOYO_MAX_PATH_OPERATION; i++)
-                               if (perm & (1 << i))
-                                       count++;
-                       if (perm & (1 << TOMOYO_TYPE_READ_WRITE))
-                               count -= 2;
-                       break;
-               case TOMOYO_TYPE_PATH2_ACL:
-                       perm = container_of(ptr, struct tomoyo_path2_acl, head)
-                               ->perm;
-                       for (i = 0; i < TOMOYO_MAX_PATH2_OPERATION; i++)
-                               if (perm & (1 << i))
-                                       count++;
-                       break;
+       struct tomoyo_preference **pref;
+       bool *verbose;
+       if (!strcmp(name, "enforcing")) {
+               if (use_default) {
+                       pref = &profile->enforcing;
+                       goto set_default;
                }
+               profile->enforcing = &profile->preference;
+               verbose = &profile->preference.enforcing_verbose;
+               goto set_verbose;
        }
-       if (count < tomoyo_check_flags(domain, TOMOYO_MAX_ACCEPT_ENTRY))
-               return true;
-       if (!domain->quota_warned) {
-               domain->quota_warned = true;
-               printk(KERN_WARNING "TOMOYO-WARNING: "
-                      "Domain '%s' has so many ACLs to hold. "
-                      "Stopped learning mode.\n", domain->domainname->name);
+       if (!strcmp(name, "permissive")) {
+               if (use_default) {
+                       pref = &profile->permissive;
+                       goto set_default;
+               }
+               profile->permissive = &profile->preference;
+               verbose = &profile->preference.permissive_verbose;
+               goto set_verbose;
        }
-       return false;
+       if (!strcmp(name, "learning")) {
+               if (use_default) {
+                       pref = &profile->learning;
+                       goto set_default;
+               }
+               profile->learning = &profile->preference;
+               tomoyo_set_uint(&profile->preference.learning_max_entry, value,
+                            "max_entry");
+               verbose = &profile->preference.learning_verbose;
+               goto set_verbose;
+       }
+       return;
+ set_default:
+       *pref = &tomoyo_default_profile.preference;
+       return;
+ set_verbose:
+       tomoyo_set_bool(verbose, value, "verbose");
 }
 
-/**
- * tomoyo_find_or_assign_new_profile - Create a new profile.
- *
- * @profile: Profile number to create.
- *
- * Returns pointer to "struct tomoyo_profile" on success, NULL otherwise.
- */
-static struct tomoyo_profile *tomoyo_find_or_assign_new_profile(const unsigned
-                                                               int profile)
+static int tomoyo_set_mode(char *name, const char *value,
+                          const bool use_default,
+                          struct tomoyo_profile *profile)
 {
-       struct tomoyo_profile *ptr = NULL;
-       int i;
-
-       if (profile >= TOMOYO_MAX_PROFILES)
-               return NULL;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               return NULL;
-       ptr = tomoyo_profile_ptr[profile];
-       if (ptr)
-               goto ok;
-       ptr = kmalloc(sizeof(*ptr), GFP_NOFS);
-       if (!tomoyo_memory_ok(ptr)) {
-               kfree(ptr);
-               ptr = NULL;
-               goto ok;
+       u8 i;
+       u8 config;
+       if (!strcmp(name, "CONFIG")) {
+               i = TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX;
+               config = profile->default_config;
+       } else if (tomoyo_str_starts(&name, "CONFIG::")) {
+               config = 0;
+               for (i = 0; i < TOMOYO_MAX_MAC_INDEX
+                            + TOMOYO_MAX_MAC_CATEGORY_INDEX; i++) {
+                       if (strcmp(name, tomoyo_mac_keywords[i]))
+                               continue;
+                       config = profile->config[i];
+                       break;
+               }
+               if (i == TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX)
+                       return -EINVAL;
+       } else {
+               return -EINVAL;
        }
-       for (i = 0; i < TOMOYO_MAX_CONTROL_INDEX; i++)
-               ptr->value[i] = tomoyo_control_array[i].current_value;
-       mb(); /* Avoid out-of-order execution. */
-       tomoyo_profile_ptr[profile] = ptr;
- ok:
-       mutex_unlock(&tomoyo_policy_lock);
-       return ptr;
+       if (use_default) {
+               config = TOMOYO_CONFIG_USE_DEFAULT;
+       } else {
+               u8 mode;
+               for (mode = 0; mode < 4; mode++)
+                       if (strstr(value, tomoyo_mode[mode]))
+                               /*
+                                * Update lower 3 bits in order to distinguish
+                                * 'config' from 'TOMOYO_CONFIG_USE_DEAFULT'.
+                                */
+                               config = (config & ~7) | mode;
+       }
+       if (i < TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX)
+               profile->config[i] = config;
+       else if (config != TOMOYO_CONFIG_USE_DEFAULT)
+               profile->default_config = config;
+       return 0;
 }
 
 /**
- * tomoyo_write_profile - Write to profile table.
+ * tomoyo_write_profile - Write profile table.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
  *
@@ -980,153 +430,165 @@ static int tomoyo_write_profile(struct tomoyo_io_buffer *head)
 {
        char *data = head->write_buf;
        unsigned int i;
-       unsigned int value;
+       bool use_default = false;
        char *cp;
        struct tomoyo_profile *profile;
-       unsigned long num;
-
-       cp = strchr(data, '-');
-       if (cp)
-               *cp = '\0';
-       if (strict_strtoul(data, 10, &num))
-               return -EINVAL;
-       if (cp)
+       if (sscanf(data, "PROFILE_VERSION=%u", &tomoyo_profile_version) == 1)
+               return 0;
+       i = simple_strtoul(data, &cp, 10);
+       if (data == cp) {
+               profile = &tomoyo_default_profile;
+       } else {
+               if (*cp != '-')
+                       return -EINVAL;
                data = cp + 1;
-       profile = tomoyo_find_or_assign_new_profile(num);
-       if (!profile)
-               return -EINVAL;
+               profile = tomoyo_assign_profile(i);
+               if (!profile)
+                       return -EINVAL;
+       }
        cp = strchr(data, '=');
        if (!cp)
                return -EINVAL;
-       *cp = '\0';
+       *cp++ = '\0';
+       if (profile != &tomoyo_default_profile)
+               use_default = strstr(cp, "use_default") != NULL;
+       if (tomoyo_str_starts(&data, "PREFERENCE::")) {
+               tomoyo_set_pref(data, cp, use_default, profile);
+               return 0;
+       }
+       if (profile == &tomoyo_default_profile)
+               return -EINVAL;
        if (!strcmp(data, "COMMENT")) {
                const struct tomoyo_path_info *old_comment = profile->comment;
-               profile->comment = tomoyo_get_name(cp + 1);
+               profile->comment = tomoyo_get_name(cp);
                tomoyo_put_name(old_comment);
                return 0;
        }
-       for (i = 0; i < TOMOYO_MAX_CONTROL_INDEX; i++) {
-               if (strcmp(data, tomoyo_control_array[i].keyword))
-                       continue;
-               if (sscanf(cp + 1, "%u", &value) != 1) {
-                       int j;
-                       const char **modes;
-                       switch (i) {
-                       case TOMOYO_VERBOSE:
-                               modes = tomoyo_mode_2;
-                               break;
-                       default:
-                               modes = tomoyo_mode_4;
-                               break;
-                       }
-                       for (j = 0; j < 4; j++) {
-                               if (strcmp(cp + 1, modes[j]))
-                                       continue;
-                               value = j;
-                               break;
-                       }
-                       if (j == 4)
-                               return -EINVAL;
-               } else if (value > tomoyo_control_array[i].max_value) {
-                       value = tomoyo_control_array[i].max_value;
-               }
-               profile->value[i] = value;
-               return 0;
+       return tomoyo_set_mode(data, cp, use_default, profile);
+}
+
+static void tomoyo_print_preference(struct tomoyo_io_buffer *head,
+                                   const int idx)
+{
+       struct tomoyo_preference *pref = &tomoyo_default_profile.preference;
+       const struct tomoyo_profile *profile = idx >= 0 ?
+               tomoyo_profile_ptr[idx] : NULL;
+       char buffer[16] = "";
+       if (profile) {
+               buffer[sizeof(buffer) - 1] = '\0';
+               snprintf(buffer, sizeof(buffer) - 1, "%u-", idx);
        }
-       return -EINVAL;
+       if (profile) {
+               pref = profile->learning;
+               if (pref == &tomoyo_default_profile.preference)
+                       goto skip1;
+       }
+       tomoyo_io_printf(head, "%sPREFERENCE::%s={ "
+                        "verbose=%s max_entry=%u }\n",
+                        buffer, "learning",
+                        tomoyo_yesno(pref->learning_verbose),
+                        pref->learning_max_entry);
+ skip1:
+       if (profile) {
+               pref = profile->permissive;
+               if (pref == &tomoyo_default_profile.preference)
+                       goto skip2;
+       }
+       tomoyo_io_printf(head, "%sPREFERENCE::%s={ verbose=%s }\n",
+                        buffer, "permissive",
+                        tomoyo_yesno(pref->permissive_verbose));
+ skip2:
+       if (profile) {
+               pref = profile->enforcing;
+               if (pref == &tomoyo_default_profile.preference)
+                       return;
+       }
+       tomoyo_io_printf(head, "%sPREFERENCE::%s={ verbose=%s }\n",
+                        buffer, "enforcing",
+                        tomoyo_yesno(pref->enforcing_verbose));
+}
+
+static void tomoyo_print_config(struct tomoyo_io_buffer *head, const u8 config)
+{
+       tomoyo_io_printf(head, "={ mode=%s }\n", tomoyo_mode[config & 3]);
 }
 
 /**
- * tomoyo_read_profile - Read from profile table.
+ * tomoyo_read_profile - Read profile table.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
- *
- * Returns 0.
  */
-static int tomoyo_read_profile(struct tomoyo_io_buffer *head)
+static void tomoyo_read_profile(struct tomoyo_io_buffer *head)
 {
-       static const int total = TOMOYO_MAX_CONTROL_INDEX + 1;
-       int step;
-
-       if (head->read_eof)
-               return 0;
-       for (step = head->read_step; step < TOMOYO_MAX_PROFILES * total;
-            step++) {
-               const u8 index = step / total;
-               u8 type = step % total;
-               const struct tomoyo_profile *profile
-                       = tomoyo_profile_ptr[index];
-               head->read_step = step;
-               if (!profile)
-                       continue;
-               if (!type) { /* Print profile' comment tag. */
-                       if (!tomoyo_io_printf(head, "%u-COMMENT=%s\n",
-                                             index, profile->comment ?
-                                             profile->comment->name : ""))
+       u8 index;
+       const struct tomoyo_profile *profile;
+ next:
+       index = head->r.index;
+       profile = tomoyo_profile_ptr[index];
+       switch (head->r.step) {
+       case 0:
+               tomoyo_io_printf(head, "PROFILE_VERSION=%s\n", "20090903");
+               tomoyo_print_preference(head, -1);
+               head->r.step++;
+               break;
+       case 1:
+               for ( ; head->r.index < TOMOYO_MAX_PROFILES;
+                     head->r.index++)
+                       if (tomoyo_profile_ptr[head->r.index])
                                break;
-                       continue;
+               if (head->r.index == TOMOYO_MAX_PROFILES)
+                       return;
+               head->r.step++;
+               break;
+       case 2:
+               {
+                       const struct tomoyo_path_info *comment =
+                               profile->comment;
+                       tomoyo_io_printf(head, "%u-COMMENT=", index);
+                       tomoyo_set_string(head, comment ? comment->name : "");
+                       tomoyo_set_lf(head);
+                       head->r.step++;
                }
-               type--;
-               if (type < TOMOYO_MAX_CONTROL_INDEX) {
-                       const unsigned int value = profile->value[type];
-                       const char **modes = NULL;
-                       const char *keyword
-                               = tomoyo_control_array[type].keyword;
-                       switch (tomoyo_control_array[type].max_value) {
-                       case 3:
-                               modes = tomoyo_mode_4;
-                               break;
-                       case 1:
-                               modes = tomoyo_mode_2;
-                               break;
-                       }
-                       if (modes) {
-                               if (!tomoyo_io_printf(head, "%u-%s=%s\n", index,
-                                                     keyword, modes[value]))
-                                       break;
-                       } else {
-                               if (!tomoyo_io_printf(head, "%u-%s=%u\n", index,
-                                                     keyword, value))
-                                       break;
-                       }
+               break;
+       case 3:
+               {
+                       tomoyo_io_printf(head, "%u-%s", index, "CONFIG");
+                       tomoyo_print_config(head, profile->default_config);
+                       head->r.bit = 0;
+                       head->r.step++;
+               }
+               break;
+       case 4:
+               for ( ; head->r.bit < TOMOYO_MAX_MAC_INDEX
+                             + TOMOYO_MAX_MAC_CATEGORY_INDEX; head->r.bit++) {
+                       const u8 i = head->r.bit;
+                       const u8 config = profile->config[i];
+                       if (config == TOMOYO_CONFIG_USE_DEFAULT)
+                               continue;
+                       tomoyo_io_printf(head, "%u-%s%s", index, "CONFIG::",
+                                        tomoyo_mac_keywords[i]);
+                       tomoyo_print_config(head, config);
+                       head->r.bit++;
+                       break;
+               }
+               if (head->r.bit == TOMOYO_MAX_MAC_INDEX
+                   + TOMOYO_MAX_MAC_CATEGORY_INDEX) {
+                       tomoyo_print_preference(head, index);
+                       head->r.index++;
+                       head->r.step = 1;
                }
+               break;
        }
-       if (step == TOMOYO_MAX_PROFILES * total)
-               head->read_eof = true;
-       return 0;
+       if (tomoyo_flush(head))
+               goto next;
 }
 
-/*
- * tomoyo_policy_manager_list is used for holding list of domainnames or
- * programs which are permitted to modify configuration via
- * /sys/kernel/security/tomoyo/ interface.
- *
- * An entry is added by
- *
- * # echo '<kernel> /sbin/mingetty /bin/login /bin/bash' > \
- *                                        /sys/kernel/security/tomoyo/manager
- *  (if you want to specify by a domainname)
- *
- *  or
- *
- * # echo '/usr/lib/ccs/editpolicy' > /sys/kernel/security/tomoyo/manager
- *  (if you want to specify by a program's location)
- *
- * and is deleted by
- *
- * # echo 'delete <kernel> /sbin/mingetty /bin/login /bin/bash' > \
- *                                        /sys/kernel/security/tomoyo/manager
- *
- *  or
- *
- * # echo 'delete /usr/lib/ccs/editpolicy' > \
- *                                        /sys/kernel/security/tomoyo/manager
- *
- * and all entries are retrieved by
- *
- * # cat /sys/kernel/security/tomoyo/manager
- */
-LIST_HEAD(tomoyo_policy_manager_list);
+static bool tomoyo_same_manager(const struct tomoyo_acl_head *a,
+                               const struct tomoyo_acl_head *b)
+{
+       return container_of(a, struct tomoyo_manager, head)->manager ==
+               container_of(b, struct tomoyo_manager, head)->manager;
+}
 
 /**
  * tomoyo_update_manager_entry - Add a manager entry.
@@ -1141,47 +603,29 @@ LIST_HEAD(tomoyo_policy_manager_list);
 static int tomoyo_update_manager_entry(const char *manager,
                                       const bool is_delete)
 {
-       struct tomoyo_policy_manager_entry *ptr;
-       struct tomoyo_policy_manager_entry e = { };
-       int error = is_delete ? -ENOENT : -ENOMEM;
+       struct tomoyo_manager e = { };
+       int error;
 
-       if (tomoyo_is_domain_def(manager)) {
-               if (!tomoyo_is_correct_domain(manager))
+       if (tomoyo_domain_def(manager)) {
+               if (!tomoyo_correct_domain(manager))
                        return -EINVAL;
                e.is_domain = true;
        } else {
-               if (!tomoyo_is_correct_path(manager, 1, -1, -1))
+               if (!tomoyo_correct_path(manager))
                        return -EINVAL;
        }
        e.manager = tomoyo_get_name(manager);
        if (!e.manager)
                return -ENOMEM;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) {
-               if (ptr->manager != e.manager)
-                       continue;
-               ptr->is_deleted = is_delete;
-               error = 0;
-               break;
-       }
-       if (!is_delete && error) {
-               struct tomoyo_policy_manager_entry *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
-               if (entry) {
-                       list_add_tail_rcu(&entry->list,
-                                         &tomoyo_policy_manager_list);
-                       error = 0;
-               }
-       }
-       mutex_unlock(&tomoyo_policy_lock);
- out:
+       error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
+                                    &tomoyo_policy_list[TOMOYO_ID_MANAGER],
+                                    tomoyo_same_manager);
        tomoyo_put_name(e.manager);
        return error;
 }
 
 /**
- * tomoyo_write_manager_policy - Write manager policy.
+ * tomoyo_write_manager - Write manager policy.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
  *
@@ -1189,7 +633,7 @@ static int tomoyo_update_manager_entry(const char *manager,
  *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_write_manager_policy(struct tomoyo_io_buffer *head)
+static int tomoyo_write_manager(struct tomoyo_io_buffer *head)
 {
        char *data = head->write_buf;
        bool is_delete = tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE);
@@ -1202,47 +646,41 @@ static int tomoyo_write_manager_policy(struct tomoyo_io_buffer *head)
 }
 
 /**
- * tomoyo_read_manager_policy - Read manager policy.
+ * tomoyo_read_manager - Read manager policy.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
  *
- * Returns 0.
- *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_read_manager_policy(struct tomoyo_io_buffer *head)
+static void tomoyo_read_manager(struct tomoyo_io_buffer *head)
 {
-       struct list_head *pos;
-       bool done = true;
-
-       if (head->read_eof)
-               return 0;
-       list_for_each_cookie(pos, head->read_var2,
-                            &tomoyo_policy_manager_list) {
-               struct tomoyo_policy_manager_entry *ptr;
-               ptr = list_entry(pos, struct tomoyo_policy_manager_entry,
-                                list);
-               if (ptr->is_deleted)
+       if (head->r.eof)
+               return;
+       list_for_each_cookie(head->r.acl,
+                            &tomoyo_policy_list[TOMOYO_ID_MANAGER]) {
+               struct tomoyo_manager *ptr =
+                       list_entry(head->r.acl, typeof(*ptr), head.list);
+               if (ptr->head.is_deleted)
                        continue;
-               done = tomoyo_io_printf(head, "%s\n", ptr->manager->name);
-               if (!done)
-                       break;
+               if (!tomoyo_flush(head))
+                       return;
+               tomoyo_set_string(head, ptr->manager->name);
+               tomoyo_set_lf(head);
        }
-       head->read_eof = done;
-       return 0;
+       head->r.eof = true;
 }
 
 /**
- * tomoyo_is_policy_manager - Check whether the current process is a policy manager.
+ * tomoyo_manager - Check whether the current process is a policy manager.
  *
  * Returns true if the current process is permitted to modify policy
  * via /sys/kernel/security/tomoyo/ interface.
  *
  * Caller holds tomoyo_read_lock().
  */
-static bool tomoyo_is_policy_manager(void)
+static bool tomoyo_manager(void)
 {
-       struct tomoyo_policy_manager_entry *ptr;
+       struct tomoyo_manager *ptr;
        const char *exe;
        const struct task_struct *task = current;
        const struct tomoyo_path_info *domainname = tomoyo_domain()->domainname;
@@ -1252,8 +690,9 @@ static bool tomoyo_is_policy_manager(void)
                return true;
        if (!tomoyo_manage_by_non_root && (task->cred->uid || task->cred->euid))
                return false;
-       list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) {
-               if (!ptr->is_deleted && ptr->is_domain
+       list_for_each_entry_rcu(ptr, &tomoyo_policy_list[TOMOYO_ID_MANAGER],
+                               head.list) {
+               if (!ptr->head.is_deleted && ptr->is_domain
                    && !tomoyo_pathcmp(domainname, ptr->manager)) {
                        found = true;
                        break;
@@ -1264,8 +703,9 @@ static bool tomoyo_is_policy_manager(void)
        exe = tomoyo_get_exe();
        if (!exe)
                return false;
-       list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list, list) {
-               if (!ptr->is_deleted && !ptr->is_domain
+       list_for_each_entry_rcu(ptr, &tomoyo_policy_list[TOMOYO_ID_MANAGER],
+                               head.list) {
+               if (!ptr->head.is_deleted && !ptr->is_domain
                    && !strcmp(exe, ptr->manager->name)) {
                        found = true;
                        break;
@@ -1285,7 +725,7 @@ static bool tomoyo_is_policy_manager(void)
 }
 
 /**
- * tomoyo_is_select_one - Parse select command.
+ * tomoyo_select_one - Parse select command.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
  * @data: String to parse.
@@ -1294,23 +734,31 @@ static bool tomoyo_is_policy_manager(void)
  *
  * Caller holds tomoyo_read_lock().
  */
-static bool tomoyo_is_select_one(struct tomoyo_io_buffer *head,
-                                const char *data)
+static bool tomoyo_select_one(struct tomoyo_io_buffer *head, const char *data)
 {
        unsigned int pid;
        struct tomoyo_domain_info *domain = NULL;
+       bool global_pid = false;
 
-       if (sscanf(data, "pid=%u", &pid) == 1) {
+       if (!strcmp(data, "allow_execute")) {
+               head->r.print_execute_only = true;
+               return true;
+       }
+       if (sscanf(data, "pid=%u", &pid) == 1 ||
+           (global_pid = true, sscanf(data, "global-pid=%u", &pid) == 1)) {
                struct task_struct *p;
                rcu_read_lock();
                read_lock(&tasklist_lock);
-               p = find_task_by_vpid(pid);
+               if (global_pid)
+                       p = find_task_by_pid_ns(pid, &init_pid_ns);
+               else
+                       p = find_task_by_vpid(pid);
                if (p)
                        domain = tomoyo_real_domain(p);
                read_unlock(&tasklist_lock);
                rcu_read_unlock();
        } else if (!strncmp(data, "domain=", 7)) {
-               if (tomoyo_is_domain_def(data + 7))
+               if (tomoyo_domain_def(data + 7))
                        domain = tomoyo_find_domain(data + 7);
        } else
                return false;
@@ -1318,24 +766,13 @@ static bool tomoyo_is_select_one(struct tomoyo_io_buffer *head,
        /* Accessing read_buf is safe because head->io_sem is held. */
        if (!head->read_buf)
                return true; /* Do nothing if open(O_WRONLY). */
-       head->read_avail = 0;
+       memset(&head->r, 0, sizeof(head->r));
+       head->r.print_this_domain_only = true;
+       head->r.eof = !domain;
+       head->r.domain = &domain->list;
        tomoyo_io_printf(head, "# select %s\n", data);
-       head->read_single_domain = true;
-       head->read_eof = !domain;
-       if (domain) {
-               struct tomoyo_domain_info *d;
-               head->read_var1 = NULL;
-               list_for_each_entry_rcu(d, &tomoyo_domain_list, list) {
-                       if (d == domain)
-                               break;
-                       head->read_var1 = &d->list;
-               }
-               head->read_var2 = NULL;
-               head->read_bit = 0;
-               head->read_step = 0;
-               if (domain->is_deleted)
-                       tomoyo_io_printf(head, "# This is a deleted domain.\n");
-       }
+       if (domain && domain->is_deleted)
+               tomoyo_io_printf(head, "# This is a deleted domain.\n");
        return true;
 }
 
@@ -1373,7 +810,24 @@ static int tomoyo_delete_domain(char *domainname)
 }
 
 /**
- * tomoyo_write_domain_policy - Write domain policy.
+ * tomoyo_write_domain2 - Write domain policy.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ *
+ * Returns 0 on success, negative value otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+static int tomoyo_write_domain2(char *data, struct tomoyo_domain_info *domain,
+                               const bool is_delete)
+{
+       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_ALLOW_MOUNT))
+               return tomoyo_write_mount(data, domain, is_delete);
+       return tomoyo_write_file(data, domain, is_delete);
+}
+
+/**
+ * tomoyo_write_domain - Write domain policy.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
  *
@@ -1381,7 +835,7 @@ static int tomoyo_delete_domain(char *domainname)
  *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_write_domain_policy(struct tomoyo_io_buffer *head)
+static int tomoyo_write_domain(struct tomoyo_io_buffer *head)
 {
        char *data = head->write_buf;
        struct tomoyo_domain_info *domain = head->write_var1;
@@ -1393,19 +847,19 @@ static int tomoyo_write_domain_policy(struct tomoyo_io_buffer *head)
                is_delete = true;
        else if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_SELECT))
                is_select = true;
-       if (is_select && tomoyo_is_select_one(head, data))
+       if (is_select && tomoyo_select_one(head, data))
                return 0;
        /* Don't allow updating policies by non manager programs. */
-       if (!tomoyo_is_policy_manager())
+       if (!tomoyo_manager())
                return -EPERM;
-       if (tomoyo_is_domain_def(data)) {
+       if (tomoyo_domain_def(data)) {
                domain = NULL;
                if (is_delete)
                        tomoyo_delete_domain(data);
                else if (is_select)
                        domain = tomoyo_find_domain(data);
                else
-                       domain = tomoyo_find_or_assign_new_domain(data, 0);
+                       domain = tomoyo_assign_domain(data, 0);
                head->write_var1 = domain;
                return 0;
        }
@@ -1422,179 +876,198 @@ static int tomoyo_write_domain_policy(struct tomoyo_io_buffer *head)
                domain->ignore_global_allow_read = !is_delete;
                return 0;
        }
-       return tomoyo_write_file_policy(data, domain, is_delete);
+       if (!strcmp(data, TOMOYO_KEYWORD_QUOTA_EXCEEDED)) {
+               domain->quota_warned = !is_delete;
+               return 0;
+       }
+       if (!strcmp(data, TOMOYO_KEYWORD_TRANSITION_FAILED)) {
+               domain->transition_failed = !is_delete;
+               return 0;
+       }
+       return tomoyo_write_domain2(data, domain, is_delete);
 }
 
 /**
- * tomoyo_print_path_acl - Print a single path ACL entry.
+ * tomoyo_fns - Find next set bit.
  *
- * @head: Pointer to "struct tomoyo_io_buffer".
- * @ptr:  Pointer to "struct tomoyo_path_acl".
+ * @perm: 8 bits value.
+ * @bit:  First bit to find.
  *
- * Returns true on success, false otherwise.
+ * Returns next on-bit on success, 8 otherwise.
  */
-static bool tomoyo_print_path_acl(struct tomoyo_io_buffer *head,
-                                 struct tomoyo_path_acl *ptr)
+static u8 tomoyo_fns(const u8 perm, u8 bit)
 {
-       int pos;
-       u8 bit;
-       const u32 perm = ptr->perm | (((u32) ptr->perm_high) << 16);
-
-       for (bit = head->read_bit; bit < TOMOYO_MAX_PATH_OPERATION; bit++) {
-               if (!(perm & (1 << bit)))
-                       continue;
-               /* Print "read/write" instead of "read" and "write". */
-               if ((bit == TOMOYO_TYPE_READ || bit == TOMOYO_TYPE_WRITE)
-                   && (perm & (1 << TOMOYO_TYPE_READ_WRITE)))
-                       continue;
-               pos = head->read_avail;
-               if (!tomoyo_io_printf(head, "allow_%s ",
-                                     tomoyo_path2keyword(bit)) ||
-                   !tomoyo_print_name_union(head, &ptr->name) ||
-                   !tomoyo_io_printf(head, "\n"))
-                       goto out;
-       }
-       head->read_bit = 0;
-       return true;
- out:
-       head->read_bit = bit;
-       head->read_avail = pos;
-       return false;
+       for ( ; bit < 8; bit++)
+               if (perm & (1 << bit))
+                       break;
+       return bit;
 }
 
 /**
- * tomoyo_print_path2_acl - Print a double path ACL entry.
+ * tomoyo_print_entry - Print an ACL entry.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
- * @ptr:  Pointer to "struct tomoyo_path2_acl".
+ * @acl:  Pointer to an ACL entry.
  *
  * Returns true on success, false otherwise.
  */
-static bool tomoyo_print_path2_acl(struct tomoyo_io_buffer *head,
-                                  struct tomoyo_path2_acl *ptr)
+static bool tomoyo_print_entry(struct tomoyo_io_buffer *head,
+                              struct tomoyo_acl_info *acl)
 {
-       int pos;
-       const u8 perm = ptr->perm;
+       const u8 acl_type = acl->type;
        u8 bit;
 
-       for (bit = head->read_bit; bit < TOMOYO_MAX_PATH2_OPERATION; bit++) {
-               if (!(perm & (1 << bit)))
-                       continue;
-               pos = head->read_avail;
-               if (!tomoyo_io_printf(head, "allow_%s ",
-                                     tomoyo_path22keyword(bit)) ||
-                   !tomoyo_print_name_union(head, &ptr->name1) ||
-                   !tomoyo_print_name_union(head, &ptr->name2) ||
-                   !tomoyo_io_printf(head, "\n"))
-                       goto out;
+       if (acl->is_deleted)
+               return true;
+ next:
+       bit = head->r.bit;
+       if (!tomoyo_flush(head))
+               return false;
+       else if (acl_type == TOMOYO_TYPE_PATH_ACL) {
+               struct tomoyo_path_acl *ptr =
+                       container_of(acl, typeof(*ptr), head);
+               const u16 perm = ptr->perm;
+               for ( ; bit < TOMOYO_MAX_PATH_OPERATION; bit++) {
+                       if (!(perm & (1 << bit)))
+                               continue;
+                       if (head->r.print_execute_only &&
+                           bit != TOMOYO_TYPE_EXECUTE)
+                               continue;
+                       /* Print "read/write" instead of "read" and "write". */
+                       if ((bit == TOMOYO_TYPE_READ ||
+                            bit == TOMOYO_TYPE_WRITE)
+                           && (perm & (1 << TOMOYO_TYPE_READ_WRITE)))
+                               continue;
+                       break;
+               }
+               if (bit >= TOMOYO_MAX_PATH_OPERATION)
+                       goto done;
+               tomoyo_io_printf(head, "allow_%s", tomoyo_path_keyword[bit]);
+               tomoyo_print_name_union(head, &ptr->name);
+       } else if (head->r.print_execute_only) {
+               return true;
+       } else if (acl_type == TOMOYO_TYPE_PATH2_ACL) {
+               struct tomoyo_path2_acl *ptr =
+                       container_of(acl, typeof(*ptr), head);
+               bit = tomoyo_fns(ptr->perm, bit);
+               if (bit >= TOMOYO_MAX_PATH2_OPERATION)
+                       goto done;
+               tomoyo_io_printf(head, "allow_%s", tomoyo_path2_keyword[bit]);
+               tomoyo_print_name_union(head, &ptr->name1);
+               tomoyo_print_name_union(head, &ptr->name2);
+       } else if (acl_type == TOMOYO_TYPE_PATH_NUMBER_ACL) {
+               struct tomoyo_path_number_acl *ptr =
+                       container_of(acl, typeof(*ptr), head);
+               bit = tomoyo_fns(ptr->perm, bit);
+               if (bit >= TOMOYO_MAX_PATH_NUMBER_OPERATION)
+                       goto done;
+               tomoyo_io_printf(head, "allow_%s",
+                                tomoyo_path_number_keyword[bit]);
+               tomoyo_print_name_union(head, &ptr->name);
+               tomoyo_print_number_union(head, &ptr->number);
+       } else if (acl_type == TOMOYO_TYPE_MKDEV_ACL) {
+               struct tomoyo_mkdev_acl *ptr =
+                       container_of(acl, typeof(*ptr), head);
+               bit = tomoyo_fns(ptr->perm, bit);
+               if (bit >= TOMOYO_MAX_MKDEV_OPERATION)
+                       goto done;
+               tomoyo_io_printf(head, "allow_%s", tomoyo_mkdev_keyword[bit]);
+               tomoyo_print_name_union(head, &ptr->name);
+               tomoyo_print_number_union(head, &ptr->mode);
+               tomoyo_print_number_union(head, &ptr->major);
+               tomoyo_print_number_union(head, &ptr->minor);
+       } else if (acl_type == TOMOYO_TYPE_MOUNT_ACL) {
+               struct tomoyo_mount_acl *ptr =
+                       container_of(acl, typeof(*ptr), head);
+               tomoyo_io_printf(head, "allow_mount");
+               tomoyo_print_name_union(head, &ptr->dev_name);
+               tomoyo_print_name_union(head, &ptr->dir_name);
+               tomoyo_print_name_union(head, &ptr->fs_type);
+               tomoyo_print_number_union(head, &ptr->flags);
        }
-       head->read_bit = 0;
+       head->r.bit = bit + 1;
+       tomoyo_io_printf(head, "\n");
+       if (acl_type != TOMOYO_TYPE_MOUNT_ACL)
+               goto next;
+ done:
+       head->r.bit = 0;
        return true;
- out:
-       head->read_bit = bit;
-       head->read_avail = pos;
-       return false;
 }
 
 /**
- * tomoyo_print_entry - Print an ACL entry.
+ * tomoyo_read_domain2 - Read domain policy.
  *
- * @head: Pointer to "struct tomoyo_io_buffer".
- * @ptr:  Pointer to an ACL entry.
+ * @head:   Pointer to "struct tomoyo_io_buffer".
+ * @domain: Pointer to "struct tomoyo_domain_info".
+ *
+ * Caller holds tomoyo_read_lock().
  *
  * Returns true on success, false otherwise.
  */
-static bool tomoyo_print_entry(struct tomoyo_io_buffer *head,
-                              struct tomoyo_acl_info *ptr)
+static bool tomoyo_read_domain2(struct tomoyo_io_buffer *head,
+                               struct tomoyo_domain_info *domain)
 {
-       const u8 acl_type = ptr->type;
-
-       if (acl_type == TOMOYO_TYPE_PATH_ACL) {
-               struct tomoyo_path_acl *acl
-                       = container_of(ptr, struct tomoyo_path_acl, head);
-               return tomoyo_print_path_acl(head, acl);
-       }
-       if (acl_type == TOMOYO_TYPE_PATH2_ACL) {
-               struct tomoyo_path2_acl *acl
-                       = container_of(ptr, struct tomoyo_path2_acl, head);
-               return tomoyo_print_path2_acl(head, acl);
+       list_for_each_cookie(head->r.acl, &domain->acl_info_list) {
+               struct tomoyo_acl_info *ptr =
+                       list_entry(head->r.acl, typeof(*ptr), list);
+               if (!tomoyo_print_entry(head, ptr))
+                       return false;
        }
-       BUG(); /* This must not happen. */
-       return false;
+       head->r.acl = NULL;
+       return true;
 }
 
 /**
- * tomoyo_read_domain_policy - Read domain policy.
+ * tomoyo_read_domain - Read domain policy.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
  *
- * Returns 0.
- *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_read_domain_policy(struct tomoyo_io_buffer *head)
+static void tomoyo_read_domain(struct tomoyo_io_buffer *head)
 {
-       struct list_head *dpos;
-       struct list_head *apos;
-       bool done = true;
-
-       if (head->read_eof)
-               return 0;
-       if (head->read_step == 0)
-               head->read_step = 1;
-       list_for_each_cookie(dpos, head->read_var1, &tomoyo_domain_list) {
-               struct tomoyo_domain_info *domain;
-               const char *quota_exceeded = "";
-               const char *transition_failed = "";
-               const char *ignore_global_allow_read = "";
-               domain = list_entry(dpos, struct tomoyo_domain_info, list);
-               if (head->read_step != 1)
-                       goto acl_loop;
-               if (domain->is_deleted && !head->read_single_domain)
-                       continue;
-               /* Print domainname and flags. */
-               if (domain->quota_warned)
-                       quota_exceeded = "quota_exceeded\n";
-               if (domain->transition_failed)
-                       transition_failed = "transition_failed\n";
-               if (domain->ignore_global_allow_read)
-                       ignore_global_allow_read
-                               = TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ "\n";
-               done = tomoyo_io_printf(head, "%s\n" TOMOYO_KEYWORD_USE_PROFILE
-                                       "%u\n%s%s%s\n",
-                                       domain->domainname->name,
-                                       domain->profile, quota_exceeded,
-                                       transition_failed,
-                                       ignore_global_allow_read);
-               if (!done)
-                       break;
-               head->read_step = 2;
-acl_loop:
-               if (head->read_step == 3)
-                       goto tail_mark;
-               /* Print ACL entries in the domain. */
-               list_for_each_cookie(apos, head->read_var2,
-                                    &domain->acl_info_list) {
-                       struct tomoyo_acl_info *ptr
-                               = list_entry(apos, struct tomoyo_acl_info,
-                                            list);
-                       done = tomoyo_print_entry(head, ptr);
-                       if (!done)
-                               break;
+       if (head->r.eof)
+               return;
+       list_for_each_cookie(head->r.domain, &tomoyo_domain_list) {
+               struct tomoyo_domain_info *domain =
+                       list_entry(head->r.domain, typeof(*domain), list);
+               switch (head->r.step) {
+               case 0:
+                       if (domain->is_deleted &&
+                           !head->r.print_this_domain_only)
+                               continue;
+                       /* Print domainname and flags. */
+                       tomoyo_set_string(head, domain->domainname->name);
+                       tomoyo_set_lf(head);
+                       tomoyo_io_printf(head,
+                                        TOMOYO_KEYWORD_USE_PROFILE "%u\n",
+                                        domain->profile);
+                       if (domain->quota_warned)
+                               tomoyo_set_string(head, "quota_exceeded\n");
+                       if (domain->transition_failed)
+                               tomoyo_set_string(head, "transition_failed\n");
+                       if (domain->ignore_global_allow_read)
+                               tomoyo_set_string(head,
+                                      TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ
+                                                 "\n");
+                       head->r.step++;
+                       tomoyo_set_lf(head);
+                       /* fall through */
+               case 1:
+                       if (!tomoyo_read_domain2(head, domain))
+                               return;
+                       head->r.step++;
+                       if (!tomoyo_set_lf(head))
+                               return;
+                       /* fall through */
+               case 2:
+                       head->r.step = 0;
+                       if (head->r.print_this_domain_only)
+                               goto done;
                }
-               if (!done)
-                       break;
-               head->read_step = 3;
-tail_mark:
-               done = tomoyo_io_printf(head, "\n");
-               if (!done)
-                       break;
-               head->read_step = 1;
-               if (head->read_single_domain)
-                       break;
        }
-       head->read_eof = done;
-       return 0;
+ done:
+       head->r.eof = true;
 }
 
 /**
@@ -1607,7 +1080,7 @@ tail_mark:
  * This is equivalent to doing
  *
  *     ( echo "select " $domainname; echo "use_profile " $profile ) |
- *     /usr/lib/ccs/loadpolicy -d
+ *     /usr/sbin/tomoyo-loadpolicy -d
  *
  * Caller holds tomoyo_read_lock().
  */
@@ -1631,279 +1104,637 @@ static int tomoyo_write_domain_profile(struct tomoyo_io_buffer *head)
 }
 
 /**
- * tomoyo_read_domain_profile - Read only domainname and profile.
+ * tomoyo_read_domain_profile - Read only domainname and profile.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ *
+ * Returns list of profile number and domainname pairs.
+ *
+ * This is equivalent to doing
+ *
+ *     grep -A 1 '^<kernel>' /sys/kernel/security/tomoyo/domain_policy |
+ *     awk ' { if ( domainname == "" ) { if ( $1 == "<kernel>" )
+ *     domainname = $0; } else if ( $1 == "use_profile" ) {
+ *     print $2 " " domainname; domainname = ""; } } ; '
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+static void tomoyo_read_domain_profile(struct tomoyo_io_buffer *head)
+{
+       if (head->r.eof)
+               return;
+       list_for_each_cookie(head->r.domain, &tomoyo_domain_list) {
+               struct tomoyo_domain_info *domain =
+                       list_entry(head->r.domain, typeof(*domain), list);
+               if (domain->is_deleted)
+                       continue;
+               if (!tomoyo_flush(head))
+                       return;
+               tomoyo_io_printf(head, "%u ", domain->profile);
+               tomoyo_set_string(head, domain->domainname->name);
+               tomoyo_set_lf(head);
+       }
+       head->r.eof = true;
+}
+
+/**
+ * tomoyo_write_pid: Specify PID to obtain domainname.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ *
+ * Returns 0.
+ */
+static int tomoyo_write_pid(struct tomoyo_io_buffer *head)
+{
+       head->r.eof = false;
+       return 0;
+}
+
+/**
+ * tomoyo_read_pid - Get domainname of the specified PID.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ *
+ * Returns the domainname which the specified PID is in on success,
+ * empty string otherwise.
+ * The PID is specified by tomoyo_write_pid() so that the user can obtain
+ * using read()/write() interface rather than sysctl() interface.
+ */
+static void tomoyo_read_pid(struct tomoyo_io_buffer *head)
+{
+       char *buf = head->write_buf;
+       bool global_pid = false;
+       unsigned int pid;
+       struct task_struct *p;
+       struct tomoyo_domain_info *domain = NULL;
+
+       /* Accessing write_buf is safe because head->io_sem is held. */
+       if (!buf) {
+               head->r.eof = true;
+               return; /* Do nothing if open(O_RDONLY). */
+       }
+       if (head->r.w_pos || head->r.eof)
+               return;
+       head->r.eof = true;
+       if (tomoyo_str_starts(&buf, "global-pid "))
+               global_pid = true;
+       pid = (unsigned int) simple_strtoul(buf, NULL, 10);
+       rcu_read_lock();
+       read_lock(&tasklist_lock);
+       if (global_pid)
+               p = find_task_by_pid_ns(pid, &init_pid_ns);
+       else
+               p = find_task_by_vpid(pid);
+       if (p)
+               domain = tomoyo_real_domain(p);
+       read_unlock(&tasklist_lock);
+       rcu_read_unlock();
+       if (!domain)
+               return;
+       tomoyo_io_printf(head, "%u %u ", pid, domain->profile);
+       tomoyo_set_string(head, domain->domainname->name);
+}
+
+static const char *tomoyo_transition_type[TOMOYO_MAX_TRANSITION_TYPE] = {
+       [TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE]
+       = TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN,
+       [TOMOYO_TRANSITION_CONTROL_INITIALIZE]
+       = TOMOYO_KEYWORD_INITIALIZE_DOMAIN,
+       [TOMOYO_TRANSITION_CONTROL_NO_KEEP] = TOMOYO_KEYWORD_NO_KEEP_DOMAIN,
+       [TOMOYO_TRANSITION_CONTROL_KEEP] = TOMOYO_KEYWORD_KEEP_DOMAIN
+};
+
+static const char *tomoyo_group_name[TOMOYO_MAX_GROUP] = {
+       [TOMOYO_PATH_GROUP] = TOMOYO_KEYWORD_PATH_GROUP,
+       [TOMOYO_NUMBER_GROUP] = TOMOYO_KEYWORD_NUMBER_GROUP
+};
+
+/**
+ * tomoyo_write_exception - Write exception policy.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ *
+ * Returns 0 on success, negative value otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+static int tomoyo_write_exception(struct tomoyo_io_buffer *head)
+{
+       char *data = head->write_buf;
+       bool is_delete = tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE);
+       u8 i;
+       static const struct {
+               const char *keyword;
+               int (*write) (char *, const bool);
+       } tomoyo_callback[4] = {
+               { TOMOYO_KEYWORD_AGGREGATOR, tomoyo_write_aggregator },
+               { TOMOYO_KEYWORD_FILE_PATTERN, tomoyo_write_pattern },
+               { TOMOYO_KEYWORD_DENY_REWRITE, tomoyo_write_no_rewrite },
+               { TOMOYO_KEYWORD_ALLOW_READ, tomoyo_write_globally_readable },
+       };
+
+       for (i = 0; i < TOMOYO_MAX_TRANSITION_TYPE; i++)
+               if (tomoyo_str_starts(&data, tomoyo_transition_type[i]))
+                       return tomoyo_write_transition_control(data, is_delete,
+                                                              i);
+       for (i = 0; i < 4; i++)
+               if (tomoyo_str_starts(&data, tomoyo_callback[i].keyword))
+                       return tomoyo_callback[i].write(data, is_delete);
+       for (i = 0; i < TOMOYO_MAX_GROUP; i++)
+               if (tomoyo_str_starts(&data, tomoyo_group_name[i]))
+                       return tomoyo_write_group(data, is_delete, i);
+       return -EINVAL;
+}
+
+/**
+ * tomoyo_read_group - Read "struct tomoyo_path_group"/"struct tomoyo_number_group" list.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ * @idx:  Index number.
+ *
+ * Returns true on success, false otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+static bool tomoyo_read_group(struct tomoyo_io_buffer *head, const int idx)
+{
+       list_for_each_cookie(head->r.group, &tomoyo_group_list[idx]) {
+               struct tomoyo_group *group =
+                       list_entry(head->r.group, typeof(*group), list);
+               list_for_each_cookie(head->r.acl, &group->member_list) {
+                       struct tomoyo_acl_head *ptr =
+                               list_entry(head->r.acl, typeof(*ptr), list);
+                       if (ptr->is_deleted)
+                               continue;
+                       if (!tomoyo_flush(head))
+                               return false;
+                       tomoyo_set_string(head, tomoyo_group_name[idx]);
+                       tomoyo_set_string(head, group->group_name->name);
+                       if (idx == TOMOYO_PATH_GROUP) {
+                               tomoyo_set_space(head);
+                               tomoyo_set_string(head, container_of
+                                              (ptr, struct tomoyo_path_group,
+                                               head)->member_name->name);
+                       } else if (idx == TOMOYO_NUMBER_GROUP) {
+                               tomoyo_print_number_union(head, &container_of
+                                                         (ptr,
+                                                  struct tomoyo_number_group,
+                                                          head)->number);
+                       }
+                       tomoyo_set_lf(head);
+               }
+               head->r.acl = NULL;
+       }
+       head->r.group = NULL;
+       return true;
+}
+
+/**
+ * tomoyo_read_policy - Read "struct tomoyo_..._entry" list.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
+ * @idx:  Index number.
  *
- * Returns list of profile number and domainname pairs.
- *
- * This is equivalent to doing
- *
- *     grep -A 1 '^<kernel>' /sys/kernel/security/tomoyo/domain_policy |
- *     awk ' { if ( domainname == "" ) { if ( $1 == "<kernel>" )
- *     domainname = $0; } else if ( $1 == "use_profile" ) {
- *     print $2 " " domainname; domainname = ""; } } ; '
+ * Returns true on success, false otherwise.
  *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_read_domain_profile(struct tomoyo_io_buffer *head)
+static bool tomoyo_read_policy(struct tomoyo_io_buffer *head, const int idx)
 {
-       struct list_head *pos;
-       bool done = true;
-
-       if (head->read_eof)
-               return 0;
-       list_for_each_cookie(pos, head->read_var1, &tomoyo_domain_list) {
-               struct tomoyo_domain_info *domain;
-               domain = list_entry(pos, struct tomoyo_domain_info, list);
-               if (domain->is_deleted)
+       list_for_each_cookie(head->r.acl, &tomoyo_policy_list[idx]) {
+               struct tomoyo_acl_head *acl =
+                       container_of(head->r.acl, typeof(*acl), list);
+               if (acl->is_deleted)
                        continue;
-               done = tomoyo_io_printf(head, "%u %s\n", domain->profile,
-                                       domain->domainname->name);
-               if (!done)
+               if (!tomoyo_flush(head))
+                       return false;
+               switch (idx) {
+               case TOMOYO_ID_TRANSITION_CONTROL:
+                       {
+                               struct tomoyo_transition_control *ptr =
+                                       container_of(acl, typeof(*ptr), head);
+                               tomoyo_set_string(head,
+                                                 tomoyo_transition_type
+                                                 [ptr->type]);
+                               if (ptr->program)
+                                       tomoyo_set_string(head,
+                                                         ptr->program->name);
+                               if (ptr->program && ptr->domainname)
+                                       tomoyo_set_string(head, " from ");
+                               if (ptr->domainname)
+                                       tomoyo_set_string(head,
+                                                         ptr->domainname->
+                                                         name);
+                       }
+                       break;
+               case TOMOYO_ID_GLOBALLY_READABLE:
+                       {
+                               struct tomoyo_readable_file *ptr =
+                                       container_of(acl, typeof(*ptr), head);
+                               tomoyo_set_string(head,
+                                                 TOMOYO_KEYWORD_ALLOW_READ);
+                               tomoyo_set_string(head, ptr->filename->name);
+                       }
+                       break;
+               case TOMOYO_ID_AGGREGATOR:
+                       {
+                               struct tomoyo_aggregator *ptr =
+                                       container_of(acl, typeof(*ptr), head);
+                               tomoyo_set_string(head,
+                                                 TOMOYO_KEYWORD_AGGREGATOR);
+                               tomoyo_set_string(head,
+                                                 ptr->original_name->name);
+                               tomoyo_set_space(head);
+                               tomoyo_set_string(head,
+                                              ptr->aggregated_name->name);
+                       }
+                       break;
+               case TOMOYO_ID_PATTERN:
+                       {
+                               struct tomoyo_no_pattern *ptr =
+                                       container_of(acl, typeof(*ptr), head);
+                               tomoyo_set_string(head,
+                                                 TOMOYO_KEYWORD_FILE_PATTERN);
+                               tomoyo_set_string(head, ptr->pattern->name);
+                       }
+                       break;
+               case TOMOYO_ID_NO_REWRITE:
+                       {
+                               struct tomoyo_no_rewrite *ptr =
+                                       container_of(acl, typeof(*ptr), head);
+                               tomoyo_set_string(head,
+                                                 TOMOYO_KEYWORD_DENY_REWRITE);
+                               tomoyo_set_string(head, ptr->pattern->name);
+                       }
                        break;
+               default:
+                       continue;
+               }
+               tomoyo_set_lf(head);
        }
-       head->read_eof = done;
-       return 0;
+       head->r.acl = NULL;
+       return true;
 }
 
 /**
- * tomoyo_write_pid: Specify PID to obtain domainname.
+ * tomoyo_read_exception - Read exception policy.
  *
  * @head: Pointer to "struct tomoyo_io_buffer".
  *
- * Returns 0.
+ * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_write_pid(struct tomoyo_io_buffer *head)
+static void tomoyo_read_exception(struct tomoyo_io_buffer *head)
 {
-       unsigned long pid;
-       /* No error check. */
-       strict_strtoul(head->write_buf, 10, &pid);
-       head->read_step = (int) pid;
-       head->read_eof = false;
-       return 0;
+       if (head->r.eof)
+               return;
+       while (head->r.step < TOMOYO_MAX_POLICY &&
+              tomoyo_read_policy(head, head->r.step))
+               head->r.step++;
+       if (head->r.step < TOMOYO_MAX_POLICY)
+               return;
+       while (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP &&
+              tomoyo_read_group(head, head->r.step - TOMOYO_MAX_POLICY))
+               head->r.step++;
+       if (head->r.step < TOMOYO_MAX_POLICY + TOMOYO_MAX_GROUP)
+               return;
+       head->r.eof = true;
 }
 
 /**
- * tomoyo_read_pid - Get domainname of the specified PID.
+ * tomoyo_print_header - Get header line of audit log.
  *
- * @head: Pointer to "struct tomoyo_io_buffer".
+ * @r: Pointer to "struct tomoyo_request_info".
  *
- * Returns the domainname which the specified PID is in on success,
- * empty string otherwise.
- * The PID is specified by tomoyo_write_pid() so that the user can obtain
- * using read()/write() interface rather than sysctl() interface.
+ * Returns string representation.
+ *
+ * This function uses kmalloc(), so caller must kfree() if this function
+ * didn't return NULL.
  */
-static int tomoyo_read_pid(struct tomoyo_io_buffer *head)
+static char *tomoyo_print_header(struct tomoyo_request_info *r)
 {
-       if (head->read_avail == 0 && !head->read_eof) {
-               const int pid = head->read_step;
-               struct task_struct *p;
-               struct tomoyo_domain_info *domain = NULL;
-               rcu_read_lock();
-               read_lock(&tasklist_lock);
-               p = find_task_by_vpid(pid);
-               if (p)
-                       domain = tomoyo_real_domain(p);
-               read_unlock(&tasklist_lock);
-               rcu_read_unlock();
-               if (domain)
-                       tomoyo_io_printf(head, "%d %u %s", pid, domain->profile,
-                                        domain->domainname->name);
-               head->read_eof = true;
-       }
-       return 0;
+       struct timeval tv;
+       const pid_t gpid = task_pid_nr(current);
+       static const int tomoyo_buffer_len = 4096;
+       char *buffer = kmalloc(tomoyo_buffer_len, GFP_NOFS);
+       if (!buffer)
+               return NULL;
+       do_gettimeofday(&tv);
+       snprintf(buffer, tomoyo_buffer_len - 1,
+                "#timestamp=%lu profile=%u mode=%s (global-pid=%u)"
+                " task={ pid=%u ppid=%u uid=%u gid=%u euid=%u"
+                " egid=%u suid=%u sgid=%u fsuid=%u fsgid=%u }",
+                tv.tv_sec, r->profile, tomoyo_mode[r->mode], gpid,
+                (pid_t) sys_getpid(), (pid_t) sys_getppid(),
+                current_uid(), current_gid(), current_euid(),
+                current_egid(), current_suid(), current_sgid(),
+                current_fsuid(), current_fsgid());
+       return buffer;
 }
 
 /**
- * tomoyo_write_exception_policy - Write exception policy.
+ * tomoyo_init_audit_log - Allocate buffer for audit logs.
  *
- * @head: Pointer to "struct tomoyo_io_buffer".
+ * @len: Required size.
+ * @r:   Pointer to "struct tomoyo_request_info".
  *
- * Returns 0 on success, negative value otherwise.
+ * Returns pointer to allocated memory.
  *
- * Caller holds tomoyo_read_lock().
+ * The @len is updated to add the header lines' size on success.
+ *
+ * This function uses kzalloc(), so caller must kfree() if this function
+ * didn't return NULL.
  */
-static int tomoyo_write_exception_policy(struct tomoyo_io_buffer *head)
+static char *tomoyo_init_audit_log(int *len, struct tomoyo_request_info *r)
 {
-       char *data = head->write_buf;
-       bool is_delete = tomoyo_str_starts(&data, TOMOYO_KEYWORD_DELETE);
+       char *buf = NULL;
+       const char *header;
+       const char *domainname;
+       if (!r->domain)
+               r->domain = tomoyo_domain();
+       domainname = r->domain->domainname->name;
+       header = tomoyo_print_header(r);
+       if (!header)
+               return NULL;
+       *len += strlen(domainname) + strlen(header) + 10;
+       buf = kzalloc(*len, GFP_NOFS);
+       if (buf)
+               snprintf(buf, (*len) - 1, "%s\n%s\n", header, domainname);
+       kfree(header);
+       return buf;
+}
 
-       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_KEEP_DOMAIN))
-               return tomoyo_write_domain_keeper_policy(data, false,
-                                                        is_delete);
-       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_NO_KEEP_DOMAIN))
-               return tomoyo_write_domain_keeper_policy(data, true, is_delete);
-       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_INITIALIZE_DOMAIN))
-               return tomoyo_write_domain_initializer_policy(data, false,
-                                                             is_delete);
-       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN))
-               return tomoyo_write_domain_initializer_policy(data, true,
-                                                             is_delete);
-       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_ALIAS))
-               return tomoyo_write_alias_policy(data, is_delete);
-       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_ALLOW_READ))
-               return tomoyo_write_globally_readable_policy(data, is_delete);
-       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_FILE_PATTERN))
-               return tomoyo_write_pattern_policy(data, is_delete);
-       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_DENY_REWRITE))
-               return tomoyo_write_no_rewrite_policy(data, is_delete);
-       if (tomoyo_str_starts(&data, TOMOYO_KEYWORD_PATH_GROUP))
-               return tomoyo_write_path_group_policy(data, is_delete);
-       return -EINVAL;
+/* Wait queue for tomoyo_query_list. */
+static DECLARE_WAIT_QUEUE_HEAD(tomoyo_query_wait);
+
+/* Lock for manipulating tomoyo_query_list. */
+static DEFINE_SPINLOCK(tomoyo_query_list_lock);
+
+/* Structure for query. */
+struct tomoyo_query {
+       struct list_head list;
+       char *query;
+       int query_len;
+       unsigned int serial;
+       int timer;
+       int answer;
+};
+
+/* The list for "struct tomoyo_query". */
+static LIST_HEAD(tomoyo_query_list);
+
+/*
+ * Number of "struct file" referring /sys/kernel/security/tomoyo/query
+ * interface.
+ */
+static atomic_t tomoyo_query_observers = ATOMIC_INIT(0);
+
+/**
+ * tomoyo_supervisor - Ask for the supervisor's decision.
+ *
+ * @r:       Pointer to "struct tomoyo_request_info".
+ * @fmt:     The printf()'s format string, followed by parameters.
+ *
+ * Returns 0 if the supervisor decided to permit the access request which
+ * violated the policy in enforcing mode, TOMOYO_RETRY_REQUEST if the
+ * supervisor decided to retry the access request which violated the policy in
+ * enforcing mode, 0 if it is not in enforcing mode, -EPERM otherwise.
+ */
+int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
+{
+       va_list args;
+       int error = -EPERM;
+       int pos;
+       int len;
+       static unsigned int tomoyo_serial;
+       struct tomoyo_query *entry = NULL;
+       bool quota_exceeded = false;
+       char *header;
+       switch (r->mode) {
+               char *buffer;
+       case TOMOYO_CONFIG_LEARNING:
+               if (!tomoyo_domain_quota_is_ok(r))
+                       return 0;
+               va_start(args, fmt);
+               len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 4;
+               va_end(args);
+               buffer = kmalloc(len, GFP_NOFS);
+               if (!buffer)
+                       return 0;
+               va_start(args, fmt);
+               vsnprintf(buffer, len - 1, fmt, args);
+               va_end(args);
+               tomoyo_normalize_line(buffer);
+               tomoyo_write_domain2(buffer, r->domain, false);
+               kfree(buffer);
+               /* fall through */
+       case TOMOYO_CONFIG_PERMISSIVE:
+               return 0;
+       }
+       if (!r->domain)
+               r->domain = tomoyo_domain();
+       if (!atomic_read(&tomoyo_query_observers))
+               return -EPERM;
+       va_start(args, fmt);
+       len = vsnprintf((char *) &pos, sizeof(pos) - 1, fmt, args) + 32;
+       va_end(args);
+       header = tomoyo_init_audit_log(&len, r);
+       if (!header)
+               goto out;
+       entry = kzalloc(sizeof(*entry), GFP_NOFS);
+       if (!entry)
+               goto out;
+       entry->query = kzalloc(len, GFP_NOFS);
+       if (!entry->query)
+               goto out;
+       len = ksize(entry->query);
+       spin_lock(&tomoyo_query_list_lock);
+       if (tomoyo_quota_for_query && tomoyo_query_memory_size + len +
+           sizeof(*entry) >= tomoyo_quota_for_query) {
+               quota_exceeded = true;
+       } else {
+               tomoyo_query_memory_size += len + sizeof(*entry);
+               entry->serial = tomoyo_serial++;
+       }
+       spin_unlock(&tomoyo_query_list_lock);
+       if (quota_exceeded)
+               goto out;
+       pos = snprintf(entry->query, len - 1, "Q%u-%hu\n%s",
+                      entry->serial, r->retry, header);
+       kfree(header);
+       header = NULL;
+       va_start(args, fmt);
+       vsnprintf(entry->query + pos, len - 1 - pos, fmt, args);
+       entry->query_len = strlen(entry->query) + 1;
+       va_end(args);
+       spin_lock(&tomoyo_query_list_lock);
+       list_add_tail(&entry->list, &tomoyo_query_list);
+       spin_unlock(&tomoyo_query_list_lock);
+       /* Give 10 seconds for supervisor's opinion. */
+       for (entry->timer = 0;
+            atomic_read(&tomoyo_query_observers) && entry->timer < 100;
+            entry->timer++) {
+               wake_up(&tomoyo_query_wait);
+               set_current_state(TASK_INTERRUPTIBLE);
+               schedule_timeout(HZ / 10);
+               if (entry->answer)
+                       break;
+       }
+       spin_lock(&tomoyo_query_list_lock);
+       list_del(&entry->list);
+       tomoyo_query_memory_size -= len + sizeof(*entry);
+       spin_unlock(&tomoyo_query_list_lock);
+       switch (entry->answer) {
+       case 3: /* Asked to retry by administrator. */
+               error = TOMOYO_RETRY_REQUEST;
+               r->retry++;
+               break;
+       case 1:
+               /* Granted by administrator. */
+               error = 0;
+               break;
+       case 0:
+               /* Timed out. */
+               break;
+       default:
+               /* Rejected by administrator. */
+               break;
+       }
+ out:
+       if (entry)
+               kfree(entry->query);
+       kfree(entry);
+       kfree(header);
+       return error;
 }
 
 /**
- * tomoyo_read_exception_policy - Read exception policy.
+ * tomoyo_poll_query - poll() for /sys/kernel/security/tomoyo/query.
  *
- * @head: Pointer to "struct tomoyo_io_buffer".
+ * @file: Pointer to "struct file".
+ * @wait: Pointer to "poll_table".
  *
- * Returns 0 on success, -EINVAL otherwise.
+ * Returns POLLIN | POLLRDNORM when ready to read, 0 otherwise.
  *
- * Caller holds tomoyo_read_lock().
+ * Waits for access requests which violated policy in enforcing mode.
  */
-static int tomoyo_read_exception_policy(struct tomoyo_io_buffer *head)
+static int tomoyo_poll_query(struct file *file, poll_table *wait)
 {
-       if (!head->read_eof) {
-               switch (head->read_step) {
-               case 0:
-                       head->read_var2 = NULL;
-                       head->read_step = 1;
-               case 1:
-                       if (!tomoyo_read_domain_keeper_policy(head))
-                               break;
-                       head->read_var2 = NULL;
-                       head->read_step = 2;
-               case 2:
-                       if (!tomoyo_read_globally_readable_policy(head))
-                               break;
-                       head->read_var2 = NULL;
-                       head->read_step = 3;
-               case 3:
-                       head->read_var2 = NULL;
-                       head->read_step = 4;
-               case 4:
-                       if (!tomoyo_read_domain_initializer_policy(head))
-                               break;
-                       head->read_var2 = NULL;
-                       head->read_step = 5;
-               case 5:
-                       if (!tomoyo_read_alias_policy(head))
-                               break;
-                       head->read_var2 = NULL;
-                       head->read_step = 6;
-               case 6:
-                       head->read_var2 = NULL;
-                       head->read_step = 7;
-               case 7:
-                       if (!tomoyo_read_file_pattern(head))
-                               break;
-                       head->read_var2 = NULL;
-                       head->read_step = 8;
-               case 8:
-                       if (!tomoyo_read_no_rewrite_policy(head))
-                               break;
-                       head->read_var2 = NULL;
-                       head->read_step = 9;
-               case 9:
-                       if (!tomoyo_read_path_group_policy(head))
-                               break;
-                       head->read_var1 = NULL;
-                       head->read_var2 = NULL;
-                       head->read_step = 10;
-               case 10:
-                       head->read_eof = true;
+       struct list_head *tmp;
+       bool found = false;
+       u8 i;
+       for (i = 0; i < 2; i++) {
+               spin_lock(&tomoyo_query_list_lock);
+               list_for_each(tmp, &tomoyo_query_list) {
+                       struct tomoyo_query *ptr =
+                               list_entry(tmp, typeof(*ptr), list);
+                       if (ptr->answer)
+                               continue;
+                       found = true;
                        break;
-               default:
-                       return -EINVAL;
                }
+               spin_unlock(&tomoyo_query_list_lock);
+               if (found)
+                       return POLLIN | POLLRDNORM;
+               if (i)
+                       break;
+               poll_wait(file, &tomoyo_query_wait, wait);
        }
        return 0;
 }
 
-/* path to policy loader */
-static const char *tomoyo_loader = "/sbin/tomoyo-init";
-
 /**
- * tomoyo_policy_loader_exists - Check whether /sbin/tomoyo-init exists.
+ * tomoyo_read_query - Read access requests which violated policy in enforcing mode.
  *
- * Returns true if /sbin/tomoyo-init exists, false otherwise.
+ * @head: Pointer to "struct tomoyo_io_buffer".
  */
-static bool tomoyo_policy_loader_exists(void)
+static void tomoyo_read_query(struct tomoyo_io_buffer *head)
 {
-       /*
-        * Don't activate MAC if the policy loader doesn't exist.
-        * If the initrd includes /sbin/init but real-root-dev has not
-        * mounted on / yet, activating MAC will block the system since
-        * policies are not loaded yet.
-        * Thus, let do_execve() call this function everytime.
-        */
-       struct path path;
-
-       if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) {
-               printk(KERN_INFO "Not activating Mandatory Access Control now "
-                      "since %s doesn't exist.\n", tomoyo_loader);
-               return false;
+       struct list_head *tmp;
+       int pos = 0;
+       int len = 0;
+       char *buf;
+       if (head->r.w_pos)
+               return;
+       if (head->read_buf) {
+               kfree(head->read_buf);
+               head->read_buf = NULL;
+       }
+       spin_lock(&tomoyo_query_list_lock);
+       list_for_each(tmp, &tomoyo_query_list) {
+               struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list);
+               if (ptr->answer)
+                       continue;
+               if (pos++ != head->r.query_index)
+                       continue;
+               len = ptr->query_len;
+               break;
+       }
+       spin_unlock(&tomoyo_query_list_lock);
+       if (!len) {
+               head->r.query_index = 0;
+               return;
+       }
+       buf = kzalloc(len, GFP_NOFS);
+       if (!buf)
+               return;
+       pos = 0;
+       spin_lock(&tomoyo_query_list_lock);
+       list_for_each(tmp, &tomoyo_query_list) {
+               struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list);
+               if (ptr->answer)
+                       continue;
+               if (pos++ != head->r.query_index)
+                       continue;
+               /*
+                * Some query can be skipped because tomoyo_query_list
+                * can change, but I don't care.
+                */
+               if (len == ptr->query_len)
+                       memmove(buf, ptr->query, len);
+               break;
+       }
+       spin_unlock(&tomoyo_query_list_lock);
+       if (buf[0]) {
+               head->read_buf = buf;
+               head->r.w[head->r.w_pos++] = buf;
+               head->r.query_index++;
+       } else {
+               kfree(buf);
        }
-       path_put(&path);
-       return true;
 }
 
 /**
- * tomoyo_load_policy - Run external policy loader to load policy.
+ * tomoyo_write_answer - Write the supervisor's decision.
  *
- * @filename: The program about to start.
- *
- * This function checks whether @filename is /sbin/init , and if so
- * invoke /sbin/tomoyo-init and wait for the termination of /sbin/tomoyo-init
- * and then continues invocation of /sbin/init.
- * /sbin/tomoyo-init reads policy files in /etc/tomoyo/ directory and
- * writes to /sys/kernel/security/tomoyo/ interfaces.
+ * @head: Pointer to "struct tomoyo_io_buffer".
  *
- * Returns nothing.
+ * Returns 0 on success, -EINVAL otherwise.
  */
-void tomoyo_load_policy(const char *filename)
+static int tomoyo_write_answer(struct tomoyo_io_buffer *head)
 {
-       char *argv[2];
-       char *envp[3];
-
-       if (tomoyo_policy_loaded)
-               return;
-       /*
-        * Check filename is /sbin/init or /sbin/tomoyo-start.
-        * /sbin/tomoyo-start is a dummy filename in case where /sbin/init can't
-        * be passed.
-        * You can create /sbin/tomoyo-start by
-        * "ln -s /bin/true /sbin/tomoyo-start".
-        */
-       if (strcmp(filename, "/sbin/init") &&
-           strcmp(filename, "/sbin/tomoyo-start"))
-               return;
-       if (!tomoyo_policy_loader_exists())
-               return;
-
-       printk(KERN_INFO "Calling %s to load policy. Please wait.\n",
-              tomoyo_loader);
-       argv[0] = (char *) tomoyo_loader;
-       argv[1] = NULL;
-       envp[0] = "HOME=/";
-       envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
-       envp[2] = NULL;
-       call_usermodehelper(argv[0], argv, envp, 1);
-
-       printk(KERN_INFO "TOMOYO: 2.2.0   2009/04/01\n");
-       printk(KERN_INFO "Mandatory Access Control activated.\n");
-       tomoyo_policy_loaded = true;
-       { /* Check all profiles currently assigned to domains are defined. */
-               struct tomoyo_domain_info *domain;
-               list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
-                       const u8 profile = domain->profile;
-                       if (tomoyo_profile_ptr[profile])
-                               continue;
-                       panic("Profile %u (used by '%s') not defined.\n",
-                             profile, domain->domainname->name);
-               }
+       char *data = head->write_buf;
+       struct list_head *tmp;
+       unsigned int serial;
+       unsigned int answer;
+       spin_lock(&tomoyo_query_list_lock);
+       list_for_each(tmp, &tomoyo_query_list) {
+               struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list);
+               ptr->timer = 0;
        }
+       spin_unlock(&tomoyo_query_list_lock);
+       if (sscanf(data, "A%u=%u", &serial, &answer) != 2)
+               return -EINVAL;
+       spin_lock(&tomoyo_query_list_lock);
+       list_for_each(tmp, &tomoyo_query_list) {
+               struct tomoyo_query *ptr = list_entry(tmp, typeof(*ptr), list);
+               if (ptr->serial != serial)
+                       continue;
+               if (!ptr->answer)
+                       ptr->answer = answer;
+               break;
+       }
+       spin_unlock(&tomoyo_query_list_lock);
+       return 0;
 }
 
 /**
@@ -1913,13 +1744,12 @@ void tomoyo_load_policy(const char *filename)
  *
  * Returns version information.
  */
-static int tomoyo_read_version(struct tomoyo_io_buffer *head)
+static void tomoyo_read_version(struct tomoyo_io_buffer *head)
 {
-       if (!head->read_eof) {
-               tomoyo_io_printf(head, "2.2.0");
-               head->read_eof = true;
+       if (!head->r.eof) {
+               tomoyo_io_printf(head, "2.3.0");
+               head->r.eof = true;
        }
-       return 0;
 }
 
 /**
@@ -1929,18 +1759,17 @@ static int tomoyo_read_version(struct tomoyo_io_buffer *head)
  *
  * Returns the current process's domainname.
  */
-static int tomoyo_read_self_domain(struct tomoyo_io_buffer *head)
+static void tomoyo_read_self_domain(struct tomoyo_io_buffer *head)
 {
-       if (!head->read_eof) {
+       if (!head->r.eof) {
                /*
                 * tomoyo_domain()->domainname != NULL
                 * because every process belongs to a domain and
                 * the domain's name cannot be NULL.
                 */
                tomoyo_io_printf(head, "%s", tomoyo_domain()->domainname->name);
-               head->read_eof = true;
+               head->r.eof = true;
        }
-       return 0;
 }
 
 /**
@@ -1953,23 +1782,24 @@ static int tomoyo_read_self_domain(struct tomoyo_io_buffer *head)
  *
  * Caller acquires tomoyo_read_lock().
  */
-static int tomoyo_open_control(const u8 type, struct file *file)
+int tomoyo_open_control(const u8 type, struct file *file)
 {
        struct tomoyo_io_buffer *head = kzalloc(sizeof(*head), GFP_NOFS);
 
        if (!head)
                return -ENOMEM;
        mutex_init(&head->io_sem);
+       head->type = type;
        switch (type) {
        case TOMOYO_DOMAINPOLICY:
                /* /sys/kernel/security/tomoyo/domain_policy */
-               head->write = tomoyo_write_domain_policy;
-               head->read = tomoyo_read_domain_policy;
+               head->write = tomoyo_write_domain;
+               head->read = tomoyo_read_domain;
                break;
        case TOMOYO_EXCEPTIONPOLICY:
                /* /sys/kernel/security/tomoyo/exception_policy */
-               head->write = tomoyo_write_exception_policy;
-               head->read = tomoyo_read_exception_policy;
+               head->write = tomoyo_write_exception;
+               head->read = tomoyo_read_exception;
                break;
        case TOMOYO_SELFDOMAIN:
                /* /sys/kernel/security/tomoyo/self_domain */
@@ -2001,10 +1831,15 @@ static int tomoyo_open_control(const u8 type, struct file *file)
                head->write = tomoyo_write_profile;
                head->read = tomoyo_read_profile;
                break;
+       case TOMOYO_QUERY: /* /sys/kernel/security/tomoyo/query */
+               head->poll = tomoyo_poll_query;
+               head->write = tomoyo_write_answer;
+               head->read = tomoyo_read_query;
+               break;
        case TOMOYO_MANAGER:
                /* /sys/kernel/security/tomoyo/manager */
-               head->write = tomoyo_write_manager_policy;
-               head->read = tomoyo_read_manager_policy;
+               head->write = tomoyo_write_manager;
+               head->read = tomoyo_read_manager;
                break;
        }
        if (!(file->f_mode & FMODE_READ)) {
@@ -2013,7 +1848,9 @@ static int tomoyo_open_control(const u8 type, struct file *file)
                 * for reading.
                 */
                head->read = NULL;
-       } else {
+               head->poll = NULL;
+       } else if (!head->poll) {
+               /* Don't allocate read_buf for poll() access. */
                if (!head->readbuf_size)
                        head->readbuf_size = 4096 * 2;
                head->read_buf = kzalloc(head->readbuf_size, GFP_NOFS);
@@ -2037,7 +1874,8 @@ static int tomoyo_open_control(const u8 type, struct file *file)
                        return -ENOMEM;
                }
        }
-       head->reader_idx = tomoyo_read_lock();
+       if (type != TOMOYO_QUERY)
+               head->reader_idx = tomoyo_read_lock();
        file->private_data = head;
        /*
         * Call the handler now if the file is
@@ -2048,9 +1886,34 @@ static int tomoyo_open_control(const u8 type, struct file *file)
         */
        if (type == TOMOYO_SELFDOMAIN)
                tomoyo_read_control(file, NULL, 0);
+       /*
+        * If the file is /sys/kernel/security/tomoyo/query , increment the
+        * observer counter.
+        * The obserber counter is used by tomoyo_supervisor() to see if
+        * there is some process monitoring /sys/kernel/security/tomoyo/query.
+        */
+       else if (type == TOMOYO_QUERY)
+               atomic_inc(&tomoyo_query_observers);
        return 0;
 }
 
+/**
+ * tomoyo_poll_control - poll() for /sys/kernel/security/tomoyo/ interface.
+ *
+ * @file: Pointer to "struct file".
+ * @wait: Pointer to "poll_table".
+ *
+ * Waits for read readiness.
+ * /sys/kernel/security/tomoyo/query is handled by /usr/sbin/tomoyo-queryd .
+ */
+int tomoyo_poll_control(struct file *file, poll_table *wait)
+{
+       struct tomoyo_io_buffer *head = file->private_data;
+       if (!head->poll)
+               return -ENOSYS;
+       return head->poll(file, wait);
+}
+
 /**
  * tomoyo_read_control - read() for /sys/kernel/security/tomoyo/ interface.
  *
@@ -2062,36 +1925,23 @@ static int tomoyo_open_control(const u8 type, struct file *file)
  *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_read_control(struct file *file, char __user *buffer,
-                              const int buffer_len)
+int tomoyo_read_control(struct file *file, char __user *buffer,
+                       const int buffer_len)
 {
-       int len = 0;
+       int len;
        struct tomoyo_io_buffer *head = file->private_data;
-       char *cp;
 
        if (!head->read)
                return -ENOSYS;
        if (mutex_lock_interruptible(&head->io_sem))
                return -EINTR;
-       /* Call the policy handler. */
-       len = head->read(head);
-       if (len < 0)
-               goto out;
-       /* Write to buffer. */
-       len = head->read_avail;
-       if (len > buffer_len)
-               len = buffer_len;
-       if (!len)
-               goto out;
-       /* head->read_buf changes by some functions. */
-       cp = head->read_buf;
-       if (copy_to_user(buffer, cp, len)) {
-               len = -EFAULT;
-               goto out;
-       }
-       head->read_avail -= len;
-       memmove(cp, cp + len, head->read_avail);
- out:
+       head->read_user_buf = buffer;
+       head->read_user_buf_avail = buffer_len;
+       if (tomoyo_flush(head))
+               /* Call the policy handler. */
+               head->read(head);
+       tomoyo_flush(head);
+       len = head->read_user_buf - buffer;
        mutex_unlock(&head->io_sem);
        return len;
 }
@@ -2107,8 +1957,8 @@ static int tomoyo_read_control(struct file *file, char __user *buffer,
  *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_write_control(struct file *file, const char __user *buffer,
-                               const int buffer_len)
+int tomoyo_write_control(struct file *file, const char __user *buffer,
+                        const int buffer_len)
 {
        struct tomoyo_io_buffer *head = file->private_data;
        int error = buffer_len;
@@ -2121,8 +1971,7 @@ static int tomoyo_write_control(struct file *file, const char __user *buffer,
                return -EFAULT;
        /* Don't allow updating policies by non manager programs. */
        if (head->write != tomoyo_write_pid &&
-           head->write != tomoyo_write_domain_policy &&
-           !tomoyo_is_policy_manager())
+           head->write != tomoyo_write_domain && !tomoyo_manager())
                return -EPERM;
        if (mutex_lock_interruptible(&head->io_sem))
                return -EINTR;
@@ -2159,12 +2008,19 @@ static int tomoyo_write_control(struct file *file, const char __user *buffer,
  *
  * Caller looses tomoyo_read_lock().
  */
-static int tomoyo_close_control(struct file *file)
+int tomoyo_close_control(struct file *file)
 {
        struct tomoyo_io_buffer *head = file->private_data;
        const bool is_write = !!head->write_buf;
 
-       tomoyo_read_unlock(head->reader_idx);
+       /*
+        * If the file is /sys/kernel/security/tomoyo/query , decrement the
+        * observer counter.
+        */
+       if (head->type == TOMOYO_QUERY)
+               atomic_dec(&tomoyo_query_observers);
+       else
+               tomoyo_read_unlock(head->reader_idx);
        /* Release memory used for policy I/O. */
        kfree(head->read_buf);
        head->read_buf = NULL;
@@ -2179,129 +2035,25 @@ static int tomoyo_close_control(struct file *file)
 }
 
 /**
- * tomoyo_open - open() for /sys/kernel/security/tomoyo/ interface.
- *
- * @inode: Pointer to "struct inode".
- * @file:  Pointer to "struct file".
- *
- * Returns 0 on success, negative value otherwise.
- */
-static int tomoyo_open(struct inode *inode, struct file *file)
-{
-       const int key = ((u8 *) file->f_path.dentry->d_inode->i_private)
-               - ((u8 *) NULL);
-       return tomoyo_open_control(key, file);
-}
-
-/**
- * tomoyo_release - close() for /sys/kernel/security/tomoyo/ interface.
- *
- * @inode: Pointer to "struct inode".
- * @file:  Pointer to "struct file".
- *
- * Returns 0 on success, negative value otherwise.
- */
-static int tomoyo_release(struct inode *inode, struct file *file)
-{
-       return tomoyo_close_control(file);
-}
-
-/**
- * tomoyo_read - read() for /sys/kernel/security/tomoyo/ interface.
- *
- * @file:  Pointer to "struct file".
- * @buf:   Pointer to buffer.
- * @count: Size of @buf.
- * @ppos:  Unused.
- *
- * Returns bytes read on success, negative value otherwise.
- */
-static ssize_t tomoyo_read(struct file *file, char __user *buf, size_t count,
-                          loff_t *ppos)
-{
-       return tomoyo_read_control(file, buf, count);
-}
-
-/**
- * tomoyo_write - write() for /sys/kernel/security/tomoyo/ interface.
- *
- * @file:  Pointer to "struct file".
- * @buf:   Pointer to buffer.
- * @count: Size of @buf.
- * @ppos:  Unused.
- *
- * Returns @count on success, negative value otherwise.
- */
-static ssize_t tomoyo_write(struct file *file, const char __user *buf,
-                           size_t count, loff_t *ppos)
-{
-       return tomoyo_write_control(file, buf, count);
-}
-
-/*
- * tomoyo_operations is a "struct file_operations" which is used for handling
- * /sys/kernel/security/tomoyo/ interface.
- *
- * Some files under /sys/kernel/security/tomoyo/ directory accept open(O_RDWR).
- * See tomoyo_io_buffer for internals.
- */
-static const struct file_operations tomoyo_operations = {
-       .open    = tomoyo_open,
-       .release = tomoyo_release,
-       .read    = tomoyo_read,
-       .write   = tomoyo_write,
-};
-
-/**
- * tomoyo_create_entry - Create interface files under /sys/kernel/security/tomoyo/ directory.
- *
- * @name:   The name of the interface file.
- * @mode:   The permission of the interface file.
- * @parent: The parent directory.
- * @key:    Type of interface.
- *
- * Returns nothing.
- */
-static void __init tomoyo_create_entry(const char *name, const mode_t mode,
-                                      struct dentry *parent, const u8 key)
-{
-       securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
-                              &tomoyo_operations);
-}
-
-/**
- * tomoyo_initerface_init - Initialize /sys/kernel/security/tomoyo/ interface.
- *
- * Returns 0.
+ * tomoyo_check_profile - Check all profiles currently assigned to domains are defined.
  */
-static int __init tomoyo_initerface_init(void)
+void tomoyo_check_profile(void)
 {
-       struct dentry *tomoyo_dir;
-
-       /* Don't create securityfs entries unless registered. */
-       if (current_cred()->security != &tomoyo_kernel_domain)
-               return 0;
-
-       tomoyo_dir = securityfs_create_dir("tomoyo", NULL);
-       tomoyo_create_entry("domain_policy",    0600, tomoyo_dir,
-                           TOMOYO_DOMAINPOLICY);
-       tomoyo_create_entry("exception_policy", 0600, tomoyo_dir,
-                           TOMOYO_EXCEPTIONPOLICY);
-       tomoyo_create_entry("self_domain",      0400, tomoyo_dir,
-                           TOMOYO_SELFDOMAIN);
-       tomoyo_create_entry(".domain_status",   0600, tomoyo_dir,
-                           TOMOYO_DOMAIN_STATUS);
-       tomoyo_create_entry(".process_status",  0600, tomoyo_dir,
-                           TOMOYO_PROCESS_STATUS);
-       tomoyo_create_entry("meminfo",          0600, tomoyo_dir,
-                           TOMOYO_MEMINFO);
-       tomoyo_create_entry("profile",          0600, tomoyo_dir,
-                           TOMOYO_PROFILE);
-       tomoyo_create_entry("manager",          0600, tomoyo_dir,
-                           TOMOYO_MANAGER);
-       tomoyo_create_entry("version",          0400, tomoyo_dir,
-                           TOMOYO_VERSION);
-       return 0;
+       struct tomoyo_domain_info *domain;
+       const int idx = tomoyo_read_lock();
+       tomoyo_policy_loaded = true;
+       /* Check all profiles currently assigned to domains are defined. */
+       list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
+               const u8 profile = domain->profile;
+               if (tomoyo_profile_ptr[profile])
+                       continue;
+               panic("Profile %u (used by '%s') not defined.\n",
+                     profile, domain->domainname->name);
+       }
+       tomoyo_read_unlock(idx);
+       if (tomoyo_profile_version != 20090903)
+               panic("Profile version %u is not supported.\n",
+                     tomoyo_profile_version);
+       printk(KERN_INFO "TOMOYO: 2.3.0\n");
+       printk(KERN_INFO "Mandatory Access Control activated.\n");
 }
-
-fs_initcall(tomoyo_initerface_init);
index 9f1ae5e3ba511f8c494182663d692b9d89ed6c1e..04454cb7b24a534e84c8873a8babeb9614a8da60 100644 (file)
@@ -20,6 +20,7 @@
 #include <linux/mount.h>
 #include <linux/list.h>
 #include <linux/cred.h>
+#include <linux/poll.h>
 struct linux_binprm;
 
 /********** Constants definitions. **********/
@@ -32,20 +33,44 @@ struct linux_binprm;
 #define TOMOYO_HASH_BITS  8
 #define TOMOYO_MAX_HASH (1u<<TOMOYO_HASH_BITS)
 
-/*
- * This is the max length of a token.
- *
- * A token consists of only ASCII printable characters.
- * Non printable characters in a token is represented in \ooo style
- * octal string. Thus, \ itself is represented as \\.
- */
-#define TOMOYO_MAX_PATHNAME_LEN 4000
+#define TOMOYO_EXEC_TMPSIZE     4096
 
 /* Profile number is an integer between 0 and 255. */
 #define TOMOYO_MAX_PROFILES 256
 
+enum tomoyo_mode_index {
+       TOMOYO_CONFIG_DISABLED,
+       TOMOYO_CONFIG_LEARNING,
+       TOMOYO_CONFIG_PERMISSIVE,
+       TOMOYO_CONFIG_ENFORCING,
+       TOMOYO_CONFIG_USE_DEFAULT = 255
+};
+
+enum tomoyo_policy_id {
+       TOMOYO_ID_GROUP,
+       TOMOYO_ID_PATH_GROUP,
+       TOMOYO_ID_NUMBER_GROUP,
+       TOMOYO_ID_TRANSITION_CONTROL,
+       TOMOYO_ID_AGGREGATOR,
+       TOMOYO_ID_GLOBALLY_READABLE,
+       TOMOYO_ID_PATTERN,
+       TOMOYO_ID_NO_REWRITE,
+       TOMOYO_ID_MANAGER,
+       TOMOYO_ID_NAME,
+       TOMOYO_ID_ACL,
+       TOMOYO_ID_DOMAIN,
+       TOMOYO_MAX_POLICY
+};
+
+enum tomoyo_group_id {
+       TOMOYO_PATH_GROUP,
+       TOMOYO_NUMBER_GROUP,
+       TOMOYO_MAX_GROUP
+};
+
 /* Keywords for ACLs. */
-#define TOMOYO_KEYWORD_ALIAS                     "alias "
+#define TOMOYO_KEYWORD_AGGREGATOR                "aggregator "
+#define TOMOYO_KEYWORD_ALLOW_MOUNT               "allow_mount "
 #define TOMOYO_KEYWORD_ALLOW_READ                "allow_read "
 #define TOMOYO_KEYWORD_DELETE                    "delete "
 #define TOMOYO_KEYWORD_DENY_REWRITE              "deny_rewrite "
@@ -55,36 +80,51 @@ struct linux_binprm;
 #define TOMOYO_KEYWORD_NO_INITIALIZE_DOMAIN      "no_initialize_domain "
 #define TOMOYO_KEYWORD_NO_KEEP_DOMAIN            "no_keep_domain "
 #define TOMOYO_KEYWORD_PATH_GROUP                "path_group "
+#define TOMOYO_KEYWORD_NUMBER_GROUP              "number_group "
 #define TOMOYO_KEYWORD_SELECT                    "select "
 #define TOMOYO_KEYWORD_USE_PROFILE               "use_profile "
 #define TOMOYO_KEYWORD_IGNORE_GLOBAL_ALLOW_READ  "ignore_global_allow_read"
+#define TOMOYO_KEYWORD_QUOTA_EXCEEDED            "quota_exceeded"
+#define TOMOYO_KEYWORD_TRANSITION_FAILED         "transition_failed"
 /* A domain definition starts with <kernel>. */
 #define TOMOYO_ROOT_NAME                         "<kernel>"
 #define TOMOYO_ROOT_NAME_LEN                     (sizeof(TOMOYO_ROOT_NAME) - 1)
 
-/* Index numbers for Access Controls. */
-enum tomoyo_mac_index {
-       TOMOYO_MAC_FOR_FILE,  /* domain_policy.conf */
-       TOMOYO_MAX_ACCEPT_ENTRY,
-       TOMOYO_VERBOSE,
-       TOMOYO_MAX_CONTROL_INDEX
+/* Value type definition. */
+#define TOMOYO_VALUE_TYPE_INVALID     0
+#define TOMOYO_VALUE_TYPE_DECIMAL     1
+#define TOMOYO_VALUE_TYPE_OCTAL       2
+#define TOMOYO_VALUE_TYPE_HEXADECIMAL 3
+
+enum tomoyo_transition_type {
+       /* Do not change this order, */
+       TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE,
+       TOMOYO_TRANSITION_CONTROL_INITIALIZE,
+       TOMOYO_TRANSITION_CONTROL_NO_KEEP,
+       TOMOYO_TRANSITION_CONTROL_KEEP,
+       TOMOYO_MAX_TRANSITION_TYPE
 };
 
 /* Index numbers for Access Controls. */
 enum tomoyo_acl_entry_type_index {
        TOMOYO_TYPE_PATH_ACL,
        TOMOYO_TYPE_PATH2_ACL,
+       TOMOYO_TYPE_PATH_NUMBER_ACL,
+       TOMOYO_TYPE_MKDEV_ACL,
+       TOMOYO_TYPE_MOUNT_ACL,
 };
 
 /* Index numbers for File Controls. */
 
 /*
- * TYPE_READ_WRITE_ACL is special. TYPE_READ_WRITE_ACL is automatically set
- * if both TYPE_READ_ACL and TYPE_WRITE_ACL are set. Both TYPE_READ_ACL and
- * TYPE_WRITE_ACL are automatically set if TYPE_READ_WRITE_ACL is set.
- * TYPE_READ_WRITE_ACL is automatically cleared if either TYPE_READ_ACL or
- * TYPE_WRITE_ACL is cleared. Both TYPE_READ_ACL and TYPE_WRITE_ACL are
- * automatically cleared if TYPE_READ_WRITE_ACL is cleared.
+ * TOMOYO_TYPE_READ_WRITE is special. TOMOYO_TYPE_READ_WRITE is automatically
+ * set if both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are set.
+ * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically set if
+ * TOMOYO_TYPE_READ_WRITE is set.
+ * TOMOYO_TYPE_READ_WRITE is automatically cleared if either TOMOYO_TYPE_READ
+ * or TOMOYO_TYPE_WRITE is cleared.
+ * Both TOMOYO_TYPE_READ and TOMOYO_TYPE_WRITE are automatically cleared if
+ * TOMOYO_TYPE_READ_WRITE is cleared.
  */
 
 enum tomoyo_path_acl_index {
@@ -92,27 +132,24 @@ enum tomoyo_path_acl_index {
        TOMOYO_TYPE_EXECUTE,
        TOMOYO_TYPE_READ,
        TOMOYO_TYPE_WRITE,
-       TOMOYO_TYPE_CREATE,
        TOMOYO_TYPE_UNLINK,
-       TOMOYO_TYPE_MKDIR,
        TOMOYO_TYPE_RMDIR,
-       TOMOYO_TYPE_MKFIFO,
-       TOMOYO_TYPE_MKSOCK,
-       TOMOYO_TYPE_MKBLOCK,
-       TOMOYO_TYPE_MKCHAR,
        TOMOYO_TYPE_TRUNCATE,
        TOMOYO_TYPE_SYMLINK,
        TOMOYO_TYPE_REWRITE,
-       TOMOYO_TYPE_IOCTL,
-       TOMOYO_TYPE_CHMOD,
-       TOMOYO_TYPE_CHOWN,
-       TOMOYO_TYPE_CHGRP,
        TOMOYO_TYPE_CHROOT,
-       TOMOYO_TYPE_MOUNT,
        TOMOYO_TYPE_UMOUNT,
        TOMOYO_MAX_PATH_OPERATION
 };
 
+#define TOMOYO_RW_MASK ((1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE))
+
+enum tomoyo_mkdev_acl_index {
+       TOMOYO_TYPE_MKBLOCK,
+       TOMOYO_TYPE_MKCHAR,
+       TOMOYO_MAX_MKDEV_OPERATION
+};
+
 enum tomoyo_path2_acl_index {
        TOMOYO_TYPE_LINK,
        TOMOYO_TYPE_RENAME,
@@ -120,6 +157,18 @@ enum tomoyo_path2_acl_index {
        TOMOYO_MAX_PATH2_OPERATION
 };
 
+enum tomoyo_path_number_acl_index {
+       TOMOYO_TYPE_CREATE,
+       TOMOYO_TYPE_MKDIR,
+       TOMOYO_TYPE_MKFIFO,
+       TOMOYO_TYPE_MKSOCK,
+       TOMOYO_TYPE_IOCTL,
+       TOMOYO_TYPE_CHMOD,
+       TOMOYO_TYPE_CHOWN,
+       TOMOYO_TYPE_CHGRP,
+       TOMOYO_MAX_PATH_NUMBER_OPERATION
+};
+
 enum tomoyo_securityfs_interface_index {
        TOMOYO_DOMAINPOLICY,
        TOMOYO_EXCEPTIONPOLICY,
@@ -129,20 +178,109 @@ enum tomoyo_securityfs_interface_index {
        TOMOYO_SELFDOMAIN,
        TOMOYO_VERSION,
        TOMOYO_PROFILE,
+       TOMOYO_QUERY,
        TOMOYO_MANAGER
 };
 
+enum tomoyo_mac_index {
+       TOMOYO_MAC_FILE_EXECUTE,
+       TOMOYO_MAC_FILE_OPEN,
+       TOMOYO_MAC_FILE_CREATE,
+       TOMOYO_MAC_FILE_UNLINK,
+       TOMOYO_MAC_FILE_MKDIR,
+       TOMOYO_MAC_FILE_RMDIR,
+       TOMOYO_MAC_FILE_MKFIFO,
+       TOMOYO_MAC_FILE_MKSOCK,
+       TOMOYO_MAC_FILE_TRUNCATE,
+       TOMOYO_MAC_FILE_SYMLINK,
+       TOMOYO_MAC_FILE_REWRITE,
+       TOMOYO_MAC_FILE_MKBLOCK,
+       TOMOYO_MAC_FILE_MKCHAR,
+       TOMOYO_MAC_FILE_LINK,
+       TOMOYO_MAC_FILE_RENAME,
+       TOMOYO_MAC_FILE_CHMOD,
+       TOMOYO_MAC_FILE_CHOWN,
+       TOMOYO_MAC_FILE_CHGRP,
+       TOMOYO_MAC_FILE_IOCTL,
+       TOMOYO_MAC_FILE_CHROOT,
+       TOMOYO_MAC_FILE_MOUNT,
+       TOMOYO_MAC_FILE_UMOUNT,
+       TOMOYO_MAC_FILE_PIVOT_ROOT,
+       TOMOYO_MAX_MAC_INDEX
+};
+
+enum tomoyo_mac_category_index {
+       TOMOYO_MAC_CATEGORY_FILE,
+       TOMOYO_MAX_MAC_CATEGORY_INDEX
+};
+
+#define TOMOYO_RETRY_REQUEST 1 /* Retry this request. */
+
 /********** Structure definitions. **********/
 
 /*
- * tomoyo_page_buffer is a structure which is used for holding a pathname
- * obtained from "struct dentry" and "struct vfsmount" pair.
- * As of now, it is 4096 bytes. If users complain that 4096 bytes is too small
- * (because TOMOYO escapes non ASCII printable characters using \ooo format),
- * we will make the buffer larger.
+ * tomoyo_acl_head is a structure which is used for holding elements not in
+ * domain policy.
+ * It has following fields.
+ *
+ *  (1) "list" which is linked to tomoyo_policy_list[] .
+ *  (2) "is_deleted" is a bool which is true if marked as deleted, false
+ *      otherwise.
  */
-struct tomoyo_page_buffer {
-       char buffer[4096];
+struct tomoyo_acl_head {
+       struct list_head list;
+       bool is_deleted;
+} __packed;
+
+/*
+ * tomoyo_request_info is a structure which is used for holding
+ *
+ * (1) Domain information of current process.
+ * (2) How many retries are made for this request.
+ * (3) Profile number used for this request.
+ * (4) Access control mode of the profile.
+ */
+struct tomoyo_request_info {
+       struct tomoyo_domain_info *domain;
+       /* For holding parameters. */
+       union {
+               struct {
+                       const struct tomoyo_path_info *filename;
+                       /* For using wildcards at tomoyo_find_next_domain(). */
+                       const struct tomoyo_path_info *matched_path;
+                       u8 operation;
+               } path;
+               struct {
+                       const struct tomoyo_path_info *filename1;
+                       const struct tomoyo_path_info *filename2;
+                       u8 operation;
+               } path2;
+               struct {
+                       const struct tomoyo_path_info *filename;
+                       unsigned int mode;
+                       unsigned int major;
+                       unsigned int minor;
+                       u8 operation;
+               } mkdev;
+               struct {
+                       const struct tomoyo_path_info *filename;
+                       unsigned long number;
+                       u8 operation;
+               } path_number;
+               struct {
+                       const struct tomoyo_path_info *type;
+                       const struct tomoyo_path_info *dir;
+                       const struct tomoyo_path_info *dev;
+                       unsigned long flags;
+                       int need_dev;
+               } mount;
+       } param;
+       u8 param_type;
+       bool granted;
+       u8 retry;
+       u8 profile;
+       u8 mode; /* One of tomoyo_mode_index . */
+       u8 type;
 };
 
 /*
@@ -174,45 +312,31 @@ struct tomoyo_path_info {
 };
 
 /*
- * tomoyo_name_entry is a structure which is used for linking
+ * tomoyo_name is a structure which is used for linking
  * "struct tomoyo_path_info" into tomoyo_name_list .
  */
-struct tomoyo_name_entry {
+struct tomoyo_name {
        struct list_head list;
        atomic_t users;
        struct tomoyo_path_info entry;
 };
 
-/*
- * tomoyo_path_info_with_data is a structure which is used for holding a
- * pathname obtained from "struct dentry" and "struct vfsmount" pair.
- *
- * "struct tomoyo_path_info_with_data" consists of "struct tomoyo_path_info"
- * and buffer for the pathname, while "struct tomoyo_page_buffer" consists of
- * buffer for the pathname only.
- *
- * "struct tomoyo_path_info_with_data" is intended to allow TOMOYO to release
- * both "struct tomoyo_path_info" and buffer for the pathname by single kfree()
- * so that we don't need to return two pointers to the caller. If the caller
- * puts "struct tomoyo_path_info" on stack memory, we will be able to remove
- * "struct tomoyo_path_info_with_data".
- */
-struct tomoyo_path_info_with_data {
-       /* Keep "head" first, for this pointer is passed to kfree(). */
-       struct tomoyo_path_info head;
-       char barrier1[16]; /* Safeguard for overrun. */
-       char body[TOMOYO_MAX_PATHNAME_LEN];
-       char barrier2[16]; /* Safeguard for overrun. */
-};
-
 struct tomoyo_name_union {
        const struct tomoyo_path_info *filename;
-       struct tomoyo_path_group *group;
+       struct tomoyo_group *group;
        u8 is_group;
 };
 
-/* Structure for "path_group" directive. */
-struct tomoyo_path_group {
+struct tomoyo_number_union {
+       unsigned long values[2];
+       struct tomoyo_group *group;
+       u8 min_type;
+       u8 max_type;
+       u8 is_group;
+};
+
+/* Structure for "path_group"/"number_group" directive. */
+struct tomoyo_group {
        struct list_head list;
        const struct tomoyo_path_info *group_name;
        struct list_head member_list;
@@ -220,28 +344,35 @@ struct tomoyo_path_group {
 };
 
 /* Structure for "path_group" directive. */
-struct tomoyo_path_group_member {
-       struct list_head list;
-       bool is_deleted;
+struct tomoyo_path_group {
+       struct tomoyo_acl_head head;
        const struct tomoyo_path_info *member_name;
 };
 
+/* Structure for "number_group" directive. */
+struct tomoyo_number_group {
+       struct tomoyo_acl_head head;
+       struct tomoyo_number_union number;
+};
+
 /*
  * tomoyo_acl_info is a structure which is used for holding
  *
  *  (1) "list" which is linked to the ->acl_info_list of
  *      "struct tomoyo_domain_info"
- *  (2) "type" which tells type of the entry (either
- *      "struct tomoyo_path_acl" or "struct tomoyo_path2_acl").
+ *  (2) "is_deleted" is a bool which is true if this domain is marked as
+ *      "deleted", false otherwise.
+ *  (3) "type" which tells type of the entry.
  *
  * Packing "struct tomoyo_acl_info" allows
- * "struct tomoyo_path_acl" to embed "u8" + "u16" and
- * "struct tomoyo_path2_acl" to embed "u8"
- * without enlarging their structure size.
+ * "struct tomoyo_path_acl" to embed "u16" and "struct tomoyo_path2_acl"
+ * "struct tomoyo_path_number_acl" "struct tomoyo_mkdev_acl" to embed
+ * "u8" without enlarging their structure size.
  */
 struct tomoyo_acl_info {
        struct list_head list;
-       u8 type;
+       bool is_deleted;
+       u8 type; /* = one of values in "enum tomoyo_acl_entry_type_index". */
 } __packed;
 
 /*
@@ -299,19 +430,61 @@ struct tomoyo_domain_info {
  *  (3) "name" is the pathname.
  *
  * Directives held by this structure are "allow_read/write", "allow_execute",
- * "allow_read", "allow_write", "allow_create", "allow_unlink", "allow_mkdir",
- * "allow_rmdir", "allow_mkfifo", "allow_mksock", "allow_mkblock",
- * "allow_mkchar", "allow_truncate", "allow_symlink", "allow_rewrite",
- * "allow_chmod", "allow_chown", "allow_chgrp", "allow_chroot", "allow_mount"
- * and "allow_unmount".
+ * "allow_read", "allow_write", "allow_unlink", "allow_rmdir",
+ * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_chroot" and
+ * "allow_unmount".
  */
 struct tomoyo_path_acl {
        struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_ACL */
-       u8 perm_high;
        u16 perm;
        struct tomoyo_name_union name;
 };
 
+/*
+ * tomoyo_path_number_acl is a structure which is used for holding an
+ * entry with one pathname and one number operation.
+ * It has following fields.
+ *
+ *  (1) "head" which is a "struct tomoyo_acl_info".
+ *  (2) "perm" which is a bitmask of permitted operations.
+ *  (3) "name" is the pathname.
+ *  (4) "number" is the numeric value.
+ *
+ * Directives held by this structure are "allow_create", "allow_mkdir",
+ * "allow_ioctl", "allow_mkfifo", "allow_mksock", "allow_chmod", "allow_chown"
+ * and "allow_chgrp".
+ *
+ */
+struct tomoyo_path_number_acl {
+       struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_PATH_NUMBER_ACL */
+       u8 perm;
+       struct tomoyo_name_union name;
+       struct tomoyo_number_union number;
+};
+
+/*
+ * tomoyo_mkdev_acl is a structure which is used for holding an
+ * entry with one pathname and three numbers operation.
+ * It has following fields.
+ *
+ *  (1) "head" which is a "struct tomoyo_acl_info".
+ *  (2) "perm" which is a bitmask of permitted operations.
+ *  (3) "mode" is the create mode.
+ *  (4) "major" is the major number of device node.
+ *  (5) "minor" is the minor number of device node.
+ *
+ * Directives held by this structure are "allow_mkchar", "allow_mkblock".
+ *
+ */
+struct tomoyo_mkdev_acl {
+       struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MKDEV_ACL */
+       u8 perm;
+       struct tomoyo_name_union name;
+       struct tomoyo_number_union mode;
+       struct tomoyo_number_union major;
+       struct tomoyo_number_union minor;
+};
+
 /*
  * tomoyo_path2_acl is a structure which is used for holding an
  * entry with two pathnames operation (i.e. link(), rename() and pivot_root()).
@@ -333,53 +506,61 @@ struct tomoyo_path2_acl {
 };
 
 /*
- * tomoyo_io_buffer is a structure which is used for reading and modifying
- * configuration via /sys/kernel/security/tomoyo/ interface.
- * It has many fields. ->read_var1 , ->read_var2 , ->write_var1 are used as
- * cursors.
+ * tomoyo_mount_acl is a structure which is used for holding an
+ * entry for mount operation.
+ * It has following fields.
  *
- * Since the content of /sys/kernel/security/tomoyo/domain_policy is a list of
- * "struct tomoyo_domain_info" entries and each "struct tomoyo_domain_info"
- * entry has a list of "struct tomoyo_acl_info", we need two cursors when
- * reading (one is for traversing tomoyo_domain_list and the other is for
- * traversing "struct tomoyo_acl_info"->acl_info_list ).
+ *  (1) "head" which is a "struct tomoyo_acl_info".
+ *  (2) "dev_name" is the device name.
+ *  (3) "dir_name" is the mount point.
+ *  (4) "fs_type" is the filesystem type.
+ *  (5) "flags" is the mount flags.
  *
- * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
- * "select ", TOMOYO seeks the cursor ->read_var1 and ->write_var1 to the
- * domain with the domainname specified by the rest of that line (NULL is set
- * if seek failed).
- * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
- * "delete ", TOMOYO deletes an entry or a domain specified by the rest of that
- * line (->write_var1 is set to NULL if a domain was deleted).
- * If a line written to /sys/kernel/security/tomoyo/domain_policy starts with
- * neither "select " nor "delete ", an entry or a domain specified by that line
- * is appended.
+ * Directive held by this structure is "allow_mount".
+ */
+struct tomoyo_mount_acl {
+       struct tomoyo_acl_info head; /* type = TOMOYO_TYPE_MOUNT_ACL */
+       struct tomoyo_name_union dev_name;
+       struct tomoyo_name_union dir_name;
+       struct tomoyo_name_union fs_type;
+       struct tomoyo_number_union flags;
+};
+
+#define TOMOYO_MAX_IO_READ_QUEUE 32
+
+/*
+ * Structure for reading/writing policy via /sys/kernel/security/tomoyo
+ * interfaces.
  */
 struct tomoyo_io_buffer {
-       int (*read) (struct tomoyo_io_buffer *);
+       void (*read) (struct tomoyo_io_buffer *);
        int (*write) (struct tomoyo_io_buffer *);
+       int (*poll) (struct file *file, poll_table *wait);
        /* Exclusive lock for this structure.   */
        struct mutex io_sem;
        /* Index returned by tomoyo_read_lock(). */
        int reader_idx;
-       /* The position currently reading from. */
-       struct list_head *read_var1;
-       /* Extra variables for reading.         */
-       struct list_head *read_var2;
+       char __user *read_user_buf;
+       int read_user_buf_avail;
+       struct {
+               struct list_head *domain;
+               struct list_head *group;
+               struct list_head *acl;
+               int avail;
+               int step;
+               int query_index;
+               u16 index;
+               u8 bit;
+               u8 w_pos;
+               bool eof;
+               bool print_this_domain_only;
+               bool print_execute_only;
+               const char *w[TOMOYO_MAX_IO_READ_QUEUE];
+       } r;
        /* The position currently writing to.   */
        struct tomoyo_domain_info *write_var1;
-       /* The step for reading.                */
-       int read_step;
        /* Buffer for reading.                  */
        char *read_buf;
-       /* EOF flag for reading.                */
-       bool read_eof;
-       /* Read domain ACL of specified PID?    */
-       bool read_single_domain;
-       /* Extra variable for reading.          */
-       u8 read_bit;
-       /* Bytes available for reading.         */
-       int read_avail;
        /* Size of read buffer.                 */
        int readbuf_size;
        /* Buffer for writing.                  */
@@ -388,215 +569,203 @@ struct tomoyo_io_buffer {
        int write_avail;
        /* Size of write buffer.                */
        int writebuf_size;
+       /* Type of this interface.              */
+       u8 type;
 };
 
 /*
- * tomoyo_globally_readable_file_entry is a structure which is used for holding
+ * tomoyo_readable_file is a structure which is used for holding
  * "allow_read" entries.
  * It has following fields.
  *
- *  (1) "list" which is linked to tomoyo_globally_readable_list .
+ *  (1) "head" is "struct tomoyo_acl_head".
  *  (2) "filename" is a pathname which is allowed to open(O_RDONLY).
- *  (3) "is_deleted" is a bool which is true if marked as deleted, false
- *      otherwise.
  */
-struct tomoyo_globally_readable_file_entry {
-       struct list_head list;
+struct tomoyo_readable_file {
+       struct tomoyo_acl_head head;
        const struct tomoyo_path_info *filename;
-       bool is_deleted;
 };
 
 /*
- * tomoyo_pattern_entry is a structure which is used for holding
- * "tomoyo_pattern_list" entries.
+ * tomoyo_no_pattern is a structure which is used for holding
+ * "file_pattern" entries.
  * It has following fields.
  *
- *  (1) "list" which is linked to tomoyo_pattern_list .
+ *  (1) "head" is "struct tomoyo_acl_head".
  *  (2) "pattern" is a pathname pattern which is used for converting pathnames
  *      to pathname patterns during learning mode.
- *  (3) "is_deleted" is a bool which is true if marked as deleted, false
- *      otherwise.
  */
-struct tomoyo_pattern_entry {
-       struct list_head list;
+struct tomoyo_no_pattern {
+       struct tomoyo_acl_head head;
        const struct tomoyo_path_info *pattern;
-       bool is_deleted;
 };
 
 /*
- * tomoyo_no_rewrite_entry is a structure which is used for holding
+ * tomoyo_no_rewrite is a structure which is used for holding
  * "deny_rewrite" entries.
  * It has following fields.
  *
- *  (1) "list" which is linked to tomoyo_no_rewrite_list .
+ *  (1) "head" is "struct tomoyo_acl_head".
  *  (2) "pattern" is a pathname which is by default not permitted to modify
  *      already existing content.
- *  (3) "is_deleted" is a bool which is true if marked as deleted, false
- *      otherwise.
  */
-struct tomoyo_no_rewrite_entry {
-       struct list_head list;
+struct tomoyo_no_rewrite {
+       struct tomoyo_acl_head head;
        const struct tomoyo_path_info *pattern;
-       bool is_deleted;
 };
 
 /*
- * tomoyo_domain_initializer_entry is a structure which is used for holding
- * "initialize_domain" and "no_initialize_domain" entries.
+ * tomoyo_transition_control is a structure which is used for holding
+ * "initialize_domain"/"no_initialize_domain"/"keep_domain"/"no_keep_domain"
+ * entries.
  * It has following fields.
  *
- *  (1) "list" which is linked to tomoyo_domain_initializer_list .
- *  (2) "domainname" which is "a domainname" or "the last component of a
- *      domainname". This field is NULL if "from" clause is not specified.
- *  (3) "program" which is a program's pathname.
- *  (4) "is_deleted" is a bool which is true if marked as deleted, false
- *      otherwise.
- *  (5) "is_not" is a bool which is true if "no_initialize_domain", false
- *      otherwise.
- *  (6) "is_last_name" is a bool which is true if "domainname" is "the last
+ *  (1) "head" is "struct tomoyo_acl_head".
+ *  (2) "type" is type of this entry.
+ *  (3) "is_last_name" is a bool which is true if "domainname" is "the last
  *      component of a domainname", false otherwise.
- */
-struct tomoyo_domain_initializer_entry {
-       struct list_head list;
-       const struct tomoyo_path_info *domainname;    /* This may be NULL */
-       const struct tomoyo_path_info *program;
-       bool is_deleted;
-       bool is_not;       /* True if this entry is "no_initialize_domain".  */
-       /* True if the domainname is tomoyo_get_last_name(). */
-       bool is_last_name;
-};
-
-/*
- * tomoyo_domain_keeper_entry is a structure which is used for holding
- * "keep_domain" and "no_keep_domain" entries.
- * It has following fields.
- *
- *  (1) "list" which is linked to tomoyo_domain_keeper_list .
- *  (2) "domainname" which is "a domainname" or "the last component of a
+ *  (4) "domainname" which is "a domainname" or "the last component of a
  *      domainname".
- *  (3) "program" which is a program's pathname.
- *      This field is NULL if "from" clause is not specified.
- *  (4) "is_deleted" is a bool which is true if marked as deleted, false
- *      otherwise.
- *  (5) "is_not" is a bool which is true if "no_initialize_domain", false
- *      otherwise.
- *  (6) "is_last_name" is a bool which is true if "domainname" is "the last
- *      component of a domainname", false otherwise.
+ *  (5) "program" which is a program's pathname.
  */
-struct tomoyo_domain_keeper_entry {
-       struct list_head list;
-       const struct tomoyo_path_info *domainname;
-       const struct tomoyo_path_info *program;       /* This may be NULL */
-       bool is_deleted;
-       bool is_not;       /* True if this entry is "no_keep_domain".        */
+struct tomoyo_transition_control {
+       struct tomoyo_acl_head head;
+       u8 type; /* One of values in "enum tomoyo_transition_type".  */
        /* True if the domainname is tomoyo_get_last_name(). */
        bool is_last_name;
+       const struct tomoyo_path_info *domainname; /* Maybe NULL */
+       const struct tomoyo_path_info *program;    /* Maybe NULL */
 };
 
 /*
- * tomoyo_alias_entry is a structure which is used for holding "alias" entries.
+ * tomoyo_aggregator is a structure which is used for holding
+ * "aggregator" entries.
  * It has following fields.
  *
- *  (1) "list" which is linked to tomoyo_alias_list .
- *  (2) "original_name" which is a dereferenced pathname.
- *  (3) "aliased_name" which is a symlink's pathname.
- *  (4) "is_deleted" is a bool which is true if marked as deleted, false
- *      otherwise.
+ *  (1) "head" is "struct tomoyo_acl_head".
+ *  (2) "original_name" which is originally requested name.
+ *  (3) "aggregated_name" which is name to rewrite.
  */
-struct tomoyo_alias_entry {
-       struct list_head list;
+struct tomoyo_aggregator {
+       struct tomoyo_acl_head head;
        const struct tomoyo_path_info *original_name;
-       const struct tomoyo_path_info *aliased_name;
-       bool is_deleted;
+       const struct tomoyo_path_info *aggregated_name;
 };
 
 /*
- * tomoyo_policy_manager_entry is a structure which is used for holding list of
+ * tomoyo_manager is a structure which is used for holding list of
  * domainnames or programs which are permitted to modify configuration via
  * /sys/kernel/security/tomoyo/ interface.
  * It has following fields.
  *
- *  (1) "list" which is linked to tomoyo_policy_manager_list .
- *  (2) "manager" is a domainname or a program's pathname.
- *  (3) "is_domain" is a bool which is true if "manager" is a domainname, false
- *      otherwise.
- *  (4) "is_deleted" is a bool which is true if marked as deleted, false
+ *  (1) "head" is "struct tomoyo_acl_head".
+ *  (2) "is_domain" is a bool which is true if "manager" is a domainname, false
  *      otherwise.
+ *  (3) "manager" is a domainname or a program's pathname.
  */
-struct tomoyo_policy_manager_entry {
-       struct list_head list;
+struct tomoyo_manager {
+       struct tomoyo_acl_head head;
+       bool is_domain;  /* True if manager is a domainname. */
        /* A path to program or a domainname. */
        const struct tomoyo_path_info *manager;
-       bool is_domain;  /* True if manager is a domainname. */
-       bool is_deleted; /* True if this entry is deleted. */
+};
+
+struct tomoyo_preference {
+       unsigned int learning_max_entry;
+       bool enforcing_verbose;
+       bool learning_verbose;
+       bool permissive_verbose;
+};
+
+struct tomoyo_profile {
+       const struct tomoyo_path_info *comment;
+       struct tomoyo_preference *learning;
+       struct tomoyo_preference *permissive;
+       struct tomoyo_preference *enforcing;
+       struct tomoyo_preference preference;
+       u8 default_config;
+       u8 config[TOMOYO_MAX_MAC_INDEX + TOMOYO_MAX_MAC_CATEGORY_INDEX];
 };
 
 /********** Function prototypes. **********/
 
-/* Check whether the given name matches the given name_union. */
-bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
-                              const struct tomoyo_name_union *ptr);
+extern asmlinkage long sys_getpid(void);
+extern asmlinkage long sys_getppid(void);
+
+/* Check whether the given string starts with the given keyword. */
+bool tomoyo_str_starts(char **src, const char *find);
+/* Get tomoyo_realpath() of current process. */
+const char *tomoyo_get_exe(void);
+/* Format string. */
+void tomoyo_normalize_line(unsigned char *buffer);
+/* Print warning or error message on console. */
+void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...)
+     __attribute__ ((format(printf, 2, 3)));
+/* Check all profiles currently assigned to domains are defined. */
+void tomoyo_check_profile(void);
+/* Open operation for /sys/kernel/security/tomoyo/ interface. */
+int tomoyo_open_control(const u8 type, struct file *file);
+/* Close /sys/kernel/security/tomoyo/ interface. */
+int tomoyo_close_control(struct file *file);
+/* Poll operation for /sys/kernel/security/tomoyo/ interface. */
+int tomoyo_poll_control(struct file *file, poll_table *wait);
+/* Read operation for /sys/kernel/security/tomoyo/ interface. */
+int tomoyo_read_control(struct file *file, char __user *buffer,
+                       const int buffer_len);
+/* Write operation for /sys/kernel/security/tomoyo/ interface. */
+int tomoyo_write_control(struct file *file, const char __user *buffer,
+                        const int buffer_len);
 /* Check whether the domain has too many ACL entries to hold. */
-bool tomoyo_domain_quota_is_ok(struct tomoyo_domain_info * const domain);
-/* Transactional sprintf() for policy dump. */
-bool tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
+bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r);
+/* Print out of memory warning message. */
+void tomoyo_warn_oom(const char *function);
+/* Check whether the given name matches the given name_union. */
+const struct tomoyo_path_info *
+tomoyo_compare_name_union(const struct tomoyo_path_info *name,
+                         const struct tomoyo_name_union *ptr);
+/* Check whether the given number matches the given number_union. */
+bool tomoyo_compare_number_union(const unsigned long value,
+                                const struct tomoyo_number_union *ptr);
+int tomoyo_get_mode(const u8 profile, const u8 index);
+void tomoyo_io_printf(struct tomoyo_io_buffer *head, const char *fmt, ...)
        __attribute__ ((format(printf, 2, 3)));
 /* Check whether the domainname is correct. */
-bool tomoyo_is_correct_domain(const unsigned char *domainname);
+bool tomoyo_correct_domain(const unsigned char *domainname);
 /* Check whether the token is correct. */
-bool tomoyo_is_correct_path(const char *filename, const s8 start_type,
-                           const s8 pattern_type, const s8 end_type);
+bool tomoyo_correct_path(const char *filename);
+bool tomoyo_correct_word(const char *string);
 /* Check whether the token can be a domainname. */
-bool tomoyo_is_domain_def(const unsigned char *buffer);
+bool tomoyo_domain_def(const unsigned char *buffer);
 bool tomoyo_parse_name_union(const char *filename,
                             struct tomoyo_name_union *ptr);
 /* Check whether the given filename matches the given path_group. */
-bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
-                              const struct tomoyo_path_group *group,
-                              const bool may_use_pattern);
+const struct tomoyo_path_info *
+tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
+                         const struct tomoyo_group *group);
+/* Check whether the given value matches the given number_group. */
+bool tomoyo_number_matches_group(const unsigned long min,
+                                const unsigned long max,
+                                const struct tomoyo_group *group);
 /* Check whether the given filename matches the given pattern. */
 bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
                                 const struct tomoyo_path_info *pattern);
-/* Read "alias" entry in exception policy. */
-bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head);
-/*
- * Read "initialize_domain" and "no_initialize_domain" entry
- * in exception policy.
- */
-bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head);
-/* Read "keep_domain" and "no_keep_domain" entry in exception policy. */
-bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head);
-/* Read "file_pattern" entry in exception policy. */
-bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head);
-/* Read "path_group" entry in exception policy. */
-bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head);
-/* Read "allow_read" entry in exception policy. */
-bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head);
-/* Read "deny_rewrite" entry in exception policy. */
-bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head);
+
+bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num);
 /* Tokenize a line. */
 bool tomoyo_tokenize(char *buffer, char *w[], size_t size);
 /* Write domain policy violation warning message to console? */
 bool tomoyo_verbose_mode(const struct tomoyo_domain_info *domain);
-/* Convert double path operation to operation name. */
-const char *tomoyo_path22keyword(const u8 operation);
-/* Get the last component of the given domainname. */
-const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain);
-/* Get warning message. */
-const char *tomoyo_get_msg(const bool is_enforce);
-/* Convert single path operation to operation name. */
-const char *tomoyo_path2keyword(const u8 operation);
-/* Create "alias" entry in exception policy. */
-int tomoyo_write_alias_policy(char *data, const bool is_delete);
-/*
- * Create "initialize_domain" and "no_initialize_domain" entry
- * in exception policy.
- */
-int tomoyo_write_domain_initializer_policy(char *data, const bool is_not,
-                                          const bool is_delete);
-/* Create "keep_domain" and "no_keep_domain" entry in exception policy. */
-int tomoyo_write_domain_keeper_policy(char *data, const bool is_not,
-                                     const bool is_delete);
+/* Fill "struct tomoyo_request_info". */
+int tomoyo_init_request_info(struct tomoyo_request_info *r,
+                            struct tomoyo_domain_info *domain,
+                            const u8 index);
+/* Check permission for mount operation. */
+int tomoyo_mount_permission(char *dev_name, struct path *path, char *type,
+                           unsigned long flags, void *data_page);
+/* Create "aggregator" entry in exception policy. */
+int tomoyo_write_aggregator(char *data, const bool is_delete);
+int tomoyo_write_transition_control(char *data, const bool is_delete,
+                                   const u8 type);
 /*
  * Create "allow_read/write", "allow_execute", "allow_read", "allow_write",
  * "allow_create", "allow_unlink", "allow_mkdir", "allow_rmdir",
@@ -604,25 +773,31 @@ int tomoyo_write_domain_keeper_policy(char *data, const bool is_not,
  * "allow_truncate", "allow_symlink", "allow_rewrite", "allow_rename" and
  * "allow_link" entry in domain policy.
  */
-int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
-                            const bool is_delete);
+int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain,
+                     const bool is_delete);
 /* Create "allow_read" entry in exception policy. */
-int tomoyo_write_globally_readable_policy(char *data, const bool is_delete);
+int tomoyo_write_globally_readable(char *data, const bool is_delete);
+/* Create "allow_mount" entry in domain policy. */
+int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain,
+                      const bool is_delete);
 /* Create "deny_rewrite" entry in exception policy. */
-int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete);
+int tomoyo_write_no_rewrite(char *data, const bool is_delete);
 /* Create "file_pattern" entry in exception policy. */
-int tomoyo_write_pattern_policy(char *data, const bool is_delete);
-/* Create "path_group" entry in exception policy. */
-int tomoyo_write_path_group_policy(char *data, const bool is_delete);
+int tomoyo_write_pattern(char *data, const bool is_delete);
+/* Create "path_group"/"number_group" entry in exception policy. */
+int tomoyo_write_group(char *data, const bool is_delete, const u8 type);
+int tomoyo_supervisor(struct tomoyo_request_info *r, const char *fmt, ...)
+     __attribute__ ((format(printf, 2, 3)));
 /* Find a domain by the given name. */
 struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname);
 /* Find or create a domain by the given name. */
-struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
-                                                           domainname,
-                                                           const u8 profile);
-
-/* Allocate memory for "struct tomoyo_path_group". */
-struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name);
+struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
+                                               const u8 profile);
+struct tomoyo_profile *tomoyo_profile(const u8 profile);
+/*
+ * Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group".
+ */
+struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 type);
 
 /* Check mode for specified functionality. */
 unsigned int tomoyo_check_flags(const struct tomoyo_domain_info *domain,
@@ -632,25 +807,23 @@ void tomoyo_fill_path_info(struct tomoyo_path_info *ptr);
 /* Run policy loader when /sbin/init starts. */
 void tomoyo_load_policy(const char *filename);
 
-/* Convert binary string to ascii string. */
-int tomoyo_encode(char *buffer, int buflen, const char *str);
+void tomoyo_put_number_union(struct tomoyo_number_union *ptr);
 
-/* Returns realpath(3) of the given pathname but ignores chroot'ed root. */
-int tomoyo_realpath_from_path2(struct path *path, char *newname,
-                              int newname_len);
+/* Convert binary string to ascii string. */
+char *tomoyo_encode(const char *str);
 
 /*
- * Returns realpath(3) of the given pathname but ignores chroot'ed root.
- * These functions use kzalloc(), so the caller must call kfree()
- * if these functions didn't return NULL.
+ * Returns realpath(3) of the given pathname except that
+ * ignores chroot'ed root and does not follow the final symlink.
  */
-char *tomoyo_realpath(const char *pathname);
+char *tomoyo_realpath_nofollow(const char *pathname);
 /*
- * Same with tomoyo_realpath() except that it doesn't follow the final symlink.
+ * Returns realpath(3) of the given pathname except that
+ * ignores chroot'ed root and the pathname is already solved.
  */
-char *tomoyo_realpath_nofollow(const char *pathname);
-/* Same with tomoyo_realpath() except that the pathname is already solved. */
 char *tomoyo_realpath_from_path(struct path *path);
+/* Get patterned pathname. */
+const char *tomoyo_pattern(const struct tomoyo_path_info *filename);
 
 /* Check memory quota. */
 bool tomoyo_memory_ok(void *ptr);
@@ -663,23 +836,29 @@ void *tomoyo_commit_ok(void *data, const unsigned int size);
 const struct tomoyo_path_info *tomoyo_get_name(const char *name);
 
 /* Check for memory usage. */
-int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
+void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head);
 
 /* Set memory quota. */
 int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head);
 
-/* Initialize realpath related code. */
-void __init tomoyo_realpath_init(void);
-int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain,
+/* Initialize mm related code. */
+void __init tomoyo_mm_init(void);
+int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
                           const struct tomoyo_path_info *filename);
 int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
                                 struct path *path, const int flag);
+int tomoyo_path_number_perm(const u8 operation, struct path *path,
+                           unsigned long number);
+int tomoyo_mkdev_perm(const u8 operation, struct path *path,
+                     const unsigned int mode, unsigned int dev);
 int tomoyo_path_perm(const u8 operation, struct path *path);
 int tomoyo_path2_perm(const u8 operation, struct path *path1,
                      struct path *path2);
-int tomoyo_check_rewrite_permission(struct file *filp);
 int tomoyo_find_next_domain(struct linux_binprm *bprm);
 
+void tomoyo_print_ulong(char *buffer, const int buffer_len,
+                       const unsigned long value, const u8 type);
+
 /* Drop refcount on tomoyo_name_union. */
 void tomoyo_put_name_union(struct tomoyo_name_union *ptr);
 
@@ -688,6 +867,25 @@ void tomoyo_run_gc(void);
 
 void tomoyo_memory_free(void *ptr);
 
+int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
+                        bool is_delete, struct tomoyo_domain_info *domain,
+                        bool (*check_duplicate) (const struct tomoyo_acl_info
+                                                 *,
+                                                 const struct tomoyo_acl_info
+                                                 *),
+                        bool (*merge_duplicate) (struct tomoyo_acl_info *,
+                                                 struct tomoyo_acl_info *,
+                                                 const bool));
+int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
+                        bool is_delete, struct list_head *list,
+                        bool (*check_duplicate) (const struct tomoyo_acl_head
+                                                 *,
+                                                 const struct tomoyo_acl_head
+                                                 *));
+void tomoyo_check_acl(struct tomoyo_request_info *r,
+                     bool (*check_entry) (struct tomoyo_request_info *,
+                                          const struct tomoyo_acl_info *));
+
 /********** External variable definitions. **********/
 
 /* Lock for GC. */
@@ -696,14 +894,8 @@ extern struct srcu_struct tomoyo_ss;
 /* The list for "struct tomoyo_domain_info". */
 extern struct list_head tomoyo_domain_list;
 
-extern struct list_head tomoyo_path_group_list;
-extern struct list_head tomoyo_domain_initializer_list;
-extern struct list_head tomoyo_domain_keeper_list;
-extern struct list_head tomoyo_alias_list;
-extern struct list_head tomoyo_globally_readable_list;
-extern struct list_head tomoyo_pattern_list;
-extern struct list_head tomoyo_no_rewrite_list;
-extern struct list_head tomoyo_policy_manager_list;
+extern struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY];
+extern struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP];
 extern struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
 
 /* Lock for protecting policy. */
@@ -715,6 +907,14 @@ extern bool tomoyo_policy_loaded;
 /* The kernel's domain. */
 extern struct tomoyo_domain_info tomoyo_kernel_domain;
 
+extern const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION];
+extern const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION];
+extern const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION];
+extern const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION];
+
+extern unsigned int tomoyo_quota_for_query;
+extern unsigned int tomoyo_query_memory_size;
+
 /********** Inlined functions. **********/
 
 static inline int tomoyo_read_lock(void)
@@ -735,25 +935,25 @@ static inline bool tomoyo_pathcmp(const struct tomoyo_path_info *a,
 }
 
 /**
- * tomoyo_is_valid - Check whether the character is a valid char.
+ * tomoyo_valid - Check whether the character is a valid char.
  *
  * @c: The character to check.
  *
  * Returns true if @c is a valid character, false otherwise.
  */
-static inline bool tomoyo_is_valid(const unsigned char c)
+static inline bool tomoyo_valid(const unsigned char c)
 {
        return c > ' ' && c < 127;
 }
 
 /**
- * tomoyo_is_invalid - Check whether the character is an invalid char.
+ * tomoyo_invalid - Check whether the character is an invalid char.
  *
  * @c: The character to check.
  *
  * Returns true if @c is an invalid character, false otherwise.
  */
-static inline bool tomoyo_is_invalid(const unsigned char c)
+static inline bool tomoyo_invalid(const unsigned char c)
 {
        return c && (c <= ' ' || c >= 127);
 }
@@ -761,13 +961,13 @@ static inline bool tomoyo_is_invalid(const unsigned char c)
 static inline void tomoyo_put_name(const struct tomoyo_path_info *name)
 {
        if (name) {
-               struct tomoyo_name_entry *ptr =
-                       container_of(name, struct tomoyo_name_entry, entry);
+               struct tomoyo_name *ptr =
+                       container_of(name, typeof(*ptr), entry);
                atomic_dec(&ptr->users);
        }
 }
 
-static inline void tomoyo_put_path_group(struct tomoyo_path_group *group)
+static inline void tomoyo_put_group(struct tomoyo_group *group)
 {
        if (group)
                atomic_dec(&group->users);
@@ -784,75 +984,35 @@ static inline struct tomoyo_domain_info *tomoyo_real_domain(struct task_struct
        return task_cred_xxx(task, security);
 }
 
-static inline bool tomoyo_is_same_acl_head(const struct tomoyo_acl_info *p1,
+static inline bool tomoyo_same_acl_head(const struct tomoyo_acl_info *p1,
                                           const struct tomoyo_acl_info *p2)
 {
        return p1->type == p2->type;
 }
 
-static inline bool tomoyo_is_same_name_union
+static inline bool tomoyo_same_name_union
 (const struct tomoyo_name_union *p1, const struct tomoyo_name_union *p2)
 {
        return p1->filename == p2->filename && p1->group == p2->group &&
                p1->is_group == p2->is_group;
 }
 
-static inline bool tomoyo_is_same_path_acl(const struct tomoyo_path_acl *p1,
-                                          const struct tomoyo_path_acl *p2)
-{
-       return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
-               tomoyo_is_same_name_union(&p1->name, &p2->name);
-}
-
-static inline bool tomoyo_is_same_path2_acl(const struct tomoyo_path2_acl *p1,
-                                           const struct tomoyo_path2_acl *p2)
+static inline bool tomoyo_same_number_union
+(const struct tomoyo_number_union *p1, const struct tomoyo_number_union *p2)
 {
-       return tomoyo_is_same_acl_head(&p1->head, &p2->head) &&
-               tomoyo_is_same_name_union(&p1->name1, &p2->name1) &&
-               tomoyo_is_same_name_union(&p1->name2, &p2->name2);
-}
-
-static inline bool tomoyo_is_same_domain_initializer_entry
-(const struct tomoyo_domain_initializer_entry *p1,
- const struct tomoyo_domain_initializer_entry *p2)
-{
-       return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
-               && p1->domainname == p2->domainname
-               && p1->program == p2->program;
-}
-
-static inline bool tomoyo_is_same_domain_keeper_entry
-(const struct tomoyo_domain_keeper_entry *p1,
- const struct tomoyo_domain_keeper_entry *p2)
-{
-       return p1->is_not == p2->is_not && p1->is_last_name == p2->is_last_name
-               && p1->domainname == p2->domainname
-               && p1->program == p2->program;
-}
-
-static inline bool tomoyo_is_same_alias_entry
-(const struct tomoyo_alias_entry *p1, const struct tomoyo_alias_entry *p2)
-{
-       return p1->original_name == p2->original_name &&
-               p1->aliased_name == p2->aliased_name;
+       return p1->values[0] == p2->values[0] && p1->values[1] == p2->values[1]
+               && p1->group == p2->group && p1->min_type == p2->min_type &&
+               p1->max_type == p2->max_type && p1->is_group == p2->is_group;
 }
 
 /**
  * list_for_each_cookie - iterate over a list with cookie.
  * @pos:        the &struct list_head to use as a loop cursor.
- * @cookie:     the &struct list_head to use as a cookie.
  * @head:       the head for your list.
- *
- * Same with list_for_each_rcu() except that this primitive uses @cookie
- * so that we can continue iteration.
- * @cookie must be NULL when iteration starts, and @cookie will become
- * NULL when iteration finishes.
  */
-#define list_for_each_cookie(pos, cookie, head)                                \
-       for (({ if (!cookie)                                            \
-                                    cookie = head; }),                 \
-                    pos = rcu_dereference((cookie)->next);             \
-            prefetch(pos->next), pos != (head) || ((cookie) = NULL);   \
-            (cookie) = pos, pos = rcu_dereference(pos->next))
+#define list_for_each_cookie(pos, head)                                        \
+       if (!pos)                                                       \
+               pos =  srcu_dereference((head)->next, &tomoyo_ss);      \
+       for ( ; pos != (head); pos = srcu_dereference(pos->next, &tomoyo_ss))
 
 #endif /* !defined(_SECURITY_TOMOYO_COMMON_H) */
index cd8ba444676344f71543a1cddd42ff3069e0ccf0..35388408e475470b6c2467db248a05b1b01c2ca7 100644 (file)
@@ -1,12 +1,9 @@
 /*
  * security/tomoyo/domain.c
  *
- * Implementation of the Domain-Based Mandatory Access Control.
- *
- * Copyright (C) 2005-2009  NTT DATA CORPORATION
- *
- * Version: 2.2.0   2009/04/01
+ * Domain transition functions for TOMOYO.
  *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
  */
 
 #include "common.h"
 /* The initial domain. */
 struct tomoyo_domain_info tomoyo_kernel_domain;
 
-/*
- * tomoyo_domain_list is used for holding list of domains.
- * The ->acl_info_list of "struct tomoyo_domain_info" is used for holding
- * permissions (e.g. "allow_read /lib/libc-2.5.so") given to each domain.
- *
- * An entry is added by
- *
- * # ( echo "<kernel>"; echo "allow_execute /sbin/init" ) > \
- *                                  /sys/kernel/security/tomoyo/domain_policy
- *
- * and is deleted by
- *
- * # ( echo "<kernel>"; echo "delete allow_execute /sbin/init" ) > \
- *                                  /sys/kernel/security/tomoyo/domain_policy
- *
- * and all entries are retrieved by
- *
- * # cat /sys/kernel/security/tomoyo/domain_policy
- *
- * A domain is added by
- *
- * # echo "<kernel>" > /sys/kernel/security/tomoyo/domain_policy
- *
- * and is deleted by
- *
- * # echo "delete <kernel>" > /sys/kernel/security/tomoyo/domain_policy
- *
- * and all domains are retrieved by
- *
- * # grep '^<kernel>' /sys/kernel/security/tomoyo/domain_policy
- *
- * Normally, a domainname is monotonically getting longer because a domainname
- * which the process will belong to if an execve() operation succeeds is
- * defined as a concatenation of "current domainname" + "pathname passed to
- * execve()".
- * See tomoyo_domain_initializer_list and tomoyo_domain_keeper_list for
- * exceptions.
- */
-LIST_HEAD(tomoyo_domain_list);
-
 /**
- * tomoyo_get_last_name - Get last component of a domainname.
- *
- * @domain: Pointer to "struct tomoyo_domain_info".
- *
- * Returns the last component of the domainname.
- */
-const char *tomoyo_get_last_name(const struct tomoyo_domain_info *domain)
-{
-       const char *cp0 = domain->domainname->name;
-       const char *cp1 = strrchr(cp0, ' ');
-
-       if (cp1)
-               return cp1 + 1;
-       return cp0;
-}
-
-/*
- * tomoyo_domain_initializer_list is used for holding list of programs which
- * triggers reinitialization of domainname. Normally, a domainname is
- * monotonically getting longer. But sometimes, we restart daemon programs.
- * It would be convenient for us that "a daemon started upon system boot" and
- * "the daemon restarted from console" belong to the same domain. Thus, TOMOYO
- * provides a way to shorten domainnames.
+ * tomoyo_update_policy - Update an entry for exception policy.
  *
- * An entry is added by
- *
- * # echo 'initialize_domain /usr/sbin/httpd' > \
- *                               /sys/kernel/security/tomoyo/exception_policy
- *
- * and is deleted by
- *
- * # echo 'delete initialize_domain /usr/sbin/httpd' > \
- *                               /sys/kernel/security/tomoyo/exception_policy
- *
- * and all entries are retrieved by
- *
- * # grep ^initialize_domain /sys/kernel/security/tomoyo/exception_policy
- *
- * In the example above, /usr/sbin/httpd will belong to
- * "<kernel> /usr/sbin/httpd" domain.
- *
- * You may specify a domainname using "from" keyword.
- * "initialize_domain /usr/sbin/httpd from <kernel> /etc/rc.d/init.d/httpd"
- * will cause "/usr/sbin/httpd" executed from "<kernel> /etc/rc.d/init.d/httpd"
- * domain to belong to "<kernel> /usr/sbin/httpd" domain.
- *
- * You may add "no_" prefix to "initialize_domain".
- * "initialize_domain /usr/sbin/httpd" and
- * "no_initialize_domain /usr/sbin/httpd from <kernel> /etc/rc.d/init.d/httpd"
- * will cause "/usr/sbin/httpd" to belong to "<kernel> /usr/sbin/httpd" domain
- * unless executed from "<kernel> /etc/rc.d/init.d/httpd" domain.
- */
-LIST_HEAD(tomoyo_domain_initializer_list);
-
-/**
- * tomoyo_update_domain_initializer_entry - Update "struct tomoyo_domain_initializer_entry" list.
- *
- * @domainname: The name of domain. May be NULL.
- * @program:    The name of program.
- * @is_not:     True if it is "no_initialize_domain" entry.
- * @is_delete:  True if it is a delete request.
+ * @new_entry:       Pointer to "struct tomoyo_acl_info".
+ * @size:            Size of @new_entry in bytes.
+ * @is_delete:       True if it is a delete request.
+ * @list:            Pointer to "struct list_head".
+ * @check_duplicate: Callback function to find duplicated entry.
  *
  * Returns 0 on success, negative value otherwise.
  *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_update_domain_initializer_entry(const char *domainname,
-                                                 const char *program,
-                                                 const bool is_not,
-                                                 const bool is_delete)
+int tomoyo_update_policy(struct tomoyo_acl_head *new_entry, const int size,
+                        bool is_delete, struct list_head *list,
+                        bool (*check_duplicate) (const struct tomoyo_acl_head
+                                                 *,
+                                                 const struct tomoyo_acl_head
+                                                 *))
 {
-       struct tomoyo_domain_initializer_entry *ptr;
-       struct tomoyo_domain_initializer_entry e = { .is_not = is_not };
        int error = is_delete ? -ENOENT : -ENOMEM;
+       struct tomoyo_acl_head *entry;
 
-       if (!tomoyo_is_correct_path(program, 1, -1, -1))
-               return -EINVAL; /* No patterns allowed. */
-       if (domainname) {
-               if (!tomoyo_is_domain_def(domainname) &&
-                   tomoyo_is_correct_path(domainname, 1, -1, -1))
-                       e.is_last_name = true;
-               else if (!tomoyo_is_correct_domain(domainname))
-                       return -EINVAL;
-               e.domainname = tomoyo_get_name(domainname);
-               if (!e.domainname)
-                       goto out;
-       }
-       e.program = tomoyo_get_name(program);
-       if (!e.program)
-               goto out;
        if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list, list) {
-               if (!tomoyo_is_same_domain_initializer_entry(ptr, &e))
+               return -ENOMEM;
+       list_for_each_entry_rcu(entry, list, list) {
+               if (!check_duplicate(entry, new_entry))
                        continue;
-               ptr->is_deleted = is_delete;
+               entry->is_deleted = is_delete;
                error = 0;
                break;
        }
-       if (!is_delete && error) {
-               struct tomoyo_domain_initializer_entry *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
+       if (error && !is_delete) {
+               entry = tomoyo_commit_ok(new_entry, size);
                if (entry) {
-                       list_add_tail_rcu(&entry->list,
-                                         &tomoyo_domain_initializer_list);
+                       list_add_tail_rcu(&entry->list, list);
                        error = 0;
                }
        }
        mutex_unlock(&tomoyo_policy_lock);
- out:
-       tomoyo_put_name(e.domainname);
-       tomoyo_put_name(e.program);
        return error;
 }
 
 /**
- * tomoyo_read_domain_initializer_policy - Read "struct tomoyo_domain_initializer_entry" list.
+ * tomoyo_update_domain - Update an entry for domain policy.
  *
- * @head: Pointer to "struct tomoyo_io_buffer".
+ * @new_entry:       Pointer to "struct tomoyo_acl_info".
+ * @size:            Size of @new_entry in bytes.
+ * @is_delete:       True if it is a delete request.
+ * @domain:          Pointer to "struct tomoyo_domain_info".
+ * @check_duplicate: Callback function to find duplicated entry.
+ * @merge_duplicate: Callback function to merge duplicated entry.
  *
- * Returns true on success, false otherwise.
+ * Returns 0 on success, negative value otherwise.
  *
  * Caller holds tomoyo_read_lock().
  */
-bool tomoyo_read_domain_initializer_policy(struct tomoyo_io_buffer *head)
+int tomoyo_update_domain(struct tomoyo_acl_info *new_entry, const int size,
+                        bool is_delete, struct tomoyo_domain_info *domain,
+                        bool (*check_duplicate) (const struct tomoyo_acl_info
+                                                 *,
+                                                 const struct tomoyo_acl_info
+                                                 *),
+                        bool (*merge_duplicate) (struct tomoyo_acl_info *,
+                                                 struct tomoyo_acl_info *,
+                                                 const bool))
 {
-       struct list_head *pos;
-       bool done = true;
+       int error = is_delete ? -ENOENT : -ENOMEM;
+       struct tomoyo_acl_info *entry;
 
-       list_for_each_cookie(pos, head->read_var2,
-                            &tomoyo_domain_initializer_list) {
-               const char *no;
-               const char *from = "";
-               const char *domain = "";
-               struct tomoyo_domain_initializer_entry *ptr;
-               ptr = list_entry(pos, struct tomoyo_domain_initializer_entry,
-                                 list);
-               if (ptr->is_deleted)
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               return error;
+       list_for_each_entry_rcu(entry, &domain->acl_info_list, list) {
+               if (!check_duplicate(entry, new_entry))
                        continue;
-               no = ptr->is_not ? "no_" : "";
-               if (ptr->domainname) {
-                       from = " from ";
-                       domain = ptr->domainname->name;
+               if (merge_duplicate)
+                       entry->is_deleted = merge_duplicate(entry, new_entry,
+                                                           is_delete);
+               else
+                       entry->is_deleted = is_delete;
+               error = 0;
+               break;
+       }
+       if (error && !is_delete) {
+               entry = tomoyo_commit_ok(new_entry, size);
+               if (entry) {
+                       list_add_tail_rcu(&entry->list, &domain->acl_info_list);
+                       error = 0;
                }
-               done = tomoyo_io_printf(head,
-                                       "%s" TOMOYO_KEYWORD_INITIALIZE_DOMAIN
-                                       "%s%s%s\n", no, ptr->program->name,
-                                       from, domain);
-               if (!done)
-                       break;
        }
-       return done;
+       mutex_unlock(&tomoyo_policy_lock);
+       return error;
 }
 
-/**
- * tomoyo_write_domain_initializer_policy - Write "struct tomoyo_domain_initializer_entry" list.
- *
- * @data:      String to parse.
- * @is_not:    True if it is "no_initialize_domain" entry.
- * @is_delete: True if it is a delete request.
- *
- * Returns 0 on success, negative value otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-int tomoyo_write_domain_initializer_policy(char *data, const bool is_not,
-                                          const bool is_delete)
+void tomoyo_check_acl(struct tomoyo_request_info *r,
+                     bool (*check_entry) (struct tomoyo_request_info *,
+                                          const struct tomoyo_acl_info *))
 {
-       char *cp = strstr(data, " from ");
+       const struct tomoyo_domain_info *domain = r->domain;
+       struct tomoyo_acl_info *ptr;
 
-       if (cp) {
-               *cp = '\0';
-               return tomoyo_update_domain_initializer_entry(cp + 6, data,
-                                                             is_not,
-                                                             is_delete);
+       list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
+               if (ptr->is_deleted || ptr->type != r->param_type)
+                       continue;
+               if (check_entry(r, ptr)) {
+                       r->granted = true;
+                       return;
+               }
        }
-       return tomoyo_update_domain_initializer_entry(NULL, data, is_not,
-                                                     is_delete);
+       r->granted = false;
 }
 
+/* The list for "struct tomoyo_domain_info". */
+LIST_HEAD(tomoyo_domain_list);
+
+struct list_head tomoyo_policy_list[TOMOYO_MAX_POLICY];
+struct list_head tomoyo_group_list[TOMOYO_MAX_GROUP];
+
 /**
- * tomoyo_is_domain_initializer - Check whether the given program causes domainname reinitialization.
- *
- * @domainname: The name of domain.
- * @program:    The name of program.
- * @last_name:  The last component of @domainname.
+ * tomoyo_last_word - Get last component of a domainname.
  *
- * Returns true if executing @program reinitializes domain transition,
- * false otherwise.
+ * @domainname: Domainname to check.
  *
- * Caller holds tomoyo_read_lock().
+ * Returns the last word of @domainname.
  */
-static bool tomoyo_is_domain_initializer(const struct tomoyo_path_info *
-                                        domainname,
-                                        const struct tomoyo_path_info *program,
-                                        const struct tomoyo_path_info *
-                                        last_name)
+static const char *tomoyo_last_word(const char *name)
 {
-       struct tomoyo_domain_initializer_entry *ptr;
-       bool flag = false;
-
-       list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list, list) {
-               if (ptr->is_deleted)
-                       continue;
-               if (ptr->domainname) {
-                       if (!ptr->is_last_name) {
-                               if (ptr->domainname != domainname)
-                                       continue;
-                       } else {
-                               if (tomoyo_pathcmp(ptr->domainname, last_name))
-                                       continue;
-                       }
-               }
-               if (tomoyo_pathcmp(ptr->program, program))
-                       continue;
-               if (ptr->is_not) {
-                       flag = false;
-                       break;
-               }
-               flag = true;
-       }
-       return flag;
+        const char *cp = strrchr(name, ' ');
+        if (cp)
+                return cp + 1;
+        return name;
 }
 
-/*
- * tomoyo_domain_keeper_list is used for holding list of domainnames which
- * suppresses domain transition. Normally, a domainname is monotonically
- * getting longer. But sometimes, we want to suppress domain transition.
- * It would be convenient for us that programs executed from a login session
- * belong to the same domain. Thus, TOMOYO provides a way to suppress domain
- * transition.
- *
- * An entry is added by
- *
- * # echo 'keep_domain <kernel> /usr/sbin/sshd /bin/bash' > \
- *                              /sys/kernel/security/tomoyo/exception_policy
- *
- * and is deleted by
- *
- * # echo 'delete keep_domain <kernel> /usr/sbin/sshd /bin/bash' > \
- *                              /sys/kernel/security/tomoyo/exception_policy
- *
- * and all entries are retrieved by
- *
- * # grep ^keep_domain /sys/kernel/security/tomoyo/exception_policy
- *
- * In the example above, any process which belongs to
- * "<kernel> /usr/sbin/sshd /bin/bash" domain will remain in that domain,
- * unless explicitly specified by "initialize_domain" or "no_keep_domain".
- *
- * You may specify a program using "from" keyword.
- * "keep_domain /bin/pwd from <kernel> /usr/sbin/sshd /bin/bash"
- * will cause "/bin/pwd" executed from "<kernel> /usr/sbin/sshd /bin/bash"
- * domain to remain in "<kernel> /usr/sbin/sshd /bin/bash" domain.
- *
- * You may add "no_" prefix to "keep_domain".
- * "keep_domain <kernel> /usr/sbin/sshd /bin/bash" and
- * "no_keep_domain /usr/bin/passwd from <kernel> /usr/sbin/sshd /bin/bash" will
- * cause "/usr/bin/passwd" to belong to
- * "<kernel> /usr/sbin/sshd /bin/bash /usr/bin/passwd" domain, unless
- * explicitly specified by "initialize_domain".
- */
-LIST_HEAD(tomoyo_domain_keeper_list);
+static bool tomoyo_same_transition_control(const struct tomoyo_acl_head *a,
+                                          const struct tomoyo_acl_head *b)
+{
+       const struct tomoyo_transition_control *p1 = container_of(a,
+                                                                 typeof(*p1),
+                                                                 head);
+       const struct tomoyo_transition_control *p2 = container_of(b,
+                                                                 typeof(*p2),
+                                                                 head);
+       return p1->type == p2->type && p1->is_last_name == p2->is_last_name
+               && p1->domainname == p2->domainname
+               && p1->program == p2->program;
+}
 
 /**
- * tomoyo_update_domain_keeper_entry - Update "struct tomoyo_domain_keeper_entry" list.
+ * tomoyo_update_transition_control_entry - Update "struct tomoyo_transition_control" list.
  *
- * @domainname: The name of domain.
- * @program:    The name of program. May be NULL.
- * @is_not:     True if it is "no_keep_domain" entry.
+ * @domainname: The name of domain. Maybe NULL.
+ * @program:    The name of program. Maybe NULL.
+ * @type:       Type of transition.
  * @is_delete:  True if it is a delete request.
  *
  * Returns 0 on success, negative value otherwise.
- *
- * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_update_domain_keeper_entry(const char *domainname,
-                                            const char *program,
-                                            const bool is_not,
-                                            const bool is_delete)
+static int tomoyo_update_transition_control_entry(const char *domainname,
+                                                 const char *program,
+                                                 const u8 type,
+                                                 const bool is_delete)
 {
-       struct tomoyo_domain_keeper_entry *ptr;
-       struct tomoyo_domain_keeper_entry e = { .is_not = is_not };
+       struct tomoyo_transition_control e = { .type = type };
        int error = is_delete ? -ENOENT : -ENOMEM;
-
-       if (!tomoyo_is_domain_def(domainname) &&
-           tomoyo_is_correct_path(domainname, 1, -1, -1))
-               e.is_last_name = true;
-       else if (!tomoyo_is_correct_domain(domainname))
-               return -EINVAL;
        if (program) {
-               if (!tomoyo_is_correct_path(program, 1, -1, -1))
+               if (!tomoyo_correct_path(program))
                        return -EINVAL;
                e.program = tomoyo_get_name(program);
                if (!e.program)
                        goto out;
        }
-       e.domainname = tomoyo_get_name(domainname);
-       if (!e.domainname)
-               goto out;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, list) {
-               if (!tomoyo_is_same_domain_keeper_entry(ptr, &e))
-                       continue;
-               ptr->is_deleted = is_delete;
-               error = 0;
-               break;
-       }
-       if (!is_delete && error) {
-               struct tomoyo_domain_keeper_entry *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
-               if (entry) {
-                       list_add_tail_rcu(&entry->list,
-                                         &tomoyo_domain_keeper_list);
-                       error = 0;
+       if (domainname) {
+               if (!tomoyo_correct_domain(domainname)) {
+                       if (!tomoyo_correct_path(domainname))
+                               goto out;
+                       e.is_last_name = true;
                }
+               e.domainname = tomoyo_get_name(domainname);
+               if (!e.domainname)
+                       goto out;
        }
-       mutex_unlock(&tomoyo_policy_lock);
+       error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
+                                    &tomoyo_policy_list
+                                    [TOMOYO_ID_TRANSITION_CONTROL],
+                                    tomoyo_same_transition_control);
  out:
        tomoyo_put_name(e.domainname);
        tomoyo_put_name(e.program);
@@ -385,219 +207,133 @@ static int tomoyo_update_domain_keeper_entry(const char *domainname,
 }
 
 /**
- * tomoyo_write_domain_keeper_policy - Write "struct tomoyo_domain_keeper_entry" list.
+ * tomoyo_write_transition_control - Write "struct tomoyo_transition_control" list.
  *
  * @data:      String to parse.
- * @is_not:    True if it is "no_keep_domain" entry.
  * @is_delete: True if it is a delete request.
+ * @type:      Type of this entry.
  *
- * Caller holds tomoyo_read_lock().
- */
-int tomoyo_write_domain_keeper_policy(char *data, const bool is_not,
-                                     const bool is_delete)
-{
-       char *cp = strstr(data, " from ");
-
-       if (cp) {
-               *cp = '\0';
-               return tomoyo_update_domain_keeper_entry(cp + 6, data, is_not,
-                                                        is_delete);
-       }
-       return tomoyo_update_domain_keeper_entry(data, NULL, is_not, is_delete);
-}
-
-/**
- * tomoyo_read_domain_keeper_policy - Read "struct tomoyo_domain_keeper_entry" list.
- *
- * @head: Pointer to "struct tomoyo_io_buffer".
- *
- * Returns true on success, false otherwise.
- *
- * Caller holds tomoyo_read_lock().
+ * Returns 0 on success, negative value otherwise.
  */
-bool tomoyo_read_domain_keeper_policy(struct tomoyo_io_buffer *head)
+int tomoyo_write_transition_control(char *data, const bool is_delete,
+                                   const u8 type)
 {
-       struct list_head *pos;
-       bool done = true;
-
-       list_for_each_cookie(pos, head->read_var2,
-                            &tomoyo_domain_keeper_list) {
-               struct tomoyo_domain_keeper_entry *ptr;
-               const char *no;
-               const char *from = "";
-               const char *program = "";
-
-               ptr = list_entry(pos, struct tomoyo_domain_keeper_entry, list);
-               if (ptr->is_deleted)
-                       continue;
-               no = ptr->is_not ? "no_" : "";
-               if (ptr->program) {
-                       from = " from ";
-                       program = ptr->program->name;
-               }
-               done = tomoyo_io_printf(head,
-                                       "%s" TOMOYO_KEYWORD_KEEP_DOMAIN
-                                       "%s%s%s\n", no, program, from,
-                                       ptr->domainname->name);
-               if (!done)
-                       break;
+       char *domainname = strstr(data, " from ");
+       if (domainname) {
+               *domainname = '\0';
+               domainname += 6;
+       } else if (type == TOMOYO_TRANSITION_CONTROL_NO_KEEP ||
+                  type == TOMOYO_TRANSITION_CONTROL_KEEP) {
+               domainname = data;
+               data = NULL;
        }
-       return done;
+       return tomoyo_update_transition_control_entry(domainname, data, type,
+                                                     is_delete);
 }
 
 /**
- * tomoyo_is_domain_keeper - Check whether the given program causes domain transition suppression.
+ * tomoyo_transition_type - Get domain transition type.
  *
  * @domainname: The name of domain.
  * @program:    The name of program.
- * @last_name:  The last component of @domainname.
  *
- * Returns true if executing @program supresses domain transition,
- * false otherwise.
+ * Returns TOMOYO_TRANSITION_CONTROL_INITIALIZE if executing @program
+ * reinitializes domain transition, TOMOYO_TRANSITION_CONTROL_KEEP if executing
+ * @program suppresses domain transition, others otherwise.
  *
  * Caller holds tomoyo_read_lock().
  */
-static bool tomoyo_is_domain_keeper(const struct tomoyo_path_info *domainname,
-                                   const struct tomoyo_path_info *program,
-                                   const struct tomoyo_path_info *last_name)
+static u8 tomoyo_transition_type(const struct tomoyo_path_info *domainname,
+                                const struct tomoyo_path_info *program)
 {
-       struct tomoyo_domain_keeper_entry *ptr;
-       bool flag = false;
-
-       list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, list) {
-               if (ptr->is_deleted)
-                       continue;
-               if (!ptr->is_last_name) {
-                       if (ptr->domainname != domainname)
+       const struct tomoyo_transition_control *ptr;
+       const char *last_name = tomoyo_last_word(domainname->name);
+       u8 type;
+       for (type = 0; type < TOMOYO_MAX_TRANSITION_TYPE; type++) {
+ next:
+               list_for_each_entry_rcu(ptr, &tomoyo_policy_list
+                                       [TOMOYO_ID_TRANSITION_CONTROL],
+                                       head.list) {
+                       if (ptr->head.is_deleted || ptr->type != type)
                                continue;
-               } else {
-                       if (tomoyo_pathcmp(ptr->domainname, last_name))
+                       if (ptr->domainname) {
+                               if (!ptr->is_last_name) {
+                                       if (ptr->domainname != domainname)
+                                               continue;
+                               } else {
+                                       /*
+                                        * Use direct strcmp() since this is
+                                        * unlikely used.
+                                        */
+                                       if (strcmp(ptr->domainname->name,
+                                                  last_name))
+                                               continue;
+                               }
+                       }
+                       if (ptr->program &&
+                           tomoyo_pathcmp(ptr->program, program))
                                continue;
+                       if (type == TOMOYO_TRANSITION_CONTROL_NO_INITIALIZE) {
+                               /*
+                                * Do not check for initialize_domain if
+                                * no_initialize_domain matched.
+                                */
+                               type = TOMOYO_TRANSITION_CONTROL_NO_KEEP;
+                               goto next;
+                       }
+                       goto done;
                }
-               if (ptr->program && tomoyo_pathcmp(ptr->program, program))
-                       continue;
-               if (ptr->is_not) {
-                       flag = false;
-                       break;
-               }
-               flag = true;
        }
-       return flag;
+ done:
+       return type;
 }
 
-/*
- * tomoyo_alias_list is used for holding list of symlink's pathnames which are
- * allowed to be passed to an execve() request. Normally, the domainname which
- * the current process will belong to after execve() succeeds is calculated
- * using dereferenced pathnames. But some programs behave differently depending
- * on the name passed to argv[0]. For busybox, calculating domainname using
- * dereferenced pathnames will cause all programs in the busybox to belong to
- * the same domain. Thus, TOMOYO provides a way to allow use of symlink's
- * pathname for checking execve()'s permission and calculating domainname which
- * the current process will belong to after execve() succeeds.
- *
- * An entry is added by
- *
- * # echo 'alias /bin/busybox /bin/cat' > \
- *                            /sys/kernel/security/tomoyo/exception_policy
- *
- * and is deleted by
- *
- * # echo 'delete alias /bin/busybox /bin/cat' > \
- *                            /sys/kernel/security/tomoyo/exception_policy
- *
- * and all entries are retrieved by
- *
- * # grep ^alias /sys/kernel/security/tomoyo/exception_policy
- *
- * In the example above, if /bin/cat is a symlink to /bin/busybox and execution
- * of /bin/cat is requested, permission is checked for /bin/cat rather than
- * /bin/busybox and domainname which the current process will belong to after
- * execve() succeeds is calculated using /bin/cat rather than /bin/busybox .
- */
-LIST_HEAD(tomoyo_alias_list);
+static bool tomoyo_same_aggregator(const struct tomoyo_acl_head *a,
+                                  const struct tomoyo_acl_head *b)
+{
+       const struct tomoyo_aggregator *p1 = container_of(a, typeof(*p1), head);
+       const struct tomoyo_aggregator *p2 = container_of(b, typeof(*p2), head);
+       return p1->original_name == p2->original_name &&
+               p1->aggregated_name == p2->aggregated_name;
+}
 
 /**
- * tomoyo_update_alias_entry - Update "struct tomoyo_alias_entry" list.
+ * tomoyo_update_aggregator_entry - Update "struct tomoyo_aggregator" list.
  *
- * @original_name: The original program's real name.
- * @aliased_name:  The symbolic program's symbolic link's name.
- * @is_delete:     True if it is a delete request.
+ * @original_name:   The original program's name.
+ * @aggregated_name: The program name to use.
+ * @is_delete:       True if it is a delete request.
  *
  * Returns 0 on success, negative value otherwise.
  *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_update_alias_entry(const char *original_name,
-                                    const char *aliased_name,
-                                    const bool is_delete)
+static int tomoyo_update_aggregator_entry(const char *original_name,
+                                         const char *aggregated_name,
+                                         const bool is_delete)
 {
-       struct tomoyo_alias_entry *ptr;
-       struct tomoyo_alias_entry e = { };
+       struct tomoyo_aggregator e = { };
        int error = is_delete ? -ENOENT : -ENOMEM;
 
-       if (!tomoyo_is_correct_path(original_name, 1, -1, -1) ||
-           !tomoyo_is_correct_path(aliased_name, 1, -1, -1))
-               return -EINVAL; /* No patterns allowed. */
+       if (!tomoyo_correct_path(original_name) ||
+           !tomoyo_correct_path(aggregated_name))
+               return -EINVAL;
        e.original_name = tomoyo_get_name(original_name);
-       e.aliased_name = tomoyo_get_name(aliased_name);
-       if (!e.original_name || !e.aliased_name)
+       e.aggregated_name = tomoyo_get_name(aggregated_name);
+       if (!e.original_name || !e.aggregated_name ||
+           e.aggregated_name->is_patterned) /* No patterns allowed. */
                goto out;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(ptr, &tomoyo_alias_list, list) {
-               if (!tomoyo_is_same_alias_entry(ptr, &e))
-                       continue;
-               ptr->is_deleted = is_delete;
-               error = 0;
-               break;
-       }
-       if (!is_delete && error) {
-               struct tomoyo_alias_entry *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
-               if (entry) {
-                       list_add_tail_rcu(&entry->list, &tomoyo_alias_list);
-                       error = 0;
-               }
-       }
-       mutex_unlock(&tomoyo_policy_lock);
+       error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
+                                    &tomoyo_policy_list[TOMOYO_ID_AGGREGATOR],
+                                    tomoyo_same_aggregator);
  out:
        tomoyo_put_name(e.original_name);
-       tomoyo_put_name(e.aliased_name);
+       tomoyo_put_name(e.aggregated_name);
        return error;
 }
 
 /**
- * tomoyo_read_alias_policy - Read "struct tomoyo_alias_entry" list.
- *
- * @head: Pointer to "struct tomoyo_io_buffer".
- *
- * Returns true on success, false otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head)
-{
-       struct list_head *pos;
-       bool done = true;
-
-       list_for_each_cookie(pos, head->read_var2, &tomoyo_alias_list) {
-               struct tomoyo_alias_entry *ptr;
-
-               ptr = list_entry(pos, struct tomoyo_alias_entry, list);
-               if (ptr->is_deleted)
-                       continue;
-               done = tomoyo_io_printf(head, TOMOYO_KEYWORD_ALIAS "%s %s\n",
-                                       ptr->original_name->name,
-                                       ptr->aliased_name->name);
-               if (!done)
-                       break;
-       }
-       return done;
-}
-
-/**
- * tomoyo_write_alias_policy - Write "struct tomoyo_alias_entry" list.
+ * tomoyo_write_aggregator - Write "struct tomoyo_aggregator" list.
  *
  * @data:      String to parse.
  * @is_delete: True if it is a delete request.
@@ -606,18 +342,18 @@ bool tomoyo_read_alias_policy(struct tomoyo_io_buffer *head)
  *
  * Caller holds tomoyo_read_lock().
  */
-int tomoyo_write_alias_policy(char *data, const bool is_delete)
+int tomoyo_write_aggregator(char *data, const bool is_delete)
 {
        char *cp = strchr(data, ' ');
 
        if (!cp)
                return -EINVAL;
        *cp++ = '\0';
-       return tomoyo_update_alias_entry(data, cp, is_delete);
+       return tomoyo_update_aggregator_entry(data, cp, is_delete);
 }
 
 /**
- * tomoyo_find_or_assign_new_domain - Create a domain.
+ * tomoyo_assign_domain - Create a domain.
  *
  * @domainname: The name of domain.
  * @profile:    Profile number to assign if the domain was newly created.
@@ -626,16 +362,15 @@ int tomoyo_write_alias_policy(char *data, const bool is_delete)
  *
  * Caller holds tomoyo_read_lock().
  */
-struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
-                                                           domainname,
-                                                           const u8 profile)
+struct tomoyo_domain_info *tomoyo_assign_domain(const char *domainname,
+                                               const u8 profile)
 {
        struct tomoyo_domain_info *entry;
        struct tomoyo_domain_info *domain = NULL;
        const struct tomoyo_path_info *saved_domainname;
        bool found = false;
 
-       if (!tomoyo_is_correct_domain(domainname))
+       if (!tomoyo_correct_domain(domainname))
                return NULL;
        saved_domainname = tomoyo_get_name(domainname);
        if (!saved_domainname)
@@ -678,116 +413,118 @@ struct tomoyo_domain_info *tomoyo_find_or_assign_new_domain(const char *
  */
 int tomoyo_find_next_domain(struct linux_binprm *bprm)
 {
-       /*
-        * This function assumes that the size of buffer returned by
-        * tomoyo_realpath() = TOMOYO_MAX_PATHNAME_LEN.
-        */
-       struct tomoyo_page_buffer *tmp = kzalloc(sizeof(*tmp), GFP_NOFS);
+       struct tomoyo_request_info r;
+       char *tmp = kzalloc(TOMOYO_EXEC_TMPSIZE, GFP_NOFS);
        struct tomoyo_domain_info *old_domain = tomoyo_domain();
        struct tomoyo_domain_info *domain = NULL;
-       const char *old_domain_name = old_domain->domainname->name;
        const char *original_name = bprm->filename;
-       char *new_domain_name = NULL;
-       char *real_program_name = NULL;
-       char *symlink_program_name = NULL;
-       const u8 mode = tomoyo_check_flags(old_domain, TOMOYO_MAC_FOR_FILE);
-       const bool is_enforce = (mode == 3);
+       u8 mode;
+       bool is_enforce;
        int retval = -ENOMEM;
-       struct tomoyo_path_info r; /* real name */
-       struct tomoyo_path_info s; /* symlink name */
-       struct tomoyo_path_info l; /* last name */
-       static bool initialized;
+       bool need_kfree = false;
+       struct tomoyo_path_info rn = { }; /* real name */
 
+       mode = tomoyo_init_request_info(&r, NULL, TOMOYO_MAC_FILE_EXECUTE);
+       is_enforce = (mode == TOMOYO_CONFIG_ENFORCING);
        if (!tmp)
                goto out;
 
-       if (!initialized) {
-               /*
-                * Built-in initializers. This is needed because policies are
-                * not loaded until starting /sbin/init.
-                */
-               tomoyo_update_domain_initializer_entry(NULL, "/sbin/hotplug",
-                                                      false, false);
-               tomoyo_update_domain_initializer_entry(NULL, "/sbin/modprobe",
-                                                      false, false);
-               initialized = true;
+ retry:
+       if (need_kfree) {
+               kfree(rn.name);
+               need_kfree = false;
        }
-
-       /* Get tomoyo_realpath of program. */
+       /* Get symlink's pathname of program. */
        retval = -ENOENT;
-       /* I hope tomoyo_realpath() won't fail with -ENOMEM. */
-       real_program_name = tomoyo_realpath(original_name);
-       if (!real_program_name)
-               goto out;
-       /* Get tomoyo_realpath of symbolic link. */
-       symlink_program_name = tomoyo_realpath_nofollow(original_name);
-       if (!symlink_program_name)
+       rn.name = tomoyo_realpath_nofollow(original_name);
+       if (!rn.name)
                goto out;
-
-       r.name = real_program_name;
-       tomoyo_fill_path_info(&r);
-       s.name = symlink_program_name;
-       tomoyo_fill_path_info(&s);
-       l.name = tomoyo_get_last_name(old_domain);
-       tomoyo_fill_path_info(&l);
-
-       /* Check 'alias' directive. */
-       if (tomoyo_pathcmp(&r, &s)) {
-               struct tomoyo_alias_entry *ptr;
-               /* Is this program allowed to be called via symbolic links? */
-               list_for_each_entry_rcu(ptr, &tomoyo_alias_list, list) {
-                       if (ptr->is_deleted ||
-                           tomoyo_pathcmp(&r, ptr->original_name) ||
-                           tomoyo_pathcmp(&s, ptr->aliased_name))
+       tomoyo_fill_path_info(&rn);
+       need_kfree = true;
+
+       /* Check 'aggregator' directive. */
+       {
+               struct tomoyo_aggregator *ptr;
+               list_for_each_entry_rcu(ptr, &tomoyo_policy_list
+                                       [TOMOYO_ID_AGGREGATOR], head.list) {
+                       if (ptr->head.is_deleted ||
+                           !tomoyo_path_matches_pattern(&rn,
+                                                        ptr->original_name))
                                continue;
-                       memset(real_program_name, 0, TOMOYO_MAX_PATHNAME_LEN);
-                       strncpy(real_program_name, ptr->aliased_name->name,
-                               TOMOYO_MAX_PATHNAME_LEN - 1);
-                       tomoyo_fill_path_info(&r);
+                       kfree(rn.name);
+                       need_kfree = false;
+                       /* This is OK because it is read only. */
+                       rn = *ptr->aggregated_name;
                        break;
                }
        }
 
        /* Check execute permission. */
-       retval = tomoyo_check_exec_perm(old_domain, &r);
+       retval = tomoyo_path_permission(&r, TOMOYO_TYPE_EXECUTE, &rn);
+       if (retval == TOMOYO_RETRY_REQUEST)
+               goto retry;
        if (retval < 0)
                goto out;
+       /*
+        * To be able to specify domainnames with wildcards, use the
+        * pathname specified in the policy (which may contain
+        * wildcard) rather than the pathname passed to execve()
+        * (which never contains wildcard).
+        */
+       if (r.param.path.matched_path) {
+               if (need_kfree)
+                       kfree(rn.name);
+               need_kfree = false;
+               /* This is OK because it is read only. */
+               rn = *r.param.path.matched_path;
+       }
 
-       new_domain_name = tmp->buffer;
-       if (tomoyo_is_domain_initializer(old_domain->domainname, &r, &l)) {
+       /* Calculate domain to transit to. */
+       switch (tomoyo_transition_type(old_domain->domainname, &rn)) {
+       case TOMOYO_TRANSITION_CONTROL_INITIALIZE:
                /* Transit to the child of tomoyo_kernel_domain domain. */
-               snprintf(new_domain_name, TOMOYO_MAX_PATHNAME_LEN + 1,
-                        TOMOYO_ROOT_NAME " " "%s", real_program_name);
-       } else if (old_domain == &tomoyo_kernel_domain &&
-                  !tomoyo_policy_loaded) {
-               /*
-                * Needn't to transit from kernel domain before starting
-                * /sbin/init. But transit from kernel domain if executing
-                * initializers because they might start before /sbin/init.
-                */
-               domain = old_domain;
-       } else if (tomoyo_is_domain_keeper(old_domain->domainname, &r, &l)) {
+               snprintf(tmp, TOMOYO_EXEC_TMPSIZE - 1, TOMOYO_ROOT_NAME " "
+                        "%s", rn.name);
+               break;
+       case TOMOYO_TRANSITION_CONTROL_KEEP:
                /* Keep current domain. */
                domain = old_domain;
-       } else {
-               /* Normal domain transition. */
-               snprintf(new_domain_name, TOMOYO_MAX_PATHNAME_LEN + 1,
-                        "%s %s", old_domain_name, real_program_name);
+               break;
+       default:
+               if (old_domain == &tomoyo_kernel_domain &&
+                   !tomoyo_policy_loaded) {
+                       /*
+                        * Needn't to transit from kernel domain before
+                        * starting /sbin/init. But transit from kernel domain
+                        * if executing initializers because they might start
+                        * before /sbin/init.
+                        */
+                       domain = old_domain;
+               } else {
+                       /* Normal domain transition. */
+                       snprintf(tmp, TOMOYO_EXEC_TMPSIZE - 1, "%s %s",
+                                old_domain->domainname->name, rn.name);
+               }
+               break;
        }
-       if (domain || strlen(new_domain_name) >= TOMOYO_MAX_PATHNAME_LEN)
+       if (domain || strlen(tmp) >= TOMOYO_EXEC_TMPSIZE - 10)
                goto done;
-       domain = tomoyo_find_domain(new_domain_name);
+       domain = tomoyo_find_domain(tmp);
        if (domain)
                goto done;
-       if (is_enforce)
-               goto done;
-       domain = tomoyo_find_or_assign_new_domain(new_domain_name,
-                                                 old_domain->profile);
+       if (is_enforce) {
+               int error = tomoyo_supervisor(&r, "# wants to create domain\n"
+                                             "%s\n", tmp);
+               if (error == TOMOYO_RETRY_REQUEST)
+                       goto retry;
+               if (error < 0)
+                       goto done;
+       }
+       domain = tomoyo_assign_domain(tmp, old_domain->profile);
  done:
        if (domain)
                goto out;
-       printk(KERN_WARNING "TOMOYO-ERROR: Domain '%s' not defined.\n",
-              new_domain_name);
+       printk(KERN_WARNING "TOMOYO-ERROR: Domain '%s' not defined.\n", tmp);
        if (is_enforce)
                retval = -EPERM;
        else
@@ -798,8 +535,8 @@ int tomoyo_find_next_domain(struct linux_binprm *bprm)
        /* Update reference count on "struct tomoyo_domain_info". */
        atomic_inc(&domain->users);
        bprm->cred->security = domain;
-       kfree(real_program_name);
-       kfree(symlink_program_name);
+       if (need_kfree)
+               kfree(rn.name);
        kfree(tmp);
        return retval;
 }
index 1c6f8238ec47a1866e74f80da1d2e6c120b69ff3..9d32f182301ee6cfcfdb4d18508a7b9773f275eb 100644 (file)
@@ -1,48 +1,88 @@
 /*
  * security/tomoyo/file.c
  *
- * Implementation of the Domain-Based Mandatory Access Control.
- *
- * Copyright (C) 2005-2009  NTT DATA CORPORATION
- *
- * Version: 2.2.0   2009/04/01
+ * Pathname restriction functions.
  *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
  */
 
 #include "common.h"
 #include <linux/slab.h>
 
-/* Keyword array for single path operations. */
-static const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = {
+/* Keyword array for operations with one pathname. */
+const char *tomoyo_path_keyword[TOMOYO_MAX_PATH_OPERATION] = {
        [TOMOYO_TYPE_READ_WRITE] = "read/write",
        [TOMOYO_TYPE_EXECUTE]    = "execute",
        [TOMOYO_TYPE_READ]       = "read",
        [TOMOYO_TYPE_WRITE]      = "write",
-       [TOMOYO_TYPE_CREATE]     = "create",
        [TOMOYO_TYPE_UNLINK]     = "unlink",
-       [TOMOYO_TYPE_MKDIR]      = "mkdir",
        [TOMOYO_TYPE_RMDIR]      = "rmdir",
-       [TOMOYO_TYPE_MKFIFO]     = "mkfifo",
-       [TOMOYO_TYPE_MKSOCK]     = "mksock",
-       [TOMOYO_TYPE_MKBLOCK]    = "mkblock",
-       [TOMOYO_TYPE_MKCHAR]     = "mkchar",
        [TOMOYO_TYPE_TRUNCATE]   = "truncate",
        [TOMOYO_TYPE_SYMLINK]    = "symlink",
        [TOMOYO_TYPE_REWRITE]    = "rewrite",
+       [TOMOYO_TYPE_CHROOT]     = "chroot",
+       [TOMOYO_TYPE_UMOUNT]     = "unmount",
+};
+
+/* Keyword array for operations with one pathname and three numbers. */
+const char *tomoyo_mkdev_keyword[TOMOYO_MAX_MKDEV_OPERATION] = {
+       [TOMOYO_TYPE_MKBLOCK]    = "mkblock",
+       [TOMOYO_TYPE_MKCHAR]     = "mkchar",
+};
+
+/* Keyword array for operations with two pathnames. */
+const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION] = {
+       [TOMOYO_TYPE_LINK]       = "link",
+       [TOMOYO_TYPE_RENAME]     = "rename",
+       [TOMOYO_TYPE_PIVOT_ROOT] = "pivot_root",
+};
+
+/* Keyword array for operations with one pathname and one number. */
+const char *tomoyo_path_number_keyword[TOMOYO_MAX_PATH_NUMBER_OPERATION] = {
+       [TOMOYO_TYPE_CREATE]     = "create",
+       [TOMOYO_TYPE_MKDIR]      = "mkdir",
+       [TOMOYO_TYPE_MKFIFO]     = "mkfifo",
+       [TOMOYO_TYPE_MKSOCK]     = "mksock",
        [TOMOYO_TYPE_IOCTL]      = "ioctl",
        [TOMOYO_TYPE_CHMOD]      = "chmod",
        [TOMOYO_TYPE_CHOWN]      = "chown",
        [TOMOYO_TYPE_CHGRP]      = "chgrp",
-       [TOMOYO_TYPE_CHROOT]     = "chroot",
-       [TOMOYO_TYPE_MOUNT]      = "mount",
-       [TOMOYO_TYPE_UMOUNT]     = "unmount",
 };
 
-/* Keyword array for double path operations. */
-static const char *tomoyo_path2_keyword[TOMOYO_MAX_PATH2_OPERATION] = {
-       [TOMOYO_TYPE_LINK]    = "link",
-       [TOMOYO_TYPE_RENAME]  = "rename",
-       [TOMOYO_TYPE_PIVOT_ROOT] = "pivot_root",
+static const u8 tomoyo_p2mac[TOMOYO_MAX_PATH_OPERATION] = {
+       [TOMOYO_TYPE_READ_WRITE] = TOMOYO_MAC_FILE_OPEN,
+       [TOMOYO_TYPE_EXECUTE]    = TOMOYO_MAC_FILE_EXECUTE,
+       [TOMOYO_TYPE_READ]       = TOMOYO_MAC_FILE_OPEN,
+       [TOMOYO_TYPE_WRITE]      = TOMOYO_MAC_FILE_OPEN,
+       [TOMOYO_TYPE_UNLINK]     = TOMOYO_MAC_FILE_UNLINK,
+       [TOMOYO_TYPE_RMDIR]      = TOMOYO_MAC_FILE_RMDIR,
+       [TOMOYO_TYPE_TRUNCATE]   = TOMOYO_MAC_FILE_TRUNCATE,
+       [TOMOYO_TYPE_SYMLINK]    = TOMOYO_MAC_FILE_SYMLINK,
+       [TOMOYO_TYPE_REWRITE]    = TOMOYO_MAC_FILE_REWRITE,
+       [TOMOYO_TYPE_CHROOT]     = TOMOYO_MAC_FILE_CHROOT,
+       [TOMOYO_TYPE_UMOUNT]     = TOMOYO_MAC_FILE_UMOUNT,
+};
+
+static const u8 tomoyo_pnnn2mac[TOMOYO_MAX_MKDEV_OPERATION] = {
+       [TOMOYO_TYPE_MKBLOCK] = TOMOYO_MAC_FILE_MKBLOCK,
+       [TOMOYO_TYPE_MKCHAR]  = TOMOYO_MAC_FILE_MKCHAR,
+};
+
+static const u8 tomoyo_pp2mac[TOMOYO_MAX_PATH2_OPERATION] = {
+       [TOMOYO_TYPE_LINK]       = TOMOYO_MAC_FILE_LINK,
+       [TOMOYO_TYPE_RENAME]     = TOMOYO_MAC_FILE_RENAME,
+       [TOMOYO_TYPE_PIVOT_ROOT] = TOMOYO_MAC_FILE_PIVOT_ROOT,
+};
+
+static const u8 tomoyo_pn2mac[TOMOYO_MAX_PATH_NUMBER_OPERATION] = {
+       [TOMOYO_TYPE_CREATE] = TOMOYO_MAC_FILE_CREATE,
+       [TOMOYO_TYPE_MKDIR]  = TOMOYO_MAC_FILE_MKDIR,
+       [TOMOYO_TYPE_MKFIFO] = TOMOYO_MAC_FILE_MKFIFO,
+       [TOMOYO_TYPE_MKSOCK] = TOMOYO_MAC_FILE_MKSOCK,
+       [TOMOYO_TYPE_IOCTL]  = TOMOYO_MAC_FILE_IOCTL,
+       [TOMOYO_TYPE_CHMOD]  = TOMOYO_MAC_FILE_CHMOD,
+       [TOMOYO_TYPE_CHOWN]  = TOMOYO_MAC_FILE_CHOWN,
+       [TOMOYO_TYPE_CHGRP]  = TOMOYO_MAC_FILE_CHGRP,
 };
 
 void tomoyo_put_name_union(struct tomoyo_name_union *ptr)
@@ -50,56 +90,45 @@ void tomoyo_put_name_union(struct tomoyo_name_union *ptr)
        if (!ptr)
                return;
        if (ptr->is_group)
-               tomoyo_put_path_group(ptr->group);
+               tomoyo_put_group(ptr->group);
        else
                tomoyo_put_name(ptr->filename);
 }
 
-bool tomoyo_compare_name_union(const struct tomoyo_path_info *name,
-                              const struct tomoyo_name_union *ptr)
+const struct tomoyo_path_info *
+tomoyo_compare_name_union(const struct tomoyo_path_info *name,
+                         const struct tomoyo_name_union *ptr)
 {
        if (ptr->is_group)
-               return tomoyo_path_matches_group(name, ptr->group, 1);
-       return tomoyo_path_matches_pattern(name, ptr->filename);
+               return tomoyo_path_matches_group(name, ptr->group);
+       if (tomoyo_path_matches_pattern(name, ptr->filename))
+               return ptr->filename;
+       return NULL;
 }
 
-static bool tomoyo_compare_name_union_pattern(const struct tomoyo_path_info
-                                             *name,
-                                             const struct tomoyo_name_union
-                                             *ptr, const bool may_use_pattern)
+void tomoyo_put_number_union(struct tomoyo_number_union *ptr)
 {
-       if (ptr->is_group)
-               return tomoyo_path_matches_group(name, ptr->group,
-                                                may_use_pattern);
-       if (may_use_pattern || !ptr->filename->is_patterned)
-               return tomoyo_path_matches_pattern(name, ptr->filename);
-       return false;
+       if (ptr && ptr->is_group)
+               tomoyo_put_group(ptr->group);
 }
 
-/**
- * tomoyo_path2keyword - Get the name of single path operation.
- *
- * @operation: Type of operation.
- *
- * Returns the name of single path operation.
- */
-const char *tomoyo_path2keyword(const u8 operation)
+bool tomoyo_compare_number_union(const unsigned long value,
+                                const struct tomoyo_number_union *ptr)
 {
-       return (operation < TOMOYO_MAX_PATH_OPERATION)
-               ? tomoyo_path_keyword[operation] : NULL;
+       if (ptr->is_group)
+               return tomoyo_number_matches_group(value, value, ptr->group);
+       return value >= ptr->values[0] && value <= ptr->values[1];
 }
 
-/**
- * tomoyo_path22keyword - Get the name of double path operation.
- *
- * @operation: Type of operation.
- *
- * Returns the name of double path operation.
- */
-const char *tomoyo_path22keyword(const u8 operation)
+static void tomoyo_add_slash(struct tomoyo_path_info *buf)
 {
-       return (operation < TOMOYO_MAX_PATH2_OPERATION)
-               ? tomoyo_path2_keyword[operation] : NULL;
+       if (buf->is_dir)
+               return;
+       /*
+        * This is OK because tomoyo_encode() reserves space for appending "/".
+        */
+       strcat((char *) buf->name, "/");
+       tomoyo_fill_path_info(buf);
 }
 
 /**
@@ -121,69 +150,134 @@ static bool tomoyo_strendswith(const char *name, const char *tail)
 }
 
 /**
- * tomoyo_get_path - Get realpath.
+ * tomoyo_get_realpath - Get realpath.
  *
+ * @buf:  Pointer to "struct tomoyo_path_info".
  * @path: Pointer to "struct path".
  *
- * Returns pointer to "struct tomoyo_path_info" on success, NULL otherwise.
+ * Returns true on success, false otherwise.
  */
-static struct tomoyo_path_info *tomoyo_get_path(struct path *path)
+static bool tomoyo_get_realpath(struct tomoyo_path_info *buf, struct path *path)
 {
-       int error;
-       struct tomoyo_path_info_with_data *buf = kzalloc(sizeof(*buf),
-                                                        GFP_NOFS);
-
-       if (!buf)
-               return NULL;
-       /* Reserve one byte for appending "/". */
-       error = tomoyo_realpath_from_path2(path, buf->body,
-                                          sizeof(buf->body) - 2);
-       if (!error) {
-               buf->head.name = buf->body;
-               tomoyo_fill_path_info(&buf->head);
-               return &buf->head;
+       buf->name = tomoyo_realpath_from_path(path);
+       if (buf->name) {
+               tomoyo_fill_path_info(buf);
+               return true;
        }
-       kfree(buf);
-       return NULL;
+        return false;
 }
 
-static int tomoyo_update_path2_acl(const u8 type, const char *filename1,
-                                  const char *filename2,
-                                  struct tomoyo_domain_info *const domain,
-                                  const bool is_delete);
-static int tomoyo_update_path_acl(const u8 type, const char *filename,
-                                 struct tomoyo_domain_info *const domain,
-                                 const bool is_delete);
-
-/*
- * tomoyo_globally_readable_list is used for holding list of pathnames which
- * are by default allowed to be open()ed for reading by any process.
+/**
+ * tomoyo_audit_path_log - Audit path request log.
+ *
+ * @r: Pointer to "struct tomoyo_request_info".
  *
- * An entry is added by
+ * Returns 0 on success, negative value otherwise.
+ */
+static int tomoyo_audit_path_log(struct tomoyo_request_info *r)
+{
+       const char *operation = tomoyo_path_keyword[r->param.path.operation];
+       const struct tomoyo_path_info *filename = r->param.path.filename;
+       if (r->granted)
+               return 0;
+       tomoyo_warn_log(r, "%s %s", operation, filename->name);
+       return tomoyo_supervisor(r, "allow_%s %s\n", operation,
+                                tomoyo_pattern(filename));
+}
+
+/**
+ * tomoyo_audit_path2_log - Audit path/path request log.
  *
- * # echo 'allow_read /lib/libc-2.5.so' > \
- *                               /sys/kernel/security/tomoyo/exception_policy
+ * @r: Pointer to "struct tomoyo_request_info".
  *
- * and is deleted by
+ * Returns 0 on success, negative value otherwise.
+ */
+static int tomoyo_audit_path2_log(struct tomoyo_request_info *r)
+{
+       const char *operation = tomoyo_path2_keyword[r->param.path2.operation];
+       const struct tomoyo_path_info *filename1 = r->param.path2.filename1;
+       const struct tomoyo_path_info *filename2 = r->param.path2.filename2;
+       if (r->granted)
+               return 0;
+       tomoyo_warn_log(r, "%s %s %s", operation, filename1->name,
+                       filename2->name);
+       return tomoyo_supervisor(r, "allow_%s %s %s\n", operation,
+                                tomoyo_pattern(filename1),
+                                tomoyo_pattern(filename2));
+}
+
+/**
+ * tomoyo_audit_mkdev_log - Audit path/number/number/number request log.
  *
- * # echo 'delete allow_read /lib/libc-2.5.so' > \
- *                               /sys/kernel/security/tomoyo/exception_policy
+ * @r: Pointer to "struct tomoyo_request_info".
  *
- * and all entries are retrieved by
+ * Returns 0 on success, negative value otherwise.
+ */
+static int tomoyo_audit_mkdev_log(struct tomoyo_request_info *r)
+{
+       const char *operation = tomoyo_mkdev_keyword[r->param.mkdev.operation];
+       const struct tomoyo_path_info *filename = r->param.mkdev.filename;
+       const unsigned int major = r->param.mkdev.major;
+       const unsigned int minor = r->param.mkdev.minor;
+       const unsigned int mode = r->param.mkdev.mode;
+       if (r->granted)
+               return 0;
+       tomoyo_warn_log(r, "%s %s 0%o %u %u", operation, filename->name, mode,
+                       major, minor);
+       return tomoyo_supervisor(r, "allow_%s %s 0%o %u %u\n", operation,
+                                tomoyo_pattern(filename), mode, major, minor);
+}
+
+/**
+ * tomoyo_audit_path_number_log - Audit path/number request log.
  *
- * # grep ^allow_read /sys/kernel/security/tomoyo/exception_policy
+ * @r:     Pointer to "struct tomoyo_request_info".
+ * @error: Error code.
  *
- * In the example above, any process is allowed to
- * open("/lib/libc-2.5.so", O_RDONLY).
- * One exception is, if the domain which current process belongs to is marked
- * as "ignore_global_allow_read", current process can't do so unless explicitly
- * given "allow_read /lib/libc-2.5.so" to the domain which current process
- * belongs to.
+ * Returns 0 on success, negative value otherwise.
  */
-LIST_HEAD(tomoyo_globally_readable_list);
+static int tomoyo_audit_path_number_log(struct tomoyo_request_info *r)
+{
+       const u8 type = r->param.path_number.operation;
+       u8 radix;
+       const struct tomoyo_path_info *filename = r->param.path_number.filename;
+       const char *operation = tomoyo_path_number_keyword[type];
+       char buffer[64];
+       if (r->granted)
+               return 0;
+       switch (type) {
+       case TOMOYO_TYPE_CREATE:
+       case TOMOYO_TYPE_MKDIR:
+       case TOMOYO_TYPE_MKFIFO:
+       case TOMOYO_TYPE_MKSOCK:
+       case TOMOYO_TYPE_CHMOD:
+               radix = TOMOYO_VALUE_TYPE_OCTAL;
+               break;
+       case TOMOYO_TYPE_IOCTL:
+               radix = TOMOYO_VALUE_TYPE_HEXADECIMAL;
+               break;
+       default:
+               radix = TOMOYO_VALUE_TYPE_DECIMAL;
+               break;
+       }
+       tomoyo_print_ulong(buffer, sizeof(buffer), r->param.path_number.number,
+                          radix);
+       tomoyo_warn_log(r, "%s %s %s", operation, filename->name, buffer);
+       return tomoyo_supervisor(r, "allow_%s %s %s\n", operation,
+                                tomoyo_pattern(filename), buffer);
+}
+
+static bool tomoyo_same_globally_readable(const struct tomoyo_acl_head *a,
+                                         const struct tomoyo_acl_head *b)
+{
+       return container_of(a, struct tomoyo_readable_file,
+                           head)->filename ==
+               container_of(b, struct tomoyo_readable_file,
+                            head)->filename;
+}
 
 /**
- * tomoyo_update_globally_readable_entry - Update "struct tomoyo_globally_readable_file_entry" list.
+ * tomoyo_update_globally_readable_entry - Update "struct tomoyo_readable_file" list.
  *
  * @filename:  Filename unconditionally permitted to open() for reading.
  * @is_delete: True if it is a delete request.
@@ -195,41 +289,24 @@ LIST_HEAD(tomoyo_globally_readable_list);
 static int tomoyo_update_globally_readable_entry(const char *filename,
                                                 const bool is_delete)
 {
-       struct tomoyo_globally_readable_file_entry *ptr;
-       struct tomoyo_globally_readable_file_entry e = { };
-       int error = is_delete ? -ENOENT : -ENOMEM;
+       struct tomoyo_readable_file e = { };
+       int error;
 
-       if (!tomoyo_is_correct_path(filename, 1, 0, -1))
+       if (!tomoyo_correct_word(filename))
                return -EINVAL;
        e.filename = tomoyo_get_name(filename);
        if (!e.filename)
                return -ENOMEM;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list, list) {
-               if (ptr->filename != e.filename)
-                       continue;
-               ptr->is_deleted = is_delete;
-               error = 0;
-               break;
-       }
-       if (!is_delete && error) {
-               struct tomoyo_globally_readable_file_entry *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
-               if (entry) {
-                       list_add_tail_rcu(&entry->list,
-                                         &tomoyo_globally_readable_list);
-                       error = 0;
-               }
-       }
-       mutex_unlock(&tomoyo_policy_lock);
- out:
+       error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
+                                    &tomoyo_policy_list
+                                    [TOMOYO_ID_GLOBALLY_READABLE],
+                                    tomoyo_same_globally_readable);
        tomoyo_put_name(e.filename);
        return error;
 }
 
 /**
- * tomoyo_is_globally_readable_file - Check if the file is unconditionnaly permitted to be open()ed for reading.
+ * tomoyo_globally_readable_file - Check if the file is unconditionnaly permitted to be open()ed for reading.
  *
  * @filename: The filename to check.
  *
@@ -237,14 +314,15 @@ static int tomoyo_update_globally_readable_entry(const char *filename,
  *
  * Caller holds tomoyo_read_lock().
  */
-static bool tomoyo_is_globally_readable_file(const struct tomoyo_path_info *
+static bool tomoyo_globally_readable_file(const struct tomoyo_path_info *
                                             filename)
 {
-       struct tomoyo_globally_readable_file_entry *ptr;
+       struct tomoyo_readable_file *ptr;
        bool found = false;
 
-       list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list, list) {
-               if (!ptr->is_deleted &&
+       list_for_each_entry_rcu(ptr, &tomoyo_policy_list
+                               [TOMOYO_ID_GLOBALLY_READABLE], head.list) {
+               if (!ptr->head.is_deleted &&
                    tomoyo_path_matches_pattern(filename, ptr->filename)) {
                        found = true;
                        break;
@@ -254,7 +332,7 @@ static bool tomoyo_is_globally_readable_file(const struct tomoyo_path_info *
 }
 
 /**
- * tomoyo_write_globally_readable_policy - Write "struct tomoyo_globally_readable_file_entry" list.
+ * tomoyo_write_globally_readable - Write "struct tomoyo_readable_file" list.
  *
  * @data:      String to parse.
  * @is_delete: True if it is a delete request.
@@ -263,74 +341,20 @@ static bool tomoyo_is_globally_readable_file(const struct tomoyo_path_info *
  *
  * Caller holds tomoyo_read_lock().
  */
-int tomoyo_write_globally_readable_policy(char *data, const bool is_delete)
+int tomoyo_write_globally_readable(char *data, const bool is_delete)
 {
        return tomoyo_update_globally_readable_entry(data, is_delete);
 }
 
-/**
- * tomoyo_read_globally_readable_policy - Read "struct tomoyo_globally_readable_file_entry" list.
- *
- * @head: Pointer to "struct tomoyo_io_buffer".
- *
- * Returns true on success, false otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-bool tomoyo_read_globally_readable_policy(struct tomoyo_io_buffer *head)
+static bool tomoyo_same_pattern(const struct tomoyo_acl_head *a,
+                               const struct tomoyo_acl_head *b)
 {
-       struct list_head *pos;
-       bool done = true;
-
-       list_for_each_cookie(pos, head->read_var2,
-                            &tomoyo_globally_readable_list) {
-               struct tomoyo_globally_readable_file_entry *ptr;
-               ptr = list_entry(pos,
-                                struct tomoyo_globally_readable_file_entry,
-                                list);
-               if (ptr->is_deleted)
-                       continue;
-               done = tomoyo_io_printf(head, TOMOYO_KEYWORD_ALLOW_READ "%s\n",
-                                       ptr->filename->name);
-               if (!done)
-                       break;
-       }
-       return done;
+       return container_of(a, struct tomoyo_no_pattern, head)->pattern ==
+               container_of(b, struct tomoyo_no_pattern, head)->pattern;
 }
 
-/* tomoyo_pattern_list is used for holding list of pathnames which are used for
- * converting pathnames to pathname patterns during learning mode.
- *
- * An entry is added by
- *
- * # echo 'file_pattern /proc/\$/mounts' > \
- *                             /sys/kernel/security/tomoyo/exception_policy
- *
- * and is deleted by
- *
- * # echo 'delete file_pattern /proc/\$/mounts' > \
- *                             /sys/kernel/security/tomoyo/exception_policy
- *
- * and all entries are retrieved by
- *
- * # grep ^file_pattern /sys/kernel/security/tomoyo/exception_policy
- *
- * In the example above, if a process which belongs to a domain which is in
- * learning mode requested open("/proc/1/mounts", O_RDONLY),
- * "allow_read /proc/\$/mounts" is automatically added to the domain which that
- * process belongs to.
- *
- * It is not a desirable behavior that we have to use /proc/\$/ instead of
- * /proc/self/ when current process needs to access only current process's
- * information. As of now, LSM version of TOMOYO is using __d_path() for
- * calculating pathname. Non LSM version of TOMOYO is using its own function
- * which pretends as if /proc/self/ is not a symlink; so that we can forbid
- * current process from accessing other process's information.
- */
-LIST_HEAD(tomoyo_pattern_list);
-
 /**
- * tomoyo_update_file_pattern_entry - Update "struct tomoyo_pattern_entry" list.
+ * tomoyo_update_file_pattern_entry - Update "struct tomoyo_no_pattern" list.
  *
  * @pattern:   Pathname pattern.
  * @is_delete: True if it is a delete request.
@@ -342,39 +366,23 @@ LIST_HEAD(tomoyo_pattern_list);
 static int tomoyo_update_file_pattern_entry(const char *pattern,
                                            const bool is_delete)
 {
-       struct tomoyo_pattern_entry *ptr;
-       struct tomoyo_pattern_entry e = { .pattern = tomoyo_get_name(pattern) };
-       int error = is_delete ? -ENOENT : -ENOMEM;
+       struct tomoyo_no_pattern e = { };
+       int error;
 
+       if (!tomoyo_correct_word(pattern))
+               return -EINVAL;
+       e.pattern = tomoyo_get_name(pattern);
        if (!e.pattern)
-               return error;
-       if (!e.pattern->is_patterned)
-               goto out;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) {
-               if (e.pattern != ptr->pattern)
-                       continue;
-               ptr->is_deleted = is_delete;
-               error = 0;
-               break;
-       }
-       if (!is_delete && error) {
-               struct tomoyo_pattern_entry *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
-               if (entry) {
-                       list_add_tail_rcu(&entry->list, &tomoyo_pattern_list);
-                       error = 0;
-               }
-       }
-       mutex_unlock(&tomoyo_policy_lock);
- out:
+               return -ENOMEM;
+       error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
+                                    &tomoyo_policy_list[TOMOYO_ID_PATTERN],
+                                    tomoyo_same_pattern);
        tomoyo_put_name(e.pattern);
        return error;
 }
 
 /**
- * tomoyo_get_file_pattern - Get patterned pathname.
+ * tomoyo_pattern - Get patterned pathname.
  *
  * @filename: The filename to find patterned pathname.
  *
@@ -382,14 +390,14 @@ static int tomoyo_update_file_pattern_entry(const char *pattern,
  *
  * Caller holds tomoyo_read_lock().
  */
-static const struct tomoyo_path_info *
-tomoyo_get_file_pattern(const struct tomoyo_path_info *filename)
+const char *tomoyo_pattern(const struct tomoyo_path_info *filename)
 {
-       struct tomoyo_pattern_entry *ptr;
+       struct tomoyo_no_pattern *ptr;
        const struct tomoyo_path_info *pattern = NULL;
 
-       list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) {
-               if (ptr->is_deleted)
+       list_for_each_entry_rcu(ptr, &tomoyo_policy_list[TOMOYO_ID_PATTERN],
+                               head.list) {
+               if (ptr->head.is_deleted)
                        continue;
                if (!tomoyo_path_matches_pattern(filename, ptr->pattern))
                        continue;
@@ -403,11 +411,11 @@ tomoyo_get_file_pattern(const struct tomoyo_path_info *filename)
        }
        if (pattern)
                filename = pattern;
-       return filename;
+       return filename->name;
 }
 
 /**
- * tomoyo_write_pattern_policy - Write "struct tomoyo_pattern_entry" list.
+ * tomoyo_write_pattern - Write "struct tomoyo_no_pattern" list.
  *
  * @data:      String to parse.
  * @is_delete: True if it is a delete request.
@@ -416,71 +424,21 @@ tomoyo_get_file_pattern(const struct tomoyo_path_info *filename)
  *
  * Caller holds tomoyo_read_lock().
  */
-int tomoyo_write_pattern_policy(char *data, const bool is_delete)
+int tomoyo_write_pattern(char *data, const bool is_delete)
 {
        return tomoyo_update_file_pattern_entry(data, is_delete);
 }
 
-/**
- * tomoyo_read_file_pattern - Read "struct tomoyo_pattern_entry" list.
- *
- * @head: Pointer to "struct tomoyo_io_buffer".
- *
- * Returns true on success, false otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-bool tomoyo_read_file_pattern(struct tomoyo_io_buffer *head)
+static bool tomoyo_same_no_rewrite(const struct tomoyo_acl_head *a,
+                                  const struct tomoyo_acl_head *b)
 {
-       struct list_head *pos;
-       bool done = true;
-
-       list_for_each_cookie(pos, head->read_var2, &tomoyo_pattern_list) {
-               struct tomoyo_pattern_entry *ptr;
-               ptr = list_entry(pos, struct tomoyo_pattern_entry, list);
-               if (ptr->is_deleted)
-                       continue;
-               done = tomoyo_io_printf(head, TOMOYO_KEYWORD_FILE_PATTERN
-                                       "%s\n", ptr->pattern->name);
-               if (!done)
-                       break;
-       }
-       return done;
+       return container_of(a, struct tomoyo_no_rewrite, head)->pattern
+               == container_of(b, struct tomoyo_no_rewrite, head)
+               ->pattern;
 }
 
-/*
- * tomoyo_no_rewrite_list is used for holding list of pathnames which are by
- * default forbidden to modify already written content of a file.
- *
- * An entry is added by
- *
- * # echo 'deny_rewrite /var/log/messages' > \
- *                              /sys/kernel/security/tomoyo/exception_policy
- *
- * and is deleted by
- *
- * # echo 'delete deny_rewrite /var/log/messages' > \
- *                              /sys/kernel/security/tomoyo/exception_policy
- *
- * and all entries are retrieved by
- *
- * # grep ^deny_rewrite /sys/kernel/security/tomoyo/exception_policy
- *
- * In the example above, if a process requested to rewrite /var/log/messages ,
- * the process can't rewrite unless the domain which that process belongs to
- * has "allow_rewrite /var/log/messages" entry.
- *
- * It is not a desirable behavior that we have to add "\040(deleted)" suffix
- * when we want to allow rewriting already unlink()ed file. As of now,
- * LSM version of TOMOYO is using __d_path() for calculating pathname.
- * Non LSM version of TOMOYO is using its own function which doesn't append
- * " (deleted)" suffix if the file is already unlink()ed; so that we don't
- * need to worry whether the file is already unlink()ed or not.
- */
-LIST_HEAD(tomoyo_no_rewrite_list);
-
 /**
- * tomoyo_update_no_rewrite_entry - Update "struct tomoyo_no_rewrite_entry" list.
+ * tomoyo_update_no_rewrite_entry - Update "struct tomoyo_no_rewrite" list.
  *
  * @pattern:   Pathname pattern that are not rewritable by default.
  * @is_delete: True if it is a delete request.
@@ -492,41 +450,23 @@ LIST_HEAD(tomoyo_no_rewrite_list);
 static int tomoyo_update_no_rewrite_entry(const char *pattern,
                                          const bool is_delete)
 {
-       struct tomoyo_no_rewrite_entry *ptr;
-       struct tomoyo_no_rewrite_entry e = { };
-       int error = is_delete ? -ENOENT : -ENOMEM;
+       struct tomoyo_no_rewrite e = { };
+       int error;
 
-       if (!tomoyo_is_correct_path(pattern, 0, 0, 0))
+       if (!tomoyo_correct_word(pattern))
                return -EINVAL;
        e.pattern = tomoyo_get_name(pattern);
        if (!e.pattern)
-               return error;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) {
-               if (ptr->pattern != e.pattern)
-                       continue;
-               ptr->is_deleted = is_delete;
-               error = 0;
-               break;
-       }
-       if (!is_delete && error) {
-               struct tomoyo_no_rewrite_entry *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
-               if (entry) {
-                       list_add_tail_rcu(&entry->list,
-                                         &tomoyo_no_rewrite_list);
-                       error = 0;
-               }
-       }
-       mutex_unlock(&tomoyo_policy_lock);
- out:
+               return -ENOMEM;
+       error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
+                                    &tomoyo_policy_list[TOMOYO_ID_NO_REWRITE],
+                                    tomoyo_same_no_rewrite);
        tomoyo_put_name(e.pattern);
        return error;
 }
 
 /**
- * tomoyo_is_no_rewrite_file - Check if the given pathname is not permitted to be rewrited.
+ * tomoyo_no_rewrite_file - Check if the given pathname is not permitted to be rewrited.
  *
  * @filename: Filename to check.
  *
@@ -535,13 +475,14 @@ static int tomoyo_update_no_rewrite_entry(const char *pattern,
  *
  * Caller holds tomoyo_read_lock().
  */
-static bool tomoyo_is_no_rewrite_file(const struct tomoyo_path_info *filename)
+static bool tomoyo_no_rewrite_file(const struct tomoyo_path_info *filename)
 {
-       struct tomoyo_no_rewrite_entry *ptr;
+       struct tomoyo_no_rewrite *ptr;
        bool found = false;
 
-       list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) {
-               if (ptr->is_deleted)
+       list_for_each_entry_rcu(ptr, &tomoyo_policy_list[TOMOYO_ID_NO_REWRITE],
+                               head.list) {
+               if (ptr->head.is_deleted)
                        continue;
                if (!tomoyo_path_matches_pattern(filename, ptr->pattern))
                        continue;
@@ -552,7 +493,7 @@ static bool tomoyo_is_no_rewrite_file(const struct tomoyo_path_info *filename)
 }
 
 /**
- * tomoyo_write_no_rewrite_policy - Write "struct tomoyo_no_rewrite_entry" list.
+ * tomoyo_write_no_rewrite - Write "struct tomoyo_no_rewrite" list.
  *
  * @data:      String to parse.
  * @is_delete: True if it is a delete request.
@@ -561,214 +502,103 @@ static bool tomoyo_is_no_rewrite_file(const struct tomoyo_path_info *filename)
  *
  * Caller holds tomoyo_read_lock().
  */
-int tomoyo_write_no_rewrite_policy(char *data, const bool is_delete)
+int tomoyo_write_no_rewrite(char *data, const bool is_delete)
 {
        return tomoyo_update_no_rewrite_entry(data, is_delete);
 }
 
-/**
- * tomoyo_read_no_rewrite_policy - Read "struct tomoyo_no_rewrite_entry" list.
- *
- * @head: Pointer to "struct tomoyo_io_buffer".
- *
- * Returns true on success, false otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-bool tomoyo_read_no_rewrite_policy(struct tomoyo_io_buffer *head)
+static bool tomoyo_check_path_acl(struct tomoyo_request_info *r,
+                                 const struct tomoyo_acl_info *ptr)
 {
-       struct list_head *pos;
-       bool done = true;
-
-       list_for_each_cookie(pos, head->read_var2, &tomoyo_no_rewrite_list) {
-               struct tomoyo_no_rewrite_entry *ptr;
-               ptr = list_entry(pos, struct tomoyo_no_rewrite_entry, list);
-               if (ptr->is_deleted)
-                       continue;
-               done = tomoyo_io_printf(head, TOMOYO_KEYWORD_DENY_REWRITE
-                                       "%s\n", ptr->pattern->name);
-               if (!done)
-                       break;
+       const struct tomoyo_path_acl *acl = container_of(ptr, typeof(*acl),
+                                                        head);
+       if (acl->perm & (1 << r->param.path.operation)) {
+               r->param.path.matched_path =
+                       tomoyo_compare_name_union(r->param.path.filename,
+                                                 &acl->name);
+               return r->param.path.matched_path != NULL;
        }
-       return done;
+       return false;
 }
 
-/**
- * tomoyo_update_file_acl - Update file's read/write/execute ACL.
- *
- * @filename:  Filename.
- * @perm:      Permission (between 1 to 7).
- * @domain:    Pointer to "struct tomoyo_domain_info".
- * @is_delete: True if it is a delete request.
- *
- * Returns 0 on success, negative value otherwise.
- *
- * This is legacy support interface for older policy syntax.
- * Current policy syntax uses "allow_read/write" instead of "6",
- * "allow_read" instead of "4", "allow_write" instead of "2",
- * "allow_execute" instead of "1".
- *
- * Caller holds tomoyo_read_lock().
- */
-static int tomoyo_update_file_acl(const char *filename, u8 perm,
-                                 struct tomoyo_domain_info * const domain,
-                                 const bool is_delete)
+static bool tomoyo_check_path_number_acl(struct tomoyo_request_info *r,
+                                        const struct tomoyo_acl_info *ptr)
 {
-       if (perm > 7 || !perm) {
-               printk(KERN_DEBUG "%s: Invalid permission '%d %s'\n",
-                      __func__, perm, filename);
-               return -EINVAL;
-       }
-       if (filename[0] != '@' && tomoyo_strendswith(filename, "/"))
-               /*
-                * Only 'allow_mkdir' and 'allow_rmdir' are valid for
-                * directory permissions.
-                */
-               return 0;
-       if (perm & 4)
-               tomoyo_update_path_acl(TOMOYO_TYPE_READ, filename, domain,
-                                      is_delete);
-       if (perm & 2)
-               tomoyo_update_path_acl(TOMOYO_TYPE_WRITE, filename, domain,
-                                      is_delete);
-       if (perm & 1)
-               tomoyo_update_path_acl(TOMOYO_TYPE_EXECUTE, filename, domain,
-                                      is_delete);
-       return 0;
+       const struct tomoyo_path_number_acl *acl =
+               container_of(ptr, typeof(*acl), head);
+       return (acl->perm & (1 << r->param.path_number.operation)) &&
+               tomoyo_compare_number_union(r->param.path_number.number,
+                                           &acl->number) &&
+               tomoyo_compare_name_union(r->param.path_number.filename,
+                                         &acl->name);
 }
 
-/**
- * tomoyo_path_acl2 - Check permission for single path operation.
- *
- * @domain:          Pointer to "struct tomoyo_domain_info".
- * @filename:        Filename to check.
- * @perm:            Permission.
- * @may_use_pattern: True if patterned ACL is permitted.
- *
- * Returns 0 on success, -EPERM otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-static int tomoyo_path_acl2(const struct tomoyo_domain_info *domain,
-                           const struct tomoyo_path_info *filename,
-                           const u32 perm, const bool may_use_pattern)
+static bool tomoyo_check_path2_acl(struct tomoyo_request_info *r,
+                                  const struct tomoyo_acl_info *ptr)
 {
-       struct tomoyo_acl_info *ptr;
-       int error = -EPERM;
-
-       list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
-               struct tomoyo_path_acl *acl;
-               if (ptr->type != TOMOYO_TYPE_PATH_ACL)
-                       continue;
-               acl = container_of(ptr, struct tomoyo_path_acl, head);
-               if (perm <= 0xFFFF) {
-                       if (!(acl->perm & perm))
-                               continue;
-               } else {
-                       if (!(acl->perm_high & (perm >> 16)))
-                               continue;
-               }
-               if (!tomoyo_compare_name_union_pattern(filename, &acl->name,
-                                                       may_use_pattern))
-                       continue;
-               error = 0;
-               break;
-       }
-       return error;
+       const struct tomoyo_path2_acl *acl =
+               container_of(ptr, typeof(*acl), head);
+       return (acl->perm & (1 << r->param.path2.operation)) &&
+               tomoyo_compare_name_union(r->param.path2.filename1, &acl->name1)
+               && tomoyo_compare_name_union(r->param.path2.filename2,
+                                            &acl->name2);
 }
 
-/**
- * tomoyo_check_file_acl - Check permission for opening files.
- *
- * @domain:    Pointer to "struct tomoyo_domain_info".
- * @filename:  Filename to check.
- * @operation: Mode ("read" or "write" or "read/write" or "execute").
- *
- * Returns 0 on success, -EPERM otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-static int tomoyo_check_file_acl(const struct tomoyo_domain_info *domain,
-                                const struct tomoyo_path_info *filename,
-                                const u8 operation)
+static bool tomoyo_check_mkdev_acl(struct tomoyo_request_info *r,
+                               const struct tomoyo_acl_info *ptr)
 {
-       u32 perm = 0;
-
-       if (!tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE))
-               return 0;
-       if (operation == 6)
-               perm = 1 << TOMOYO_TYPE_READ_WRITE;
-       else if (operation == 4)
-               perm = 1 << TOMOYO_TYPE_READ;
-       else if (operation == 2)
-               perm = 1 << TOMOYO_TYPE_WRITE;
-       else if (operation == 1)
-               perm = 1 << TOMOYO_TYPE_EXECUTE;
-       else
-               BUG();
-       return tomoyo_path_acl2(domain, filename, perm, operation != 1);
+       const struct tomoyo_mkdev_acl *acl =
+               container_of(ptr, typeof(*acl), head);
+       return (acl->perm & (1 << r->param.mkdev.operation)) &&
+               tomoyo_compare_number_union(r->param.mkdev.mode,
+                                           &acl->mode) &&
+               tomoyo_compare_number_union(r->param.mkdev.major,
+                                           &acl->major) &&
+               tomoyo_compare_number_union(r->param.mkdev.minor,
+                                           &acl->minor) &&
+               tomoyo_compare_name_union(r->param.mkdev.filename,
+                                         &acl->name);
 }
 
-/**
- * tomoyo_check_file_perm2 - Check permission for opening files.
- *
- * @domain:    Pointer to "struct tomoyo_domain_info".
- * @filename:  Filename to check.
- * @perm:      Mode ("read" or "write" or "read/write" or "execute").
- * @operation: Operation name passed used for verbose mode.
- * @mode:      Access control mode.
- *
- * Returns 0 on success, negative value otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-static int tomoyo_check_file_perm2(struct tomoyo_domain_info * const domain,
-                                  const struct tomoyo_path_info *filename,
-                                  const u8 perm, const char *operation,
-                                  const u8 mode)
+static bool tomoyo_same_path_acl(const struct tomoyo_acl_info *a,
+                                const struct tomoyo_acl_info *b)
 {
-       const bool is_enforce = (mode == 3);
-       const char *msg = "<unknown>";
-       int error = 0;
+       const struct tomoyo_path_acl *p1 = container_of(a, typeof(*p1), head);
+       const struct tomoyo_path_acl *p2 = container_of(b, typeof(*p2), head);
+       return tomoyo_same_acl_head(&p1->head, &p2->head) &&
+               tomoyo_same_name_union(&p1->name, &p2->name);
+}
 
-       if (!filename)
-               return 0;
-       error = tomoyo_check_file_acl(domain, filename, perm);
-       if (error && perm == 4 && !domain->ignore_global_allow_read
-           && tomoyo_is_globally_readable_file(filename))
-               error = 0;
-       if (perm == 6)
-               msg = tomoyo_path2keyword(TOMOYO_TYPE_READ_WRITE);
-       else if (perm == 4)
-               msg = tomoyo_path2keyword(TOMOYO_TYPE_READ);
-       else if (perm == 2)
-               msg = tomoyo_path2keyword(TOMOYO_TYPE_WRITE);
-       else if (perm == 1)
-               msg = tomoyo_path2keyword(TOMOYO_TYPE_EXECUTE);
-       else
-               BUG();
-       if (!error)
-               return 0;
-       if (tomoyo_verbose_mode(domain))
-               printk(KERN_WARNING "TOMOYO-%s: Access '%s(%s) %s' denied "
-                      "for %s\n", tomoyo_get_msg(is_enforce), msg, operation,
-                      filename->name, tomoyo_get_last_name(domain));
-       if (is_enforce)
-               return error;
-       if (mode == 1 && tomoyo_domain_quota_is_ok(domain)) {
-               /* Don't use patterns for execute permission. */
-               const struct tomoyo_path_info *patterned_file = (perm != 1) ?
-                       tomoyo_get_file_pattern(filename) : filename;
-               tomoyo_update_file_acl(patterned_file->name, perm,
-                                      domain, false);
+static bool tomoyo_merge_path_acl(struct tomoyo_acl_info *a,
+                                 struct tomoyo_acl_info *b,
+                                 const bool is_delete)
+{
+       u16 * const a_perm = &container_of(a, struct tomoyo_path_acl, head)
+               ->perm;
+       u16 perm = *a_perm;
+       const u16 b_perm = container_of(b, struct tomoyo_path_acl, head)->perm;
+       if (is_delete) {
+               perm &= ~b_perm;
+               if ((perm & TOMOYO_RW_MASK) != TOMOYO_RW_MASK)
+                       perm &= ~(1 << TOMOYO_TYPE_READ_WRITE);
+               else if (!(perm & (1 << TOMOYO_TYPE_READ_WRITE)))
+                       perm &= ~TOMOYO_RW_MASK;
+       } else {
+               perm |= b_perm;
+               if ((perm & TOMOYO_RW_MASK) == TOMOYO_RW_MASK)
+                       perm |= (1 << TOMOYO_TYPE_READ_WRITE);
+               else if (perm & (1 << TOMOYO_TYPE_READ_WRITE))
+                       perm |= TOMOYO_RW_MASK;
        }
-       return 0;
+       *a_perm = perm;
+       return !perm;
 }
 
 /**
- * tomoyo_write_file_policy - Update file related list.
+ * tomoyo_update_path_acl - Update "struct tomoyo_path_acl" list.
  *
- * @data:      String to parse.
+ * @type:      Type of operation.
+ * @filename:  Filename.
  * @domain:    Pointer to "struct tomoyo_domain_info".
  * @is_delete: True if it is a delete request.
  *
@@ -776,48 +606,65 @@ static int tomoyo_check_file_perm2(struct tomoyo_domain_info * const domain,
  *
  * Caller holds tomoyo_read_lock().
  */
-int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
-                            const bool is_delete)
+static int tomoyo_update_path_acl(const u8 type, const char *filename,
+                                 struct tomoyo_domain_info * const domain,
+                                 const bool is_delete)
 {
-       char *filename = strchr(data, ' ');
-       char *filename2;
-       unsigned int perm;
-       u8 type;
-
-       if (!filename)
+       struct tomoyo_path_acl e = {
+               .head.type = TOMOYO_TYPE_PATH_ACL,
+               .perm = 1 << type
+       };
+       int error;
+       if (e.perm == (1 << TOMOYO_TYPE_READ_WRITE))
+               e.perm |= TOMOYO_RW_MASK;
+       if (!tomoyo_parse_name_union(filename, &e.name))
                return -EINVAL;
-       *filename++ = '\0';
-       if (sscanf(data, "%u", &perm) == 1)
-               return tomoyo_update_file_acl(filename, (u8) perm, domain,
-                                             is_delete);
-       if (strncmp(data, "allow_", 6))
-               goto out;
-       data += 6;
-       for (type = 0; type < TOMOYO_MAX_PATH_OPERATION; type++) {
-               if (strcmp(data, tomoyo_path_keyword[type]))
-                       continue;
-               return tomoyo_update_path_acl(type, filename, domain,
-                                             is_delete);
-       }
-       filename2 = strchr(filename, ' ');
-       if (!filename2)
-               goto out;
-       *filename2++ = '\0';
-       for (type = 0; type < TOMOYO_MAX_PATH2_OPERATION; type++) {
-               if (strcmp(data, tomoyo_path2_keyword[type]))
-                       continue;
-               return tomoyo_update_path2_acl(type, filename, filename2,
-                                              domain, is_delete);
-       }
- out:
-       return -EINVAL;
+       error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
+                                    tomoyo_same_path_acl,
+                                    tomoyo_merge_path_acl);
+       tomoyo_put_name_union(&e.name);
+       return error;
+}
+
+static bool tomoyo_same_mkdev_acl(const struct tomoyo_acl_info *a,
+                                        const struct tomoyo_acl_info *b)
+{
+       const struct tomoyo_mkdev_acl *p1 = container_of(a, typeof(*p1),
+                                                               head);
+       const struct tomoyo_mkdev_acl *p2 = container_of(b, typeof(*p2),
+                                                               head);
+       return tomoyo_same_acl_head(&p1->head, &p2->head)
+               && tomoyo_same_name_union(&p1->name, &p2->name)
+               && tomoyo_same_number_union(&p1->mode, &p2->mode)
+               && tomoyo_same_number_union(&p1->major, &p2->major)
+               && tomoyo_same_number_union(&p1->minor, &p2->minor);
+}
+
+static bool tomoyo_merge_mkdev_acl(struct tomoyo_acl_info *a,
+                                         struct tomoyo_acl_info *b,
+                                         const bool is_delete)
+{
+       u8 *const a_perm = &container_of(a, struct tomoyo_mkdev_acl,
+                                        head)->perm;
+       u8 perm = *a_perm;
+       const u8 b_perm = container_of(b, struct tomoyo_mkdev_acl, head)
+               ->perm;
+       if (is_delete)
+               perm &= ~b_perm;
+       else
+               perm |= b_perm;
+       *a_perm = perm;
+       return !perm;
 }
 
 /**
- * tomoyo_update_path_acl - Update "struct tomoyo_path_acl" list.
+ * tomoyo_update_mkdev_acl - Update "struct tomoyo_mkdev_acl" list.
  *
  * @type:      Type of operation.
  * @filename:  Filename.
+ * @mode:      Create mode.
+ * @major:     Device major number.
+ * @minor:     Device minor number.
  * @domain:    Pointer to "struct tomoyo_domain_info".
  * @is_delete: True if it is a delete request.
  *
@@ -825,71 +672,58 @@ int tomoyo_write_file_policy(char *data, struct tomoyo_domain_info *domain,
  *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_update_path_acl(const u8 type, const char *filename,
-                                 struct tomoyo_domain_info *const domain,
-                                 const bool is_delete)
+static int tomoyo_update_mkdev_acl(const u8 type, const char *filename,
+                                         char *mode, char *major, char *minor,
+                                         struct tomoyo_domain_info * const
+                                         domain, const bool is_delete)
 {
-       static const u32 tomoyo_rw_mask =
-               (1 << TOMOYO_TYPE_READ) | (1 << TOMOYO_TYPE_WRITE);
-       const u32 perm = 1 << type;
-       struct tomoyo_acl_info *ptr;
-       struct tomoyo_path_acl e = {
-               .head.type = TOMOYO_TYPE_PATH_ACL,
-               .perm_high = perm >> 16,
-               .perm = perm
+       struct tomoyo_mkdev_acl e = {
+               .head.type = TOMOYO_TYPE_MKDEV_ACL,
+               .perm = 1 << type
        };
        int error = is_delete ? -ENOENT : -ENOMEM;
-
-       if (type == TOMOYO_TYPE_READ_WRITE)
-               e.perm |= tomoyo_rw_mask;
-       if (!domain)
-               return -EINVAL;
-       if (!tomoyo_parse_name_union(filename, &e.name))
-               return -EINVAL;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+       if (!tomoyo_parse_name_union(filename, &e.name) ||
+           !tomoyo_parse_number_union(mode, &e.mode) ||
+           !tomoyo_parse_number_union(major, &e.major) ||
+           !tomoyo_parse_number_union(minor, &e.minor))
                goto out;
-       list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
-               struct tomoyo_path_acl *acl =
-                       container_of(ptr, struct tomoyo_path_acl, head);
-               if (!tomoyo_is_same_path_acl(acl, &e))
-                       continue;
-               if (is_delete) {
-                       if (perm <= 0xFFFF)
-                               acl->perm &= ~perm;
-                       else
-                               acl->perm_high &= ~(perm >> 16);
-                       if ((acl->perm & tomoyo_rw_mask) != tomoyo_rw_mask)
-                               acl->perm &= ~(1 << TOMOYO_TYPE_READ_WRITE);
-                       else if (!(acl->perm & (1 << TOMOYO_TYPE_READ_WRITE)))
-                               acl->perm &= ~tomoyo_rw_mask;
-               } else {
-                       if (perm <= 0xFFFF)
-                               acl->perm |= perm;
-                       else
-                               acl->perm_high |= (perm >> 16);
-                       if ((acl->perm & tomoyo_rw_mask) == tomoyo_rw_mask)
-                               acl->perm |= 1 << TOMOYO_TYPE_READ_WRITE;
-                       else if (acl->perm & (1 << TOMOYO_TYPE_READ_WRITE))
-                               acl->perm |= tomoyo_rw_mask;
-               }
-               error = 0;
-               break;
-       }
-       if (!is_delete && error) {
-               struct tomoyo_path_acl *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
-               if (entry) {
-                       list_add_tail_rcu(&entry->head.list,
-                                         &domain->acl_info_list);
-                       error = 0;
-               }
-       }
-       mutex_unlock(&tomoyo_policy_lock);
+       error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
+                                    tomoyo_same_mkdev_acl,
+                                    tomoyo_merge_mkdev_acl);
  out:
        tomoyo_put_name_union(&e.name);
+       tomoyo_put_number_union(&e.mode);
+       tomoyo_put_number_union(&e.major);
+       tomoyo_put_number_union(&e.minor);
        return error;
 }
 
+static bool tomoyo_same_path2_acl(const struct tomoyo_acl_info *a,
+                                 const struct tomoyo_acl_info *b)
+{
+       const struct tomoyo_path2_acl *p1 = container_of(a, typeof(*p1), head);
+       const struct tomoyo_path2_acl *p2 = container_of(b, typeof(*p2), head);
+       return tomoyo_same_acl_head(&p1->head, &p2->head)
+               && tomoyo_same_name_union(&p1->name1, &p2->name1)
+               && tomoyo_same_name_union(&p1->name2, &p2->name2);
+}
+
+static bool tomoyo_merge_path2_acl(struct tomoyo_acl_info *a,
+                                  struct tomoyo_acl_info *b,
+                                  const bool is_delete)
+{
+       u8 * const a_perm = &container_of(a, struct tomoyo_path2_acl, head)
+               ->perm;
+       u8 perm = *a_perm;
+       const u8 b_perm = container_of(b, struct tomoyo_path2_acl, head)->perm;
+       if (is_delete)
+               perm &= ~b_perm;
+       else
+               perm |= b_perm;
+       *a_perm = perm;
+       return !perm;
+}
+
 /**
  * tomoyo_update_path2_acl - Update "struct tomoyo_path2_acl" list.
  *
@@ -905,46 +739,20 @@ static int tomoyo_update_path_acl(const u8 type, const char *filename,
  */
 static int tomoyo_update_path2_acl(const u8 type, const char *filename1,
                                   const char *filename2,
-                                  struct tomoyo_domain_info *const domain,
+                                  struct tomoyo_domain_info * const domain,
                                   const bool is_delete)
 {
-       const u8 perm = 1 << type;
        struct tomoyo_path2_acl e = {
                .head.type = TOMOYO_TYPE_PATH2_ACL,
-               .perm = perm
+               .perm = 1 << type
        };
-       struct tomoyo_acl_info *ptr;
        int error = is_delete ? -ENOENT : -ENOMEM;
-
-       if (!domain)
-               return -EINVAL;
        if (!tomoyo_parse_name_union(filename1, &e.name1) ||
            !tomoyo_parse_name_union(filename2, &e.name2))
                goto out;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
-               struct tomoyo_path2_acl *acl =
-                       container_of(ptr, struct tomoyo_path2_acl, head);
-               if (!tomoyo_is_same_path2_acl(acl, &e))
-                       continue;
-               if (is_delete)
-                       acl->perm &= ~perm;
-               else
-                       acl->perm |= perm;
-               error = 0;
-               break;
-       }
-       if (!is_delete && error) {
-               struct tomoyo_path2_acl *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
-               if (entry) {
-                       list_add_tail_rcu(&entry->head.list,
-                                         &domain->acl_info_list);
-                       error = 0;
-               }
-       }
-       mutex_unlock(&tomoyo_policy_lock);
+       error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
+                                    tomoyo_same_path2_acl,
+                                    tomoyo_merge_path2_acl);
  out:
        tomoyo_put_name_union(&e.name1);
        tomoyo_put_name_union(&e.name2);
@@ -952,134 +760,158 @@ static int tomoyo_update_path2_acl(const u8 type, const char *filename1,
 }
 
 /**
- * tomoyo_path_acl - Check permission for single path operation.
- *
- * @domain:   Pointer to "struct tomoyo_domain_info".
- * @type:     Type of operation.
- * @filename: Filename to check.
- *
- * Returns 0 on success, negative value otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-static int tomoyo_path_acl(struct tomoyo_domain_info *domain, const u8 type,
-                          const struct tomoyo_path_info *filename)
-{
-       if (!tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE))
-               return 0;
-       return tomoyo_path_acl2(domain, filename, 1 << type, 1);
-}
-
-/**
- * tomoyo_path2_acl - Check permission for double path operation.
+ * tomoyo_path_permission - Check permission for single path operation.
  *
- * @domain:    Pointer to "struct tomoyo_domain_info".
- * @type:      Type of operation.
- * @filename1: First filename to check.
- * @filename2: Second filename to check.
- *
- * Returns 0 on success, -EPERM otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-static int tomoyo_path2_acl(const struct tomoyo_domain_info *domain,
-                           const u8 type,
-                           const struct tomoyo_path_info *filename1,
-                           const struct tomoyo_path_info *filename2)
-{
-       struct tomoyo_acl_info *ptr;
-       const u8 perm = 1 << type;
-       int error = -EPERM;
-
-       if (!tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE))
-               return 0;
-       list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
-               struct tomoyo_path2_acl *acl;
-               if (ptr->type != TOMOYO_TYPE_PATH2_ACL)
-                       continue;
-               acl = container_of(ptr, struct tomoyo_path2_acl, head);
-               if (!(acl->perm & perm))
-                       continue;
-               if (!tomoyo_compare_name_union(filename1, &acl->name1))
-                       continue;
-               if (!tomoyo_compare_name_union(filename2, &acl->name2))
-                       continue;
-               error = 0;
-               break;
-       }
-       return error;
-}
-
-/**
- * tomoyo_path_permission2 - Check permission for single path operation.
- *
- * @domain:    Pointer to "struct tomoyo_domain_info".
+ * @r:         Pointer to "struct tomoyo_request_info".
  * @operation: Type of operation.
  * @filename:  Filename to check.
- * @mode:      Access control mode.
  *
  * Returns 0 on success, negative value otherwise.
  *
  * Caller holds tomoyo_read_lock().
  */
-static int tomoyo_path_permission2(struct tomoyo_domain_info *const domain,
-                                  u8 operation,
-                                  const struct tomoyo_path_info *filename,
-                                  const u8 mode)
+int tomoyo_path_permission(struct tomoyo_request_info *r, u8 operation,
+                          const struct tomoyo_path_info *filename)
 {
-       const char *msg;
        int error;
-       const bool is_enforce = (mode == 3);
 
-       if (!mode)
-               return 0;
  next:
-       error = tomoyo_path_acl(domain, operation, filename);
-       msg = tomoyo_path2keyword(operation);
-       if (!error)
-               goto ok;
-       if (tomoyo_verbose_mode(domain))
-               printk(KERN_WARNING "TOMOYO-%s: Access '%s %s' denied for %s\n",
-                      tomoyo_get_msg(is_enforce), msg, filename->name,
-                      tomoyo_get_last_name(domain));
-       if (mode == 1 && tomoyo_domain_quota_is_ok(domain)) {
-               const char *name = tomoyo_get_file_pattern(filename)->name;
-               tomoyo_update_path_acl(operation, name, domain, false);
-       }
-       if (!is_enforce)
-               error = 0;
- ok:
+       r->type = tomoyo_p2mac[operation];
+       r->mode = tomoyo_get_mode(r->profile, r->type);
+       if (r->mode == TOMOYO_CONFIG_DISABLED)
+               return 0;
+       r->param_type = TOMOYO_TYPE_PATH_ACL;
+       r->param.path.filename = filename;
+       r->param.path.operation = operation;
+       do {
+               tomoyo_check_acl(r, tomoyo_check_path_acl);
+               if (!r->granted && operation == TOMOYO_TYPE_READ &&
+                   !r->domain->ignore_global_allow_read &&
+                   tomoyo_globally_readable_file(filename))
+                       r->granted = true;
+               error = tomoyo_audit_path_log(r);
+               /*
+                * Do not retry for execute request, for alias may have
+                * changed.
+                */
+       } while (error == TOMOYO_RETRY_REQUEST &&
+                operation != TOMOYO_TYPE_EXECUTE);
        /*
         * Since "allow_truncate" doesn't imply "allow_rewrite" permission,
         * we need to check "allow_rewrite" permission if the filename is
         * specified by "deny_rewrite" keyword.
         */
        if (!error && operation == TOMOYO_TYPE_TRUNCATE &&
-           tomoyo_is_no_rewrite_file(filename)) {
+           tomoyo_no_rewrite_file(filename)) {
                operation = TOMOYO_TYPE_REWRITE;
                goto next;
        }
        return error;
 }
 
+static bool tomoyo_same_path_number_acl(const struct tomoyo_acl_info *a,
+                                       const struct tomoyo_acl_info *b)
+{
+       const struct tomoyo_path_number_acl *p1 = container_of(a, typeof(*p1),
+                                                              head);
+       const struct tomoyo_path_number_acl *p2 = container_of(b, typeof(*p2),
+                                                              head);
+       return tomoyo_same_acl_head(&p1->head, &p2->head)
+               && tomoyo_same_name_union(&p1->name, &p2->name)
+               && tomoyo_same_number_union(&p1->number, &p2->number);
+}
+
+static bool tomoyo_merge_path_number_acl(struct tomoyo_acl_info *a,
+                                        struct tomoyo_acl_info *b,
+                                        const bool is_delete)
+{
+       u8 * const a_perm = &container_of(a, struct tomoyo_path_number_acl,
+                                         head)->perm;
+       u8 perm = *a_perm;
+       const u8 b_perm = container_of(b, struct tomoyo_path_number_acl, head)
+               ->perm;
+       if (is_delete)
+               perm &= ~b_perm;
+       else
+               perm |= b_perm;
+       *a_perm = perm;
+       return !perm;
+}
+
 /**
- * tomoyo_check_exec_perm - Check permission for "execute".
+ * tomoyo_update_path_number_acl - Update ioctl/chmod/chown/chgrp ACL.
+ *
+ * @type:      Type of operation.
+ * @filename:  Filename.
+ * @number:    Number.
+ * @domain:    Pointer to "struct tomoyo_domain_info".
+ * @is_delete: True if it is a delete request.
  *
- * @domain:   Pointer to "struct tomoyo_domain_info".
- * @filename: Check permission for "execute".
+ * Returns 0 on success, negative value otherwise.
+ */
+static int tomoyo_update_path_number_acl(const u8 type, const char *filename,
+                                        char *number,
+                                        struct tomoyo_domain_info * const
+                                        domain,
+                                        const bool is_delete)
+{
+       struct tomoyo_path_number_acl e = {
+               .head.type = TOMOYO_TYPE_PATH_NUMBER_ACL,
+               .perm = 1 << type
+       };
+       int error = is_delete ? -ENOENT : -ENOMEM;
+       if (!tomoyo_parse_name_union(filename, &e.name))
+               return -EINVAL;
+       if (!tomoyo_parse_number_union(number, &e.number))
+               goto out;
+       error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
+                                    tomoyo_same_path_number_acl,
+                                    tomoyo_merge_path_number_acl);
+ out:
+       tomoyo_put_name_union(&e.name);
+       tomoyo_put_number_union(&e.number);
+       return error;
+}
+
+/**
+ * tomoyo_path_number_perm - Check permission for "create", "mkdir", "mkfifo", "mksock", "ioctl", "chmod", "chown", "chgrp".
  *
- * Returns 0 on success, negativevalue otherwise.
+ * @type:   Type of operation.
+ * @path:   Pointer to "struct path".
+ * @number: Number.
  *
- * Caller holds tomoyo_read_lock().
+ * Returns 0 on success, negative value otherwise.
  */
-int tomoyo_check_exec_perm(struct tomoyo_domain_info *domain,
-                          const struct tomoyo_path_info *filename)
+int tomoyo_path_number_perm(const u8 type, struct path *path,
+                           unsigned long number)
 {
-       const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE);
+       struct tomoyo_request_info r;
+       int error = -ENOMEM;
+       struct tomoyo_path_info buf;
+       int idx;
 
-       if (!mode)
+       if (tomoyo_init_request_info(&r, NULL, tomoyo_pn2mac[type])
+           == TOMOYO_CONFIG_DISABLED || !path->mnt || !path->dentry)
                return 0;
-       return tomoyo_check_file_perm2(domain, filename, 1, "do_execve", mode);
+       idx = tomoyo_read_lock();
+       if (!tomoyo_get_realpath(&buf, path))
+               goto out;
+       if (type == TOMOYO_TYPE_MKDIR)
+               tomoyo_add_slash(&buf);
+       r.param_type = TOMOYO_TYPE_PATH_NUMBER_ACL;
+       r.param.path_number.operation = type;
+       r.param.path_number.filename = &buf;
+       r.param.path_number.number = number;
+       do {
+               tomoyo_check_acl(&r, tomoyo_check_path_number_acl);
+               error = tomoyo_audit_path_number_log(&r);
+       } while (error == TOMOYO_RETRY_REQUEST);
+       kfree(buf.name);
+ out:
+       tomoyo_read_unlock(idx);
+       if (r.mode != TOMOYO_CONFIG_ENFORCING)
+               error = 0;
+       return error;
 }
 
 /**
@@ -1096,24 +928,17 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
 {
        const u8 acc_mode = ACC_MODE(flag);
        int error = -ENOMEM;
-       struct tomoyo_path_info *buf;
-       const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE);
-       const bool is_enforce = (mode == 3);
+       struct tomoyo_path_info buf;
+       struct tomoyo_request_info r;
        int idx;
 
-       if (!mode || !path->mnt)
-               return 0;
-       if (acc_mode == 0)
-               return 0;
-       if (path->dentry->d_inode && S_ISDIR(path->dentry->d_inode->i_mode))
-               /*
-                * I don't check directories here because mkdir() and rmdir()
-                * don't call me.
-                */
+       if (!path->mnt ||
+           (path->dentry->d_inode && S_ISDIR(path->dentry->d_inode->i_mode)))
                return 0;
+       buf.name = NULL;
+       r.mode = TOMOYO_CONFIG_DISABLED;
        idx = tomoyo_read_lock();
-       buf = tomoyo_get_path(path);
-       if (!buf)
+       if (!tomoyo_get_realpath(&buf, path))
                goto out;
        error = 0;
        /*
@@ -1121,28 +946,43 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
         * we need to check "allow_rewrite" permission when the filename is not
         * opened for append mode or the filename is truncated at open time.
         */
-       if ((acc_mode & MAY_WRITE) &&
-           ((flag & O_TRUNC) || !(flag & O_APPEND)) &&
-           (tomoyo_is_no_rewrite_file(buf))) {
-               error = tomoyo_path_permission2(domain, TOMOYO_TYPE_REWRITE,
-                                               buf, mode);
+       if ((acc_mode & MAY_WRITE) && !(flag & O_APPEND)
+           && tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_REWRITE)
+           != TOMOYO_CONFIG_DISABLED) {
+               if (!tomoyo_get_realpath(&buf, path)) {
+                       error = -ENOMEM;
+                       goto out;
+               }
+               if (tomoyo_no_rewrite_file(&buf))
+                       error = tomoyo_path_permission(&r, TOMOYO_TYPE_REWRITE,
+                                                      &buf);
+       }
+       if (!error && acc_mode &&
+           tomoyo_init_request_info(&r, domain, TOMOYO_MAC_FILE_OPEN)
+           != TOMOYO_CONFIG_DISABLED) {
+               u8 operation;
+               if (!buf.name && !tomoyo_get_realpath(&buf, path)) {
+                       error = -ENOMEM;
+                       goto out;
+               }
+               if (acc_mode == (MAY_READ | MAY_WRITE))
+                       operation = TOMOYO_TYPE_READ_WRITE;
+               else if (acc_mode == MAY_READ)
+                       operation = TOMOYO_TYPE_READ;
+               else
+                       operation = TOMOYO_TYPE_WRITE;
+               error = tomoyo_path_permission(&r, operation, &buf);
        }
-       if (!error)
-               error = tomoyo_check_file_perm2(domain, buf, acc_mode, "open",
-                                               mode);
-       if (!error && (flag & O_TRUNC))
-               error = tomoyo_path_permission2(domain, TOMOYO_TYPE_TRUNCATE,
-                                               buf, mode);
  out:
-       kfree(buf);
+       kfree(buf.name);
        tomoyo_read_unlock(idx);
-       if (!is_enforce)
+       if (r.mode != TOMOYO_CONFIG_ENFORCING)
                error = 0;
        return error;
 }
 
 /**
- * tomoyo_path_perm - Check permission for "create", "unlink", "mkdir", "rmdir", "mkfifo", "mksock", "mkblock", "mkchar", "truncate", "symlink", "ioctl", "chmod", "chown", "chgrp", "chroot", "mount" and "unmount".
+ * tomoyo_path_perm - Check permission for "unlink", "rmdir", "truncate", "symlink", "rewrite", "chroot" and "unmount".
  *
  * @operation: Type of operation.
  * @path:      Pointer to "struct path".
@@ -1152,71 +992,79 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
 int tomoyo_path_perm(const u8 operation, struct path *path)
 {
        int error = -ENOMEM;
-       struct tomoyo_path_info *buf;
-       struct tomoyo_domain_info *domain = tomoyo_domain();
-       const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE);
-       const bool is_enforce = (mode == 3);
+       struct tomoyo_path_info buf;
+       struct tomoyo_request_info r;
        int idx;
 
-       if (!mode || !path->mnt)
+       if (!path->mnt)
                return 0;
+       if (tomoyo_init_request_info(&r, NULL, tomoyo_p2mac[operation])
+           == TOMOYO_CONFIG_DISABLED)
+               return 0;
+       buf.name = NULL;
        idx = tomoyo_read_lock();
-       buf = tomoyo_get_path(path);
-       if (!buf)
+       if (!tomoyo_get_realpath(&buf, path))
                goto out;
        switch (operation) {
-       case TOMOYO_TYPE_MKDIR:
+       case TOMOYO_TYPE_REWRITE:
+               if (!tomoyo_no_rewrite_file(&buf)) {
+                       error = 0;
+                       goto out;
+               }
+               break;
        case TOMOYO_TYPE_RMDIR:
        case TOMOYO_TYPE_CHROOT:
-               if (!buf->is_dir) {
-                       /*
-                        * tomoyo_get_path() reserves space for appending "/."
-                        */
-                       strcat((char *) buf->name, "/");
-                       tomoyo_fill_path_info(buf);
-               }
+       case TOMOYO_TYPE_UMOUNT:
+               tomoyo_add_slash(&buf);
+               break;
        }
-       error = tomoyo_path_permission2(domain, operation, buf, mode);
+       error = tomoyo_path_permission(&r, operation, &buf);
  out:
-       kfree(buf);
+       kfree(buf.name);
        tomoyo_read_unlock(idx);
-       if (!is_enforce)
+       if (r.mode != TOMOYO_CONFIG_ENFORCING)
                error = 0;
        return error;
 }
 
 /**
- * tomoyo_check_rewrite_permission - Check permission for "rewrite".
+ * tomoyo_mkdev_perm - Check permission for "mkblock" and "mkchar".
  *
- * @filp: Pointer to "struct file".
+ * @operation: Type of operation. (TOMOYO_TYPE_MKCHAR or TOMOYO_TYPE_MKBLOCK)
+ * @path:      Pointer to "struct path".
+ * @mode:      Create mode.
+ * @dev:       Device number.
  *
  * Returns 0 on success, negative value otherwise.
  */
-int tomoyo_check_rewrite_permission(struct file *filp)
+int tomoyo_mkdev_perm(const u8 operation, struct path *path,
+                            const unsigned int mode, unsigned int dev)
 {
+       struct tomoyo_request_info r;
        int error = -ENOMEM;
-       struct tomoyo_domain_info *domain = tomoyo_domain();
-       const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE);
-       const bool is_enforce = (mode == 3);
-       struct tomoyo_path_info *buf;
+       struct tomoyo_path_info buf;
        int idx;
 
-       if (!mode || !filp->f_path.mnt)
+       if (!path->mnt ||
+           tomoyo_init_request_info(&r, NULL, tomoyo_pnnn2mac[operation])
+           == TOMOYO_CONFIG_DISABLED)
                return 0;
-
        idx = tomoyo_read_lock();
-       buf = tomoyo_get_path(&filp->f_path);
-       if (!buf)
-               goto out;
-       if (!tomoyo_is_no_rewrite_file(buf)) {
-               error = 0;
-               goto out;
+       error = -ENOMEM;
+       if (tomoyo_get_realpath(&buf, path)) {
+               dev = new_decode_dev(dev);
+               r.param_type = TOMOYO_TYPE_MKDEV_ACL;
+               r.param.mkdev.filename = &buf;
+               r.param.mkdev.operation = operation;
+               r.param.mkdev.mode = mode;
+               r.param.mkdev.major = MAJOR(dev);
+               r.param.mkdev.minor = MINOR(dev);
+               tomoyo_check_acl(&r, tomoyo_check_mkdev_acl);
+               error = tomoyo_audit_mkdev_log(&r);
+               kfree(buf.name);
        }
-       error = tomoyo_path_permission2(domain, TOMOYO_TYPE_REWRITE, buf, mode);
- out:
-       kfree(buf);
        tomoyo_read_unlock(idx);
-       if (!is_enforce)
+       if (r.mode != TOMOYO_CONFIG_ENFORCING)
                error = 0;
        return error;
 }
@@ -1234,56 +1082,99 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
                      struct path *path2)
 {
        int error = -ENOMEM;
-       struct tomoyo_path_info *buf1, *buf2;
-       struct tomoyo_domain_info *domain = tomoyo_domain();
-       const u8 mode = tomoyo_check_flags(domain, TOMOYO_MAC_FOR_FILE);
-       const bool is_enforce = (mode == 3);
-       const char *msg;
+       struct tomoyo_path_info buf1;
+       struct tomoyo_path_info buf2;
+       struct tomoyo_request_info r;
        int idx;
 
-       if (!mode || !path1->mnt || !path2->mnt)
+       if (!path1->mnt || !path2->mnt ||
+           tomoyo_init_request_info(&r, NULL, tomoyo_pp2mac[operation])
+           == TOMOYO_CONFIG_DISABLED)
                return 0;
+       buf1.name = NULL;
+       buf2.name = NULL;
        idx = tomoyo_read_lock();
-       buf1 = tomoyo_get_path(path1);
-       buf2 = tomoyo_get_path(path2);
-       if (!buf1 || !buf2)
-               goto out;
-       {
-               struct dentry *dentry = path1->dentry;
-               if (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)) {
-                       /*
-                        * tomoyo_get_path() reserves space for appending "/."
-                        */
-                       if (!buf1->is_dir) {
-                               strcat((char *) buf1->name, "/");
-                               tomoyo_fill_path_info(buf1);
-                       }
-                       if (!buf2->is_dir) {
-                               strcat((char *) buf2->name, "/");
-                               tomoyo_fill_path_info(buf2);
-                       }
-               }
-       }
-       error = tomoyo_path2_acl(domain, operation, buf1, buf2);
-       msg = tomoyo_path22keyword(operation);
-       if (!error)
+       if (!tomoyo_get_realpath(&buf1, path1) ||
+           !tomoyo_get_realpath(&buf2, path2))
                goto out;
-       if (tomoyo_verbose_mode(domain))
-               printk(KERN_WARNING "TOMOYO-%s: Access '%s %s %s' "
-                      "denied for %s\n", tomoyo_get_msg(is_enforce),
-                      msg, buf1->name, buf2->name,
-                      tomoyo_get_last_name(domain));
-       if (mode == 1 && tomoyo_domain_quota_is_ok(domain)) {
-               const char *name1 = tomoyo_get_file_pattern(buf1)->name;
-               const char *name2 = tomoyo_get_file_pattern(buf2)->name;
-               tomoyo_update_path2_acl(operation, name1, name2, domain,
-                                       false);
-       }
+       switch (operation) {
+               struct dentry *dentry;
+       case TOMOYO_TYPE_RENAME:
+        case TOMOYO_TYPE_LINK:
+               dentry = path1->dentry;
+               if (!dentry->d_inode || !S_ISDIR(dentry->d_inode->i_mode))
+                        break;
+                /* fall through */
+        case TOMOYO_TYPE_PIVOT_ROOT:
+                tomoyo_add_slash(&buf1);
+                tomoyo_add_slash(&buf2);
+               break;
+        }
+       r.param_type = TOMOYO_TYPE_PATH2_ACL;
+       r.param.path2.operation = operation;
+       r.param.path2.filename1 = &buf1;
+       r.param.path2.filename2 = &buf2;
+       do {
+               tomoyo_check_acl(&r, tomoyo_check_path2_acl);
+               error = tomoyo_audit_path2_log(&r);
+       } while (error == TOMOYO_RETRY_REQUEST);
  out:
-       kfree(buf1);
-       kfree(buf2);
+       kfree(buf1.name);
+       kfree(buf2.name);
        tomoyo_read_unlock(idx);
-       if (!is_enforce)
+       if (r.mode != TOMOYO_CONFIG_ENFORCING)
                error = 0;
        return error;
 }
+
+/**
+ * tomoyo_write_file - Update file related list.
+ *
+ * @data:      String to parse.
+ * @domain:    Pointer to "struct tomoyo_domain_info".
+ * @is_delete: True if it is a delete request.
+ *
+ * Returns 0 on success, negative value otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+int tomoyo_write_file(char *data, struct tomoyo_domain_info *domain,
+                     const bool is_delete)
+{
+       char *w[5];
+       u8 type;
+       if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0])
+               return -EINVAL;
+       if (strncmp(w[0], "allow_", 6))
+               goto out;
+       w[0] += 6;
+       for (type = 0; type < TOMOYO_MAX_PATH_OPERATION; type++) {
+               if (strcmp(w[0], tomoyo_path_keyword[type]))
+                       continue;
+               return tomoyo_update_path_acl(type, w[1], domain, is_delete);
+       }
+       if (!w[2][0])
+               goto out;
+       for (type = 0; type < TOMOYO_MAX_PATH2_OPERATION; type++) {
+               if (strcmp(w[0], tomoyo_path2_keyword[type]))
+                       continue;
+               return tomoyo_update_path2_acl(type, w[1], w[2], domain,
+                                              is_delete);
+       }
+       for (type = 0; type < TOMOYO_MAX_PATH_NUMBER_OPERATION; type++) {
+               if (strcmp(w[0], tomoyo_path_number_keyword[type]))
+                       continue;
+               return tomoyo_update_path_number_acl(type, w[1], w[2], domain,
+                                                    is_delete);
+       }
+       if (!w[3][0] || !w[4][0])
+               goto out;
+       for (type = 0; type < TOMOYO_MAX_MKDEV_OPERATION; type++) {
+               if (strcmp(w[0], tomoyo_mkdev_keyword[type]))
+                       continue;
+               return tomoyo_update_mkdev_acl(type, w[1], w[2], w[3],
+                                              w[4], domain, is_delete);
+       }
+ out:
+       return -EINVAL;
+}
index b9cc71b04314b0b50b8f301cacb9b9ac432ad963..a877e4c3b1019d962da68ad792816d8e6aa28e1d 100644 (file)
 #include <linux/kthread.h>
 #include <linux/slab.h>
 
-enum tomoyo_gc_id {
-       TOMOYO_ID_PATH_GROUP,
-       TOMOYO_ID_PATH_GROUP_MEMBER,
-       TOMOYO_ID_DOMAIN_INITIALIZER,
-       TOMOYO_ID_DOMAIN_KEEPER,
-       TOMOYO_ID_ALIAS,
-       TOMOYO_ID_GLOBALLY_READABLE,
-       TOMOYO_ID_PATTERN,
-       TOMOYO_ID_NO_REWRITE,
-       TOMOYO_ID_MANAGER,
-       TOMOYO_ID_NAME,
-       TOMOYO_ID_ACL,
-       TOMOYO_ID_DOMAIN
-};
-
-struct tomoyo_gc_entry {
+struct tomoyo_gc {
        struct list_head list;
        int type;
-       void *element;
+       struct list_head *element;
 };
 static LIST_HEAD(tomoyo_gc_queue);
 static DEFINE_MUTEX(tomoyo_gc_mutex);
 
 /* Caller holds tomoyo_policy_lock mutex. */
-static bool tomoyo_add_to_gc(const int type, void *element)
+static bool tomoyo_add_to_gc(const int type, struct list_head *element)
 {
-       struct tomoyo_gc_entry *entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
+       struct tomoyo_gc *entry = kzalloc(sizeof(*entry), GFP_ATOMIC);
        if (!entry)
                return false;
        entry->type = type;
        entry->element = element;
        list_add(&entry->list, &tomoyo_gc_queue);
+       list_del_rcu(element);
        return true;
 }
 
-static void tomoyo_del_allow_read
-(struct tomoyo_globally_readable_file_entry *ptr)
+static void tomoyo_del_allow_read(struct list_head *element)
 {
+       struct tomoyo_readable_file *ptr =
+               container_of(element, typeof(*ptr), head.list);
        tomoyo_put_name(ptr->filename);
 }
 
-static void tomoyo_del_file_pattern(struct tomoyo_pattern_entry *ptr)
+static void tomoyo_del_file_pattern(struct list_head *element)
 {
+       struct tomoyo_no_pattern *ptr =
+               container_of(element, typeof(*ptr), head.list);
        tomoyo_put_name(ptr->pattern);
 }
 
-static void tomoyo_del_no_rewrite(struct tomoyo_no_rewrite_entry *ptr)
+static void tomoyo_del_no_rewrite(struct list_head *element)
 {
+       struct tomoyo_no_rewrite *ptr =
+               container_of(element, typeof(*ptr), head.list);
        tomoyo_put_name(ptr->pattern);
 }
 
-static void tomoyo_del_domain_initializer
-(struct tomoyo_domain_initializer_entry *ptr)
+static void tomoyo_del_transition_control(struct list_head *element)
 {
+       struct tomoyo_transition_control *ptr =
+               container_of(element, typeof(*ptr), head.list);
        tomoyo_put_name(ptr->domainname);
        tomoyo_put_name(ptr->program);
 }
 
-static void tomoyo_del_domain_keeper(struct tomoyo_domain_keeper_entry *ptr)
-{
-       tomoyo_put_name(ptr->domainname);
-       tomoyo_put_name(ptr->program);
-}
-
-static void tomoyo_del_alias(struct tomoyo_alias_entry *ptr)
+static void tomoyo_del_aggregator(struct list_head *element)
 {
+       struct tomoyo_aggregator *ptr =
+               container_of(element, typeof(*ptr), head.list);
        tomoyo_put_name(ptr->original_name);
-       tomoyo_put_name(ptr->aliased_name);
+       tomoyo_put_name(ptr->aggregated_name);
 }
 
-static void tomoyo_del_manager(struct tomoyo_policy_manager_entry *ptr)
+static void tomoyo_del_manager(struct list_head *element)
 {
+       struct tomoyo_manager *ptr =
+               container_of(element, typeof(*ptr), head.list);
        tomoyo_put_name(ptr->manager);
 }
 
-static void tomoyo_del_acl(struct tomoyo_acl_info *acl)
+static void tomoyo_del_acl(struct list_head *element)
 {
+       struct tomoyo_acl_info *acl =
+               container_of(element, typeof(*acl), list);
        switch (acl->type) {
        case TOMOYO_TYPE_PATH_ACL:
                {
@@ -104,14 +96,41 @@ static void tomoyo_del_acl(struct tomoyo_acl_info *acl)
                        tomoyo_put_name_union(&entry->name2);
                }
                break;
-       default:
-               printk(KERN_WARNING "Unknown type\n");
+       case TOMOYO_TYPE_PATH_NUMBER_ACL:
+               {
+                       struct tomoyo_path_number_acl *entry
+                               = container_of(acl, typeof(*entry), head);
+                       tomoyo_put_name_union(&entry->name);
+                       tomoyo_put_number_union(&entry->number);
+               }
+               break;
+       case TOMOYO_TYPE_MKDEV_ACL:
+               {
+                       struct tomoyo_mkdev_acl *entry
+                               = container_of(acl, typeof(*entry), head);
+                       tomoyo_put_name_union(&entry->name);
+                       tomoyo_put_number_union(&entry->mode);
+                       tomoyo_put_number_union(&entry->major);
+                       tomoyo_put_number_union(&entry->minor);
+               }
+               break;
+       case TOMOYO_TYPE_MOUNT_ACL:
+               {
+                       struct tomoyo_mount_acl *entry
+                               = container_of(acl, typeof(*entry), head);
+                       tomoyo_put_name_union(&entry->dev_name);
+                       tomoyo_put_name_union(&entry->dir_name);
+                       tomoyo_put_name_union(&entry->fs_type);
+                       tomoyo_put_number_union(&entry->flags);
+               }
                break;
        }
 }
 
-static bool tomoyo_del_domain(struct tomoyo_domain_info *domain)
+static bool tomoyo_del_domain(struct list_head *element)
 {
+       struct tomoyo_domain_info *domain =
+               container_of(element, typeof(*domain), list);
        struct tomoyo_acl_info *acl;
        struct tomoyo_acl_info *tmp;
        /*
@@ -139,7 +158,7 @@ static bool tomoyo_del_domain(struct tomoyo_domain_info *domain)
        if (atomic_read(&domain->users))
                return false;
        list_for_each_entry_safe(acl, tmp, &domain->acl_info_list, list) {
-               tomoyo_del_acl(acl);
+               tomoyo_del_acl(&acl->list);
                tomoyo_memory_free(acl);
        }
        tomoyo_put_name(domain->domainname);
@@ -147,135 +166,70 @@ static bool tomoyo_del_domain(struct tomoyo_domain_info *domain)
 }
 
 
-static void tomoyo_del_name(const struct tomoyo_name_entry *ptr)
+static void tomoyo_del_name(struct list_head *element)
 {
+       const struct tomoyo_name *ptr =
+               container_of(element, typeof(*ptr), list);
 }
 
-static void tomoyo_del_path_group_member(struct tomoyo_path_group_member
-                                        *member)
+static void tomoyo_del_path_group(struct list_head *element)
 {
+       struct tomoyo_path_group *member =
+               container_of(element, typeof(*member), head.list);
        tomoyo_put_name(member->member_name);
 }
 
-static void tomoyo_del_path_group(struct tomoyo_path_group *group)
+static void tomoyo_del_group(struct list_head *element)
 {
+       struct tomoyo_group *group =
+               container_of(element, typeof(*group), list);
        tomoyo_put_name(group->group_name);
 }
 
+static void tomoyo_del_number_group(struct list_head *element)
+{
+       struct tomoyo_number_group *member =
+               container_of(element, typeof(*member), head.list);
+}
+
+static bool tomoyo_collect_member(struct list_head *member_list, int id)
+{
+       struct tomoyo_acl_head *member;
+       list_for_each_entry(member, member_list, list) {
+               if (!member->is_deleted)
+                       continue;
+               if (!tomoyo_add_to_gc(id, &member->list))
+                       return false;
+       }
+        return true;
+}
+
+static bool tomoyo_collect_acl(struct tomoyo_domain_info *domain)
+{
+       struct tomoyo_acl_info *acl;
+       list_for_each_entry(acl, &domain->acl_info_list, list) {
+               if (!acl->is_deleted)
+                       continue;
+               if (!tomoyo_add_to_gc(TOMOYO_ID_ACL, &acl->list))
+                       return false;
+       }
+       return true;
+}
+
 static void tomoyo_collect_entry(void)
 {
+       int i;
        if (mutex_lock_interruptible(&tomoyo_policy_lock))
                return;
-       {
-               struct tomoyo_globally_readable_file_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_globally_readable_list,
-                                       list) {
-                       if (!ptr->is_deleted)
-                               continue;
-                       if (tomoyo_add_to_gc(TOMOYO_ID_GLOBALLY_READABLE, ptr))
-                               list_del_rcu(&ptr->list);
-                       else
-                               break;
-               }
-       }
-       {
-               struct tomoyo_pattern_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_pattern_list, list) {
-                       if (!ptr->is_deleted)
-                               continue;
-                       if (tomoyo_add_to_gc(TOMOYO_ID_PATTERN, ptr))
-                               list_del_rcu(&ptr->list);
-                       else
-                               break;
-               }
-       }
-       {
-               struct tomoyo_no_rewrite_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_no_rewrite_list, list) {
-                       if (!ptr->is_deleted)
-                               continue;
-                       if (tomoyo_add_to_gc(TOMOYO_ID_NO_REWRITE, ptr))
-                               list_del_rcu(&ptr->list);
-                       else
-                               break;
-               }
-       }
-       {
-               struct tomoyo_domain_initializer_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_domain_initializer_list,
-                                       list) {
-                       if (!ptr->is_deleted)
-                               continue;
-                       if (tomoyo_add_to_gc(TOMOYO_ID_DOMAIN_INITIALIZER, ptr))
-                               list_del_rcu(&ptr->list);
-                       else
-                               break;
-               }
-       }
-       {
-               struct tomoyo_domain_keeper_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_domain_keeper_list, list) {
-                       if (!ptr->is_deleted)
-                               continue;
-                       if (tomoyo_add_to_gc(TOMOYO_ID_DOMAIN_KEEPER, ptr))
-                               list_del_rcu(&ptr->list);
-                       else
-                               break;
-               }
-       }
-       {
-               struct tomoyo_alias_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_alias_list, list) {
-                       if (!ptr->is_deleted)
-                               continue;
-                       if (tomoyo_add_to_gc(TOMOYO_ID_ALIAS, ptr))
-                               list_del_rcu(&ptr->list);
-                       else
-                               break;
-               }
-       }
-       {
-               struct tomoyo_policy_manager_entry *ptr;
-               list_for_each_entry_rcu(ptr, &tomoyo_policy_manager_list,
-                                       list) {
-                       if (!ptr->is_deleted)
-                               continue;
-                       if (tomoyo_add_to_gc(TOMOYO_ID_MANAGER, ptr))
-                               list_del_rcu(&ptr->list);
-                       else
-                               break;
-               }
+       for (i = 0; i < TOMOYO_MAX_POLICY; i++) {
+               if (!tomoyo_collect_member(&tomoyo_policy_list[i], i))
+                       goto unlock;
        }
        {
                struct tomoyo_domain_info *domain;
                list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
-                       struct tomoyo_acl_info *acl;
-                       list_for_each_entry_rcu(acl, &domain->acl_info_list,
-                                               list) {
-                               switch (acl->type) {
-                               case TOMOYO_TYPE_PATH_ACL:
-                                       if (container_of(acl,
-                                        struct tomoyo_path_acl,
-                                                        head)->perm ||
-                                           container_of(acl,
-                                        struct tomoyo_path_acl,
-                                                        head)->perm_high)
-                                               continue;
-                                       break;
-                               case TOMOYO_TYPE_PATH2_ACL:
-                                       if (container_of(acl,
-                                        struct tomoyo_path2_acl,
-                                                        head)->perm)
-                                               continue;
-                                       break;
-                               default:
-                                       continue;
-                               }
-                               if (tomoyo_add_to_gc(TOMOYO_ID_ACL, acl))
-                                       list_del_rcu(&acl->list);
-                               else
-                                       break;
-                       }
+                       if (!tomoyo_collect_acl(domain))
+                               goto unlock;
                        if (!domain->is_deleted || atomic_read(&domain->users))
                                continue;
                        /*
@@ -283,104 +237,92 @@ static void tomoyo_collect_entry(void)
                         * refer this domain after successful execve().
                         * We recheck domain->users after SRCU synchronization.
                         */
-                       if (tomoyo_add_to_gc(TOMOYO_ID_DOMAIN, domain))
-                               list_del_rcu(&domain->list);
-                       else
-                               break;
+                       if (!tomoyo_add_to_gc(TOMOYO_ID_DOMAIN, &domain->list))
+                               goto unlock;
                }
        }
-       {
-               int i;
-               for (i = 0; i < TOMOYO_MAX_HASH; i++) {
-                       struct tomoyo_name_entry *ptr;
-                       list_for_each_entry_rcu(ptr, &tomoyo_name_list[i],
-                                               list) {
-                               if (atomic_read(&ptr->users))
-                                       continue;
-                               if (tomoyo_add_to_gc(TOMOYO_ID_NAME, ptr))
-                                       list_del_rcu(&ptr->list);
-                               else {
-                                       i = TOMOYO_MAX_HASH;
-                                       break;
-                               }
-                       }
+       for (i = 0; i < TOMOYO_MAX_HASH; i++) {
+               struct tomoyo_name *ptr;
+               list_for_each_entry_rcu(ptr, &tomoyo_name_list[i], list) {
+                       if (atomic_read(&ptr->users))
+                               continue;
+                       if (!tomoyo_add_to_gc(TOMOYO_ID_NAME, &ptr->list))
+                               goto unlock;
                }
        }
-       {
-               struct tomoyo_path_group *group;
-               list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) {
-                       struct tomoyo_path_group_member *member;
-                       list_for_each_entry_rcu(member, &group->member_list,
-                                               list) {
-                               if (!member->is_deleted)
-                                       continue;
-                               if (tomoyo_add_to_gc(TOMOYO_ID_PATH_GROUP_MEMBER,
-                                                    member))
-                                       list_del_rcu(&member->list);
-                               else
-                                       break;
-                       }
+       for (i = 0; i < TOMOYO_MAX_GROUP; i++) {
+               struct list_head *list = &tomoyo_group_list[i];
+               int id;
+               struct tomoyo_group *group;
+               switch (i) {
+               case 0:
+                       id = TOMOYO_ID_PATH_GROUP;
+                       break;
+               default:
+                       id = TOMOYO_ID_NUMBER_GROUP;
+                       break;
+               }
+               list_for_each_entry(group, list, list) {
+                       if (!tomoyo_collect_member(&group->member_list, id))
+                               goto unlock;
                        if (!list_empty(&group->member_list) ||
                            atomic_read(&group->users))
                                continue;
-                       if (tomoyo_add_to_gc(TOMOYO_ID_PATH_GROUP, group))
-                               list_del_rcu(&group->list);
-                       else
-                               break;
+                       if (!tomoyo_add_to_gc(TOMOYO_ID_GROUP, &group->list))
+                               goto unlock;
                }
        }
+ unlock:
        mutex_unlock(&tomoyo_policy_lock);
 }
 
 static void tomoyo_kfree_entry(void)
 {
-       struct tomoyo_gc_entry *p;
-       struct tomoyo_gc_entry *tmp;
+       struct tomoyo_gc *p;
+       struct tomoyo_gc *tmp;
 
        list_for_each_entry_safe(p, tmp, &tomoyo_gc_queue, list) {
+               struct list_head *element = p->element;
                switch (p->type) {
-               case TOMOYO_ID_DOMAIN_INITIALIZER:
-                       tomoyo_del_domain_initializer(p->element);
-                       break;
-               case TOMOYO_ID_DOMAIN_KEEPER:
-                       tomoyo_del_domain_keeper(p->element);
+               case TOMOYO_ID_TRANSITION_CONTROL:
+                       tomoyo_del_transition_control(element);
                        break;
-               case TOMOYO_ID_ALIAS:
-                       tomoyo_del_alias(p->element);
+               case TOMOYO_ID_AGGREGATOR:
+                       tomoyo_del_aggregator(element);
                        break;
                case TOMOYO_ID_GLOBALLY_READABLE:
-                       tomoyo_del_allow_read(p->element);
+                       tomoyo_del_allow_read(element);
                        break;
                case TOMOYO_ID_PATTERN:
-                       tomoyo_del_file_pattern(p->element);
+                       tomoyo_del_file_pattern(element);
                        break;
                case TOMOYO_ID_NO_REWRITE:
-                       tomoyo_del_no_rewrite(p->element);
+                       tomoyo_del_no_rewrite(element);
                        break;
                case TOMOYO_ID_MANAGER:
-                       tomoyo_del_manager(p->element);
+                       tomoyo_del_manager(element);
                        break;
                case TOMOYO_ID_NAME:
-                       tomoyo_del_name(p->element);
+                       tomoyo_del_name(element);
                        break;
                case TOMOYO_ID_ACL:
-                       tomoyo_del_acl(p->element);
+                       tomoyo_del_acl(element);
                        break;
                case TOMOYO_ID_DOMAIN:
-                       if (!tomoyo_del_domain(p->element))
+                       if (!tomoyo_del_domain(element))
                                continue;
                        break;
-               case TOMOYO_ID_PATH_GROUP_MEMBER:
-                       tomoyo_del_path_group_member(p->element);
-                       break;
                case TOMOYO_ID_PATH_GROUP:
-                       tomoyo_del_path_group(p->element);
+                       tomoyo_del_path_group(element);
                        break;
-               default:
-                       printk(KERN_WARNING "Unknown type\n");
+               case TOMOYO_ID_GROUP:
+                       tomoyo_del_group(element);
+                       break;
+               case TOMOYO_ID_NUMBER_GROUP:
+                       tomoyo_del_number_group(element);
                        break;
                }
-               tomoyo_memory_free(p->element);
+               tomoyo_memory_free(element);
                list_del(&p->list);
                kfree(p);
        }
diff --git a/security/tomoyo/group.c b/security/tomoyo/group.c
new file mode 100644 (file)
index 0000000..e94352c
--- /dev/null
@@ -0,0 +1,130 @@
+/*
+ * security/tomoyo/group.c
+ *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
+ */
+
+#include <linux/slab.h>
+#include "common.h"
+
+static bool tomoyo_same_path_group(const struct tomoyo_acl_head *a,
+                               const struct tomoyo_acl_head *b)
+{
+       return container_of(a, struct tomoyo_path_group, head)->member_name ==
+               container_of(b, struct tomoyo_path_group, head)->member_name;
+}
+
+static bool tomoyo_same_number_group(const struct tomoyo_acl_head *a,
+                                 const struct tomoyo_acl_head *b)
+{
+       return !memcmp(&container_of(a, struct tomoyo_number_group, head)
+                      ->number,
+                      &container_of(b, struct tomoyo_number_group, head)
+                      ->number,
+                      sizeof(container_of(a, struct tomoyo_number_group, head)
+                             ->number));
+}
+
+/**
+ * tomoyo_write_group - Write "struct tomoyo_path_group"/"struct tomoyo_number_group" list.
+ *
+ * @data:      String to parse.
+ * @is_delete: True if it is a delete request.
+ * @type:      Type of this group.
+ *
+ * Returns 0 on success, negative value otherwise.
+ */
+int tomoyo_write_group(char *data, const bool is_delete, const u8 type)
+{
+       struct tomoyo_group *group;
+       struct list_head *member;
+       char *w[2];
+       int error = -EINVAL;
+       if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0])
+               return -EINVAL;
+       group = tomoyo_get_group(w[0], type);
+       if (!group)
+               return -ENOMEM;
+       member = &group->member_list;
+       if (type == TOMOYO_PATH_GROUP) {
+               struct tomoyo_path_group e = { };
+               e.member_name = tomoyo_get_name(w[1]);
+               if (!e.member_name) {
+                       error = -ENOMEM;
+                       goto out;
+               }
+               error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
+                                            member, tomoyo_same_path_group);
+               tomoyo_put_name(e.member_name);
+       } else if (type == TOMOYO_NUMBER_GROUP) {
+               struct tomoyo_number_group e = { };
+               if (w[1][0] == '@'
+                   || !tomoyo_parse_number_union(w[1], &e.number)
+                   || e.number.values[0] > e.number.values[1])
+                       goto out;
+               error = tomoyo_update_policy(&e.head, sizeof(e), is_delete,
+                                            member, tomoyo_same_number_group);
+               /*
+                * tomoyo_put_number_union() is not needed because
+                * w[1][0] != '@'.
+                */
+       }
+ out:
+       tomoyo_put_group(group);
+       return error;
+}
+
+/**
+ * tomoyo_path_matches_group - Check whether the given pathname matches members of the given pathname group.
+ *
+ * @pathname:        The name of pathname.
+ * @group:           Pointer to "struct tomoyo_path_group".
+ *
+ * Returns matched member's pathname if @pathname matches pathnames in @group,
+ * NULL otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+const struct tomoyo_path_info *
+tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
+                         const struct tomoyo_group *group)
+{
+       struct tomoyo_path_group *member;
+       list_for_each_entry_rcu(member, &group->member_list, head.list) {
+               if (member->head.is_deleted)
+                       continue;
+               if (!tomoyo_path_matches_pattern(pathname, member->member_name))
+                       continue;
+               return member->member_name;
+       }
+       return NULL;
+}
+
+/**
+ * tomoyo_number_matches_group - Check whether the given number matches members of the given number group.
+ *
+ * @min:   Min number.
+ * @max:   Max number.
+ * @group: Pointer to "struct tomoyo_number_group".
+ *
+ * Returns true if @min and @max partially overlaps @group, false otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+bool tomoyo_number_matches_group(const unsigned long min,
+                                const unsigned long max,
+                                const struct tomoyo_group *group)
+{
+       struct tomoyo_number_group *member;
+       bool matched = false;
+       list_for_each_entry_rcu(member, &group->member_list, head.list) {
+               if (member->head.is_deleted)
+                       continue;
+               if (min > member->number.values[1] ||
+                   max < member->number.values[0])
+                       continue;
+               matched = true;
+               break;
+       }
+       return matched;
+}
diff --git a/security/tomoyo/load_policy.c b/security/tomoyo/load_policy.c
new file mode 100644 (file)
index 0000000..bbada7c
--- /dev/null
@@ -0,0 +1,81 @@
+/*
+ * security/tomoyo/load_policy.c
+ *
+ * Policy loader launcher for TOMOYO.
+ *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
+ */
+
+#include "common.h"
+
+/* path to policy loader */
+static const char *tomoyo_loader = "/sbin/tomoyo-init";
+
+/**
+ * tomoyo_policy_loader_exists - Check whether /sbin/tomoyo-init exists.
+ *
+ * Returns true if /sbin/tomoyo-init exists, false otherwise.
+ */
+static bool tomoyo_policy_loader_exists(void)
+{
+       /*
+        * Don't activate MAC if the policy loader doesn't exist.
+        * If the initrd includes /sbin/init but real-root-dev has not
+        * mounted on / yet, activating MAC will block the system since
+        * policies are not loaded yet.
+        * Thus, let do_execve() call this function everytime.
+        */
+       struct path path;
+
+       if (kern_path(tomoyo_loader, LOOKUP_FOLLOW, &path)) {
+               printk(KERN_INFO "Not activating Mandatory Access Control now "
+                      "since %s doesn't exist.\n", tomoyo_loader);
+               return false;
+       }
+       path_put(&path);
+       return true;
+}
+
+/**
+ * tomoyo_load_policy - Run external policy loader to load policy.
+ *
+ * @filename: The program about to start.
+ *
+ * This function checks whether @filename is /sbin/init , and if so
+ * invoke /sbin/tomoyo-init and wait for the termination of /sbin/tomoyo-init
+ * and then continues invocation of /sbin/init.
+ * /sbin/tomoyo-init reads policy files in /etc/tomoyo/ directory and
+ * writes to /sys/kernel/security/tomoyo/ interfaces.
+ *
+ * Returns nothing.
+ */
+void tomoyo_load_policy(const char *filename)
+{
+       char *argv[2];
+       char *envp[3];
+
+       if (tomoyo_policy_loaded)
+               return;
+       /*
+        * Check filename is /sbin/init or /sbin/tomoyo-start.
+        * /sbin/tomoyo-start is a dummy filename in case where /sbin/init can't
+        * be passed.
+        * You can create /sbin/tomoyo-start by
+        * "ln -s /bin/true /sbin/tomoyo-start".
+        */
+       if (strcmp(filename, "/sbin/init") &&
+           strcmp(filename, "/sbin/tomoyo-start"))
+               return;
+       if (!tomoyo_policy_loader_exists())
+               return;
+
+       printk(KERN_INFO "Calling %s to load policy. Please wait.\n",
+              tomoyo_loader);
+       argv[0] = (char *) tomoyo_loader;
+       argv[1] = NULL;
+       envp[0] = "HOME=/";
+       envp[1] = "PATH=/sbin:/bin:/usr/sbin:/usr/bin";
+       envp[2] = NULL;
+       call_usermodehelper(argv[0], argv, envp, 1);
+       tomoyo_check_profile();
+}
diff --git a/security/tomoyo/memory.c b/security/tomoyo/memory.c
new file mode 100644 (file)
index 0000000..2976126
--- /dev/null
@@ -0,0 +1,282 @@
+/*
+ * security/tomoyo/memory.c
+ *
+ * Memory management functions for TOMOYO.
+ *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
+ */
+
+#include <linux/hash.h>
+#include <linux/slab.h>
+#include "common.h"
+
+/**
+ * tomoyo_warn_oom - Print out of memory warning message.
+ *
+ * @function: Function's name.
+ */
+void tomoyo_warn_oom(const char *function)
+{
+       /* Reduce error messages. */
+       static pid_t tomoyo_last_pid;
+       const pid_t pid = current->pid;
+       if (tomoyo_last_pid != pid) {
+               printk(KERN_WARNING "ERROR: Out of memory at %s.\n",
+                      function);
+               tomoyo_last_pid = pid;
+       }
+       if (!tomoyo_policy_loaded)
+               panic("MAC Initialization failed.\n");
+}
+
+/* Memory allocated for policy. */
+static atomic_t tomoyo_policy_memory_size;
+/* Quota for holding policy. */
+static unsigned int tomoyo_quota_for_policy;
+
+/**
+ * tomoyo_memory_ok - Check memory quota.
+ *
+ * @ptr: Pointer to allocated memory.
+ *
+ * Returns true on success, false otherwise.
+ *
+ * Returns true if @ptr is not NULL and quota not exceeded, false otherwise.
+ */
+bool tomoyo_memory_ok(void *ptr)
+{
+       size_t s = ptr ? ksize(ptr) : 0;
+       atomic_add(s, &tomoyo_policy_memory_size);
+       if (ptr && (!tomoyo_quota_for_policy ||
+                   atomic_read(&tomoyo_policy_memory_size)
+                   <= tomoyo_quota_for_policy)) {
+               memset(ptr, 0, s);
+               return true;
+       }
+       atomic_sub(s, &tomoyo_policy_memory_size);
+       tomoyo_warn_oom(__func__);
+       return false;
+}
+
+/**
+ * tomoyo_commit_ok - Check memory quota.
+ *
+ * @data:   Data to copy from.
+ * @size:   Size in byte.
+ *
+ * Returns pointer to allocated memory on success, NULL otherwise.
+ * @data is zero-cleared on success.
+ */
+void *tomoyo_commit_ok(void *data, const unsigned int size)
+{
+       void *ptr = kzalloc(size, GFP_NOFS);
+       if (tomoyo_memory_ok(ptr)) {
+               memmove(ptr, data, size);
+               memset(data, 0, size);
+               return ptr;
+       }
+       return NULL;
+}
+
+/**
+ * tomoyo_memory_free - Free memory for elements.
+ *
+ * @ptr:  Pointer to allocated memory.
+ */
+void tomoyo_memory_free(void *ptr)
+{
+       atomic_sub(ksize(ptr), &tomoyo_policy_memory_size);
+       kfree(ptr);
+}
+
+/**
+ * tomoyo_get_group - Allocate memory for "struct tomoyo_path_group"/"struct tomoyo_number_group".
+ *
+ * @group_name: The name of address group.
+ * @idx:        Index number.
+ *
+ * Returns pointer to "struct tomoyo_group" on success, NULL otherwise.
+ */
+struct tomoyo_group *tomoyo_get_group(const char *group_name, const u8 idx)
+{
+       struct tomoyo_group e = { };
+       struct tomoyo_group *group = NULL;
+       bool found = false;
+       if (!tomoyo_correct_word(group_name) || idx >= TOMOYO_MAX_GROUP)
+               return NULL;
+       e.group_name = tomoyo_get_name(group_name);
+       if (!e.group_name)
+               return NULL;
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               goto out;
+       list_for_each_entry(group, &tomoyo_group_list[idx], list) {
+               if (e.group_name != group->group_name)
+                       continue;
+               atomic_inc(&group->users);
+               found = true;
+               break;
+       }
+       if (!found) {
+               struct tomoyo_group *entry = tomoyo_commit_ok(&e, sizeof(e));
+               if (entry) {
+                       INIT_LIST_HEAD(&entry->member_list);
+                       atomic_set(&entry->users, 1);
+                       list_add_tail_rcu(&entry->list,
+                                         &tomoyo_group_list[idx]);
+                       group = entry;
+                       found = true;
+               }
+       }
+       mutex_unlock(&tomoyo_policy_lock);
+ out:
+       tomoyo_put_name(e.group_name);
+       return found ? group : NULL;
+}
+
+/*
+ * tomoyo_name_list is used for holding string data used by TOMOYO.
+ * Since same string data is likely used for multiple times (e.g.
+ * "/lib/libc-2.5.so"), TOMOYO shares string data in the form of
+ * "const struct tomoyo_path_info *".
+ */
+struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
+
+/**
+ * tomoyo_get_name - Allocate permanent memory for string data.
+ *
+ * @name: The string to store into the permernent memory.
+ *
+ * Returns pointer to "struct tomoyo_path_info" on success, NULL otherwise.
+ */
+const struct tomoyo_path_info *tomoyo_get_name(const char *name)
+{
+       struct tomoyo_name *ptr;
+       unsigned int hash;
+       int len;
+       int allocated_len;
+       struct list_head *head;
+
+       if (!name)
+               return NULL;
+       len = strlen(name) + 1;
+       hash = full_name_hash((const unsigned char *) name, len - 1);
+       head = &tomoyo_name_list[hash_long(hash, TOMOYO_HASH_BITS)];
+       if (mutex_lock_interruptible(&tomoyo_policy_lock))
+               return NULL;
+       list_for_each_entry(ptr, head, list) {
+               if (hash != ptr->entry.hash || strcmp(name, ptr->entry.name))
+                       continue;
+               atomic_inc(&ptr->users);
+               goto out;
+       }
+       ptr = kzalloc(sizeof(*ptr) + len, GFP_NOFS);
+       allocated_len = ptr ? ksize(ptr) : 0;
+       if (!ptr || (tomoyo_quota_for_policy &&
+                    atomic_read(&tomoyo_policy_memory_size) + allocated_len
+                    > tomoyo_quota_for_policy)) {
+               kfree(ptr);
+               ptr = NULL;
+               tomoyo_warn_oom(__func__);
+               goto out;
+       }
+       atomic_add(allocated_len, &tomoyo_policy_memory_size);
+       ptr->entry.name = ((char *) ptr) + sizeof(*ptr);
+       memmove((char *) ptr->entry.name, name, len);
+       atomic_set(&ptr->users, 1);
+       tomoyo_fill_path_info(&ptr->entry);
+       list_add_tail(&ptr->list, head);
+ out:
+       mutex_unlock(&tomoyo_policy_lock);
+       return ptr ? &ptr->entry : NULL;
+}
+
+/**
+ * tomoyo_mm_init - Initialize mm related code.
+ */
+void __init tomoyo_mm_init(void)
+{
+       int idx;
+
+       for (idx = 0; idx < TOMOYO_MAX_POLICY; idx++)
+               INIT_LIST_HEAD(&tomoyo_policy_list[idx]);
+       for (idx = 0; idx < TOMOYO_MAX_GROUP; idx++)
+               INIT_LIST_HEAD(&tomoyo_group_list[idx]);
+       for (idx = 0; idx < TOMOYO_MAX_HASH; idx++)
+               INIT_LIST_HEAD(&tomoyo_name_list[idx]);
+       INIT_LIST_HEAD(&tomoyo_kernel_domain.acl_info_list);
+       tomoyo_kernel_domain.domainname = tomoyo_get_name(TOMOYO_ROOT_NAME);
+       list_add_tail_rcu(&tomoyo_kernel_domain.list, &tomoyo_domain_list);
+       idx = tomoyo_read_lock();
+       if (tomoyo_find_domain(TOMOYO_ROOT_NAME) != &tomoyo_kernel_domain)
+               panic("Can't register tomoyo_kernel_domain");
+       {
+               /* Load built-in policy. */
+               tomoyo_write_transition_control("/sbin/hotplug", false,
+                                       TOMOYO_TRANSITION_CONTROL_INITIALIZE);
+               tomoyo_write_transition_control("/sbin/modprobe", false,
+                                       TOMOYO_TRANSITION_CONTROL_INITIALIZE);
+       }
+       tomoyo_read_unlock(idx);
+}
+
+
+/* Memory allocated for query lists. */
+unsigned int tomoyo_query_memory_size;
+/* Quota for holding query lists. */
+unsigned int tomoyo_quota_for_query;
+
+/**
+ * tomoyo_read_memory_counter - Check for memory usage in bytes.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ *
+ * Returns memory usage.
+ */
+void tomoyo_read_memory_counter(struct tomoyo_io_buffer *head)
+{
+       if (!head->r.eof) {
+               const unsigned int policy
+                       = atomic_read(&tomoyo_policy_memory_size);
+               const unsigned int query = tomoyo_query_memory_size;
+               char buffer[64];
+
+               memset(buffer, 0, sizeof(buffer));
+               if (tomoyo_quota_for_policy)
+                       snprintf(buffer, sizeof(buffer) - 1,
+                                "   (Quota: %10u)",
+                                tomoyo_quota_for_policy);
+               else
+                       buffer[0] = '\0';
+               tomoyo_io_printf(head, "Policy:       %10u%s\n", policy,
+                                buffer);
+               if (tomoyo_quota_for_query)
+                       snprintf(buffer, sizeof(buffer) - 1,
+                                "   (Quota: %10u)",
+                                tomoyo_quota_for_query);
+               else
+                       buffer[0] = '\0';
+               tomoyo_io_printf(head, "Query lists:  %10u%s\n", query,
+                                buffer);
+               tomoyo_io_printf(head, "Total:        %10u\n", policy + query);
+               head->r.eof = true;
+       }
+}
+
+/**
+ * tomoyo_write_memory_quota - Set memory quota.
+ *
+ * @head: Pointer to "struct tomoyo_io_buffer".
+ *
+ * Returns 0.
+ */
+int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head)
+{
+       char *data = head->write_buf;
+       unsigned int size;
+
+       if (sscanf(data, "Policy: %u", &size) == 1)
+               tomoyo_quota_for_policy = size;
+       else if (sscanf(data, "Query lists: %u", &size) == 1)
+               tomoyo_quota_for_query = size;
+       return 0;
+}
diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
new file mode 100644 (file)
index 0000000..82bf8c2
--- /dev/null
@@ -0,0 +1,284 @@
+/*
+ * security/tomoyo/mount.c
+ *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
+ */
+
+#include <linux/slab.h>
+#include "common.h"
+
+/* Keywords for mount restrictions. */
+
+/* Allow to call 'mount --bind /source_dir /dest_dir' */
+#define TOMOYO_MOUNT_BIND_KEYWORD                        "--bind"
+/* Allow to call 'mount --move /old_dir    /new_dir ' */
+#define TOMOYO_MOUNT_MOVE_KEYWORD                        "--move"
+/* Allow to call 'mount -o remount /dir             ' */
+#define TOMOYO_MOUNT_REMOUNT_KEYWORD                     "--remount"
+/* Allow to call 'mount --make-unbindable /dir'       */
+#define TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD             "--make-unbindable"
+/* Allow to call 'mount --make-private /dir'          */
+#define TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD                "--make-private"
+/* Allow to call 'mount --make-slave /dir'            */
+#define TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD                  "--make-slave"
+/* Allow to call 'mount --make-shared /dir'           */
+#define TOMOYO_MOUNT_MAKE_SHARED_KEYWORD                 "--make-shared"
+
+/**
+ * tomoyo_audit_mount_log - Audit mount log.
+ *
+ * @r: Pointer to "struct tomoyo_request_info".
+ *
+ * Returns 0 on success, negative value otherwise.
+ */
+static int tomoyo_audit_mount_log(struct tomoyo_request_info *r)
+{
+       const char *dev = r->param.mount.dev->name;
+       const char *dir = r->param.mount.dir->name;
+       const char *type = r->param.mount.type->name;
+       const unsigned long flags = r->param.mount.flags;
+       if (r->granted)
+               return 0;
+       if (!strcmp(type, TOMOYO_MOUNT_REMOUNT_KEYWORD))
+               tomoyo_warn_log(r, "mount -o remount %s 0x%lX", dir, flags);
+       else if (!strcmp(type, TOMOYO_MOUNT_BIND_KEYWORD)
+                || !strcmp(type, TOMOYO_MOUNT_MOVE_KEYWORD))
+               tomoyo_warn_log(r, "mount %s %s %s 0x%lX", type, dev, dir,
+                               flags);
+       else if (!strcmp(type, TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD) ||
+                !strcmp(type, TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD) ||
+                !strcmp(type, TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD) ||
+                !strcmp(type, TOMOYO_MOUNT_MAKE_SHARED_KEYWORD))
+               tomoyo_warn_log(r, "mount %s %s 0x%lX", type, dir, flags);
+       else
+               tomoyo_warn_log(r, "mount -t %s %s %s 0x%lX", type, dev, dir,
+                               flags);
+       return tomoyo_supervisor(r,
+                                TOMOYO_KEYWORD_ALLOW_MOUNT "%s %s %s 0x%lX\n",
+                                tomoyo_pattern(r->param.mount.dev),
+                                tomoyo_pattern(r->param.mount.dir), type,
+                                flags);
+}
+
+static bool tomoyo_check_mount_acl(struct tomoyo_request_info *r,
+                                  const struct tomoyo_acl_info *ptr)
+{
+       const struct tomoyo_mount_acl *acl =
+               container_of(ptr, typeof(*acl), head);
+       return tomoyo_compare_number_union(r->param.mount.flags, &acl->flags) &&
+               tomoyo_compare_name_union(r->param.mount.type, &acl->fs_type) &&
+               tomoyo_compare_name_union(r->param.mount.dir, &acl->dir_name) &&
+               (!r->param.mount.need_dev ||
+                tomoyo_compare_name_union(r->param.mount.dev, &acl->dev_name));
+}
+
+/**
+ * tomoyo_mount_acl - Check permission for mount() operation.
+ *
+ * @r:        Pointer to "struct tomoyo_request_info".
+ * @dev_name: Name of device file.
+ * @dir:      Pointer to "struct path".
+ * @type:     Name of filesystem type.
+ * @flags:    Mount options.
+ *
+ * Returns 0 on success, negative value otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+static int tomoyo_mount_acl(struct tomoyo_request_info *r, char *dev_name,
+                           struct path *dir, char *type, unsigned long flags)
+{
+       struct path path;
+       struct file_system_type *fstype = NULL;
+       const char *requested_type = NULL;
+       const char *requested_dir_name = NULL;
+       const char *requested_dev_name = NULL;
+       struct tomoyo_path_info rtype;
+       struct tomoyo_path_info rdev;
+       struct tomoyo_path_info rdir;
+       int need_dev = 0;
+       int error = -ENOMEM;
+
+       /* Get fstype. */
+       requested_type = tomoyo_encode(type);
+       if (!requested_type)
+               goto out;
+       rtype.name = requested_type;
+       tomoyo_fill_path_info(&rtype);
+
+       /* Get mount point. */
+       requested_dir_name = tomoyo_realpath_from_path(dir);
+       if (!requested_dir_name) {
+               error = -ENOMEM;
+               goto out;
+       }
+       rdir.name = requested_dir_name;
+       tomoyo_fill_path_info(&rdir);
+
+       /* Compare fs name. */
+       if (!strcmp(type, TOMOYO_MOUNT_REMOUNT_KEYWORD)) {
+               /* dev_name is ignored. */
+       } else if (!strcmp(type, TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD) ||
+                  !strcmp(type, TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD) ||
+                  !strcmp(type, TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD) ||
+                  !strcmp(type, TOMOYO_MOUNT_MAKE_SHARED_KEYWORD)) {
+               /* dev_name is ignored. */
+       } else if (!strcmp(type, TOMOYO_MOUNT_BIND_KEYWORD) ||
+                  !strcmp(type, TOMOYO_MOUNT_MOVE_KEYWORD)) {
+               need_dev = -1; /* dev_name is a directory */
+       } else {
+               fstype = get_fs_type(type);
+               if (!fstype) {
+                       error = -ENODEV;
+                       goto out;
+               }
+               if (fstype->fs_flags & FS_REQUIRES_DEV)
+                       /* dev_name is a block device file. */
+                       need_dev = 1;
+       }
+       if (need_dev) {
+               /* Get mount point or device file. */
+               if (kern_path(dev_name, LOOKUP_FOLLOW, &path)) {
+                       error = -ENOENT;
+                       goto out;
+               }
+               requested_dev_name = tomoyo_realpath_from_path(&path);
+               if (!requested_dev_name) {
+                       error = -ENOENT;
+                       goto out;
+               }
+       } else {
+               /* Map dev_name to "<NULL>" if no dev_name given. */
+               if (!dev_name)
+                       dev_name = "<NULL>";
+               requested_dev_name = tomoyo_encode(dev_name);
+               if (!requested_dev_name) {
+                       error = -ENOMEM;
+                       goto out;
+               }
+       }
+       rdev.name = requested_dev_name;
+       tomoyo_fill_path_info(&rdev);
+       r->param_type = TOMOYO_TYPE_MOUNT_ACL;
+       r->param.mount.need_dev = need_dev;
+       r->param.mount.dev = &rdev;
+       r->param.mount.dir = &rdir;
+       r->param.mount.type = &rtype;
+       r->param.mount.flags = flags;
+       do {
+               tomoyo_check_acl(r, tomoyo_check_mount_acl);
+               error = tomoyo_audit_mount_log(r);
+       } while (error == TOMOYO_RETRY_REQUEST);
+ out:
+       kfree(requested_dev_name);
+       kfree(requested_dir_name);
+       if (fstype)
+               put_filesystem(fstype);
+       kfree(requested_type);
+       return error;
+}
+
+/**
+ * tomoyo_mount_permission - Check permission for mount() operation.
+ *
+ * @dev_name:  Name of device file.
+ * @path:      Pointer to "struct path".
+ * @type:      Name of filesystem type. May be NULL.
+ * @flags:     Mount options.
+ * @data_page: Optional data. May be NULL.
+ *
+ * Returns 0 on success, negative value otherwise.
+ */
+int tomoyo_mount_permission(char *dev_name, struct path *path, char *type,
+                           unsigned long flags, void *data_page)
+{
+       struct tomoyo_request_info r;
+       int error;
+       int idx;
+
+       if (tomoyo_init_request_info(&r, NULL, TOMOYO_MAC_FILE_MOUNT)
+           == TOMOYO_CONFIG_DISABLED)
+               return 0;
+       if ((flags & MS_MGC_MSK) == MS_MGC_VAL)
+               flags &= ~MS_MGC_MSK;
+       if (flags & MS_REMOUNT) {
+               type = TOMOYO_MOUNT_REMOUNT_KEYWORD;
+               flags &= ~MS_REMOUNT;
+       }
+       if (flags & MS_MOVE) {
+               type = TOMOYO_MOUNT_MOVE_KEYWORD;
+               flags &= ~MS_MOVE;
+       }
+       if (flags & MS_BIND) {
+               type = TOMOYO_MOUNT_BIND_KEYWORD;
+               flags &= ~MS_BIND;
+       }
+       if (flags & MS_UNBINDABLE) {
+               type = TOMOYO_MOUNT_MAKE_UNBINDABLE_KEYWORD;
+               flags &= ~MS_UNBINDABLE;
+       }
+       if (flags & MS_PRIVATE) {
+               type = TOMOYO_MOUNT_MAKE_PRIVATE_KEYWORD;
+               flags &= ~MS_PRIVATE;
+       }
+       if (flags & MS_SLAVE) {
+               type = TOMOYO_MOUNT_MAKE_SLAVE_KEYWORD;
+               flags &= ~MS_SLAVE;
+       }
+       if (flags & MS_SHARED) {
+               type = TOMOYO_MOUNT_MAKE_SHARED_KEYWORD;
+               flags &= ~MS_SHARED;
+       }
+       if (!type)
+               type = "<NULL>";
+       idx = tomoyo_read_lock();
+       error = tomoyo_mount_acl(&r, dev_name, path, type, flags);
+       tomoyo_read_unlock(idx);
+       return error;
+}
+
+static bool tomoyo_same_mount_acl(const struct tomoyo_acl_info *a,
+                                 const struct tomoyo_acl_info *b)
+{
+       const struct tomoyo_mount_acl *p1 = container_of(a, typeof(*p1), head);
+       const struct tomoyo_mount_acl *p2 = container_of(b, typeof(*p2), head);
+       return tomoyo_same_acl_head(&p1->head, &p2->head) &&
+               tomoyo_same_name_union(&p1->dev_name, &p2->dev_name) &&
+               tomoyo_same_name_union(&p1->dir_name, &p2->dir_name) &&
+               tomoyo_same_name_union(&p1->fs_type, &p2->fs_type) &&
+               tomoyo_same_number_union(&p1->flags, &p2->flags);
+}
+
+/**
+ * tomoyo_write_mount - Write "struct tomoyo_mount_acl" list.
+ *
+ * @data:      String to parse.
+ * @domain:    Pointer to "struct tomoyo_domain_info".
+ * @is_delete: True if it is a delete request.
+ *
+ * Returns 0 on success, negative value otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+int tomoyo_write_mount(char *data, struct tomoyo_domain_info *domain,
+                      const bool is_delete)
+{
+       struct tomoyo_mount_acl e = { .head.type = TOMOYO_TYPE_MOUNT_ACL };
+       int error = is_delete ? -ENOENT : -ENOMEM;
+       char *w[4];
+       if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[3][0])
+               return -EINVAL;
+       if (!tomoyo_parse_name_union(w[0], &e.dev_name) ||
+           !tomoyo_parse_name_union(w[1], &e.dir_name) ||
+           !tomoyo_parse_name_union(w[2], &e.fs_type) ||
+           !tomoyo_parse_number_union(w[3], &e.flags))
+               goto out;
+       error = tomoyo_update_domain(&e.head, sizeof(e), is_delete, domain,
+                                    tomoyo_same_mount_acl, NULL);
+ out:
+       tomoyo_put_name_union(&e.dev_name);
+       tomoyo_put_name_union(&e.dir_name);
+       tomoyo_put_name_union(&e.fs_type);
+       tomoyo_put_number_union(&e.flags);
+       return error;
+}
diff --git a/security/tomoyo/path_group.c b/security/tomoyo/path_group.c
deleted file mode 100644 (file)
index c988041..0000000
+++ /dev/null
@@ -1,172 +0,0 @@
-/*
- * security/tomoyo/path_group.c
- *
- * Copyright (C) 2005-2009  NTT DATA CORPORATION
- */
-
-#include <linux/slab.h>
-#include "common.h"
-/* The list for "struct ccs_path_group". */
-LIST_HEAD(tomoyo_path_group_list);
-
-/**
- * tomoyo_get_path_group - Allocate memory for "struct tomoyo_path_group".
- *
- * @group_name: The name of pathname group.
- *
- * Returns pointer to "struct tomoyo_path_group" on success, NULL otherwise.
- */
-struct tomoyo_path_group *tomoyo_get_path_group(const char *group_name)
-{
-       struct tomoyo_path_group *entry = NULL;
-       struct tomoyo_path_group *group = NULL;
-       const struct tomoyo_path_info *saved_group_name;
-       int error = -ENOMEM;
-       if (!tomoyo_is_correct_path(group_name, 0, 0, 0) ||
-           !group_name[0])
-               return NULL;
-       saved_group_name = tomoyo_get_name(group_name);
-       if (!saved_group_name)
-               return NULL;
-       entry = kzalloc(sizeof(*entry), GFP_NOFS);
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(group, &tomoyo_path_group_list, list) {
-               if (saved_group_name != group->group_name)
-                       continue;
-               atomic_inc(&group->users);
-               error = 0;
-               break;
-       }
-       if (error && tomoyo_memory_ok(entry)) {
-               INIT_LIST_HEAD(&entry->member_list);
-               entry->group_name = saved_group_name;
-               saved_group_name = NULL;
-               atomic_set(&entry->users, 1);
-               list_add_tail_rcu(&entry->list, &tomoyo_path_group_list);
-               group = entry;
-               entry = NULL;
-               error = 0;
-       }
-       mutex_unlock(&tomoyo_policy_lock);
- out:
-       tomoyo_put_name(saved_group_name);
-       kfree(entry);
-       return !error ? group : NULL;
-}
-
-/**
- * tomoyo_write_path_group_policy - Write "struct tomoyo_path_group" list.
- *
- * @data:      String to parse.
- * @is_delete: True if it is a delete request.
- *
- * Returns 0 on success, nagative value otherwise.
- */
-int tomoyo_write_path_group_policy(char *data, const bool is_delete)
-{
-       struct tomoyo_path_group *group;
-       struct tomoyo_path_group_member *member;
-       struct tomoyo_path_group_member e = { };
-       int error = is_delete ? -ENOENT : -ENOMEM;
-       char *w[2];
-       if (!tomoyo_tokenize(data, w, sizeof(w)) || !w[1][0])
-               return -EINVAL;
-       group = tomoyo_get_path_group(w[0]);
-       if (!group)
-               return -ENOMEM;
-       e.member_name = tomoyo_get_name(w[1]);
-       if (!e.member_name)
-               goto out;
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               goto out;
-       list_for_each_entry_rcu(member, &group->member_list, list) {
-               if (member->member_name != e.member_name)
-                       continue;
-               member->is_deleted = is_delete;
-               error = 0;
-               break;
-       }
-       if (!is_delete && error) {
-               struct tomoyo_path_group_member *entry =
-                       tomoyo_commit_ok(&e, sizeof(e));
-               if (entry) {
-                       list_add_tail_rcu(&entry->list, &group->member_list);
-                       error = 0;
-               }
-       }
-       mutex_unlock(&tomoyo_policy_lock);
- out:
-       tomoyo_put_name(e.member_name);
-       tomoyo_put_path_group(group);
-       return error;
-}
-
-/**
- * tomoyo_read_path_group_policy - Read "struct tomoyo_path_group" list.
- *
- * @head: Pointer to "struct tomoyo_io_buffer".
- *
- * Returns true on success, false otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-bool tomoyo_read_path_group_policy(struct tomoyo_io_buffer *head)
-{
-       struct list_head *gpos;
-       struct list_head *mpos;
-       list_for_each_cookie(gpos, head->read_var1, &tomoyo_path_group_list) {
-               struct tomoyo_path_group *group;
-               group = list_entry(gpos, struct tomoyo_path_group, list);
-               list_for_each_cookie(mpos, head->read_var2,
-                                    &group->member_list) {
-                       struct tomoyo_path_group_member *member;
-                       member = list_entry(mpos,
-                                           struct tomoyo_path_group_member,
-                                           list);
-                       if (member->is_deleted)
-                               continue;
-                       if (!tomoyo_io_printf(head, TOMOYO_KEYWORD_PATH_GROUP
-                                             "%s %s\n",
-                                             group->group_name->name,
-                                             member->member_name->name))
-                               return false;
-               }
-       }
-       return true;
-}
-
-/**
- * tomoyo_path_matches_group - Check whether the given pathname matches members of the given pathname group.
- *
- * @pathname:        The name of pathname.
- * @group:           Pointer to "struct tomoyo_path_group".
- * @may_use_pattern: True if wild card is permitted.
- *
- * Returns true if @pathname matches pathnames in @group, false otherwise.
- *
- * Caller holds tomoyo_read_lock().
- */
-bool tomoyo_path_matches_group(const struct tomoyo_path_info *pathname,
-                              const struct tomoyo_path_group *group,
-                              const bool may_use_pattern)
-{
-       struct tomoyo_path_group_member *member;
-       bool matched = false;
-       list_for_each_entry_rcu(member, &group->member_list, list) {
-               if (member->is_deleted)
-                       continue;
-               if (!member->member_name->is_patterned) {
-                       if (tomoyo_pathcmp(pathname, member->member_name))
-                               continue;
-               } else if (may_use_pattern) {
-                       if (!tomoyo_path_matches_pattern(pathname,
-                                                        member->member_name))
-                               continue;
-               } else
-                       continue;
-               matched = true;
-               break;
-       }
-       return matched;
-}
index d1b96f0196216cb23f9da450ac75413b6ffd69c6..ed8ccd680102b53d98f9b98cb9a3aa05c8143090 100644 (file)
 /*
  * security/tomoyo/realpath.c
  *
- * Get the canonicalized absolute pathnames. The basis for TOMOYO.
- *
- * Copyright (C) 2005-2009  NTT DATA CORPORATION
- *
- * Version: 2.2.0   2009/04/01
+ * Pathname calculation functions for TOMOYO.
  *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
  */
 
 #include <linux/types.h>
 #include <linux/mount.h>
 #include <linux/mnt_namespace.h>
 #include <linux/fs_struct.h>
-#include <linux/hash.h>
 #include <linux/magic.h>
 #include <linux/slab.h>
+#include <net/sock.h>
 #include "common.h"
 
 /**
  * tomoyo_encode: Convert binary string to ascii string.
  *
- * @buffer:  Buffer for ASCII string.
- * @buflen:  Size of @buffer.
- * @str:     Binary string.
+ * @str: String in binary format.
+ *
+ * Returns pointer to @str in ascii format on success, NULL otherwise.
  *
- * Returns 0 on success, -ENOMEM otherwise.
+ * This function uses kzalloc(), so caller must kfree() if this function
+ * didn't return NULL.
  */
-int tomoyo_encode(char *buffer, int buflen, const char *str)
+char *tomoyo_encode(const char *str)
 {
-       while (1) {
-               const unsigned char c = *(unsigned char *) str++;
+       int len = 0;
+       const char *p = str;
+       char *cp;
+       char *cp0;
 
-               if (tomoyo_is_valid(c)) {
-                       if (--buflen <= 0)
-                               break;
-                       *buffer++ = (char) c;
-                       if (c != '\\')
-                               continue;
-                       if (--buflen <= 0)
-                               break;
-                       *buffer++ = (char) c;
-                       continue;
-               }
-               if (!c) {
-                       if (--buflen <= 0)
-                               break;
-                       *buffer = '\0';
-                       return 0;
+       if (!p)
+               return NULL;
+       while (*p) {
+               const unsigned char c = *p++;
+               if (c == '\\')
+                       len += 2;
+               else if (c > ' ' && c < 127)
+                       len++;
+               else
+                       len += 4;
+       }
+       len++;
+       /* Reserve space for appending "/". */
+       cp = kzalloc(len + 10, GFP_NOFS);
+       if (!cp)
+               return NULL;
+       cp0 = cp;
+       p = str;
+       while (*p) {
+               const unsigned char c = *p++;
+
+               if (c == '\\') {
+                       *cp++ = '\\';
+                       *cp++ = '\\';
+               } else if (c > ' ' && c < 127) {
+                       *cp++ = c;
+               } else {
+                       *cp++ = '\\';
+                       *cp++ = (c >> 6) + '0';
+                       *cp++ = ((c >> 3) & 7) + '0';
+                       *cp++ = (c & 7) + '0';
                }
-               buflen -= 4;
-               if (buflen <= 0)
-                       break;
-               *buffer++ = '\\';
-               *buffer++ = (c >> 6) + '0';
-               *buffer++ = ((c >> 3) & 7) + '0';
-               *buffer++ = (c & 7) + '0';
        }
-       return -ENOMEM;
+       return cp0;
 }
 
 /**
- * tomoyo_realpath_from_path2 - Returns realpath(3) of the given dentry but ignores chroot'ed root.
+ * tomoyo_realpath_from_path - Returns realpath(3) of the given pathname but ignores chroot'ed root.
  *
- * @path:        Pointer to "struct path".
- * @newname:     Pointer to buffer to return value in.
- * @newname_len: Size of @newname.
+ * @path: Pointer to "struct path".
  *
- * Returns 0 on success, negative value otherwise.
+ * Returns the realpath of the given @path on success, NULL otherwise.
  *
  * If dentry is a directory, trailing '/' is appended.
  * Characters out of 0x20 < c < 0x7F range are converted to
  * \ooo style octal string.
  * Character \ is converted to \\ string.
+ *
+ * These functions use kzalloc(), so the caller must call kfree()
+ * if these functions didn't return NULL.
  */
-int tomoyo_realpath_from_path2(struct path *path, char *newname,
-                              int newname_len)
+char *tomoyo_realpath_from_path(struct path *path)
 {
-       int error = -ENOMEM;
+       char *buf = NULL;
+       char *name = NULL;
+       unsigned int buf_len = PAGE_SIZE / 2;
        struct dentry *dentry = path->dentry;
-       char *sp;
-
-       if (!dentry || !path->mnt || !newname || newname_len <= 2048)
-               return -EINVAL;
-       if (dentry->d_op && dentry->d_op->d_dname) {
+       bool is_dir;
+       if (!dentry)
+               return NULL;
+       is_dir = dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode);
+       while (1) {
+               struct path ns_root = { .mnt = NULL, .dentry = NULL };
+               char *pos;
+               buf_len <<= 1;
+               kfree(buf);
+               buf = kmalloc(buf_len, GFP_NOFS);
+               if (!buf)
+                       break;
+               /* Get better name for socket. */
+               if (dentry->d_sb && dentry->d_sb->s_magic == SOCKFS_MAGIC) {
+                       struct inode *inode = dentry->d_inode;
+                       struct socket *sock = inode ? SOCKET_I(inode) : NULL;
+                       struct sock *sk = sock ? sock->sk : NULL;
+                       if (sk) {
+                               snprintf(buf, buf_len - 1, "socket:[family=%u:"
+                                        "type=%u:protocol=%u]", sk->sk_family,
+                                        sk->sk_type, sk->sk_protocol);
+                       } else {
+                               snprintf(buf, buf_len - 1, "socket:[unknown]");
+                       }
+                       name = tomoyo_encode(buf);
+                       break;
+               }
                /* For "socket:[\$]" and "pipe:[\$]". */
-               static const int offset = 1536;
-               sp = dentry->d_op->d_dname(dentry, newname + offset,
-                                          newname_len - offset);
-       } else {
-               struct path ns_root = {.mnt = NULL, .dentry = NULL};
-
+               if (dentry->d_op && dentry->d_op->d_dname) {
+                       pos = dentry->d_op->d_dname(dentry, buf, buf_len - 1);
+                       if (IS_ERR(pos))
+                               continue;
+                       name = tomoyo_encode(pos);
+                       break;
+               }
+               /* If we don't have a vfsmount, we can't calculate. */
+               if (!path->mnt)
+                       break;
                spin_lock(&dcache_lock);
                /* go to whatever namespace root we are under */
-               sp = __d_path(path, &ns_root, newname, newname_len);
+               pos = __d_path(path, &ns_root, buf, buf_len);
                spin_unlock(&dcache_lock);
                /* Prepend "/proc" prefix if using internal proc vfs mount. */
-               if (!IS_ERR(sp) && (path->mnt->mnt_flags & MNT_INTERNAL) &&
+               if (!IS_ERR(pos) && (path->mnt->mnt_flags & MNT_INTERNAL) &&
                    (path->mnt->mnt_sb->s_magic == PROC_SUPER_MAGIC)) {
-                       sp -= 5;
-                       if (sp >= newname)
-                               memcpy(sp, "/proc", 5);
+                       pos -= 5;
+                       if (pos >= buf)
+                               memcpy(pos, "/proc", 5);
                        else
-                               sp = ERR_PTR(-ENOMEM);
-               }
-       }
-       if (IS_ERR(sp))
-               error = PTR_ERR(sp);
-       else
-               error = tomoyo_encode(newname, sp - newname, sp);
-       /* Append trailing '/' if dentry is a directory. */
-       if (!error && dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode)
-           && *newname) {
-               sp = newname + strlen(newname);
-               if (*(sp - 1) != '/') {
-                       if (sp < newname + newname_len - 4) {
-                               *sp++ = '/';
-                               *sp = '\0';
-                       } else {
-                               error = -ENOMEM;
-                       }
+                               pos = ERR_PTR(-ENOMEM);
                }
+               if (IS_ERR(pos))
+                       continue;
+               name = tomoyo_encode(pos);
+               break;
        }
-       if (error)
-               printk(KERN_WARNING "tomoyo_realpath: Pathname too long.\n");
-       return error;
-}
-
-/**
- * tomoyo_realpath_from_path - Returns realpath(3) of the given pathname but ignores chroot'ed root.
- *
- * @path: Pointer to "struct path".
- *
- * Returns the realpath of the given @path on success, NULL otherwise.
- *
- * These functions use kzalloc(), so the caller must call kfree()
- * if these functions didn't return NULL.
- */
-char *tomoyo_realpath_from_path(struct path *path)
-{
-       char *buf = kzalloc(sizeof(struct tomoyo_page_buffer), GFP_NOFS);
-
-       BUILD_BUG_ON(sizeof(struct tomoyo_page_buffer)
-                    <= TOMOYO_MAX_PATHNAME_LEN - 1);
-       if (!buf)
-               return NULL;
-       if (tomoyo_realpath_from_path2(path, buf,
-                                      TOMOYO_MAX_PATHNAME_LEN - 1) == 0)
-               return buf;
        kfree(buf);
-       return NULL;
-}
-
-/**
- * tomoyo_realpath - Get realpath of a pathname.
- *
- * @pathname: The pathname to solve.
- *
- * Returns the realpath of @pathname on success, NULL otherwise.
- */
-char *tomoyo_realpath(const char *pathname)
-{
-       struct path path;
-
-       if (pathname && kern_path(pathname, LOOKUP_FOLLOW, &path) == 0) {
-               char *buf = tomoyo_realpath_from_path(&path);
-               path_put(&path);
-               return buf;
+       if (!name)
+               tomoyo_warn_oom(__func__);
+       else if (is_dir && *name) {
+               /* Append trailing '/' if dentry is a directory. */
+               char *pos = name + strlen(name) - 1;
+               if (*pos != '/')
+                       /*
+                        * This is OK because tomoyo_encode() reserves space
+                        * for appending "/".
+                        */
+                       *++pos = '/';
        }
-       return NULL;
+       return name;
 }
 
 /**
@@ -189,191 +179,3 @@ char *tomoyo_realpath_nofollow(const char *pathname)
        }
        return NULL;
 }
-
-/* Memory allocated for non-string data. */
-static atomic_t tomoyo_policy_memory_size;
-/* Quota for holding policy. */
-static unsigned int tomoyo_quota_for_policy;
-
-/**
- * tomoyo_memory_ok - Check memory quota.
- *
- * @ptr: Pointer to allocated memory.
- *
- * Returns true on success, false otherwise.
- *
- * Caller holds tomoyo_policy_lock.
- * Memory pointed by @ptr will be zeroed on success.
- */
-bool tomoyo_memory_ok(void *ptr)
-{
-       int allocated_len = ptr ? ksize(ptr) : 0;
-       atomic_add(allocated_len, &tomoyo_policy_memory_size);
-       if (ptr && (!tomoyo_quota_for_policy ||
-                   atomic_read(&tomoyo_policy_memory_size)
-                   <= tomoyo_quota_for_policy)) {
-               memset(ptr, 0, allocated_len);
-               return true;
-       }
-       printk(KERN_WARNING "ERROR: Out of memory "
-              "for tomoyo_alloc_element().\n");
-       if (!tomoyo_policy_loaded)
-               panic("MAC Initialization failed.\n");
-       return false;
-}
-
-/**
- * tomoyo_commit_ok - Check memory quota.
- *
- * @data:   Data to copy from.
- * @size:   Size in byte.
- *
- * Returns pointer to allocated memory on success, NULL otherwise.
- */
-void *tomoyo_commit_ok(void *data, const unsigned int size)
-{
-       void *ptr = kzalloc(size, GFP_NOFS);
-       if (tomoyo_memory_ok(ptr)) {
-               memmove(ptr, data, size);
-               memset(data, 0, size);
-               return ptr;
-       }
-       return NULL;
-}
-
-/**
- * tomoyo_memory_free - Free memory for elements.
- *
- * @ptr:  Pointer to allocated memory.
- */
-void tomoyo_memory_free(void *ptr)
-{
-       atomic_sub(ksize(ptr), &tomoyo_policy_memory_size);
-       kfree(ptr);
-}
-
-/*
- * tomoyo_name_list is used for holding string data used by TOMOYO.
- * Since same string data is likely used for multiple times (e.g.
- * "/lib/libc-2.5.so"), TOMOYO shares string data in the form of
- * "const struct tomoyo_path_info *".
- */
-struct list_head tomoyo_name_list[TOMOYO_MAX_HASH];
-
-/**
- * tomoyo_get_name - Allocate permanent memory for string data.
- *
- * @name: The string to store into the permernent memory.
- *
- * Returns pointer to "struct tomoyo_path_info" on success, NULL otherwise.
- */
-const struct tomoyo_path_info *tomoyo_get_name(const char *name)
-{
-       struct tomoyo_name_entry *ptr;
-       unsigned int hash;
-       int len;
-       int allocated_len;
-       struct list_head *head;
-
-       if (!name)
-               return NULL;
-       len = strlen(name) + 1;
-       hash = full_name_hash((const unsigned char *) name, len - 1);
-       head = &tomoyo_name_list[hash_long(hash, TOMOYO_HASH_BITS)];
-       if (mutex_lock_interruptible(&tomoyo_policy_lock))
-               return NULL;
-       list_for_each_entry(ptr, head, list) {
-               if (hash != ptr->entry.hash || strcmp(name, ptr->entry.name))
-                       continue;
-               atomic_inc(&ptr->users);
-               goto out;
-       }
-       ptr = kzalloc(sizeof(*ptr) + len, GFP_NOFS);
-       allocated_len = ptr ? ksize(ptr) : 0;
-       if (!ptr || (tomoyo_quota_for_policy &&
-                    atomic_read(&tomoyo_policy_memory_size) + allocated_len
-                    > tomoyo_quota_for_policy)) {
-               kfree(ptr);
-               printk(KERN_WARNING "ERROR: Out of memory "
-                      "for tomoyo_get_name().\n");
-               if (!tomoyo_policy_loaded)
-                       panic("MAC Initialization failed.\n");
-               ptr = NULL;
-               goto out;
-       }
-       atomic_add(allocated_len, &tomoyo_policy_memory_size);
-       ptr->entry.name = ((char *) ptr) + sizeof(*ptr);
-       memmove((char *) ptr->entry.name, name, len);
-       atomic_set(&ptr->users, 1);
-       tomoyo_fill_path_info(&ptr->entry);
-       list_add_tail(&ptr->list, head);
- out:
-       mutex_unlock(&tomoyo_policy_lock);
-       return ptr ? &ptr->entry : NULL;
-}
-
-/**
- * tomoyo_realpath_init - Initialize realpath related code.
- */
-void __init tomoyo_realpath_init(void)
-{
-       int i;
-
-       BUILD_BUG_ON(TOMOYO_MAX_PATHNAME_LEN > PATH_MAX);
-       for (i = 0; i < TOMOYO_MAX_HASH; i++)
-               INIT_LIST_HEAD(&tomoyo_name_list[i]);
-       INIT_LIST_HEAD(&tomoyo_kernel_domain.acl_info_list);
-       tomoyo_kernel_domain.domainname = tomoyo_get_name(TOMOYO_ROOT_NAME);
-       /*
-        * tomoyo_read_lock() is not needed because this function is
-        * called before the first "delete" request.
-        */
-       list_add_tail_rcu(&tomoyo_kernel_domain.list, &tomoyo_domain_list);
-       if (tomoyo_find_domain(TOMOYO_ROOT_NAME) != &tomoyo_kernel_domain)
-               panic("Can't register tomoyo_kernel_domain");
-}
-
-/**
- * tomoyo_read_memory_counter - Check for memory usage in bytes.
- *
- * @head: Pointer to "struct tomoyo_io_buffer".
- *
- * Returns memory usage.
- */
-int tomoyo_read_memory_counter(struct tomoyo_io_buffer *head)
-{
-       if (!head->read_eof) {
-               const unsigned int policy
-                       = atomic_read(&tomoyo_policy_memory_size);
-               char buffer[64];
-
-               memset(buffer, 0, sizeof(buffer));
-               if (tomoyo_quota_for_policy)
-                       snprintf(buffer, sizeof(buffer) - 1,
-                                "   (Quota: %10u)",
-                                tomoyo_quota_for_policy);
-               else
-                       buffer[0] = '\0';
-               tomoyo_io_printf(head, "Policy:  %10u%s\n", policy, buffer);
-               tomoyo_io_printf(head, "Total:   %10u\n", policy);
-               head->read_eof = true;
-       }
-       return 0;
-}
-
-/**
- * tomoyo_write_memory_quota - Set memory quota.
- *
- * @head: Pointer to "struct tomoyo_io_buffer".
- *
- * Returns 0.
- */
-int tomoyo_write_memory_quota(struct tomoyo_io_buffer *head)
-{
-       char *data = head->write_buf;
-       unsigned int size;
-
-       if (sscanf(data, "Policy: %u", &size) == 1)
-               tomoyo_quota_for_policy = size;
-       return 0;
-}
diff --git a/security/tomoyo/securityfs_if.c b/security/tomoyo/securityfs_if.c
new file mode 100644 (file)
index 0000000..e43d555
--- /dev/null
@@ -0,0 +1,155 @@
+/*
+ * security/tomoyo/common.c
+ *
+ * Securityfs interface for TOMOYO.
+ *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
+ */
+
+#include <linux/security.h>
+#include "common.h"
+
+/**
+ * tomoyo_open - open() for /sys/kernel/security/tomoyo/ interface.
+ *
+ * @inode: Pointer to "struct inode".
+ * @file:  Pointer to "struct file".
+ *
+ * Returns 0 on success, negative value otherwise.
+ */
+static int tomoyo_open(struct inode *inode, struct file *file)
+{
+       const int key = ((u8 *) file->f_path.dentry->d_inode->i_private)
+               - ((u8 *) NULL);
+       return tomoyo_open_control(key, file);
+}
+
+/**
+ * tomoyo_release - close() for /sys/kernel/security/tomoyo/ interface.
+ *
+ * @inode: Pointer to "struct inode".
+ * @file:  Pointer to "struct file".
+ *
+ * Returns 0 on success, negative value otherwise.
+ */
+static int tomoyo_release(struct inode *inode, struct file *file)
+{
+       return tomoyo_close_control(file);
+}
+
+/**
+ * tomoyo_poll - poll() for /proc/ccs/ interface.
+ *
+ * @file: Pointer to "struct file".
+ * @wait: Pointer to "poll_table".
+ *
+ * Returns 0 on success, negative value otherwise.
+ */
+static unsigned int tomoyo_poll(struct file *file, poll_table *wait)
+{
+       return tomoyo_poll_control(file, wait);
+}
+
+/**
+ * tomoyo_read - read() for /sys/kernel/security/tomoyo/ interface.
+ *
+ * @file:  Pointer to "struct file".
+ * @buf:   Pointer to buffer.
+ * @count: Size of @buf.
+ * @ppos:  Unused.
+ *
+ * Returns bytes read on success, negative value otherwise.
+ */
+static ssize_t tomoyo_read(struct file *file, char __user *buf, size_t count,
+                          loff_t *ppos)
+{
+       return tomoyo_read_control(file, buf, count);
+}
+
+/**
+ * tomoyo_write - write() for /sys/kernel/security/tomoyo/ interface.
+ *
+ * @file:  Pointer to "struct file".
+ * @buf:   Pointer to buffer.
+ * @count: Size of @buf.
+ * @ppos:  Unused.
+ *
+ * Returns @count on success, negative value otherwise.
+ */
+static ssize_t tomoyo_write(struct file *file, const char __user *buf,
+                           size_t count, loff_t *ppos)
+{
+       return tomoyo_write_control(file, buf, count);
+}
+
+/*
+ * tomoyo_operations is a "struct file_operations" which is used for handling
+ * /sys/kernel/security/tomoyo/ interface.
+ *
+ * Some files under /sys/kernel/security/tomoyo/ directory accept open(O_RDWR).
+ * See tomoyo_io_buffer for internals.
+ */
+static const struct file_operations tomoyo_operations = {
+       .open    = tomoyo_open,
+       .release = tomoyo_release,
+       .poll    = tomoyo_poll,
+       .read    = tomoyo_read,
+       .write   = tomoyo_write,
+       .llseek  = noop_llseek,
+};
+
+/**
+ * tomoyo_create_entry - Create interface files under /sys/kernel/security/tomoyo/ directory.
+ *
+ * @name:   The name of the interface file.
+ * @mode:   The permission of the interface file.
+ * @parent: The parent directory.
+ * @key:    Type of interface.
+ *
+ * Returns nothing.
+ */
+static void __init tomoyo_create_entry(const char *name, const mode_t mode,
+                                      struct dentry *parent, const u8 key)
+{
+       securityfs_create_file(name, mode, parent, ((u8 *) NULL) + key,
+                              &tomoyo_operations);
+}
+
+/**
+ * tomoyo_initerface_init - Initialize /sys/kernel/security/tomoyo/ interface.
+ *
+ * Returns 0.
+ */
+static int __init tomoyo_initerface_init(void)
+{
+       struct dentry *tomoyo_dir;
+
+       /* Don't create securityfs entries unless registered. */
+       if (current_cred()->security != &tomoyo_kernel_domain)
+               return 0;
+
+       tomoyo_dir = securityfs_create_dir("tomoyo", NULL);
+       tomoyo_create_entry("query",            0600, tomoyo_dir,
+                           TOMOYO_QUERY);
+       tomoyo_create_entry("domain_policy",    0600, tomoyo_dir,
+                           TOMOYO_DOMAINPOLICY);
+       tomoyo_create_entry("exception_policy", 0600, tomoyo_dir,
+                           TOMOYO_EXCEPTIONPOLICY);
+       tomoyo_create_entry("self_domain",      0400, tomoyo_dir,
+                           TOMOYO_SELFDOMAIN);
+       tomoyo_create_entry(".domain_status",   0600, tomoyo_dir,
+                           TOMOYO_DOMAIN_STATUS);
+       tomoyo_create_entry(".process_status",  0600, tomoyo_dir,
+                           TOMOYO_PROCESS_STATUS);
+       tomoyo_create_entry("meminfo",          0600, tomoyo_dir,
+                           TOMOYO_MEMINFO);
+       tomoyo_create_entry("profile",          0600, tomoyo_dir,
+                           TOMOYO_PROFILE);
+       tomoyo_create_entry("manager",          0600, tomoyo_dir,
+                           TOMOYO_MANAGER);
+       tomoyo_create_entry("version",          0400, tomoyo_dir,
+                           TOMOYO_VERSION);
+       return 0;
+}
+
+fs_initcall(tomoyo_initerface_init);
index dedd97d0c163675a116ec48c95acd119b8547400..95d3f95722378583c4a0bbd1bb97f77d4368d155 100644 (file)
@@ -3,10 +3,7 @@
  *
  * LSM hooks for TOMOYO Linux.
  *
- * Copyright (C) 2005-2009  NTT DATA CORPORATION
- *
- * Version: 2.2.0   2009/04/01
- *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
  */
 
 #include <linux/security.h>
@@ -96,8 +93,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
        return tomoyo_check_open_permission(domain, &bprm->file->f_path, O_RDONLY);
 }
 
-static int tomoyo_path_truncate(struct path *path, loff_t length,
-                               unsigned int time_attrs)
+static int tomoyo_path_truncate(struct path *path)
 {
        return tomoyo_path_perm(TOMOYO_TYPE_TRUNCATE, path);
 }
@@ -112,7 +108,8 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
                             int mode)
 {
        struct path path = { parent->mnt, dentry };
-       return tomoyo_path_perm(TOMOYO_TYPE_MKDIR, &path);
+       return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
+                                      mode & S_IALLUGO);
 }
 
 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
@@ -133,6 +130,7 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
 {
        struct path path = { parent->mnt, dentry };
        int type = TOMOYO_TYPE_CREATE;
+       const unsigned int perm = mode & S_IALLUGO;
 
        switch (mode & S_IFMT) {
        case S_IFCHR:
@@ -141,6 +139,12 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
        case S_IFBLK:
                type = TOMOYO_TYPE_MKBLOCK;
                break;
+       default:
+               goto no_dev;
+       }
+       return tomoyo_mkdev_perm(type, &path, perm, dev);
+ no_dev:
+       switch (mode & S_IFMT) {
        case S_IFIFO:
                type = TOMOYO_TYPE_MKFIFO;
                break;
@@ -148,7 +152,7 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
                type = TOMOYO_TYPE_MKSOCK;
                break;
        }
-       return tomoyo_path_perm(type, &path);
+       return tomoyo_path_number_perm(type, &path, perm);
 }
 
 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
@@ -173,7 +177,7 @@ static int tomoyo_file_fcntl(struct file *file, unsigned int cmd,
                             unsigned long arg)
 {
        if (cmd == F_SETFL && ((arg ^ file->f_flags) & O_APPEND))
-               return tomoyo_check_rewrite_permission(file);
+               return tomoyo_path_perm(TOMOYO_TYPE_REWRITE, &file->f_path);
        return 0;
 }
 
@@ -189,23 +193,24 @@ static int tomoyo_dentry_open(struct file *f, const struct cred *cred)
 static int tomoyo_file_ioctl(struct file *file, unsigned int cmd,
                             unsigned long arg)
 {
-       return tomoyo_path_perm(TOMOYO_TYPE_IOCTL, &file->f_path);
+       return tomoyo_path_number_perm(TOMOYO_TYPE_IOCTL, &file->f_path, cmd);
 }
 
 static int tomoyo_path_chmod(struct dentry *dentry, struct vfsmount *mnt,
                             mode_t mode)
 {
        struct path path = { mnt, dentry };
-       return tomoyo_path_perm(TOMOYO_TYPE_CHMOD, &path);
+       return tomoyo_path_number_perm(TOMOYO_TYPE_CHMOD, &path,
+                                      mode & S_IALLUGO);
 }
 
 static int tomoyo_path_chown(struct path *path, uid_t uid, gid_t gid)
 {
        int error = 0;
        if (uid != (uid_t) -1)
-               error = tomoyo_path_perm(TOMOYO_TYPE_CHOWN, path);
+               error = tomoyo_path_number_perm(TOMOYO_TYPE_CHOWN, path, uid);
        if (!error && gid != (gid_t) -1)
-               error = tomoyo_path_perm(TOMOYO_TYPE_CHGRP, path);
+               error = tomoyo_path_number_perm(TOMOYO_TYPE_CHGRP, path, gid);
        return error;
 }
 
@@ -217,7 +222,7 @@ static int tomoyo_path_chroot(struct path *path)
 static int tomoyo_sb_mount(char *dev_name, struct path *path,
                           char *type, unsigned long flags, void *data)
 {
-       return tomoyo_path_perm(TOMOYO_TYPE_MOUNT, path);
+       return tomoyo_mount_permission(dev_name, path, type, flags, data);
 }
 
 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
@@ -277,7 +282,7 @@ static int __init tomoyo_init(void)
                panic("Failure registering TOMOYO Linux");
        printk(KERN_INFO "TOMOYO Linux initialized\n");
        cred->security = &tomoyo_kernel_domain;
-       tomoyo_realpath_init();
+       tomoyo_mm_init();
        return 0;
 }
 
diff --git a/security/tomoyo/util.c b/security/tomoyo/util.c
new file mode 100644 (file)
index 0000000..9bfc1ee
--- /dev/null
@@ -0,0 +1,963 @@
+/*
+ * security/tomoyo/util.c
+ *
+ * Utility functions for TOMOYO.
+ *
+ * Copyright (C) 2005-2010  NTT DATA CORPORATION
+ */
+
+#include <linux/slab.h>
+#include "common.h"
+
+/* Lock for protecting policy. */
+DEFINE_MUTEX(tomoyo_policy_lock);
+
+/* Has /sbin/init started? */
+bool tomoyo_policy_loaded;
+
+/**
+ * tomoyo_parse_ulong - Parse an "unsigned long" value.
+ *
+ * @result: Pointer to "unsigned long".
+ * @str:    Pointer to string to parse.
+ *
+ * Returns value type on success, 0 otherwise.
+ *
+ * The @src is updated to point the first character after the value
+ * on success.
+ */
+static u8 tomoyo_parse_ulong(unsigned long *result, char **str)
+{
+       const char *cp = *str;
+       char *ep;
+       int base = 10;
+       if (*cp == '0') {
+               char c = *(cp + 1);
+               if (c == 'x' || c == 'X') {
+                       base = 16;
+                       cp += 2;
+               } else if (c >= '0' && c <= '7') {
+                       base = 8;
+                       cp++;
+               }
+       }
+       *result = simple_strtoul(cp, &ep, base);
+       if (cp == ep)
+               return 0;
+       *str = ep;
+       switch (base) {
+       case 16:
+               return TOMOYO_VALUE_TYPE_HEXADECIMAL;
+       case 8:
+               return TOMOYO_VALUE_TYPE_OCTAL;
+       default:
+               return TOMOYO_VALUE_TYPE_DECIMAL;
+       }
+}
+
+/**
+ * tomoyo_print_ulong - Print an "unsigned long" value.
+ *
+ * @buffer:     Pointer to buffer.
+ * @buffer_len: Size of @buffer.
+ * @value:      An "unsigned long" value.
+ * @type:       Type of @value.
+ *
+ * Returns nothing.
+ */
+void tomoyo_print_ulong(char *buffer, const int buffer_len,
+                       const unsigned long value, const u8 type)
+{
+       if (type == TOMOYO_VALUE_TYPE_DECIMAL)
+               snprintf(buffer, buffer_len, "%lu", value);
+       else if (type == TOMOYO_VALUE_TYPE_OCTAL)
+               snprintf(buffer, buffer_len, "0%lo", value);
+       else if (type == TOMOYO_VALUE_TYPE_HEXADECIMAL)
+               snprintf(buffer, buffer_len, "0x%lX", value);
+       else
+               snprintf(buffer, buffer_len, "type(%u)", type);
+}
+
+/**
+ * tomoyo_parse_name_union - Parse a tomoyo_name_union.
+ *
+ * @filename: Name or name group.
+ * @ptr:      Pointer to "struct tomoyo_name_union".
+ *
+ * Returns true on success, false otherwise.
+ */
+bool tomoyo_parse_name_union(const char *filename,
+                            struct tomoyo_name_union *ptr)
+{
+       if (!tomoyo_correct_word(filename))
+               return false;
+       if (filename[0] == '@') {
+               ptr->group = tomoyo_get_group(filename + 1, TOMOYO_PATH_GROUP);
+               ptr->is_group = true;
+               return ptr->group != NULL;
+       }
+       ptr->filename = tomoyo_get_name(filename);
+       ptr->is_group = false;
+       return ptr->filename != NULL;
+}
+
+/**
+ * tomoyo_parse_number_union - Parse a tomoyo_number_union.
+ *
+ * @data: Number or number range or number group.
+ * @ptr:  Pointer to "struct tomoyo_number_union".
+ *
+ * Returns true on success, false otherwise.
+ */
+bool tomoyo_parse_number_union(char *data, struct tomoyo_number_union *num)
+{
+       u8 type;
+       unsigned long v;
+       memset(num, 0, sizeof(*num));
+       if (data[0] == '@') {
+               if (!tomoyo_correct_word(data))
+                       return false;
+               num->group = tomoyo_get_group(data + 1, TOMOYO_NUMBER_GROUP);
+               num->is_group = true;
+               return num->group != NULL;
+       }
+       type = tomoyo_parse_ulong(&v, &data);
+       if (!type)
+               return false;
+       num->values[0] = v;
+       num->min_type = type;
+       if (!*data) {
+               num->values[1] = v;
+               num->max_type = type;
+               return true;
+       }
+       if (*data++ != '-')
+               return false;
+       type = tomoyo_parse_ulong(&v, &data);
+       if (!type || *data)
+               return false;
+       num->values[1] = v;
+       num->max_type = type;
+       return true;
+}
+
+/**
+ * tomoyo_byte_range - Check whether the string is a \ooo style octal value.
+ *
+ * @str: Pointer to the string.
+ *
+ * Returns true if @str is a \ooo style octal value, false otherwise.
+ *
+ * TOMOYO uses \ooo style representation for 0x01 - 0x20 and 0x7F - 0xFF.
+ * This function verifies that \ooo is in valid range.
+ */
+static inline bool tomoyo_byte_range(const char *str)
+{
+       return *str >= '0' && *str++ <= '3' &&
+               *str >= '0' && *str++ <= '7' &&
+               *str >= '0' && *str <= '7';
+}
+
+/**
+ * tomoyo_alphabet_char - Check whether the character is an alphabet.
+ *
+ * @c: The character to check.
+ *
+ * Returns true if @c is an alphabet character, false otherwise.
+ */
+static inline bool tomoyo_alphabet_char(const char c)
+{
+       return (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z');
+}
+
+/**
+ * tomoyo_make_byte - Make byte value from three octal characters.
+ *
+ * @c1: The first character.
+ * @c2: The second character.
+ * @c3: The third character.
+ *
+ * Returns byte value.
+ */
+static inline u8 tomoyo_make_byte(const u8 c1, const u8 c2, const u8 c3)
+{
+       return ((c1 - '0') << 6) + ((c2 - '0') << 3) + (c3 - '0');
+}
+
+/**
+ * tomoyo_str_starts - Check whether the given string starts with the given keyword.
+ *
+ * @src:  Pointer to pointer to the string.
+ * @find: Pointer to the keyword.
+ *
+ * Returns true if @src starts with @find, false otherwise.
+ *
+ * The @src is updated to point the first character after the @find
+ * if @src starts with @find.
+ */
+bool tomoyo_str_starts(char **src, const char *find)
+{
+       const int len = strlen(find);
+       char *tmp = *src;
+
+       if (strncmp(tmp, find, len))
+               return false;
+       tmp += len;
+       *src = tmp;
+       return true;
+}
+
+/**
+ * tomoyo_normalize_line - Format string.
+ *
+ * @buffer: The line to normalize.
+ *
+ * Leading and trailing whitespaces are removed.
+ * Multiple whitespaces are packed into single space.
+ *
+ * Returns nothing.
+ */
+void tomoyo_normalize_line(unsigned char *buffer)
+{
+       unsigned char *sp = buffer;
+       unsigned char *dp = buffer;
+       bool first = true;
+
+       while (tomoyo_invalid(*sp))
+               sp++;
+       while (*sp) {
+               if (!first)
+                       *dp++ = ' ';
+               first = false;
+               while (tomoyo_valid(*sp))
+                       *dp++ = *sp++;
+               while (tomoyo_invalid(*sp))
+                       sp++;
+       }
+       *dp = '\0';
+}
+
+/**
+ * tomoyo_tokenize - Tokenize string.
+ *
+ * @buffer: The line to tokenize.
+ * @w:      Pointer to "char *".
+ * @size:   Sizeof @w .
+ *
+ * Returns true on success, false otherwise.
+ */
+bool tomoyo_tokenize(char *buffer, char *w[], size_t size)
+{
+       int count = size / sizeof(char *);
+       int i;
+       for (i = 0; i < count; i++)
+               w[i] = "";
+       for (i = 0; i < count; i++) {
+               char *cp = strchr(buffer, ' ');
+               if (cp)
+                       *cp = '\0';
+               w[i] = buffer;
+               if (!cp)
+                       break;
+               buffer = cp + 1;
+       }
+       return i < count || !*buffer;
+}
+
+/**
+ * tomoyo_correct_word2 - Validate a string.
+ *
+ * @string: The string to check. May be non-'\0'-terminated.
+ * @len:    Length of @string.
+ *
+ * Check whether the given string follows the naming rules.
+ * Returns true if @string follows the naming rules, false otherwise.
+ */
+static bool tomoyo_correct_word2(const char *string, size_t len)
+{
+       const char *const start = string;
+       bool in_repetition = false;
+       unsigned char c;
+       unsigned char d;
+       unsigned char e;
+       if (!len)
+               goto out;
+       while (len--) {
+               c = *string++;
+               if (c == '\\') {
+                       if (!len--)
+                               goto out;
+                       c = *string++;
+                       switch (c) {
+                       case '\\':  /* "\\" */
+                               continue;
+                       case '$':   /* "\$" */
+                       case '+':   /* "\+" */
+                       case '?':   /* "\?" */
+                       case '*':   /* "\*" */
+                       case '@':   /* "\@" */
+                       case 'x':   /* "\x" */
+                       case 'X':   /* "\X" */
+                       case 'a':   /* "\a" */
+                       case 'A':   /* "\A" */
+                       case '-':   /* "\-" */
+                               continue;
+                       case '{':   /* "/\{" */
+                               if (string - 3 < start || *(string - 3) != '/')
+                                       break;
+                               in_repetition = true;
+                               continue;
+                       case '}':   /* "\}/" */
+                               if (*string != '/')
+                                       break;
+                               if (!in_repetition)
+                                       break;
+                               in_repetition = false;
+                               continue;
+                       case '0':   /* "\ooo" */
+                       case '1':
+                       case '2':
+                       case '3':
+                               if (!len-- || !len--)
+                                       break;
+                               d = *string++;
+                               e = *string++;
+                               if (d < '0' || d > '7' || e < '0' || e > '7')
+                                       break;
+                               c = tomoyo_make_byte(c, d, e);
+                               if (tomoyo_invalid(c))
+                                       continue; /* pattern is not \000 */
+                       }
+                       goto out;
+               } else if (in_repetition && c == '/') {
+                       goto out;
+               } else if (tomoyo_invalid(c)) {
+                       goto out;
+               }
+       }
+       if (in_repetition)
+               goto out;
+       return true;
+ out:
+       return false;
+}
+
+/**
+ * tomoyo_correct_word - Validate a string.
+ *
+ * @string: The string to check.
+ *
+ * Check whether the given string follows the naming rules.
+ * Returns true if @string follows the naming rules, false otherwise.
+ */
+bool tomoyo_correct_word(const char *string)
+{
+       return tomoyo_correct_word2(string, strlen(string));
+}
+
+/**
+ * tomoyo_correct_path - Validate a pathname.
+ *
+ * @filename: The pathname to check.
+ *
+ * Check whether the given pathname follows the naming rules.
+ * Returns true if @filename follows the naming rules, false otherwise.
+ */
+bool tomoyo_correct_path(const char *filename)
+{
+       return *filename == '/' && tomoyo_correct_word(filename);
+}
+
+/**
+ * tomoyo_correct_domain - Check whether the given domainname follows the naming rules.
+ *
+ * @domainname: The domainname to check.
+ *
+ * Returns true if @domainname follows the naming rules, false otherwise.
+ */
+bool tomoyo_correct_domain(const unsigned char *domainname)
+{
+       if (!domainname || strncmp(domainname, TOMOYO_ROOT_NAME,
+                                  TOMOYO_ROOT_NAME_LEN))
+               goto out;
+       domainname += TOMOYO_ROOT_NAME_LEN;
+       if (!*domainname)
+               return true;
+       if (*domainname++ != ' ')
+               goto out;
+       while (1) {
+               const unsigned char *cp = strchr(domainname, ' ');
+               if (!cp)
+                       break;
+               if (*domainname != '/' ||
+                   !tomoyo_correct_word2(domainname, cp - domainname - 1))
+                       goto out;
+               domainname = cp + 1;
+       }
+       return tomoyo_correct_path(domainname);
+ out:
+       return false;
+}
+
+/**
+ * tomoyo_domain_def - Check whether the given token can be a domainname.
+ *
+ * @buffer: The token to check.
+ *
+ * Returns true if @buffer possibly be a domainname, false otherwise.
+ */
+bool tomoyo_domain_def(const unsigned char *buffer)
+{
+       return !strncmp(buffer, TOMOYO_ROOT_NAME, TOMOYO_ROOT_NAME_LEN);
+}
+
+/**
+ * tomoyo_find_domain - Find a domain by the given name.
+ *
+ * @domainname: The domainname to find.
+ *
+ * Returns pointer to "struct tomoyo_domain_info" if found, NULL otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+struct tomoyo_domain_info *tomoyo_find_domain(const char *domainname)
+{
+       struct tomoyo_domain_info *domain;
+       struct tomoyo_path_info name;
+
+       name.name = domainname;
+       tomoyo_fill_path_info(&name);
+       list_for_each_entry_rcu(domain, &tomoyo_domain_list, list) {
+               if (!domain->is_deleted &&
+                   !tomoyo_pathcmp(&name, domain->domainname))
+                       return domain;
+       }
+       return NULL;
+}
+
+/**
+ * tomoyo_const_part_length - Evaluate the initial length without a pattern in a token.
+ *
+ * @filename: The string to evaluate.
+ *
+ * Returns the initial length without a pattern in @filename.
+ */
+static int tomoyo_const_part_length(const char *filename)
+{
+       char c;
+       int len = 0;
+
+       if (!filename)
+               return 0;
+       while ((c = *filename++) != '\0') {
+               if (c != '\\') {
+                       len++;
+                       continue;
+               }
+               c = *filename++;
+               switch (c) {
+               case '\\':  /* "\\" */
+                       len += 2;
+                       continue;
+               case '0':   /* "\ooo" */
+               case '1':
+               case '2':
+               case '3':
+                       c = *filename++;
+                       if (c < '0' || c > '7')
+                               break;
+                       c = *filename++;
+                       if (c < '0' || c > '7')
+                               break;
+                       len += 4;
+                       continue;
+               }
+               break;
+       }
+       return len;
+}
+
+/**
+ * tomoyo_fill_path_info - Fill in "struct tomoyo_path_info" members.
+ *
+ * @ptr: Pointer to "struct tomoyo_path_info" to fill in.
+ *
+ * The caller sets "struct tomoyo_path_info"->name.
+ */
+void tomoyo_fill_path_info(struct tomoyo_path_info *ptr)
+{
+       const char *name = ptr->name;
+       const int len = strlen(name);
+
+       ptr->const_len = tomoyo_const_part_length(name);
+       ptr->is_dir = len && (name[len - 1] == '/');
+       ptr->is_patterned = (ptr->const_len < len);
+       ptr->hash = full_name_hash(name, len);
+}
+
+/**
+ * tomoyo_file_matches_pattern2 - Pattern matching without '/' character and "\-" pattern.
+ *
+ * @filename:     The start of string to check.
+ * @filename_end: The end of string to check.
+ * @pattern:      The start of pattern to compare.
+ * @pattern_end:  The end of pattern to compare.
+ *
+ * Returns true if @filename matches @pattern, false otherwise.
+ */
+static bool tomoyo_file_matches_pattern2(const char *filename,
+                                        const char *filename_end,
+                                        const char *pattern,
+                                        const char *pattern_end)
+{
+       while (filename < filename_end && pattern < pattern_end) {
+               char c;
+               if (*pattern != '\\') {
+                       if (*filename++ != *pattern++)
+                               return false;
+                       continue;
+               }
+               c = *filename;
+               pattern++;
+               switch (*pattern) {
+                       int i;
+                       int j;
+               case '?':
+                       if (c == '/') {
+                               return false;
+                       } else if (c == '\\') {
+                               if (filename[1] == '\\')
+                                       filename++;
+                               else if (tomoyo_byte_range(filename + 1))
+                                       filename += 3;
+                               else
+                                       return false;
+                       }
+                       break;
+               case '\\':
+                       if (c != '\\')
+                               return false;
+                       if (*++filename != '\\')
+                               return false;
+                       break;
+               case '+':
+                       if (!isdigit(c))
+                               return false;
+                       break;
+               case 'x':
+                       if (!isxdigit(c))
+                               return false;
+                       break;
+               case 'a':
+                       if (!tomoyo_alphabet_char(c))
+                               return false;
+                       break;
+               case '0':
+               case '1':
+               case '2':
+               case '3':
+                       if (c == '\\' && tomoyo_byte_range(filename + 1)
+                           && strncmp(filename + 1, pattern, 3) == 0) {
+                               filename += 3;
+                               pattern += 2;
+                               break;
+                       }
+                       return false; /* Not matched. */
+               case '*':
+               case '@':
+                       for (i = 0; i <= filename_end - filename; i++) {
+                               if (tomoyo_file_matches_pattern2(
+                                                   filename + i, filename_end,
+                                                   pattern + 1, pattern_end))
+                                       return true;
+                               c = filename[i];
+                               if (c == '.' && *pattern == '@')
+                                       break;
+                               if (c != '\\')
+                                       continue;
+                               if (filename[i + 1] == '\\')
+                                       i++;
+                               else if (tomoyo_byte_range(filename + i + 1))
+                                       i += 3;
+                               else
+                                       break; /* Bad pattern. */
+                       }
+                       return false; /* Not matched. */
+               default:
+                       j = 0;
+                       c = *pattern;
+                       if (c == '$') {
+                               while (isdigit(filename[j]))
+                                       j++;
+                       } else if (c == 'X') {
+                               while (isxdigit(filename[j]))
+                                       j++;
+                       } else if (c == 'A') {
+                               while (tomoyo_alphabet_char(filename[j]))
+                                       j++;
+                       }
+                       for (i = 1; i <= j; i++) {
+                               if (tomoyo_file_matches_pattern2(
+                                                   filename + i, filename_end,
+                                                   pattern + 1, pattern_end))
+                                       return true;
+                       }
+                       return false; /* Not matched or bad pattern. */
+               }
+               filename++;
+               pattern++;
+       }
+       while (*pattern == '\\' &&
+              (*(pattern + 1) == '*' || *(pattern + 1) == '@'))
+               pattern += 2;
+       return filename == filename_end && pattern == pattern_end;
+}
+
+/**
+ * tomoyo_file_matches_pattern - Pattern matching without '/' character.
+ *
+ * @filename:     The start of string to check.
+ * @filename_end: The end of string to check.
+ * @pattern:      The start of pattern to compare.
+ * @pattern_end:  The end of pattern to compare.
+ *
+ * Returns true if @filename matches @pattern, false otherwise.
+ */
+static bool tomoyo_file_matches_pattern(const char *filename,
+                                       const char *filename_end,
+                                       const char *pattern,
+                                       const char *pattern_end)
+{
+       const char *pattern_start = pattern;
+       bool first = true;
+       bool result;
+
+       while (pattern < pattern_end - 1) {
+               /* Split at "\-" pattern. */
+               if (*pattern++ != '\\' || *pattern++ != '-')
+                       continue;
+               result = tomoyo_file_matches_pattern2(filename,
+                                                     filename_end,
+                                                     pattern_start,
+                                                     pattern - 2);
+               if (first)
+                       result = !result;
+               if (result)
+                       return false;
+               first = false;
+               pattern_start = pattern;
+       }
+       result = tomoyo_file_matches_pattern2(filename, filename_end,
+                                             pattern_start, pattern_end);
+       return first ? result : !result;
+}
+
+/**
+ * tomoyo_path_matches_pattern2 - Do pathname pattern matching.
+ *
+ * @f: The start of string to check.
+ * @p: The start of pattern to compare.
+ *
+ * Returns true if @f matches @p, false otherwise.
+ */
+static bool tomoyo_path_matches_pattern2(const char *f, const char *p)
+{
+       const char *f_delimiter;
+       const char *p_delimiter;
+
+       while (*f && *p) {
+               f_delimiter = strchr(f, '/');
+               if (!f_delimiter)
+                       f_delimiter = f + strlen(f);
+               p_delimiter = strchr(p, '/');
+               if (!p_delimiter)
+                       p_delimiter = p + strlen(p);
+               if (*p == '\\' && *(p + 1) == '{')
+                       goto recursive;
+               if (!tomoyo_file_matches_pattern(f, f_delimiter, p,
+                                                p_delimiter))
+                       return false;
+               f = f_delimiter;
+               if (*f)
+                       f++;
+               p = p_delimiter;
+               if (*p)
+                       p++;
+       }
+       /* Ignore trailing "\*" and "\@" in @pattern. */
+       while (*p == '\\' &&
+              (*(p + 1) == '*' || *(p + 1) == '@'))
+               p += 2;
+       return !*f && !*p;
+ recursive:
+       /*
+        * The "\{" pattern is permitted only after '/' character.
+        * This guarantees that below "*(p - 1)" is safe.
+        * Also, the "\}" pattern is permitted only before '/' character
+        * so that "\{" + "\}" pair will not break the "\-" operator.
+        */
+       if (*(p - 1) != '/' || p_delimiter <= p + 3 || *p_delimiter != '/' ||
+           *(p_delimiter - 1) != '}' || *(p_delimiter - 2) != '\\')
+               return false; /* Bad pattern. */
+       do {
+               /* Compare current component with pattern. */
+               if (!tomoyo_file_matches_pattern(f, f_delimiter, p + 2,
+                                                p_delimiter - 2))
+                       break;
+               /* Proceed to next component. */
+               f = f_delimiter;
+               if (!*f)
+                       break;
+               f++;
+               /* Continue comparison. */
+               if (tomoyo_path_matches_pattern2(f, p_delimiter + 1))
+                       return true;
+               f_delimiter = strchr(f, '/');
+       } while (f_delimiter);
+       return false; /* Not matched. */
+}
+
+/**
+ * tomoyo_path_matches_pattern - Check whether the given filename matches the given pattern.
+ *
+ * @filename: The filename to check.
+ * @pattern:  The pattern to compare.
+ *
+ * Returns true if matches, false otherwise.
+ *
+ * The following patterns are available.
+ *   \\     \ itself.
+ *   \ooo   Octal representation of a byte.
+ *   \*     Zero or more repetitions of characters other than '/'.
+ *   \@     Zero or more repetitions of characters other than '/' or '.'.
+ *   \?     1 byte character other than '/'.
+ *   \$     One or more repetitions of decimal digits.
+ *   \+     1 decimal digit.
+ *   \X     One or more repetitions of hexadecimal digits.
+ *   \x     1 hexadecimal digit.
+ *   \A     One or more repetitions of alphabet characters.
+ *   \a     1 alphabet character.
+ *
+ *   \-     Subtraction operator.
+ *
+ *   /\{dir\}/   '/' + 'One or more repetitions of dir/' (e.g. /dir/ /dir/dir/
+ *               /dir/dir/dir/ ).
+ */
+bool tomoyo_path_matches_pattern(const struct tomoyo_path_info *filename,
+                                const struct tomoyo_path_info *pattern)
+{
+       const char *f = filename->name;
+       const char *p = pattern->name;
+       const int len = pattern->const_len;
+
+       /* If @pattern doesn't contain pattern, I can use strcmp(). */
+       if (!pattern->is_patterned)
+               return !tomoyo_pathcmp(filename, pattern);
+       /* Don't compare directory and non-directory. */
+       if (filename->is_dir != pattern->is_dir)
+               return false;
+       /* Compare the initial length without patterns. */
+       if (strncmp(f, p, len))
+               return false;
+       f += len;
+       p += len;
+       return tomoyo_path_matches_pattern2(f, p);
+}
+
+/**
+ * tomoyo_get_exe - Get tomoyo_realpath() of current process.
+ *
+ * Returns the tomoyo_realpath() of current process on success, NULL otherwise.
+ *
+ * This function uses kzalloc(), so the caller must call kfree()
+ * if this function didn't return NULL.
+ */
+const char *tomoyo_get_exe(void)
+{
+       struct mm_struct *mm = current->mm;
+       struct vm_area_struct *vma;
+       const char *cp = NULL;
+
+       if (!mm)
+               return NULL;
+       down_read(&mm->mmap_sem);
+       for (vma = mm->mmap; vma; vma = vma->vm_next) {
+               if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file) {
+                       cp = tomoyo_realpath_from_path(&vma->vm_file->f_path);
+                       break;
+               }
+       }
+       up_read(&mm->mmap_sem);
+       return cp;
+}
+
+/**
+ * tomoyo_get_mode - Get MAC mode.
+ *
+ * @profile: Profile number.
+ * @index:   Index number of functionality.
+ *
+ * Returns mode.
+ */
+int tomoyo_get_mode(const u8 profile, const u8 index)
+{
+       u8 mode;
+       const u8 category = TOMOYO_MAC_CATEGORY_FILE;
+       if (!tomoyo_policy_loaded)
+               return TOMOYO_CONFIG_DISABLED;
+       mode = tomoyo_profile(profile)->config[index];
+       if (mode == TOMOYO_CONFIG_USE_DEFAULT)
+               mode = tomoyo_profile(profile)->config[category];
+       if (mode == TOMOYO_CONFIG_USE_DEFAULT)
+               mode = tomoyo_profile(profile)->default_config;
+       return mode & 3;
+}
+
+/**
+ * tomoyo_init_request_info - Initialize "struct tomoyo_request_info" members.
+ *
+ * @r:      Pointer to "struct tomoyo_request_info" to initialize.
+ * @domain: Pointer to "struct tomoyo_domain_info". NULL for tomoyo_domain().
+ * @index:  Index number of functionality.
+ *
+ * Returns mode.
+ */
+int tomoyo_init_request_info(struct tomoyo_request_info *r,
+                            struct tomoyo_domain_info *domain, const u8 index)
+{
+       u8 profile;
+       memset(r, 0, sizeof(*r));
+       if (!domain)
+               domain = tomoyo_domain();
+       r->domain = domain;
+       profile = domain->profile;
+       r->profile = profile;
+       r->type = index;
+       r->mode = tomoyo_get_mode(profile, index);
+       return r->mode;
+}
+
+/**
+ * tomoyo_last_word - Get last component of a line.
+ *
+ * @line: A line.
+ *
+ * Returns the last word of a line.
+ */
+const char *tomoyo_last_word(const char *name)
+{
+       const char *cp = strrchr(name, ' ');
+       if (cp)
+               return cp + 1;
+       return name;
+}
+
+/**
+ * tomoyo_warn_log - Print warning or error message on console.
+ *
+ * @r:   Pointer to "struct tomoyo_request_info".
+ * @fmt: The printf()'s format string, followed by parameters.
+ */
+void tomoyo_warn_log(struct tomoyo_request_info *r, const char *fmt, ...)
+{
+       va_list args;
+       char *buffer;
+       const struct tomoyo_domain_info * const domain = r->domain;
+       const struct tomoyo_profile *profile = tomoyo_profile(domain->profile);
+       switch (r->mode) {
+       case TOMOYO_CONFIG_ENFORCING:
+               if (!profile->enforcing->enforcing_verbose)
+                       return;
+               break;
+       case TOMOYO_CONFIG_PERMISSIVE:
+               if (!profile->permissive->permissive_verbose)
+                       return;
+               break;
+       case TOMOYO_CONFIG_LEARNING:
+               if (!profile->learning->learning_verbose)
+                       return;
+               break;
+       }
+       buffer = kmalloc(4096, GFP_NOFS);
+       if (!buffer)
+               return;
+       va_start(args, fmt);
+       vsnprintf(buffer, 4095, fmt, args);
+       va_end(args);
+       buffer[4095] = '\0';
+       printk(KERN_WARNING "%s: Access %s denied for %s\n",
+              r->mode == TOMOYO_CONFIG_ENFORCING ? "ERROR" : "WARNING", buffer,
+              tomoyo_last_word(domain->domainname->name));
+       kfree(buffer);
+}
+
+/**
+ * tomoyo_domain_quota_is_ok - Check for domain's quota.
+ *
+ * @r: Pointer to "struct tomoyo_request_info".
+ *
+ * Returns true if the domain is not exceeded quota, false otherwise.
+ *
+ * Caller holds tomoyo_read_lock().
+ */
+bool tomoyo_domain_quota_is_ok(struct tomoyo_request_info *r)
+{
+       unsigned int count = 0;
+       struct tomoyo_domain_info *domain = r->domain;
+       struct tomoyo_acl_info *ptr;
+
+       if (r->mode != TOMOYO_CONFIG_LEARNING)
+               return false;
+       if (!domain)
+               return true;
+       list_for_each_entry_rcu(ptr, &domain->acl_info_list, list) {
+               if (ptr->is_deleted)
+                       continue;
+               switch (ptr->type) {
+                       u16 perm;
+                       u8 i;
+               case TOMOYO_TYPE_PATH_ACL:
+                       perm = container_of(ptr, struct tomoyo_path_acl, head)
+                               ->perm;
+                       for (i = 0; i < TOMOYO_MAX_PATH_OPERATION; i++)
+                               if (perm & (1 << i))
+                                       count++;
+                       if (perm & (1 << TOMOYO_TYPE_READ_WRITE))
+                               count -= 2;
+                       break;
+               case TOMOYO_TYPE_PATH2_ACL:
+                       perm = container_of(ptr, struct tomoyo_path2_acl, head)
+                               ->perm;
+                       for (i = 0; i < TOMOYO_MAX_PATH2_OPERATION; i++)
+                               if (perm & (1 << i))
+                                       count++;
+                       break;
+               case TOMOYO_TYPE_PATH_NUMBER_ACL:
+                       perm = container_of(ptr, struct tomoyo_path_number_acl,
+                                           head)->perm;
+                       for (i = 0; i < TOMOYO_MAX_PATH_NUMBER_OPERATION; i++)
+                               if (perm & (1 << i))
+                                       count++;
+                       break;
+               case TOMOYO_TYPE_MKDEV_ACL:
+                       perm = container_of(ptr, struct tomoyo_mkdev_acl,
+                                           head)->perm;
+                       for (i = 0; i < TOMOYO_MAX_MKDEV_OPERATION; i++)
+                               if (perm & (1 << i))
+                                       count++;
+                       break;
+               default:
+                       count++;
+               }
+       }
+       if (count < tomoyo_profile(domain->profile)->learning->
+           learning_max_entry)
+               return true;
+       if (!domain->quota_warned) {
+               domain->quota_warned = true;
+               printk(KERN_WARNING "TOMOYO-WARNING: "
+                      "Domain '%s' has so many ACLs to hold. "
+                      "Stopped learning mode.\n", domain->domainname->name);
+       }
+       return false;
+}
diff --git a/tools/perf/arch/arm/Makefile b/tools/perf/arch/arm/Makefile
new file mode 100644 (file)
index 0000000..15130b5
--- /dev/null
@@ -0,0 +1,4 @@
+ifndef NO_DWARF
+PERF_HAVE_DWARF_REGS := 1
+LIB_OBJS += $(OUTPUT)arch/$(ARCH)/util/dwarf-regs.o
+endif
diff --git a/tools/perf/arch/arm/util/dwarf-regs.c b/tools/perf/arch/arm/util/dwarf-regs.c
new file mode 100644 (file)
index 0000000..fff6450
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ * Mapping of DWARF debug register numbers into register names.
+ *
+ * Copyright (C) 2010 Will Deacon, ARM Ltd.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ */
+
+#include <libio.h>
+#include <dwarf-regs.h>
+
+struct pt_regs_dwarfnum {
+       const char *name;
+       unsigned int dwarfnum;
+};
+
+#define STR(s) #s
+#define REG_DWARFNUM_NAME(r, num) {.name = r, .dwarfnum = num}
+#define GPR_DWARFNUM_NAME(num) \
+       {.name = STR(%r##num), .dwarfnum = num}
+#define REG_DWARFNUM_END {.name = NULL, .dwarfnum = 0}
+
+/*
+ * Reference:
+ * http://infocenter.arm.com/help/topic/com.arm.doc.ihi0040a/IHI0040A_aadwarf.pdf
+ */
+static const struct pt_regs_dwarfnum regdwarfnum_table[] = {
+       GPR_DWARFNUM_NAME(0),
+       GPR_DWARFNUM_NAME(1),
+       GPR_DWARFNUM_NAME(2),
+       GPR_DWARFNUM_NAME(3),
+       GPR_DWARFNUM_NAME(4),
+       GPR_DWARFNUM_NAME(5),
+       GPR_DWARFNUM_NAME(6),
+       GPR_DWARFNUM_NAME(7),
+       GPR_DWARFNUM_NAME(8),
+       GPR_DWARFNUM_NAME(9),
+       GPR_DWARFNUM_NAME(10),
+       REG_DWARFNUM_NAME("%fp", 11),
+       REG_DWARFNUM_NAME("%ip", 12),
+       REG_DWARFNUM_NAME("%sp", 13),
+       REG_DWARFNUM_NAME("%lr", 14),
+       REG_DWARFNUM_NAME("%pc", 15),
+       REG_DWARFNUM_END,
+};
+
+/**
+ * get_arch_regstr() - lookup register name from it's DWARF register number
+ * @n: the DWARF register number
+ *
+ * get_arch_regstr() returns the name of the register in struct
+ * regdwarfnum_table from it's DWARF register number. If the register is not
+ * found in the table, this returns NULL;
+ */
+const char *get_arch_regstr(unsigned int n)
+{
+       const struct pt_regs_dwarfnum *roff;
+       for (roff = regdwarfnum_table; roff->name != NULL; roff++)
+               if (roff->dwarfnum == n)
+                       return roff->name;
+       return NULL;
+}