From owner-svn-src-projects@freebsd.org Sun Nov 15 19:30:57 2015 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id A66A0A30AE5 for ; Sun, 15 Nov 2015 19:30:57 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 7748B1A70; Sun, 15 Nov 2015 19:30:57 +0000 (UTC) (envelope-from nwhitehorn@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tAFJUuNH069070; Sun, 15 Nov 2015 19:30:56 GMT (envelope-from nwhitehorn@FreeBSD.org) Received: (from nwhitehorn@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tAFJUuX2069068; Sun, 15 Nov 2015 19:30:56 GMT (envelope-from nwhitehorn@FreeBSD.org) Message-Id: <201511151930.tAFJUuX2069068@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: nwhitehorn set sender to nwhitehorn@FreeBSD.org using -f From: Nathan Whitehorn Date: Sun, 15 Nov 2015 19:30:56 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r290872 - projects/powernv/powerpc/powernv X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 15 Nov 2015 19:30:57 -0000 Author: nwhitehorn Date: Sun Nov 15 19:30:56 2015 New Revision: 290872 URL: https://svnweb.freebsd.org/changeset/base/290872 Log: Let the system read the OPAL RTC. Sponsored by: FreeBSD Foundation Modified: projects/powernv/powerpc/powernv/opal.h projects/powernv/powerpc/powernv/opal_dev.c Modified: projects/powernv/powerpc/powernv/opal.h ============================================================================== --- projects/powernv/powerpc/powernv/opal.h Sun Nov 15 18:56:58 2015 (r290871) +++ projects/powernv/powerpc/powernv/opal.h Sun Nov 15 19:30:56 2015 (r290872) @@ -40,8 +40,11 @@ int opal_call(uint64_t token, ...); #define OPAL_CONSOLE_WRITE 1 #define OPAL_CONSOLE_READ 2 +#define OPAL_RTC_READ 3 +#define OPAL_RTC_WRITE 4 #define OPAL_CEC_POWER_DOWN 5 #define OPAL_CEC_REBOOT 6 +#define OPAL_POLL_EVENTS 10 #define OPAL_PCI_CONFIG_READ_BYTE 13 #define OPAL_PCI_CONFIG_READ_HALF_WORD 14 #define OPAL_PCI_CONFIG_READ_WORD 15 @@ -51,7 +54,7 @@ int opal_call(uint64_t token, ...); #define OPAL_SET_XIVE 19 #define OPAL_GET_XIVE 20 #define OPAL_PCI_SET_PE 31 -#define OPAL_START_CPU 41 +#define OPAL_START_CPU 41 #define OPAL_PCI_MAP_PE_DMA_WINDOW_REAL 45 /* For OPAL_PCI_SET_PE */ Modified: projects/powernv/powerpc/powernv/opal_dev.c ============================================================================== --- projects/powernv/powerpc/powernv/opal_dev.c Sun Nov 15 18:56:58 2015 (r290871) +++ projects/powernv/powerpc/powernv/opal_dev.c Sun Nov 15 19:30:56 2015 (r290872) @@ -37,6 +37,10 @@ __FBSDID("$FreeBSD$"); #include #include #include +#include + +#include +#include #include #include @@ -104,9 +108,19 @@ opaldev_attach(device_t dev) { phandle_t child; device_t cdev; + uint64_t junk; + int rv; struct ofw_bus_devinfo *dinfo; - if (0 /* XXX NOT YET TEST FOR RTC */) + /* Test for RTC support and register clock if it works */ + rv = opal_call(OPAL_RTC_READ, vtophys(&junk), vtophys(&junk)); + do { + rv = opal_call(OPAL_RTC_READ, vtophys(&junk), vtophys(&junk)); + if (rv == OPAL_BUSY_EVENT) + rv = opal_call(OPAL_POLL_EVENTS, 0); + } while (rv == OPAL_BUSY_EVENT); + + if (rv == OPAL_SUCCESS) clock_register(dev, 2000); EVENTHANDLER_REGISTER(shutdown_final, opal_shutdown, NULL, @@ -134,13 +148,56 @@ opaldev_attach(device_t dev) } static int -opal_gettime(device_t dev, struct timespec *ts) { - return (ENXIO); +bcd2bin32(int bcd) +{ + int out = 0; + + out += bcd2bin(bcd & 0xff); + out += 100*bcd2bin((bcd & 0x0000ff00) >> 8); + out += 10000*bcd2bin((bcd & 0x00ff0000) >> 16); + out += 1000000*bcd2bin((bcd & 0xffff0000) >> 24); + + return (out); +} + +static int +opal_gettime(device_t dev, struct timespec *ts) +{ + int rv; + struct clocktime ct; + uint32_t ymd; + uint64_t hmsm; + + do { + rv = opal_call(OPAL_RTC_READ, vtophys(&ymd), vtophys(&hmsm)); + if (rv == OPAL_BUSY_EVENT) { + rv = opal_call(OPAL_POLL_EVENTS, 0); + pause("opalrtc", 1); + } + } while (rv == OPAL_BUSY_EVENT); + + if (rv != OPAL_SUCCESS) + return (ENXIO); + + hmsm = be64toh(hmsm); + ymd = be32toh(ymd); + + ct.nsec = bcd2bin32((hmsm & 0x000000ffffff0000) >> 16) * 1000; + ct.sec = bcd2bin((hmsm & 0x0000ff0000000000) >> 40); + ct.min = bcd2bin((hmsm & 0x00ff000000000000) >> 48); + ct.hour = bcd2bin((hmsm & 0xff00000000000000) >> 56); + + ct.day = bcd2bin((ymd & 0x000000ff) >> 0); + ct.mon = bcd2bin((ymd & 0x0000ff00) >> 8); + ct.year = bcd2bin32((ymd & 0xffff0000) >> 16); + + return (clock_ct_to_ts(&ct, ts)); } static int opal_settime(device_t dev, struct timespec *ts) { + return (0); }