summaryrefslogtreecommitdiffstats
path: root/drivers/staging/greybus/core.c
AgeCommit message (Expand)Author
2017-01-07staging: greybus: remove timesync protocol supportGreg Kroah-Hartman
2016-07-21greybus: pm: add error handling to bundle activationBartosz Golaszewski
2016-07-20greybus: timesync: probe shouldn't complete until FrameTime sync doesBryan O'Donoghue
2016-07-16greybus: hd: arche-platform: implement greybus shutdownDavid Lin
2016-07-14greybus: bundle: add runtime pm supportDavid Lin
2016-07-14greybus: bundle: add activate and deactivateDavid Lin
2016-06-09greybus: hd: Export host device tracepoint from hd.cViresh Kumar
2016-06-09greybus: core: Make greybus_match_one_id() return boolViresh Kumar
2016-06-09greybus: bootrom: Compile as a separate moduleViresh Kumar
2016-06-09greybus: fix forced disable of offloaded connectionsJohan Hovold
2016-06-06greybus: timesync: Bind TimeSync into GreybusBryan O'Donoghue
2016-05-27greybus: core: avoid I/O to disconnected interfacesJohan Hovold
2016-05-26greybus: tracing: fix hd tracesAlex Elder
2016-05-20greybus: legacy: remove legacy driver supportDavid Lin
2016-05-13greybus: core: Rename greybus_module_match()Viresh Kumar
2016-05-04greybus: core: add MODULE uevent var for all control devicesSandeep Patil
2016-04-25greybus: core: add module abstractionJohan Hovold
2016-04-21greybus: core: make the control object be a deviceJohan Hovold
2016-04-04greybus: firmware: Rename to bootrom protocolViresh Kumar
2016-02-26greybus: expose full 32 bits of vid/pid to userspaceGreg Kroah-Hartman
2016-02-01greybus: firmware: convert to bundle driverJohan Hovold
2016-01-21greybus: core: defer connection creation to driver probeJohan Hovold
2016-01-21greybus: add bundle class to the bundle ueventGreg Kroah-Hartman
2016-01-19greybus: core: disable bundle connections on hot-unplugJohan Hovold
2016-01-19greybus: svc: drop legacy-protocol dependencyJohan Hovold
2016-01-19greybus: control: drop legacy-protocol dependencyJohan Hovold
2016-01-19greybus: core: add defensive connection disable post disconnectJohan Hovold
2016-01-19greybus: core: disable incoming operations pre disconnectJohan Hovold
2016-01-19greybus: legacy: add legacy-protocol bundle driverJohan Hovold
2016-01-13greybus: uevent: add GREYBUS_ID to ueventGreg Kroah-Hartman
2016-01-09greybus: core: fix greybus device matchingJohan Hovold
2016-01-09greybus: core: fix greybus driver registrationJohan Hovold
2015-12-04greybus: core: add bundle id to bundle ueventsJohan Hovold
2015-12-03greybus: core: add interface id to interface and bundle ueventsJohan Hovold
2015-12-03greybus: core: add bus id to ueventsJohan Hovold
2015-11-25greybus: kill the endoJohan Hovold
2015-11-25greybus: svc: register svc device at helloJohan Hovold
2015-11-25greybus: hd: make host device a deviceJohan Hovold
2015-11-25greybus: interface: rename vendor and product attributesJohan Hovold
2015-11-21greybus: move id-matching back to coreJohan Hovold
2015-11-04greybus: create host-device compilation unitJohan Hovold
2015-11-04greybus: connection: kill gb_hd_connections_exitJohan Hovold
2015-10-21greybus: endo: move greybus_endo_setup() to endo.cViresh Kumar
2015-10-19greybus: core: remove uevent handling for gb_connectionGreg Kroah-Hartman
2015-09-23greybus: tracepoints: add tracepoints for host_device tx/rxBryan O'Donoghue
2015-09-18greybus: operation, core: hook tracepoints into message opertionsBryan O'Donoghue
2015-09-03greybus: connection: call gb_connection_exit() from gb_connection_destroy()Viresh Kumar
2015-09-03greybus: core: fix hd-creation error pathJohan Hovold
2015-09-02greybus: add num_cports field to greybus hdFabien Parent
2015-08-11greybus: Merge branch 'master' into branch 'svc'.Greg Kroah-Hartman
' href='#n408'>408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
// SPDX-License-Identifier: GPL-2.0-or-later
/*
**	DINO manager
**
**	(c) Copyright 1999 Red Hat Software
**	(c) Copyright 1999 SuSE GmbH
**	(c) Copyright 1999,2000 Hewlett-Packard Company
**	(c) Copyright 2000 Grant Grundler
**	(c) Copyright 2006-2019 Helge Deller
**
**
**	This module provides access to Dino PCI bus (config/IOport spaces)
**	and helps manage Dino IRQ lines.
**
**	Dino interrupt handling is a bit complicated.
**	Dino always writes to the broadcast EIR via irr0 for now.
**	(BIG WARNING: using broadcast EIR is a really bad thing for SMP!)
**	Only one processor interrupt is used for the 11 IRQ line 
**	inputs to dino.
**
**	The different between Built-in Dino and Card-Mode
**	dino is in chip initialization and pci device initialization.
**
**	Linux drivers can only use Card-Mode Dino if pci devices I/O port
**	BARs are configured and used by the driver. Programming MMIO address 
**	requires substantial knowledge of available Host I/O address ranges
**	is currently not supported.  Port/Config accessor functions are the
**	same. "BIOS" differences are handled within the existing routines.
*/

/*	Changes :
**	2001-06-14 : Clement Moyroud (moyroudc@esiee.fr)
**		- added support for the integrated RS232. 	
*/

/*
** TODO: create a virtual address for each Dino HPA.
**       GSC code might be able to do this since IODC data tells us
**       how many pages are used. PCI subsystem could (must?) do this
**       for PCI drivers devices which implement/use MMIO registers.
*/

#include <linux/delay.h>
#include <linux/types.h>
#include <linux/kernel.h>
#include <linux/pci.h>
#include <linux/init.h>
#include <linux/ioport.h>
#include <linux/slab.h>
#include <linux/interrupt.h>	/* for struct irqaction */
#include <linux/spinlock.h>	/* for spinlock_t and prototypes */

#include <asm/pdc.h>
#include <asm/page.h>
#include <asm/io.h>
#include <asm/hardware.h>

#include "gsc.h"
#include "iommu.h"

#undef DINO_DEBUG

#ifdef DINO_DEBUG
#define DBG(x...) printk(x)
#else
#define DBG(x...)
#endif

/*
** Config accessor functions only pass in the 8-bit bus number
** and not the 8-bit "PCI Segment" number. Each Dino will be
** assigned a PCI bus number based on "when" it's discovered.
**
** The "secondary" bus number is set to this before calling
** pci_scan_bus(). If any PPB's are present, the scan will
** discover them and update the "secondary" and "subordinate"
** fields in Dino's pci_bus structure.
**
** Changes in the configuration *will* result in a different
** bus number for each dino.
*/

#define is_card_dino(id)	((id)->hw_type == HPHW_A_DMA)
#define is_cujo(id)		((id)->hversion == 0x682)

#define DINO_IAR0		0x004
#define DINO_IODC_ADDR		0x008
#define DINO_IODC_DATA_0	0x008
#define DINO_IODC_DATA_1	0x008
#define DINO_IRR0		0x00C
#define DINO_IAR1		0x010
#define DINO_IRR1		0x014
#define DINO_IMR		0x018
#define DINO_IPR		0x01C
#define DINO_TOC_ADDR		0x020
#define DINO_ICR		0x024
#define DINO_ILR		0x028
#define DINO_IO_COMMAND		0x030
#define DINO_IO_STATUS		0x034
#define DINO_IO_CONTROL		0x038
#define DINO_IO_GSC_ERR_RESP	0x040
#define DINO_IO_ERR_INFO	0x044
#define DINO_IO_PCI_ERR_RESP	0x048
#define DINO_IO_FBB_EN		0x05c
#define DINO_IO_ADDR_EN		0x060
#define DINO_PCI_ADDR		0x064
#define DINO_CONFIG_DATA	0x068
#define DINO_IO_DATA		0x06c
#define DINO_MEM_DATA		0x070	/* Dino 3.x only */
#define DINO_GSC2X_CONFIG	0x7b4
#define DINO_GMASK		0x800
#define DINO_PAMR		0x804
#define DINO_PAPR		0x808
#define DINO_DAMODE		0x80c
#define DINO_PCICMD		0x810
#define DINO_PCISTS		0x814
#define DINO_MLTIM		0x81c
#define DINO_BRDG_FEAT		0x820
#define DINO_PCIROR		0x824
#define DINO_PCIWOR		0x828
#define DINO_TLTIM		0x830

#define DINO_IRQS 11		/* bits 0-10 are architected */
#define DINO_IRR_MASK	0x5ff	/* only 10 bits are implemented */
#define DINO_LOCAL_IRQS (DINO_IRQS+1)

#define DINO_MASK_IRQ(x)	(1<<(x))

#define PCIINTA   0x001
#define PCIINTB   0x002
#define PCIINTC   0x004
#define PCIINTD   0x008
#define PCIINTE   0x010
#define PCIINTF   0x020
#define GSCEXTINT 0x040
/* #define xxx       0x080 - bit 7 is "default" */
/* #define xxx    0x100 - bit 8 not used */
/* #define xxx    0x200 - bit 9 not used */
#define RS232INT  0x400

struct dino_device
{
	struct pci_hba_data	hba;	/* 'C' inheritance - must be first */
	spinlock_t		dinosaur_pen;
	unsigned long		txn_addr; /* EIR addr to generate interrupt */ 
	u32			txn_data; /* EIR data assign to each dino */ 
	u32 			imr;	  /* IRQ's which are enabled */ 
	int			global_irq[DINO_LOCAL_IRQS]; /* map IMR bit to global irq */
#ifdef DINO_DEBUG
	unsigned int		dino_irr0; /* save most recent IRQ line stat */
#endif
};

static inline struct dino_device *DINO_DEV(struct pci_hba_data *hba)
{
	return container_of(hba, struct dino_device, hba);
}

/* Check if PCI device is behind a Card-mode Dino. */
static int pci_dev_is_behind_card_dino(struct pci_dev *dev)
{
	struct dino_device *dino_dev;

	dino_dev = DINO_DEV(parisc_walk_tree(dev->bus->bridge));
	return is_card_dino(&dino_dev->hba.dev->id);
}

/*
 * Dino Configuration Space Accessor Functions
 */

#define DINO_CFG_TOK(bus,dfn,pos) ((u32) ((bus)<<16 | (dfn)<<8 | (pos)))

/*
 * keep the current highest bus count to assist in allocating busses.  This
 * tries to keep a global bus count total so that when we discover an 
 * entirely new bus, it can be given a unique bus number.
 */
static int dino_current_bus = 0;

static int dino_cfg_read(struct pci_bus *bus, unsigned int devfn, int where,
		int size, u32 *val)
{
	struct dino_device *d = DINO_DEV(parisc_walk_tree(bus->bridge));
	u32 local_bus = (bus->parent == NULL) ? 0 : bus->busn_res.start;
	u32 v = DINO_CFG_TOK(local_bus, devfn, where & ~3);
	void __iomem *base_addr = d->hba.base_addr;
	unsigned long flags;

	DBG("%s: %p, %d, %d, %d\n", __func__, base_addr, devfn, where,
									size);
	spin_lock_irqsave(&d->dinosaur_pen, flags);

	/* tell HW which CFG address */
	__raw_writel(v, base_addr + DINO_PCI_ADDR);

	/* generate cfg read cycle */
	if (size == 1) {
		*val = readb(base_addr + DINO_CONFIG_DATA + (where & 3));
	} else if (size == 2) {
		*val = readw(base_addr + DINO_CONFIG_DATA + (where & 2));
	} else if (size == 4) {
		*