add legacy I/O port & memory APIs to /proc/bus/pci
Subsystems (2)
PATCH 1/1 add legacy I/O port & memory APIs to /proc/bus/pci
This patch documents the /proc/bus/pci interface and adds some optional architecture specific APIs for accessing legacy I/O port and memory space. This is necessary on platforms where legacy I/O port space doesn't 'soft fail' like it does on PCs, and is useful for systems that can route legacy space to different PCI busses.
I've incorporated all the feedback I've received so far, so I think it's ready to send on to Andrew for inclusion, if someone could give the proc-pci.txt documentation a last read (and/or comment on other stuff I may have missed).
Thanks,
Jesse
arch/ia64/pci/pci.c +104 -1
@@ -514,11 +514,19 @@ pci_mmap_page_range (struct pci_dev *dev*/ return -EINVAL ; +if (mmap_state == pci_mmap_legacy_mem) { +unsigned long addr; +int ret; +if ((ret =pci_get_legacy_mem (dev, &addr))) +return ret; + vma->vm_pgoff += addr >>PAGE_SHIFT ; + } +/* * Leave vm_pgoff as-is, the PCI space address is the physical * address on this platform. */ - vma->vm_flags |= (VM_SHM |VM_LOCKED |VM_IO ); + vma->vm_flags |= (VM_SHM |VM_RESERVED |VM_IO );if (write_combine) vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot);
@@ -533,6 +541,101 @@ pci_mmap_page_range (struct pci_dev *dev }/** +* ia64_pci_get_legacy_mem - generic legacy mem routine +* @dev: device pointer +* @addr: caller allocated variable for the base address +* +* Find the base of legacy memory for @dev. This is typically the first +* megabyte of bus address space for @dev or is simply 0 on platforms whose +* chipsets support legacy I/O and memory routing. Returns 0 on success +* or a standard error code on failure. +* +* This is the ia64 generic version of this routine. Other platforms +* are free to override it with a machine vector. +*/ +int ia64_pci_get_legacy_mem (struct pci_dev *dev,unsigned long *addr) +{ + *addr =0 ; +return 0 ; +} + +/** +* ia64_pci_legacy_read - read from legacy I/O space +* @dev: device to read +* @port: legacy port value +* @val: caller allocated storage for returned value +* @size: number of bytes to read +* +* Simply reads @size bytes from @port and puts the result in @val. +* +* Again, this (and the write routine) are generic versions that can be +* overridden by the platform. This is necessary on platforms that don't +* support legacy I/O routing or that hard fail on legacy I/O timeouts. +*/ +int ia64_pci_legacy_read (struct pci_dev *dev,u16 port,u32 *val,u8 size) +{ +int ret =0 ; +unsigned long paddr = port; +unsigned long *addr; + +switch (size) { +case 1 : + addr = (unsigned long *)paddr; + *val = (u8)(*(volatile u8 *)(addr)); +break ; +case 2 : + addr = (unsigned long *)paddr; + *val = (u16)(*(volatile u16 *)(addr)); +break ; +case 4 : + addr = (unsigned long *)paddr; + *val = (u32)(*(volatile u32 *)(addr)); +break ; +default : + ret = -EINVAL ; +break ; + } + +return ret; +} + +/** +* ia64_pci_legacy_write - perform a legacy I/O write +* @dev: device pointer +* @port: port to write +* @val: value to write +* @size: number of bytes to write from @val +* +* Simply writes @size bytes of @val to @port. +*/ +int ia64_pci_legacy_write (struct pci_dev *dev,u16 port,u32 val,u8 size) +{ +int ret =0 ; +unsigned long paddr = port; +unsigned long *addr; + +switch (size) { +case 1 : + addr = (unsigned long *)paddr; + *(volatile u8 *)(addr) = (u8)(val); +break ; +case 2 : + addr = (unsigned long *)paddr; + *(volatile u16 *)(addr) = (u16)(val); +break ; +case 4 : + addr = (unsigned long *)paddr; + *(volatile u32 *)(addr) = (u32)(val); +break ; +default : + ret = -EINVAL ; +break ; + } + +return ret; +} + +/** * pci_cacheline_size - determine cacheline size for PCI devices * @dev: void *
arch/ia64/sn/pci/pci_dma.c +74 -0
77 lines not on this page · raw message
Documentation/filesystems/proc-pci.txt +126 -0
126 lines not on this page · raw message
drivers/pci/proc.c +89 -11
149 lines not on this page · raw message
include/asm-ia64/machvec.h +24 -0
@@ -20,6 +20,7 @@ struct scatterlist;struct irq_desc ;struct page ;struct mm_struct ; +struct pci_dev ;typedef void ia64_mv_setup_t (char **);typedef void ia64_mv_cpu_init_t (void );
@@ -31,6 +32,11 @@ typedef void ia64_mv_tlb_migrate_finish_typedef struct irq_desc *ia64_mv_irq_desc (unsigned int );typedef u8 ia64_mv_irq_to_vector (unsigned int );typedef unsigned int ia64_mv_local_vector_to_irq (u8 ); +typedef int ia64_mv_pci_get_legacy_mem_t (struct pci_dev *,unsigned long *); +typedef int ia64_mv_pci_legacy_read_t (struct pci_dev *,u16 port,u32 *val, +u8 size); +typedef int ia64_mv_pci_legacy_write_t (struct pci_dev *,u16 port,u32 val, +u8 size);/* DMA-mapping interface: */ typedef void ia64_mv_dma_init (void );
@@ -125,6 +131,9 @@ extern void machvec_tlb_migrate_finish (# define platform_irq_desc ia64_mv.irq_desc# define platform_irq_to_vector ia64_mv.irq_to_vector# define platform_local_vector_to_irq ia64_mv.local_vector_to_irq +# define platform_pci_get_legacy_mem ia64_mv.pci_get_legacy_mem +# define platform_pci_legacy_read ia64_mv.pci_legacy_read +# define platform_pci_legacy_write ia64_mv.pci_legacy_write# define platform_inb ia64_mv.inb# define platform_inw ia64_mv.inw# define platform_inl ia64_mv.inl
@@ -172,6 +181,9 @@ struct ia64_machine_vector {ia64_mv_irq_desc *irq_desc;ia64_mv_irq_to_vector *irq_to_vector;ia64_mv_local_vector_to_irq *local_vector_to_irq; +ia64_mv_pci_get_legacy_mem_t *pci_get_legacy_mem; +ia64_mv_pci_legacy_read_t *pci_legacy_read; +ia64_mv_pci_legacy_write_t *pci_legacy_write;ia64_mv_inb_t *inb;ia64_mv_inw_t *inw;ia64_mv_inl_t *inl;
@@ -215,6 +227,9 @@ struct ia64_machine_vector { platform_irq_desc, \ platform_irq_to_vector, \ platform_local_vector_to_irq, \ + platform_pci_get_legacy_mem, \ + platform_pci_legacy_read, \ + platform_pci_legacy_write, \ platform_inb, \ platform_inw, \ platform_inl, \
@@ -330,6 +345,15 @@ extern ia64_mv_dma_supported swiotlb_dm#ifndef platform_local_vector_to_irq# define platform_local_vector_to_irq __ia64_local_vector_to_irq#endif +#ifndef platform_pci_get_legacy_mem +# define platform_pci_get_legacy_mem ia64_pci_get_legacy_mem +#endif +#ifndef platform_pci_legacy_read +# define platform_pci_legacy_read ia64_pci_legacy_read +#endif +#ifndef platform_pci_legacy_write +# define platform_pci_legacy_write ia64_pci_legacy_write +#endif #ifndef platform_inb# define platform_inb __ia64_inb#endif
include/asm-ia64/machvec_init.h +3 -0
@@ -5,6 +5,9 @@ extern ia64_mv_global_tlb_purge_t ia64_gextern ia64_mv_irq_desc __ia64_irq_desc;extern ia64_mv_irq_to_vector __ia64_irq_to_vector;extern ia64_mv_local_vector_to_irq __ia64_local_vector_to_irq; +extern ia64_mv_pci_get_legacy_mem_t ia64_pci_get_legacy_mem; +extern ia64_mv_pci_legacy_read_t ia64_pci_legacy_read; +extern ia64_mv_pci_legacy_write_t ia64_pci_legacy_write;extern ia64_mv_inb_t __ia64_inb;extern ia64_mv_inw_t __ia64_inw;
include/asm-ia64/machvec_sn2.h +6 -0
@@ -43,6 +43,9 @@ extern ia64_mv_tlb_migrate_finish_t sn_textern ia64_mv_irq_desc sn_irq_desc;extern ia64_mv_irq_to_vector sn_irq_to_vector;extern ia64_mv_local_vector_to_irq sn_local_vector_to_irq; +extern ia64_mv_pci_get_legacy_mem_t sn_pci_get_legacy_mem; +extern ia64_mv_pci_legacy_read_t sn_pci_legacy_read; +extern ia64_mv_pci_legacy_write_t sn_pci_legacy_write;extern ia64_mv_inb_t __sn_inb;extern ia64_mv_inw_t __sn_inw;extern ia64_mv_inl_t __sn_inl;
@@ -105,6 +108,9 @@ extern ia64_mv_dma_supported sn_dma_sup#define platform_irq_desc sn_irq_desc#define platform_irq_to_vector sn_irq_to_vector#define platform_local_vector_to_irq sn_local_vector_to_irq +#define platform_pci_get_legacy_mem sn_pci_get_legacy_mem +#define platform_pci_legacy_read sn_pci_legacy_read +#define platform_pci_legacy_write sn_pci_legacy_write#define platform_dma_init machvec_noop#define platform_dma_alloc_coherent sn_dma_alloc_coherent#define platform_dma_free_coherent sn_dma_free_coherent
include/asm-ia64/pci.h +4 -0
@@ -85,6 +85,10 @@ extern int pcibios_prep_mwi (struct pci_#define HAVE_PCI_MMAP extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine); +#define HAVE_PCI_LEGACY +#define pci_get_legacy_mem platform_pci_get_legacy_mem +#define pci_legacy_read platform_pci_legacy_read +#define pci_legacy_write platform_pci_legacy_writestruct pci_window {struct resource resource;
include/asm-ia64/sn/sn_sal.h +47 -0
53 lines not on this page · raw message
include/linux/pci.h +11 -1
@@ -455,6 +455,9 @@#define PCIIOC_MMAP_IS_IO (PCIIOC_BASE | 0x01)/* Set mmap state to I/O space. */ #define PCIIOC_MMAP_IS_MEM (PCIIOC_BASE | 0x02)/* Set mmap state to MEM space. */ #define PCIIOC_WRITE_COMBINE (PCIIOC_BASE | 0x03)/* Enable/disable write-combining. */ +#define PCIIOC_RW_LEGACY_IO (PCIIOC_BASE | 0x04)/* Read/write access functions go to legacy space */ +#define PCIIOC_RW_CONFIG (PCIIOC_BASE | 0x05)/* Read/write access functions go to config space */ +#define PCIIOC_MMAP_IS_LEGACY_MEM (PCIIOC_BASE | 0x6)/* Legacy memory */ #ifdef __KERNEL__
@@ -468,7 +471,14 @@/* File state for mmap()s on /proc/bus/pci/X/Y */ enum pci_mmap_state { pci_mmap_io, - pci_mmap_mem + pci_mmap_mem, + pci_mmap_legacy_mem +}; + +/* Mode state for read/write routines on /proc/bus/pci/X/Y */ +enum pci_rw_state { + pci_rw_config,/* r/w config space */ + pci_rw_legacy_io/* r/w legacy I/O port space */ };/* This defines the direction arg to the DMA mapping routines. */
Quoted 9 lines · Jesse Barnes
This patch documents the
/proc/bus/pciinterface and adds some optional architecture specific APIs for accessing legacy I/O port and memory space. This is necessary on platforms where legacy I/O port space doesn't 'soft fail' like it does on PCs, and is useful for systems that can route legacy space to different PCI busses.I've incorporated all the feedback I've received so far, so I think it's ready to send on to Andrew for inclusion, if someone could give the proc-pci.txt documentation a last read (and/or comment on other stuff I may have missed).
meta-comment:
Would you (and not just you :) include a diffstat summary so we can see which files are being changed? something like this:
Documentation/filesystems/proc-pci.txt | 126 +++++++++++++++++++++++++++++++++ arch/ia64/pci/pci.c | 105 +++++++++++++++++++++++++++ arch/ia64/sn/pci/pci_dma.c | 74 +++++++++++++++++++ drivers/pci/proc.c | 100 +++++++++++++++++++++++--- include/asm-ia64/machvec.h | 24 ++++++ include/asm-ia64/machvec_init.h | 3 include/asm-ia64/machvec_sn2.h | 6 + include/asm-ia64/pci.h | 4 + include/asm-ia64/sn/sn_sal.h | 47 ++++++++++++ include/linux/pci.h | 12 ++- 10 files changed, 488 insertions(+), 13 deletions(-)
Signature · 1 line
~Randy
Quoted 5 lines · Randy.Dunlap
meta-comment:
Would you (and not just you :) include a diffstat summary so we can see which files are being changed? something like this:
Quoted 13 lines
Documentation/filesystems/proc-pci.txt | 126 +++++++++++++++++++++++++++++++++ arch/ia64/pci/pci.c | 105 +++++++++++++++++++++++++++ arch/ia64/sn/pci/pci_dma.c | 74 +++++++++++++++++++ drivers/pci/proc.c | 100 +++++++++++++++++++++++--- include/asm-ia64/machvec.h | 24 ++++++ include/asm-ia64/machvec_init.h | 3 include/asm-ia64/machvec_sn2.h | 6 + include/asm-ia64/pci.h | 4 + include/asm-ia64/sn/sn_sal.h | 47 ++++++++++++ include/linux/pci.h | 12 ++- 10 files changed, 488 insertions(+), 13 deletions(-)
Sure, I keep forgetting to do that for the larger patches. Thanks for reminding me.
Jesse
Quoted 16 lines · Randy.Dunlap
Quoted 9 lines · Jesse Barnes
This patch documents the
/proc/bus/pciinterface and adds some optional architecture specific APIs for accessing legacy I/O port and memory space. This is necessary on platforms where legacy I/O port space doesn't 'soft fail' like it does on PCs, and is useful for systems that can route legacy space to different PCI busses.I've incorporated all the feedback I've received so far, so I think it's ready to send on to Andrew for inclusion, if someone could give the proc-pci.txt documentation a last read (and/or comment on other stuff I may have missed).
meta-comment:
Would you (and not just you :) include a diffstat summary so we can see which files are being changed? something like this:
Quoted 22 lines
Documentation/filesystems/proc-pci.txt | 126 +++++++++++++++++++++++++++++++++ arch/ia64/pci/pci.c | 105 +++++++++++++++++++++++++++ arch/ia64/sn/pci/pci_dma.c | 74 +++++++++++++++++++ drivers/pci/proc.c | 100 +++++++++++++++++++++++--- include/asm-ia64/machvec.h | 24 ++++++ include/asm-ia64/machvec_init.h | 3 include/asm-ia64/machvec_sn2.h | 6 + include/asm-ia64/pci.h | 4 + include/asm-ia64/sn/sn_sal.h | 47 ++++++++++++ include/linux/pci.h | 12 ++- 10 files changed, 488 insertions(+), 13 deletions(-)Signature · 6 lines
~Randy - To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected] More majordomo info at http://vger.kernel.org/majordomo-info.html Please read the FAQ at http://www.tux.org/lkml/
Here is a little perl diddy that accomplishes same:
#!/usr/bin/env perl
# ds # Created Fri Oct 22 2004 by [email protected] # $Id: ds,v 1.11 2004/11/05 23:24:06 dwm Exp $
require 5.6.1;
use Getopt::Long 2.33;
use Pod::Usage;
use Data::Dumper;
use Config;
### variables and subroutines ##
$opt_debug = 0;
$opt_help = 0;
$opt_man = 0;
$stat_flags = "";
$diff_flags = "-Nwupa";
@dirs = ();
@tops = ();
sub infer_orig ( $ ) {
my $suf = "$_[0]\$";
my $x = $ENV{PWD};
my $basedir;
($basedir = $x) =~ s,.*/,,;
if ($basedir =~ m{$suf}) {
($tops[0] = $basedir) =~ s{$suf}{};
$tops[1] = $basedir;
return 1;
}
return 0;
}
############# main ####################
GetOptions (
'debug' => \$opt_debug,
'diffflags=s' => \$diff_flags,
'dirs=s' => \@dirs,
'help|?' => \$opt_help,
'man' => \$opt_man,
'statflags=s' => \$stat_flags,
'tops=s' => \@tops,
'verbose+' => \$verbose,
)
or pod2usage(2);pod2usage (1) if $opt_help;
pod2usage (-verbose => 2) if $opt_man;
( $prog = $0 ) =~ s{.*/}{}o;
## If no arguments were given, then allow STDIN to be used only ## if it's not connected to a terminal (otherwise print usage) pod2usage ("$prog: No files given.") if ((@ARGV == 0) && (-t STDIN));
# setbuf on STDERR. $ofh = select (STDERR); $| = 1; select ($ofh);
@diffout = ();
$kill_errs = ($verbose) ? "" : "2>/dev/null";
#
# if tops is not set, infer the older directory. Long Term - find out if cvs file.
#
if (not scalar @tops) {
my @os = ( "\.edit" ); while ($od = shift @os) {
last if (infer_orig $od);
}
}if (not scalar @tops) {
pod2usage ("$prog: could not infer, need to define tops.");
}if (not -d $tops[0]) {
if (-d "../$tops[0]") {
chdir '..';
print STDERR qx{pwd} if $verbose;
}
else {
die "could not find $tops[0]\n";
}
}while ($path = shift @ARGV) {
my $recurse = (-d "$tops[0]/$path") ? 'r' : '';
$cmd = "diff $diff_flags${recurse} $tops[0]/$path $tops[1]/$path $kill_errs";
print "tops={@tops}\n$cmd\n" if $opt_debug;
open DIFFIN, "$cmd |" or die "open {$cmd}\n";
while (<DIFFIN>) {
next if (m{^Common});
push @diffout, $_;
}
}open DSI, "|diffstat $stat_flags" or die "open stat pipe\n"; print DSI @diffout;
print while (<DSI>);
close DSI;
print "\n", @diffout;
__END__
=head1 NAME
B<ds> - diffstat + diff from one command
=head1 SYNOPSIS
B<ds> [options] ...
=head1 OPTIONS
=over 4
=item B<--debug>
run without action, printing debug messages.
=item B<--diffflags>
flags to pass to diff. default -Nwupa.
=item B<--help>
print the synopsis only. see B<--man>.
=item B<--man>
print the complete manpage.
=item B<--statflags>
flags to pass to diffstat. default is {$stat_flags}.
=item B<--tops>
Top level directories to diff with the appended paths. If not specified, infer from current directory if possible.
=item B<--verbose>
whistle while we work. multiple calls increase the verbosity level.
=back
=head1 DESCRIPTION
Runs diff over the list of files, collecting the output. When complete, outputs the stats followed by the diffs to stdout.
=head1 EXAMPLES
examples
=head1 NOTE
note
=head1 BUGS
Undoubtedly. Contact the author with the particulars if this is stopping your progress.
=head1 FILES
B<ds> - perl script
=head1 AUTHOR
Doug Maxey <[email protected]>
=cut
Quoted 5 lines · Jesse Barnes
This patch documents the
/proc/bus/pciinterface and adds some optional architecture specific APIs for accessing legacy I/O port and memory space. This is necessary on platforms where legacy I/O port space doesn't 'soft fail' like it does on PCs, and is useful for systems that can route legacy space to different PCI busses.
Please don't add more interfaces to procfs. And ioctl() on procfs is even more evil.
Quoted 9 lines · Christoph Hellwig
Quoted 5 lines · Jesse Barnes
This patch documents the
/proc/bus/pciinterface and adds some optional architecture specific APIs for accessing legacy I/O port and memory space. This is necessary on platforms where legacy I/O port space doesn't 'soft fail' like it does on PCs, and is useful for systems that can route legacy space to different PCI busses.Please don't add more interfaces to procfs. And
ioctl()on procfs is even more evil.
Oh come on, there's already an API there, and now it's documented even! The additions are straightforward and there's no where else to put them... /sys doesn't seem like a good place either, would you prefer a device driver?
I really don't see what the problem is though. /proc/bus/pci is a commonly used API and I don't see it going away. These extensions just make it a little more usable on platforms like sn2 and ppc.
Jesse
Quoted 5 lines · Jesse Barnes
This patch documents the
/proc/bus/pciinterface and adds some optional architecture specific APIs for accessing legacy I/O port and memory space. This is necessary on platforms where legacy I/O port space doesn't 'soft fail' like it does on PCs, and is useful for systems that can route legacy space to different PCI busses.
But we didn't resolve anything with respect to multiple PCI domains, did we? As far as I can see, /proc/bus/pci currently doesn't support multiple domains at all. I don't like the idea of adding new stuff that we already know is insufficient for machines in the very near future. True, it's just extending an existing interface, but it seems like if we're going to the trouble of changing X, we might as well address multiple domains at the same time.
Quoted 7 lines · Bjorn Helgaas
Quoted 5 lines · Jesse Barnes
This patch documents the
/proc/bus/pciinterface and adds some optional architecture specific APIs for accessing legacy I/O port and memory space. This is necessary on platforms where legacy I/O port space doesn't 'soft fail' like it does on PCs, and is useful for systems that can route legacy space to different PCI busses.
Quoted 7 lines
But we didn't resolve anything with respect to multiple PCI domains, did we? As far as I can see,
/proc/bus/pcicurrently doesn't support multiple domains at all. I don't like the idea of adding new stuff that we already know is insufficient for machines in the very near future. True, it's just extending an existing interface, but it seems like if we're going to the trouble of changing X, we might as well address multiple domains at the same time.
The problem with adding domain support is that it'll break existing users, unless it's added on the side somehow. One thought I had was to document that /proc/bus/pci/ contains only busses from domain 0. Machines with more than 1 domain could create /proc/bus/pci/domain/DDDD directories with busses in the DDDD domain underneath. That wouldn't break existing applications, and would let you get at domains other than 0 if you needed to.
Jesse
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jesse Barnes
Jesse> +int ia64_pci_legacy_read(struct pci_dev *dev, u16 port, u32 *val, u8 size)
Jesse> +{
Jesse> + int ret = 0;
Jesse> :
Jesse> + case 1:
Jesse> + addr = (unsigned long *)paddr;
Jesse> + *val = (u8)(*(volatile u8 *)(addr));
Jesse> + break;
Jesse> + case 2:
Jesse> + addr = (unsigned long *)paddr;
Jesse> + *val = (u16)(*(volatile u16 *)(addr));
Jesse> + break;
Jesse> :
Jesse> +}
Jesse> +int ia64_pci_legacy_write(struct pci_dev *dev, u16 port, u32 val, u8 size)
Jesse> +{
Jesse> + switch (size) {
Jesse> + case 1:
Jesse> + addr = (unsigned long *)paddr;
Jesse> + *(volatile u8 *)(addr) = (u8)(val);
Jesse> + break;
Jesse> + case 2:
Jesse> + addr = (unsigned long *)paddr;
Jesse> + *(volatile u16 *)(addr) = (u16)(val);
Jesse> + break;
Jesse> :
Jesse> + }No offense, but what's up with this castamania?
--david
Quoted 29 lines · David Mosberger
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On Thu, 16 Dec 2004 08:50:19 -0800, Jesse Barnes
<[email protected]> said:Jesse> +int ia64_pci_legacy_read(struct
pci_dev*dev, u16 port, u32 *val,
u8 size) Jesse> +{
Jesse> + int ret = 0;
Jesse> :
Jesse> + case 1:Jesse> + addr = (unsigned long *)paddr; Jesse> + *val = (u8)(*(volatile u8 *)(addr)); Jesse> + break; Jesse> + case 2: Jesse> + addr = (unsigned long *)paddr; Jesse> + *val = (u16)(*(volatile u16 *)(addr)); Jesse> + break;Jesse> :
Jesse> +}Jesse> +int ia64_pci_legacy_write(struct
pci_dev*dev, u16 port, u32 val,
u8 size) Jesse> +{
Jesse> + switch (size) {
Jesse> + case 1:Jesse> + addr = (unsigned long *)paddr; Jesse> + *(volatile u8 *)(addr) = (u8)(val); Jesse> + break; Jesse> + case 2: Jesse> + addr = (unsigned long *)paddr; Jesse> + *(volatile u16 *)(addr) = (u16)(val); Jesse> + break;
Quoted 4 lines
Jesse> :
Jesse> + }No offense, but what's up with this castamania?
Leftovers from other code. I don't actually use this stuff on sn2, someone with a DIG test box will have to verify it (willy pointed out that I should probably just be using the appropriate inX our outX routine here instead, which makes sense).
Jesse
Quoted 1 line · Jesse Barnes
Quoted 1 line
No offense, but what's up with this castamania?
Maybe this is a little better? I talked with Bjorn and willy on irc about this and there are some other approaches we could take. I still think domain support is a separate issue from the additions in this patch, but there are definitely other ways to export this stuff to userspace. One would be adding sys_ioport system call to ia64 that would allow reads and writes to arbitrary I/O ports (not just legacy ones) coupled with exporting the legacy memory base address in /proc/iomem somewhere and letting users map it in /dev/mem. Doing things that way wouldn't help platforms like ppc though, and the API would be a bit more confusing (more places to poke to find the info you need).
Jesse
===== arch/ia64/pci/pci.c 1.59 vs edited =====
arch/ia64/pci/pci.c +94 -1
@@ -514,11 +514,19 @@*/ return -EINVAL ; +if (mmap_state == pci_mmap_legacy_mem) { +unsigned long addr; +int ret; +if ((ret =pci_get_legacy_mem (dev, &addr))) +return ret; + vma->vm_pgoff += addr >>PAGE_SHIFT ; + } +/* * Leave vm_pgoff as-is, the PCI space address is the physical * address on this platform. */ - vma->vm_flags |= (VM_SHM |VM_LOCKED |VM_IO ); + vma->vm_flags |= (VM_SHM |VM_RESERVED |VM_IO );if (write_combine) vma->vm_page_prot =pgprot_writecombine (vma->vm_page_prot);
@@ -530,6 +538,91 @@return -EAGAIN ;return 0 ; +} + +/** +* ia64_pci_get_legacy_mem - generic legacy mem routine +* @dev: device pointer +* @addr: caller allocated variable for the base address +* +* Find the base of legacy memory for @dev. This is typically the first +* megabyte of bus address space for @dev or is simply 0 on platforms whose +* chipsets support legacy I/O and memory routing. Returns 0 on success +* or a standard error code on failure. +* +* This is the ia64 generic version of this routine. Other platforms +* are free to override it with a machine vector. +*/ +int ia64_pci_get_legacy_mem (struct pci_dev *dev,unsigned long *addr) +{ + *addr =0 ; +return 0 ; +} + +/** +* ia64_pci_legacy_read - read from legacy I/O space +* @dev: device to read +* @port: legacy port value +* @val: caller allocated storage for returned value +* @size: number of bytes to read +* +* Simply reads @size bytes from @port and puts the result in @val. +* +* Again, this (and the write routine) are generic versions that can be +* overridden by the platform. This is necessary on platforms that don't +* support legacy I/O routing or that hard fail on legacy I/O timeouts. +*/ +int ia64_pci_legacy_read (struct pci_dev *dev,u16 port,u32 *val,u8 size) +{ +int ret =0 ; + +switch (size) { +case 1 : + *val =inb (port); +break ; +case 2 : + *val =inw (port); +break ; +case 4 : + *val =inl (port); +break ; +default : + ret = -EINVAL ; +break ; + } + +return ret; +} + +/** +* ia64_pci_legacy_write - perform a legacy I/O write +* @dev: device pointer +* @port: port to write +* @val: value to write +* @size: number of bytes to write from @val +* +* Simply writes @size bytes of @val to @port. +*/ +int ia64_pci_legacy_write (struct pci_dev *dev,u16 port,u32 val,u8 size) +{ +int ret =0 ; + +switch (size) { +case 1 : +outb ((unsigned char )val, port); +break ; +case 2 : +outw ((unsigned short )val, port); +break ; +case 4 : +outl ((unsigned int )val, port); +break ; +default : + ret = -EINVAL ; +break ; + } + +return ret; }/**
===== arch/ia64/sn/pci/pci_dma.c 1.2 vs edited =====
arch/ia64/sn/pci/pci_dma.c +74 -0
77 lines not on this page · raw message
===== drivers/pci/proc.c 1.41 vs edited =====
drivers/pci/proc.c +89 -11
149 lines not on this page · raw message
===== include/asm-ia64/machvec.h 1.29 vs edited =====
include/asm-ia64/machvec.h +24 -0
@@ -20,6 +20,7 @@struct irq_desc ;struct page ;struct mm_struct ; +struct pci_dev ;typedef void ia64_mv_setup_t (char **);typedef void ia64_mv_cpu_init_t (void );
@@ -31,6 +32,11 @@typedef struct irq_desc *ia64_mv_irq_desc (unsigned int );typedef u8 ia64_mv_irq_to_vector (unsigned int );typedef unsigned int ia64_mv_local_vector_to_irq (u8 ); +typedef int ia64_mv_pci_get_legacy_mem_t (struct pci_dev *,unsigned long *); +typedef int ia64_mv_pci_legacy_read_t (struct pci_dev *,u16 port,u32 *val, +u8 size); +typedef int ia64_mv_pci_legacy_write_t (struct pci_dev *,u16 port,u32 val, +u8 size);/* DMA-mapping interface: */ typedef void ia64_mv_dma_init (void );
@@ -125,6 +131,9 @@# define platform_irq_desc ia64_mv.irq_desc# define platform_irq_to_vector ia64_mv.irq_to_vector# define platform_local_vector_to_irq ia64_mv.local_vector_to_irq +# define platform_pci_get_legacy_mem ia64_mv.pci_get_legacy_mem +# define platform_pci_legacy_read ia64_mv.pci_legacy_read +# define platform_pci_legacy_write ia64_mv.pci_legacy_write# define platform_inb ia64_mv.inb# define platform_inw ia64_mv.inw# define platform_inl ia64_mv.inl
@@ -172,6 +181,9 @@ia64_mv_irq_desc *irq_desc;ia64_mv_irq_to_vector *irq_to_vector;ia64_mv_local_vector_to_irq *local_vector_to_irq; +ia64_mv_pci_get_legacy_mem_t *pci_get_legacy_mem; +ia64_mv_pci_legacy_read_t *pci_legacy_read; +ia64_mv_pci_legacy_write_t *pci_legacy_write;ia64_mv_inb_t *inb;ia64_mv_inw_t *inw;ia64_mv_inl_t *inl;
@@ -215,6 +227,9 @@ platform_irq_desc, \ platform_irq_to_vector, \ platform_local_vector_to_irq, \ + platform_pci_get_legacy_mem, \ + platform_pci_legacy_read, \ + platform_pci_legacy_write, \ platform_inb, \ platform_inw, \ platform_inl, \
@@ -329,6 +344,15 @@#endif #ifndef platform_local_vector_to_irq# define platform_local_vector_to_irq __ia64_local_vector_to_irq +#endif +#ifndef platform_pci_get_legacy_mem +# define platform_pci_get_legacy_mem ia64_pci_get_legacy_mem +#endif +#ifndef platform_pci_legacy_read +# define platform_pci_legacy_read ia64_pci_legacy_read +#endif +#ifndef platform_pci_legacy_write +# define platform_pci_legacy_write ia64_pci_legacy_write#endif #ifndef platform_inb# define platform_inb __ia64_inb
===== include/asm-ia64/machvec_init.h 1.8 vs edited =====
include/asm-ia64/machvec_init.h +3 -0
@@ -5,6 +5,9 @@extern ia64_mv_irq_desc __ia64_irq_desc;extern ia64_mv_irq_to_vector __ia64_irq_to_vector;extern ia64_mv_local_vector_to_irq __ia64_local_vector_to_irq; +extern ia64_mv_pci_get_legacy_mem_t ia64_pci_get_legacy_mem; +extern ia64_mv_pci_legacy_read_t ia64_pci_legacy_read; +extern ia64_mv_pci_legacy_write_t ia64_pci_legacy_write;extern ia64_mv_inb_t __ia64_inb;extern ia64_mv_inw_t __ia64_inw;
===== include/asm-ia64/machvec_sn2.h 1.16 vs edited =====
include/asm-ia64/machvec_sn2.h +6 -0
@@ -43,6 +43,9 @@extern ia64_mv_irq_desc sn_irq_desc;extern ia64_mv_irq_to_vector sn_irq_to_vector;extern ia64_mv_local_vector_to_irq sn_local_vector_to_irq; +extern ia64_mv_pci_get_legacy_mem_t sn_pci_get_legacy_mem; +extern ia64_mv_pci_legacy_read_t sn_pci_legacy_read; +extern ia64_mv_pci_legacy_write_t sn_pci_legacy_write;extern ia64_mv_inb_t __sn_inb;extern ia64_mv_inw_t __sn_inw;extern ia64_mv_inl_t __sn_inl;
@@ -105,6 +108,9 @@#define platform_irq_desc sn_irq_desc#define platform_irq_to_vector sn_irq_to_vector#define platform_local_vector_to_irq sn_local_vector_to_irq +#define platform_pci_get_legacy_mem sn_pci_get_legacy_mem +#define platform_pci_legacy_read sn_pci_legacy_read +#define platform_pci_legacy_write sn_pci_legacy_write#define platform_dma_init machvec_noop#define platform_dma_alloc_coherent sn_dma_alloc_coherent#define platform_dma_free_coherent sn_dma_free_coherent
===== include/asm-ia64/pci.h 1.27 vs edited =====
include/asm-ia64/pci.h +4 -0
@@ -85,6 +85,10 @@#define HAVE_PCI_MMAP extern int pci_mmap_page_range (struct pci_dev *dev,struct vm_area_struct *vma,enum pci_mmap_state mmap_state,int write_combine); +#define HAVE_PCI_LEGACY +#define pci_get_legacy_mem platform_pci_get_legacy_mem +#define pci_legacy_read platform_pci_legacy_read +#define pci_legacy_write platform_pci_legacy_writestruct pci_window {struct resource resource;
===== include/asm-ia64/sn/sn_sal.h 1.17 vs edited =====
include/asm-ia64/sn/sn_sal.h +47 -0
53 lines not on this page · raw message
===== include/linux/pci.h 1.142 vs edited =====
include/linux/pci.h +11 -1
@@ -455,6 +455,9 @@#define PCIIOC_MMAP_IS_IO (PCIIOC_BASE | 0x01)/* Set mmap state to I/O space. */ #define PCIIOC_MMAP_IS_MEM (PCIIOC_BASE | 0x02)/* Set mmap state to MEM space. */ #define PCIIOC_WRITE_COMBINE (PCIIOC_BASE | 0x03)/* Enable/disable write-combining. */ +#define PCIIOC_RW_LEGACY_IO (PCIIOC_BASE | 0x04)/* Read/write access functions go to legacy space */ +#define PCIIOC_RW_CONFIG (PCIIOC_BASE | 0x05)/* Read/write access functions go to config space */ +#define PCIIOC_MMAP_IS_LEGACY_MEM (PCIIOC_BASE | 0x6)/* Legacy memory */ #ifdef __KERNEL__
@@ -468,7 +471,14 @@/* File state for mmap()s on /proc/bus/pci/X/Y */ enum pci_mmap_state { pci_mmap_io, - pci_mmap_mem + pci_mmap_mem, + pci_mmap_legacy_mem +}; + +/* Mode state for read/write routines on /proc/bus/pci/X/Y */ +enum pci_rw_state { + pci_rw_config,/* r/w config space */ + pci_rw_legacy_io/* r/w legacy I/O port space */ };/* This defines the direction arg to the DMA mapping routines. */
filesystems/proc-pci.txt new file +127 -0
127 lines not on this page · raw message
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line
Quoted 1 line · Jesse Barnes
Jesse> On Thursday, December 16, 2004 10:56 am, Jesse Barnes wrote:
Jesse> Maybe this is a little better?
The ia64_pci_legacy_{read,write}() functions definitely look much better, except I don't think you need any casts in the outX() calls.
--david
Quoted 9 lines · David Mosberger
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
On Thu, 16 Dec 2004 11:07:56 -0800, Jesse Barnes
<[email protected]> said:Jesse> On Thursday, December 16, 2004 10:56 am, Jesse Barnes wrote:
Jesse> Maybe this is a little better?
The ia64_pci_legacy_{read,write}() functions definitely look much better, except I don't think you need any casts in the
outX()calls.
You're right, I've removed them.
Thanks,
Jesse